/// <summary> /// Uploads three objects /// 1. Activity library /// 2. Activities associated with the activity library /// 3. Activity Library dependency list /// </summary> /// <param name="request">StoreLibraryAndActivitiesRequestDC object</param> /// <returns>StatusReplyDC object</returns> public static List<StoreActivitiesDC> UploadActivityLibraryAndDependentActivities(StoreLibraryAndActivitiesRequestDC request) { List<StoreActivitiesDC> reply = new List<StoreActivitiesDC>(); reply.Add(new StoreActivitiesDC()); StatusReplyDC status = new StatusReplyDC(); var publishingState = String.Empty; Tuple<bool, string> dependencyCheckResult; // true/false for if the dependencies pass, and a string error message if there are problems StoreActivitiesDC activityDC = new StoreActivitiesDC() { Incaller = request.Incaller, IncallerVersion = request.IncallerVersion, Locked = false, LockedBy = null, }; Version nextVersion = null; request.ActivityLibrary.Incaller = request.Incaller; request.ActivityLibrary.IncallerVersion = request.IncallerVersion; //// Check if the library is in production first. If so bail. if (IsLibraryInProduction(request.ActivityLibrary)) { status = SetUpReplyStatus(SprocValues.ACTIVITYLIBRARY_MARKED_FOR_PRODUCTION_ID, SprocValues.ACTIVITYLIBRARY_MARKED_FOR_PRODUCTION_MSG, Convert.ToString(Guid.Empty)); return SetupErrorReply(reply, status); } if (request.EnforceVersionRules) { var checkReply = ActivityBusinessService.CheckActivityExists(request.StoreActivitiesList[0]); if (checkReply.Errorcode == 0) { bool exists = false; if (bool.TryParse(checkReply.Output, out exists) && exists) { nextVersion = GetNextVersion(request.StoreActivitiesList[0], Environment.UserName); } } dependencyCheckResult = VersionHelper.CheckDependencyRules(request); if (!dependencyCheckResult.Item1) throw new VersionException(dependencyCheckResult.Item2, null); reply.Clear(); } using (var scope = new TransactionScope()) { if (string.IsNullOrEmpty(request.ActivityLibrary.StatusName)) throw new ValidationException(-1, "'Status Name' for Activity Library records cannot be null."); if (request.EnforceVersionRules) { foreach (var activity in request.StoreActivitiesList) { activityDC.Name = activity.Name; activityDC.Version = activity.OldVersion; List<StoreActivitiesDC> existingRecords = Activities.StoreActivitiesGetByName(activityDC.Name, string.Empty); if (existingRecords.Any()) { //Clear the Store Activities lock var lockReply = Activities.StoreActivitiesUpdateLock(activityDC, DateTime.Now); if (lockReply.StatusReply.Errorcode != 0) { status = SetUpReplyStatus(lockReply.StatusReply.Errorcode, lockReply.StatusReply.ErrorMessage, Convert.ToString(Guid.Empty)); return SetupErrorReply(reply, status); } } } if (nextVersion != null) { request.ActivityLibrary.VersionNumber = nextVersion.ToString(); request.StoreActivitiesList[0].Version = nextVersion.ToString(); request.StoreActivityLibraryDependenciesGroupsRequestDC.Version = nextVersion.ToString(); } } // add the entires // Create the ActivityLibrary var activityLibraryDCCreate = request.ActivityLibrary; activityLibraryDCCreate.Incaller = request.Incaller; activityLibraryDCCreate.IncallerVersion = request.IncallerVersion; ActivityLibraryDC createALreply = ActivityLibrary.ActivityLibraryCreateOrUpdate(activityLibraryDCCreate); if (createALreply.StatusReply.Errorcode != 0) { status = SetUpReplyStatus(createALreply.StatusReply.Errorcode, createALreply.StatusReply.ErrorMessage, Convert.ToString(Guid.Empty)); return SetupErrorReply(reply, status); } // Store the store activities foreach (var activity in request.StoreActivitiesList) { activity.Incaller = request.Incaller; activity.IncallerVersion = request.IncallerVersion; activity.ActivityLibraryName = request.ActivityLibrary.Name; activity.ActivityLibraryVersion = request.ActivityLibrary.VersionNumber; activity.AuthGroupName = request.ActivityLibrary.AuthGroupName; activity.Locked = true; activity.LockedBy = request.InUpdatedByUserAlias; StoreActivitiesDC createSAreply = null; createSAreply = Activities.StoreActivitiesCreateOrUpdate(activity); if (createSAreply.StatusReply.Errorcode != 0) { status = SetUpReplyStatus(createSAreply.StatusReply.Errorcode, createSAreply.StatusReply.ErrorMessage, Convert.ToString(Guid.Empty)); return SetupErrorReply(reply, status); } reply.Add(createSAreply); } if (request.TaskActivitiesList != null) //Store TaskActivityDC foreach (var ta in request.TaskActivitiesList) { ta.Incaller = request.Incaller; ta.IncallerVersion = request.IncallerVersion; if (ta.TaskActivitiesList != null && ta.TaskActivitiesList[0] != null) { if (ta.TaskActivitiesList[0].Status == TaskActivityStatus.Unassigned) { ta.TaskActivitiesList[0].Incaller = request.Incaller; ta.TaskActivitiesList[0].IncallerVersion = request.IncallerVersion; TaskActivityRepositoryService.TaskActivity_SetStatus(ta.TaskActivitiesList[0]); } else { var statusReply = ActivityRepositoryService.CheckActivityExists(ta.TaskActivitiesList[0].Activity); if (statusReply.Output != Convert.ToString(true)) //|| ta.TaskActivitiesList[0].Status == TaskActivityStatus.Assigned //|| ta.TaskActivitiesList[0].Status == TaskActivityStatus.CheckedIn) { ta.EnforceVersionRules = true; List<TaskActivityDC> taReply = SaveStoreLibraryAndTaskActivity(ta); if (taReply != null && taReply[0] != null) if (taReply[0].StatusReply.Errorcode != 0) { status = SetUpReplyStatus(taReply[0].StatusReply.Errorcode, taReply[0].StatusReply.ErrorMessage, Convert.ToString(Guid.Empty)); return SetupErrorReply(reply, status); } } } } } // Create the ActivityLibrary dependency list // store the 1st entry // create the head list try { if (request.StoreActivityLibraryDependenciesGroupsRequestDC != null) { if (request.StoreActivityLibraryDependenciesGroupsRequestDC.List != null && request.StoreActivityLibraryDependenciesGroupsRequestDC.List.Count > 0) { var headList = new ActivityLibraryDependenciesListHeadCreateOrUpdateRequestDC(); headList.Name = request.ActivityLibrary.Name; headList.Version = request.ActivityLibrary.VersionNumber; headList.Incaller = request.Incaller; headList.IncallerVersion = request.IncallerVersion; headList.InInsertedByUserAlias = request.InInsertedByUserAlias; headList.InUpdatedByUserAlias = request.InUpdatedByUserAlias; StatusReplyDC replyHeadCreate = ActivityLibraryDependency.ActivityLibraryDependenciesListHeadCreateOrUpdate(headList); if (replyHeadCreate.Errorcode != 0) return SetupErrorReply(reply, status); StatusReplyDC ActivityLibraryDependenciesCreateOrUpdateStatusReply = null; ActivityLibraryDependenciesCreateOrUpdateStatusReply = ActivityLibraryDependenciesCreateOrUpdate( request.StoreActivityLibraryDependenciesGroupsRequestDC.Name, request.StoreActivityLibraryDependenciesGroupsRequestDC.Version, request.StoreActivityLibraryDependenciesGroupsRequestDC.List, request.Incaller, request.IncallerVersion, request.InInsertedByUserAlias, request.InUpdatedByUserAlias ); if (ActivityLibraryDependenciesCreateOrUpdateStatusReply.Errorcode != 0) return SetupErrorReply(reply, ActivityLibraryDependenciesCreateOrUpdateStatusReply); } } } catch (TransactionAbortedException tex) { status = SetUpReplyStatus(SprocValues.GENERIC_CATCH_ID, "[UploadActivityLibraryAndDependentActivities]" + tex.Message, Convert.ToString(Guid.Empty)); return SetupErrorReply(reply, status); } catch (Exception ex) { status = SetUpReplyStatus(SprocValues.GENERIC_CATCH_ID, "[UploadActivityLibraryAndDependentActivities]" + ex.Message, Convert.ToString(Guid.Empty)); return SetupErrorReply(reply, status); } scope.Complete(); return reply; } }
private static StoreLibraryAndActivitiesRequestDC ConvertStoreLibraryAndTaskActivityRequestDCToStoreLibraryAndActivitiesRequestDC(StoreLibraryAndTaskActivityRequestDC request) { var saRequest = new StoreLibraryAndActivitiesRequestDC(); saRequest.ActivityLibrary = request.ActivityLibrary; saRequest.EnforceVersionRules = request.EnforceVersionRules; saRequest.Incaller = request.Incaller; saRequest.IncallerVersion = request.IncallerVersion; saRequest.InInsertedByUserAlias = request.InInsertedByUserAlias; saRequest.InUpdatedByUserAlias = request.InUpdatedByUserAlias; saRequest.StoreActivitiesList = new List<StoreActivitiesDC>(); foreach (var task in request.TaskActivitiesList) { saRequest.StoreActivitiesList.Add(task.Activity); } saRequest.StoreActivityLibraryDependenciesGroupsRequestDC = request.StoreActivityLibraryDependenciesGroupsRequestDC; return saRequest; }
/// <summary> /// Get ActivityLibrary row(s) /// </summary> /// <param name="request">request object</param> /// <returns>ActivityLibraryDC object</returns> public IList<StoreActivitiesDC> UploadActivityLibraryAndDependentActivities(StoreLibraryAndActivitiesRequestDC request) { List<StoreActivitiesDC> reply = new List<StoreActivitiesDC>(); StatusReplyDC status = null; if (request == null) { status = CWF.BAL.Services.SetUpReplyStatus(SprocValues.REQUEST_OBJECT_IS_NULL_ID, string.Format(SprocValues.REQUEST_OBJECT_IS_NULL_MSG, "request", "UploadActivityLibrarieAndDependentActivities"), ""); } if (request.ActivityLibrary == null) { status = CWF.BAL.Services.SetUpReplyStatus(SprocValues.REQUEST_OBJECT_IS_NULL_ID, string.Format(SprocValues.REQUEST_OBJECT_IS_NULL_MSG, "request.ActivityLibrary", "UploadActivityLibrarieAndDependentActivities"), ""); } if (request.StoreActivitiesList == null) { status = CWF.BAL.Services.SetUpReplyStatus(SprocValues.REQUEST_OBJECT_IS_NULL_ID, string.Format(SprocValues.REQUEST_OBJECT_IS_NULL_MSG, "request.StoreActivitiesList", "UploadActivityLibrarieAndDependentActivities"), ""); } if (status != null) { reply.Add(new StoreActivitiesDC() { StatusReply = status }); return reply; } try { reply = CWF.BAL.Services.UploadActivityLibraryAndDependentActivities(request); } catch (VersionException ex) { throw new FaultException<VersionFault>(new VersionFault { Message = ex.Message, Rule = ex.Rule, }, new FaultReason(SprocValues.VersionIncorrectFaultReasonMessage + "\r\n" + ex.Message)); } catch (BusinessException e) { e.HandleException(); } catch (Exception e) { // Handles unhandled exception. e.HandleException(); } return reply; }