public override Response PreMassOperation() { ConsoleEventHandlerComment console = new ConsoleEventHandlerComment(); kCura.EventHandler.Response retVal = new kCura.EventHandler.Response(); retVal.Success = true; retVal.Message = "Successful Pre Execute Operation method"; IDBContext dbContext = this.Helper.GetDBContext(this.Helper.GetActiveCaseID()); string sqlText = $" SELECT * FROM [Comment] WHERE ArtifactID IN (SELECT ARTIFACTID from[RESOURCE].[{ this.MassActionTableName}]) "; System.Data.DataRowCollection results = dbContext.ExecuteSqlStatementAsDataTable(sqlText).Rows; foreach (System.Data.DataRow row in results) { DTOs.RDO comme = new DTOs.RDO((int)row.ItemArray[0]); comme.ArtifactTypeGuids.Add(new Guid(ARTIFACT_TYPE)); comme.Fields.Add(new DTOs.FieldValue(new Guid(COMMENT_FIELD_GUID.ToString()), row.ItemArray[1])); console.insertJob(dbContext, this.Helper.GetAuthenticationManager().UserInfo.FullName, comme); DTOs.Choice choice = new DTOs.Choice(ERROR_TYPE_FIELD_GUID); comme.Fields.Add(new DTOs.FieldValue(TYPE_FIELD_GUID, choice)); using (kCura.Relativity.Client.IRSAPIClient client = this.Helper.GetServicesManager().CreateProxy <kCura.Relativity.Client.IRSAPIClient>(Relativity.API.ExecutionIdentity.System)) { client.APIOptions.WorkspaceID = this.Helper.GetActiveCaseID(); client.Repositories.RDO.UpdateSingle(comme); } } return(retVal); }
public override Response Execute() { Response eventRes = new Response() { Success = true, Message = String.Empty }; try { System.Data.SqlClient.SqlParameter artifactId = new System.Data.SqlClient.SqlParameter("@artifacId", System.Data.SqlDbType.Int); artifactId.Value = this.ActiveArtifact.ArtifactID; int activeWorkspaceId = this.Helper.GetActiveCaseID(); this.Helper.GetDBContext(activeWorkspaceId).ExecuteNonQuerySQLStatement(DELETE_JOBS_COMMENTS_LINKED, new System.Data.SqlClient.SqlParameter[] { artifactId }); int currentUserId = this.Helper.GetAuthenticationManager().UserInfo.ArtifactID; using (kCura.Relativity.Client.IRSAPIClient client = this.Helper.GetServicesManager().CreateProxy <kCura.Relativity.Client.IRSAPIClient>(Relativity.API.ExecutionIdentity.System)) { client.APIOptions.WorkspaceID = this.Helper.GetActiveCaseID(); kCura.Relativity.Client.DTOs.RDO comment = client.Repositories.RDO.ReadSingle(ActiveArtifact.ArtifactID); int commentUserId = comment.SystemCreatedBy.ArtifactID; if (!currentUserId.Equals(commentUserId)) { throw new DeleteAnotherComment(); } } } catch (Exception ex) { eventRes.Success = false; eventRes.Exception = new SystemException("ProcessPreDeleteFailure failure: " + ex.Message); } return(eventRes); }
public override kCura.EventHandler.Console GetConsole(PageEvent pageEvent) { int activeWorkspaceId = this.Helper.GetActiveCaseID(); //Construct a console object to build the console appearing in the UI. kCura.EventHandler.Console returnConsole = new kCura.EventHandler.Console(); returnConsole.Items = new List <IConsoleItem>(); returnConsole.Title = CONSOLE_TITLE; string select = "<h3 style='color:#11599E'>Comments Tree</h3>"; List <string> elements = new List <string>(); elements.Add(select); using (kCura.Relativity.Client.IRSAPIClient client = this.Helper.GetServicesManager().CreateProxy <kCura.Relativity.Client.IRSAPIClient>(Relativity.API.ExecutionIdentity.System)) { client.APIOptions.WorkspaceID = this.Helper.GetActiveCaseID(); Service.SqlService.CommentSqlService commentService = new Service.SqlService.CommentSqlService(this.Helper.GetDBContext(this.Helper.GetActiveCaseID())); Service.RSAPIService.CommentRSAPIService commentRSAPIService = new Service.RSAPIService.CommentRSAPIService(client); Data.Entities.Comment comment = commentRSAPIService.Get(this.ActiveArtifact.ArtifactID); comment.CommentChilds = commentService.GetCommentsChild(comment.ArtifactId); drawCommentTree2(ref elements, (comment.CommentChilds).ToList()); returnConsole.HTMLBlocks = elements; } ConsoleHeader header = new ConsoleHeader("Console Application"); //Construct the submit job button. ConsoleButton submitJobButton = new ConsoleButton(); submitJobButton.Name = INSERT_JOB_BUTTON_NAME; submitJobButton.DisplayText = INSERT_JOB_DISPLAY_TEXT; submitJobButton.ToolTip = INSERT_JOB_TOOL_TIP; submitJobButton.RaisesPostBack = true; submitJobButton.Enabled = true; //Construct the delete job button ConsoleButton deleteJobButton = new ConsoleButton() { Name = DELETE_JOB_BUTTON_NAME, DisplayText = DELETE_JOB_DISPLAY_TEXT, ToolTip = DELETE_JOB_TOOL_TIP, RaisesPostBack = true, Enabled = true }; //Button to see the comment data ConsoleButton seeCommentButton = new ConsoleButton() { Name = "See Comment Data", DisplayText = "Commen Data", ToolTip = "Comment Data", RaisesPostBack = true, Enabled = true }; ConsoleSeparator separador = new ConsoleSeparator(); //If a job is already in the queue, change the text and disable the button. if (pageEvent == PageEvent.PreRender) { SqlParameter commentArtifactId = new SqlParameter("@commentArtifacId", System.Data.SqlDbType.Int); commentArtifactId.Value = ActiveArtifact.ArtifactID; int jobCount = this.Helper.GetDBContext(activeWorkspaceId).ExecuteSqlStatementAsScalar <Int32>(JOB_EXISTS_QUERY, new SqlParameter[] { commentArtifactId }); //Use the helper function to check if a job currently exists. Set Enabled to the opposite value. if (jobCount > 0) { submitJobButton.Enabled = false; deleteJobButton.Enabled = true; } else { submitJobButton.Enabled = true; deleteJobButton.Enabled = false; } //Get the base path to the application. String basePath = this.Application.ApplicationUrl.Substring(0, this.Application.ApplicationUrl.IndexOf("/Case/Mask/")); //Construct the path to the custom page with the current patient artifact id and current workspace. String patientProfilePageUrl = String.Format("{0}/CustomPages/{1}/Home/Index/?artifacId={2}", basePath, COMMENT_HISTORY_APPLICATION_GUID, ActiveArtifact.ArtifactID); //Create the JavaScript for the button and set the button property. String windowOpenJavaScript = String.Format("window.open('{0}', '', 'location=no,scrollbars=yes,menubar=no,toolbar=no,status=no,resizable=yes,width=300,height=400');", patientProfilePageUrl); seeCommentButton.OnClickEvent = windowOpenJavaScript; } //Add the buttons to the console. returnConsole.Items.Add(header); returnConsole.Items.Add(submitJobButton); returnConsole.Items.Add(deleteJobButton); returnConsole.Items.Add(seeCommentButton); returnConsole.Items.Add(separador); return(returnConsole); }
public override Response Execute() { Artifact activeArtifact = this.ActiveArtifact; int activeWorkspaceId = this.Helper.GetActiveCaseID(); string currentUser = this.Helper.GetAuthenticationManager().UserInfo.FullName; IDBContext dbcontext = this.Helper.GetDBContext(activeWorkspaceId); bool result = true; ConsoleEventHandlerComment consoleEventHandler = new ConsoleEventHandlerComment(); Response retVal = new Response() { Success = true, Message = String.Empty }; //verify if the comment has a parent if (!(ActiveArtifact.Fields[RELATED_COMMENT_FIELD.ToString()] == null)) { int parentCommentId = (int)ActiveArtifact.Fields[RELATED_COMMENT_FIELD.ToString()].Value.Value; kCura.Relativity.Client.DTOs.RDO parentComment = new kCura.Relativity.Client.DTOs.RDO(parentCommentId); using (kCura.Relativity.Client.IRSAPIClient client = this.Helper.GetServicesManager().CreateProxy <kCura.Relativity.Client.IRSAPIClient>(ExecutionIdentity.System)) { int workspaceId = this.Helper.GetActiveCaseID(); client.APIOptions.WorkspaceID = workspaceId; parentComment = client.Repositories.RDO.ReadSingle(parentCommentId); client.APIOptions.WorkspaceID = -1; kCura.Relativity.Client.DTOs.User userComment = new kCura.Relativity.Client.DTOs.User(parentComment.SystemCreatedBy.ArtifactID); userComment = client.Repositories.User.ReadSingle(parentComment.SystemCreatedBy.ArtifactID); if (ActiveArtifact.IsNew) { MailMessage email = new MailMessage(); string userEmail = userComment.EmailAddress; string author = this.Helper.GetAuthenticationManager().UserInfo.FullName; email.To.Add(new MailAddress(userEmail)); // sentEmailNew(email, author); } } } else { using (kCura.Relativity.Client.IRSAPIClient client = this.Helper.GetServicesManager().CreateProxy <kCura.Relativity.Client.IRSAPIClient>(ExecutionIdentity.System)) { string type = string.Empty; int workspaceId = this.Helper.GetActiveCaseID(); client.APIOptions.WorkspaceID = workspaceId; CORE.BLL.Service.RSAPIService.CommentRSAPIService commentRSAPIService = new CORE.BLL.Service.RSAPIService.CommentRSAPIService(client); CORE.DAL.Entities.Comment comment = commentRSAPIService.Get(ActiveArtifact.ArtifactID); ChoiceCollection typeChoices = (ChoiceCollection)this.ActiveArtifact.Fields[COMMENT_TYPE_FIELD_GUID.ToString()].Value.Value; foreach (Choice typeC in typeChoices) { type = typeC.Name; } comment.TypeChoosed = type; auditComment(comment, ActiveArtifact.IsNew, this.Helper.GetDBContext(workspaceId)); } } try { ChoiceCollection typeChoices = (ChoiceCollection)this.ActiveArtifact.Fields[COMMENT_TYPE_FIELD_GUID.ToString()].Value.Value; foreach (Choice typeChoice in typeChoices) { if (typeChoice.Name.Equals("Error")) { result = consoleEventHandler.insertJob(dbcontext, currentUser, activeArtifact); } else { result = consoleEventHandler.deleteJob(dbcontext, activeArtifact.ArtifactID); } } } catch (Exception e) { retVal.Success = false; retVal.Message = e.Message; } return(retVal); }
public override Response Execute() { _logger = this.Helper.GetLoggerFactory().GetLogger().ForContext <PreSaveEventHandlerComment>(); Response retVal = new Response(); retVal.Success = true; retVal.Message = string.Empty; // Console.WriteLine(output); //string output = null; try { String comment = (String)this.ActiveArtifact.Fields[COMMENT_FIEL_GUID.ToString()].Value.Value; string user = (String)this.ActiveArtifact.Fields[SYSTEM_CREATED_BY_FIELD.ToString()].Value.Value; if (!(ActiveArtifact.Fields[RELATED_COMMENT_FIELD.ToString()] == null)) { using (kCura.Relativity.Client.IRSAPIClient client = this.Helper.GetServicesManager().CreateProxy <kCura.Relativity.Client.IRSAPIClient>(Relativity.API.ExecutionIdentity.System)) { client.APIOptions.WorkspaceID = this.Helper.GetActiveCaseID(); Service.RSAPIService.CommentRSAPIService commentRSAPIService = new Service.RSAPIService.CommentRSAPIService(client); Service.SqlService.CommentSqlService commentSqlService = new Service.SqlService.CommentSqlService(this.Helper.GetDBContext(Helper.GetActiveCaseID())); int parentCommentId = (int)this.ActiveArtifact.Fields[RELATED_COMMENT_FIELD.ToString()].Value.Value; Data.Entities.Comment parentComment = new Data.Entities.Comment(parentCommentId); parentComment = commentRSAPIService.Get(parentCommentId); List <Data.Entities.Comment> commentsChild = commentSqlService.GetCommentsChild(parentComment.ArtifactId); parentComment.CommentChilds = commentsChild; int user1 = parentComment.CreatedBy.ArtifactId; int user2 = this.Helper.GetAuthenticationManager().UserInfo.ArtifactID; if (commentsChild.Count.Equals(0)) { if (user1.Equals(user2)) { throw new StartConversation(); } } } } if (String.IsNullOrWhiteSpace(comment)) { _logger.LogError($"the comment field was not fill up "); throw new FieldMissingException("Comment"); } if (!ActiveArtifact.IsNew) { using (kCura.Relativity.Client.IRSAPIClient client = this.Helper.GetServicesManager().CreateProxy <kCura.Relativity.Client.IRSAPIClient>(ExecutionIdentity.System)) { client.APIOptions.WorkspaceID = this.Helper.GetActiveCaseID(); Service.RSAPIService.CommentRSAPIService commentRSAPIService = new Service.RSAPIService.CommentRSAPIService(client); Data.Entities.Comment currentComment = new Data.Entities.Comment(ActiveArtifact.ArtifactID); currentComment = commentRSAPIService.Get(ActiveArtifact.ArtifactID); int commentUserId = currentComment.CreatedBy.ArtifactId; int currentUserId = this.Helper.GetAuthenticationManager().UserInfo.ArtifactID; if (!commentUserId.Equals(currentUserId)) { throw new DontEditAnotherComment(); } } } Boolean typeSelected = false; ChoiceCollection typeField = (ChoiceCollection)this.ActiveArtifact.Fields[TYPE_FIELD_GUID.ToString()].Value.Value; foreach (Choice typeChoice in typeField) { if (typeChoice.IsSelected) { typeSelected = true; break; } } if (!typeSelected) { throw new FieldMissingException("Comment Type"); } } catch (FieldMissingException fielMissingEx) { retVal.Success = false; retVal.Message = fielMissingEx.Message; } catch (Exception e) { retVal.Success = false; retVal.Message = e.Message; } return(retVal); }