public static TaskDelegationDTO ConvertToDTO(this TaskDelegation entity) { return(new TaskDelegationDTO { Id = entity.Id, PhaseId = entity.PhaseId, Publication = entity.Publication.ConvertToDTO(), Tasks = entity.Tasks?.Select(e => e.ConvertToDTO()).ToList() }); }
public static void CreateTestData(EFContext context) { var study = new Study { Id = 0, Description = "Study created for testing", Name = "TestStudy" }; var publications = new List <Publication> { new Publication { Active = true, StudyId = 1, Study = study, }, new Publication { Active = true, StudyId = 1, Study = study, }, new Publication { Active = true, StudyId = 1, Study = study, }, new Publication { Active = true, StudyId = 1, Study = study, } }; var fields = new[] { new Field { Name = "Title", Description = "The title of the publication", Type = FieldType.STRING }, new Field { Name = "Year", Description = "Publication year", Type = FieldType.INT }, new Field { Name = "Author", Description = "", Type = FieldType.STRING }, new Field { Name = "IsTheoretical", Description = "Indicates whether the the publication is a theoretical text", Type = FieldType.BOOL }, new Field { Name = "Group A", Description = "Group for classification criterion", Type = FieldType.BOOL }, new Field { Name = "Group B", Description = "Group for classification criterion", Type = FieldType.BOOL }, new Field { Name = "Group C", Description = "Group for classification criterion", Type = FieldType.BOOL } }; var data = new Data[] { // Title (pub 0) new Data { FieldId = 1, Field = fields[0], PublicationId = 1, Publication = publications[0], Value = "Stable theories" }, // Title (pub 1) new Data { FieldId = 1, Field = fields[0], PublicationId = 2, Publication = publications[1], Value = "Note on a min-max problem of Leo Moser" }, // Title (pub 2) new Data { FieldId = 1, Field = fields[0], PublicationId = 3, Publication = publications[2], Value = "Finite diagrams stable in power" }, // Title (pub 3) new Data { FieldId = 1, Field = fields[0], PublicationId = 4, Publication = publications[3], Value = "On theories T categorical in |T|" }, // Year (pub 0) new Data { FieldId = 2, Field = fields[1], PublicationId = 1, Publication = publications[0], Value = "1969" }, // Year (pub 1) new Data { FieldId = 2, Field = fields[1], PublicationId = 2, Publication = publications[1], Value = "1969" }, // Year (pub 2) new Data { FieldId = 2, Field = fields[1], PublicationId = 3, Publication = publications[2], Value = "1970" }, // Year (pub 3) new Data { FieldId = 2, Field = fields[1], PublicationId = 4, Publication = publications[3], Value = "1970" }, // Author (pub 0) new Data { FieldId = 3, Field = fields[2], PublicationId = 1, Publication = publications[0], Value = "Shelah, Saharon" }, // Author (pub 1) new Data { FieldId = 3, Field = fields[2], PublicationId = 2, Publication = publications[1], Value = "Shelah, Saharon" }, // Author (pub 2) new Data { FieldId = 3, Field = fields[2], PublicationId = 3, Publication = publications[2], Value = "Shelah, Saharon" }, // Author (pub 3) new Data { FieldId = 3, Field = fields[2], PublicationId = 4, Publication = publications[3], Value = "Shelah, Saharon" }, // IsTheoretical (pub 0) new Data { FieldId = 4, Field = fields[3], PublicationId = 1, Publication = publications[0], Value = "true" }, // IsTheoretical (pub 1) new Data { FieldId = 4, Field = fields[3], PublicationId = 2, Publication = publications[1], Value = "true" }, // IsTheoretical (pub 2) new Data { FieldId = 4, Field = fields[3], PublicationId = 3, Publication = publications[2], Value = "false" }, // IsTheoretical (pub 3) new Data { FieldId = 4, Field = fields[3], PublicationId = 4, Publication = publications[3], Value = "false" }, // Group A (pub 0) new Data { FieldId = 5, Field = fields[4], PublicationId = 1, Publication = publications[0], Value = "true" }, // Group A (pub 1) new Data { FieldId = 5, Field = fields[4], PublicationId = 2, Publication = publications[1], Value = "false" }, // Group A (pub 2) new Data { FieldId = 5, Field = fields[4], PublicationId = 3, Publication = publications[2], Value = "false" }, // Group A (pub 3) new Data { FieldId = 5, Field = fields[5], PublicationId = 4, Publication = publications[3], Value = "true" }, // Group B (pub 0) new Data { FieldId = 6, Field = fields[5], PublicationId = 1, Publication = publications[0], Value = "false" }, // Group B (pub 1) new Data { FieldId = 6, Field = fields[5], PublicationId = 2, Publication = publications[1], Value = "true" }, // Group B (pub 2) new Data { FieldId = 6, Field = fields[5], PublicationId = 3, Publication = publications[2], Value = "false" }, // Group B (pub 3) new Data { FieldId = 6, Field = fields[5], PublicationId = 4, Publication = publications[3], Value = "true" }, // Group C (pub 0) new Data { FieldId = 7, Field = fields[6], PublicationId = 1, Publication = publications[0], Value = "false" }, // Group C (pub 1) new Data { FieldId = 7, Field = fields[6], PublicationId = 2, Publication = publications[1], Value = "false" }, // Group C (pub 2) new Data { FieldId = 7, Field = fields[6], PublicationId = 3, Publication = publications[2], Value = "false" }, // Group C (pub 3) new Data { FieldId = 7, Field = fields[6], PublicationId = 4, Publication = publications[3], Value = "true" }, }; var exclusionCriteria = new ExclusionCriterion[] { new ExclusionCriterion { FieldId = 4, Field = fields[3], Condition = ExclusionCondition.BOOL, Operator = "true", StudyId = 1, Study = study } }; var users = new User[] { new User { Name = "Antoniusman", Password = "******" }, new User { Name = "Jacob", Password = "******" }, new User { Name = "Jonleif", Password = "******" }, new User { Name = "Jannik", Password = "******" }, new User { Name = "Lucas", Password = "******" }, }; var participants = new Participant[] { new Participant { UserId = 1, User = users[0], StudyId = 1, Study = study, Role = ParticipantRole.TEAM_MANAGER }, new Participant { UserId = 2, User = users[1], StudyId = 1, Study = study, Role = ParticipantRole.RESEARCHER }, new Participant { UserId = 3, User = users[2], StudyId = 1, Study = study, Role = ParticipantRole.RESEARCHER }, new Participant { UserId = 4, User = users[3], StudyId = 1, Study = study, Role = ParticipantRole.RESEARCHER }, new Participant { UserId = 5, User = users[4], StudyId = 1, Study = study, Role = ParticipantRole.RESEARCHER }, }; var phaseParticipants = new UserPhaseParticipant[] { new UserPhaseParticipant { PhaseId = 1, UserId = 1, }, new UserPhaseParticipant { PhaseId = 1, UserId = 2, }, new UserPhaseParticipant { PhaseId = 1, UserId = 3, }, new UserPhaseParticipant { PhaseId = 1, UserId = 4, }, new UserPhaseParticipant { PhaseId = 1, UserId = 5, }, }; var phase = new Phase { Automatic = true, ConflictManagerId = 1, ConflictManager = users[0], DisplayFields = new List <Field> { fields[0], fields[1], fields[2] }, InputFields = new List <Field> { fields[3] }, OverlapPercentage = 200, Purpose = "Decide which publications are theoretical", StudyId = 1, Study = study, UserParticipants = new List <UserPhaseParticipant> { phaseParticipants[0], phaseParticipants[1], phaseParticipants[2], phaseParticipants[3], phaseParticipants[4] } }; var taskDelegations = new TaskDelegation[] { new TaskDelegation { PhaseId = 1, Phase = phase, PublicationId = 1, Publication = publications[0] }, new TaskDelegation { PhaseId = 1, Phase = phase, PublicationId = 2, Publication = publications[1] }, new TaskDelegation { PhaseId = 1, Phase = phase, PublicationId = 3, Publication = publications[2] }, new TaskDelegation { PhaseId = 1, Phase = phase, PublicationId = 4, Publication = publications[3] }, }; var tasks = new ReviewTask[][] { new ReviewTask[] { new ReviewTask { TaskDelegationId = 1, TaskDelegation = taskDelegations[0], UserId = 1, User = users[0], IsSubmitted = false }, new ReviewTask { TaskDelegationId = 1, TaskDelegation = taskDelegations[0], UserId = 2, User = users[1], IsSubmitted = false }, }, new ReviewTask[] { new ReviewTask { TaskDelegationId = 2, TaskDelegation = taskDelegations[1], UserId = 1, User = users[0], IsSubmitted = false }, new ReviewTask { TaskDelegationId = 2, TaskDelegation = taskDelegations[1], UserId = 2, User = users[1], IsSubmitted = false }, }, new ReviewTask[] { new ReviewTask { TaskDelegationId = 3, TaskDelegation = taskDelegations[2], UserId = 1, User = users[0], IsSubmitted = false }, new ReviewTask { TaskDelegationId = 3, TaskDelegation = taskDelegations[2], UserId = 2, User = users[1], IsSubmitted = false }, }, new ReviewTask[] { new ReviewTask { TaskDelegationId = 4, TaskDelegation = taskDelegations[3], UserId = 1, User = users[0], IsSubmitted = false }, new ReviewTask { TaskDelegationId = 4, TaskDelegation = taskDelegations[3], UserId = 2, User = users[1], IsSubmitted = false }, } }; for (int i = 0; i < taskDelegations.Length; i++) { taskDelegations[i].Tasks = tasks[i]; } var answers = new[] { new Answer { FieldId = 4, Field = fields[3], ReviewTaskId = 1, ReviewTask = tasks[0][1], Value = "true" }, new Answer { FieldId = 4, Field = fields[3], ReviewTaskId = 1, ReviewTask = tasks[0][1], Value = "false" } }; ClassificationCriterion classificationCriterion = new ClassificationCriterion { Study = study, StudyId = 1, ParentCriterionId = 1 }; context.Study.Add(study); context.SaveChanges(); context.Publication.AddRange(publications.AsEnumerable()); context.SaveChanges(); context.Field.AddRange(fields); context.SaveChanges(); context.Data.AddRange(data); context.SaveChanges(); context.ExclusionCriterion.AddRange(exclusionCriteria); context.SaveChanges(); context.User.AddRange(users); context.SaveChanges(); context.Participant.AddRange(participants); context.SaveChanges(); context.Phase.Add(phase); context.UserPhaseParticipant.AddRange(phaseParticipants); context.SaveChanges(); context.TaskDelegation.AddRange(taskDelegations); foreach (ReviewTask[] t in tasks) { context.ReviewTask.AddRange(t); } context.SaveChanges(); context.AddRange(answers); context.SaveChanges(); context.ClassificationCriterion.Add(classificationCriterion); context.SaveChanges(); }
public void StartK2OOF() { string conStringIIF = this.AppConfig.IIFConnectionString; using (SqlConnection con = new SqlConnection(conStringIIF)) { con.Open(); string querySelect = "SELECT"; querySelect = querySelect + " [Src].[Id], [Src].[FromDate], [Src].[ToDate]"; querySelect = querySelect + " , [Src].[FromFQN], [Src].[ToFQN]"; querySelect = querySelect + " , [Src].[IsActive], [Src].[IsCanceled], [Src].[IsExpired]"; querySelect = querySelect + " , [Src].[IsStartedInK2], [Src].[IsEndedInK2]"; querySelect = querySelect + " FROM [dbo].[Vw_TaskDelegation_NeedK2Started] AS [Src]"; List <TaskDelegation> listTaskDelegation = new List <TaskDelegation>(); using (SqlCommand cmd = con.CreateCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = querySelect; using (SqlDataReader dr = cmd.ExecuteReader()) { int indexOf_Id = dr.GetOrdinal("Id"); int indexOf_FromDate = dr.GetOrdinal("FromDate"); int indexOf_ToDate = dr.GetOrdinal("ToDate"); int indexOf_FromFQN = dr.GetOrdinal("FromFQN"); int indexOf_ToFQN = dr.GetOrdinal("ToFQN"); int indexOf_IsActive = dr.GetOrdinal("IsActive"); int indexOf_IsCanceled = dr.GetOrdinal("IsCanceled"); int indexOf_IsExpired = dr.GetOrdinal("IsExpired"); int indexOf_IsStartedInK2 = dr.GetOrdinal("IsStartedInK2"); int indexOf_IsEndedInK2 = dr.GetOrdinal("IsEndedInK2"); while (dr.Read()) { TaskDelegation data = new TaskDelegation(); data.Id = dr.GetInt64(indexOf_Id); data.FromDate = dr.GetDateTime(indexOf_FromDate); data.ToDate = dr.GetDateTime(indexOf_ToDate); data.FromFQN = dr.GetString(indexOf_FromFQN); data.ToFQN = dr.GetString(indexOf_ToFQN); data.IsActive = dr.GetBoolean(indexOf_IsActive); data.IsCanceled = dr.GetBoolean(indexOf_IsCanceled); data.IsExpired = dr.GetBoolean(indexOf_IsExpired); data.IsStartedInK2 = dr.GetBoolean(indexOf_IsStartedInK2); data.IsEndedInK2 = dr.GetBoolean(indexOf_IsEndedInK2); listTaskDelegation.Add(data); } } } Exception innerEx = null; foreach (TaskDelegation taskDelegation in listTaskDelegation) { try { using (Connection k2Con = new Connection()) { k2Con.Open(this.AppConfig.K2Server); k2Con.ImpersonateUser(taskDelegation.FromFQN); WorklistCriteria worklistCriteria = new WorklistCriteria(); worklistCriteria.Platform = "ASP"; Destinations worktypeDestinations = new Destinations(); worktypeDestinations.Add(new Destination(taskDelegation.ToFQN, DestinationType.User)); WorkType workType = new WorkType("TaskDelegationWork_" + taskDelegation.Id.ToString(), worklistCriteria, worktypeDestinations); WorklistShare worklistShare = new WorklistShare(); worklistShare.ShareType = ShareType.OOF; worklistShare.StartDate = taskDelegation.FromDate; worklistShare.EndDate = taskDelegation.ToDate; worklistShare.WorkTypes.Add(workType); k2Con.ShareWorkList(worklistShare); k2Con.SetUserStatus(UserStatuses.OOF); string queryUpdate = "UPDATE [dbo].[TaskDelegation] SET"; queryUpdate = queryUpdate + " [IsActive] = 1"; queryUpdate = queryUpdate + ", [IsExpired] = 0"; queryUpdate = queryUpdate + ", [IsStartedInK2] = 1"; queryUpdate = queryUpdate + " WHERE [Id] = @Id"; using (SqlCommand cmd = con.CreateCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = queryUpdate; cmd.Parameters.Add(this.NewSqlParameter("Id", SqlDbType.BigInt, taskDelegation.Id)); cmd.ExecuteNonQuery(); } } } catch (Exception ex) { innerEx = ex; } } if (innerEx != null) { throw new Exception("An error occured. " + innerEx.Message, innerEx); } con.Close(); } }
public void EndK2OOF() { string conStringIIF = this.AppConfig.IIFConnectionString; using (SqlConnection con = new SqlConnection(conStringIIF)) { con.Open(); string querySelect = "SELECT"; querySelect = querySelect + " [Src].[Id], [Src].[FromDate], [Src].[ToDate]"; querySelect = querySelect + " , [Src].[FromFQN], [Src].[ToFQN]"; querySelect = querySelect + " , [Src].[IsActive], [Src].[IsCanceled], [Src].[IsExpired]"; querySelect = querySelect + " , [Src].[IsStartedInK2], [Src].[IsEndedInK2]"; querySelect = querySelect + " FROM [dbo].[Vw_TaskDelegation_NeedK2Ended] AS [Src]"; List <TaskDelegation> listTaskDelegation = new List <TaskDelegation>(); using (SqlCommand cmd = con.CreateCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = querySelect; using (SqlDataReader dr = cmd.ExecuteReader()) { int indexOf_Id = dr.GetOrdinal("Id"); int indexOf_FromDate = dr.GetOrdinal("FromDate"); int indexOf_ToDate = dr.GetOrdinal("ToDate"); int indexOf_FromFQN = dr.GetOrdinal("FromFQN"); int indexOf_ToFQN = dr.GetOrdinal("ToFQN"); int indexOf_IsActive = dr.GetOrdinal("IsActive"); int indexOf_IsCanceled = dr.GetOrdinal("IsCanceled"); int indexOf_IsExpired = dr.GetOrdinal("IsExpired"); int indexOf_IsStartedInK2 = dr.GetOrdinal("IsStartedInK2"); int indexOf_IsEndedInK2 = dr.GetOrdinal("IsEndedInK2"); while (dr.Read()) { TaskDelegation data = new TaskDelegation(); data.Id = dr.GetInt64(indexOf_Id); data.FromDate = dr.GetDateTime(indexOf_FromDate); data.ToDate = dr.GetDateTime(indexOf_ToDate); data.FromFQN = dr.GetString(indexOf_FromFQN); data.ToFQN = dr.GetString(indexOf_ToFQN); data.IsActive = dr.GetBoolean(indexOf_IsActive); data.IsCanceled = dr.GetBoolean(indexOf_IsCanceled); data.IsExpired = dr.GetBoolean(indexOf_IsExpired); data.IsStartedInK2 = dr.GetBoolean(indexOf_IsStartedInK2); data.IsEndedInK2 = dr.GetBoolean(indexOf_IsEndedInK2); listTaskDelegation.Add(data); } } } Exception innerEx = null; foreach (TaskDelegation taskDelegation in listTaskDelegation) { try { using (Connection k2Con = new Connection()) { k2Con.Open(this.AppConfig.K2Server); k2Con.ImpersonateUser(taskDelegation.FromFQN); WorklistShares worklistShares = k2Con.GetCurrentSharingSettings(ShareType.OOF); foreach (WorklistShare worklistShare in worklistShares) { WorkTypes workTypes = worklistShare.WorkTypes; bool needUnShare = false; foreach (WorkType workType in workTypes) { if (workType.Name == "TaskDelegationWork_" + taskDelegation.Id.ToString()) { needUnShare = true; break; } } if (needUnShare) { k2Con.UnShare(worklistShare); } } k2Con.SetUserStatus(UserStatuses.Available); string queryUpdate = "UPDATE [dbo].[TaskDelegation] SET"; queryUpdate = queryUpdate + " [IsActive] = 0"; if (!taskDelegation.IsCanceled) { queryUpdate = queryUpdate + ", [IsExpired] = 1"; } queryUpdate = queryUpdate + ", [IsEndedInK2] = 1"; queryUpdate = queryUpdate + " WHERE [Id] = @Id"; using (SqlCommand cmd = con.CreateCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = queryUpdate; cmd.Parameters.Add(this.NewSqlParameter("Id", SqlDbType.BigInt, taskDelegation.Id)); cmd.ExecuteNonQuery(); } } } catch (Exception ex) { innerEx = ex; } } string queryUpdateSkipped = "[dbo].[TaskDelegation_UpdateSkipped_SP]"; try { using (SqlCommand cmd = con.CreateCommand()) { cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = queryUpdateSkipped; cmd.ExecuteNonQuery(); } } catch (Exception ex) { innerEx = ex; } if (innerEx != null) { throw new Exception("An error occured. " + innerEx.Message, innerEx); } con.Close(); } }