public List <CORE.DAL.Entities.Comment> GetCommentChilds(List <CORE.DAL.Entities.Comment> comments)
        {
            List <CORE.DAL.Entities.Comment> childs    = new List <CORE.DAL.Entities.Comment>();
            List <CORE.DAL.Entities.Comment> newChilds = new List <CORE.DAL.Entities.Comment>();

            using (IRSAPIClient proxy =
                       _helper.GetServicesManager().CreateProxy <IRSAPIClient>(ExecutionIdentity.System))
            {
                int workspaceId = _workspaceID;
                proxy.APIOptions.WorkspaceID = workspaceId;
                CORE.BLL.Service.RSAPIService.CommentRSAPIService cRSAPIService  = new CORE.BLL.Service.RSAPIService.CommentRSAPIService(proxy);
                CORE.BLL.Service.SqlService.CommentSqlService     commentService = new CORE.BLL.Service.SqlService.CommentSqlService(_helper.GetDBContext(workspaceId));
                foreach (CORE.DAL.Entities.Comment item in comments)
                {
                    childs = commentService.GetCommentsChild(item.ArtifactId);


                    if (!childs.Count().Equals(0))
                    {
                        foreach (CORE.DAL.Entities.Comment child in childs)
                        {
                            CORE.DAL.Entities.Comment comment = cRSAPIService.Get(child.ArtifactId);
                            newChilds.Add(comment);
                        }
                        item.CommentChilds = GetCommentChilds(newChilds);
                    }
                    else
                    {
                        item.CommentChilds = childs;
                    }
                }
            }
            return(comments);
        }
        public CORE.DAL.Entities.Comment getDataReplyCommentByObjectManager(int commentAI, int workspaceID)
        {
            CORE.DAL.Entities.Comment comment = new RelativityAppCore.DAL.Entities.Comment(commentAI);
            Relativity.Services.Objects.DataContracts.ReadResult result = null;
            using (HttpClient client = new HttpClient())
            {
                client.DefaultRequestHeaders.Add("X-CSRF-Header", string.Empty);
                client.DefaultRequestHeaders.Add("Authorization",
                                                 "Basic " + Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes("[email protected]:Nserio.1")));
                client.DefaultRequestHeaders.Add("X-Kepler-Version", "2.0");
                client.BaseAddress = new Uri("http://192.168.0.148/Relativity.REST/api/Relativity.Objects/");

                string inputJSON = $"{{\"Request\": {{\"Object\": {{\"ArtifactID\": {commentAI}}},\"Fields\": [{{\"Name\": \"Comment\"}},{{\"Name\": \"System Created On\"}}]}}}}";
                var    url       = $"workspace/{workspaceID}/object/read";
                var    response  = client.PostAsync(url, new StringContent(inputJSON, Encoding.UTF8, "application/json")).Result;
                response.EnsureSuccessStatusCode();
                var content = response.Content.ReadAsStringAsync().Result;
                result            = JsonConvert.DeserializeObject <Relativity.Services.Objects.DataContracts.ReadResult>(content);
                comment.CreatedOn = result.Object.FieldValues[0].Value.ToString();
                comment.Name      = result.Object.FieldValues[1].Value.ToString();
            }


            return(comment);
        }
        public CORE.DAL.Entities.Comment GetCommentData(int commentAI)
        {
            CORE.DAL.Entities.Comment comment = new CORE.DAL.Entities.Comment();
            using (IObjectManager OM = _helper.GetServicesManager().CreateProxy <IObjectManager>(ExecutionIdentity.CurrentUser))
            {
                QueryRequest QR = new QueryRequest();
                QR.ObjectType = new ObjectTypeRef()
                {
                    Name = "Comment"
                };
                QR.Condition = $"'Artifact ID' == {commentAI}";
                QR.Fields    = new List <FieldRef>()
                {
                    new FieldRef()
                    {
                        Name = "Comment"
                    },
                    new FieldRef()
                    {
                        Name = "System Created On"
                    },
                    new FieldRef()
                    {
                        Name = "Thumbnail_Image_base64"
                    }
                };
                var task = OM.QueryAsync(_workspaceID, QR, 1, int.MaxValue);
                task.Wait();
                comment.Name        = task.Result.Objects.FirstOrDefault().FieldValues[0].Value.ToString();
                comment.CreatedOn   = task.Result.Objects.FirstOrDefault().FieldValues[1].Value.ToString();
                comment.imageBase64 = task.Result.Objects.FirstOrDefault().FieldValues[2].Value.ToString();
            }

            return(comment);
        }
Example #4
0
        public void auditComment(CORE.DAL.Entities.Comment comment, bool isNew, IDBContext dbContext)
        {
            string sql   = string.Empty;
            int    value = 0;

            if (isNew)
            {
                sql = $@"INSERT INTO [EDDSDBO].[AuditComment]
                           ([CommentId]
                           ,[CreatedOn]
                           ,[CreateByUserId]
                           ,[CreatedByUserName]
                           ,[ReplysAmount]
                           ,[comment]
                           ,[type])
                        VALUES
                           ({comment.ArtifactId},
		                   GETDATE(),
		                   {comment.CreatedBy.ArtifactId},
		                   '{comment.CreatedBy.Name}',
		                   0,
		                   '{comment.Name}',
		                   '{comment.TypeChoosed}'
		                   )"        ;
            }
            else
            {
                sql = $@"INSERT INTO [EDDSDBO].[AuditComment]
                           ([CommentId]
                           ,[ModifiedOn]
                           ,[ModifiedByUserId]
                           ,[ModifiedByUserName]
                           ,[ReplysAmount]
                           ,[comment]
                           ,[type])
                        VALUES
                           ({comment.ArtifactId},
		                   GETDATE(),
		                   {comment.CreatedBy.ArtifactId},
		                   '{comment.CreatedBy.Name}',
		                   0,
		                   '{comment.Name}',
		                   '{comment.TypeChoosed}'
		                   )"        ;
            }

            value = dbContext.ExecuteNonQuerySQLStatement(sql);
        }
        public CORE.DAL.Entities.Comment GetCommentDataByRsapi(int commentAI)
        {
            CORE.DAL.Entities.Comment comment = new CORE.DAL.Entities.Comment();
            using (IRSAPIClient proxy = _helper.GetServicesManager().CreateProxy <IRSAPIClient>(ExecutionIdentity.System))
            {
                proxy.APIOptions.WorkspaceID = _workspaceID;
                CORE.BLL.Service.RSAPIService.CommentRSAPIService csrsapi = new CORE.BLL.Service.RSAPIService.CommentRSAPIService(proxy);
                CORE.BLL.Service.SqlService.CommentSqlService     cssql   = new RelativityAppCore.BLL.Service.SqlService.CommentSqlService(_helper.GetDBContext(_workspaceID));
                comment = csrsapi.Get(commentAI);
                comment.CommentChilds = cssql.GetCommentsChild(comment.ArtifactId);
                List <CORE.DAL.Entities.Comment> childs = new List <RelativityAppCore.DAL.Entities.Comment>();
                foreach (var c in comment.CommentChilds)
                {
                    childs.Add(csrsapi.Get(c.ArtifactId));
                }
                comment.CommentChilds = childs;
                comment.CommentChilds = GetCommentChilds(comment.CommentChilds.ToList());
            }

            return(comment);
        }
        public IEnumerable <CORE.DAL.Entities.Comment> GetReplysByObjectManager(int artifactId)
        {
            List <CORE.DAL.Entities.Comment> childs    = new List <CORE.DAL.Entities.Comment>();
            List <CORE.DAL.Entities.Comment> newChilds = new List <CORE.DAL.Entities.Comment>();

            using (IRSAPIClient proxy =
                       _helper.GetServicesManager().CreateProxy <IRSAPIClient>(ExecutionIdentity.System))
            {
                int workspaceId = _workspaceID;
                proxy.APIOptions.WorkspaceID = workspaceId;
                CORE.BLL.Service.RSAPIService.CommentRSAPIService cRSAPIService  = new CORE.BLL.Service.RSAPIService.CommentRSAPIService(proxy);
                CORE.BLL.Service.SqlService.CommentSqlService     commentService = new CORE.BLL.Service.SqlService.CommentSqlService(_helper.GetDBContext(workspaceId));
                childs = commentService.GetCommentsChild(artifactId);
                foreach (var child in childs)
                {
                    CORE.DAL.Entities.Comment comment = getDataReplyCommentByObjectManager(child.ArtifactId, workspaceId);
                    newChilds.Add(comment);
                }
            }

            return(newChilds);
        }
        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);
        }
Example #8
0
        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);
        }