Ejemplo n.º 1
0
        private async Task <RecordEntry> CreateRecord(string folderName, string nodeId, string nodeType, string assocType)
        {
            var folderInfo = await GetRMFolder(folderName);

            var nodeInfo = await _alfrescoHttpClient.GetNodeInfo(nodeId);

            var properties = nodeInfo.Entry.Properties.As <JObject>().ToDictionary();

            int.TryParse(properties.GetNestedValueOrDefault(SpisumNames.Properties.RetentionPeriod)?.ToString(),
                         out int retentionPeriod);
            DateTime.TryParse(properties.GetNestedValueOrDefault(SpisumNames.Properties.SettleDate)?.ToString(),
                              out DateTime settleDate);

            var shreddingDate = new DateTime(settleDate.Year + 1 + retentionPeriod, 1, 1);

            await _alfrescoHttpClient.UpdateNode(nodeId, new NodeBodyUpdate()
                                                 .AddProperty(SpisumNames.Properties.ShreddingYear, shreddingDate.Year.ToString()));

            var body = new RMNodeBodyCreate
            {
                Name       = nodeInfo?.Entry?.Name,
                NodeType   = nodeType,
                Properties = new Dictionary <string, string>
                {
                    { SpisumNames.Properties.Ref, nodeId },
                    { SpisumNames.Properties.ShreddingYear, shreddingDate.Year.ToString() }
                }
            };

            properties.ForEach(x =>
            {
                var(key, value) = x;

                if (!key.StartsWith("ssl:"))
                {
                    return;
                }

                if (key.Equals(SpisumNames.Properties.Pid))
                {
                    body.Properties.Add(SpisumNames.Properties.PidRef, $"{value}");
                    body.Properties.Add(SpisumNames.Properties.Pid, $"RM-{value}");
                    return;
                }

                // Problems only with datetime for now
                if (DateTime.TryParse(value?.ToString(), out DateTime datetime))
                {
                    body.Properties.Add(key, datetime.ToAlfrescoDateTimeString());
                }
                else
                {
                    body.Properties.Add(key, $"{value}");
                }
            });

            var node = await _alfrescoHttpClient.CreateRecord(folderInfo?.Entry?.Id, body);

            // Create secondary children to orig document/file. It cannot be set from repository to RM
            await _alfrescoHttpClient.CreateNodeSecondaryChildren(node?.Entry?.Id, new ChildAssociationBody
            {
                AssocType = assocType,
                ChildId   = nodeId
            });

            // Set record as complete
            await _alfrescoHttpClient.CompleteRecord(node?.Entry?.Id);

            // Call retention date
            await _alfrescoHttpClient.ExecutionQueue(new ExecutionQueue
            {
                Name    = "editDispositionActionAsOfDate",
                NodeRef = $"workspace://SpacesStore/{node?.Entry?.Id}",
                Params  = new ExecutionQueueParams
                {
                    AsOfDate = new ExecutionQueueParamsAsOfDate
                    {
                        Iso8601 = shreddingDate.ToAlfrescoDateTimeString()
                    }
                }
            });

            return(node);
        }
Ejemplo n.º 2
0
        public async Task <List <string> > CancelComponent(string nodeId, List <string> componentsId)
        {
            List <string> unprocessedId = new List <string>();

            var parentInfo = await _alfrescoHttpClient.GetNodeInfo(nodeId, ImmutableList <Parameter> .Empty
                                                                   .Add(new Parameter(AlfrescoNames.Headers.Include, AlfrescoNames.Includes.Path, ParameterType.QueryString)));

            if (parentInfo?.Entry?.Path?.Name?.StartsWith(AlfrescoNames.Prefixes.Path + SpisumNames.Paths.Components, StringComparison.OrdinalIgnoreCase) != true)
            {
                foreach (var componentId in componentsId)
                {
                    try
                    {
                        var componentEntryBeforeDelete = await _alfrescoHttpClient.GetNodeInfo(nodeId);

                        await _alfrescoHttpClient.DeleteSecondaryChildren(nodeId, componentId);

                        await _alfrescoHttpClient.CreateNodeSecondaryChildren(nodeId, new ChildAssociationBody
                        {
                            ChildId   = componentId,
                            AssocType = SpisumNames.Associations.DeletedComponents
                        });

                        await UpdateMainFileComponentVersionProperties(nodeId, componentId, SpisumNames.VersionOperation.Remove);

                        try
                        {
                            var componentPid = componentEntryBeforeDelete?.GetPid();


                            if (parentInfo?.Entry?.NodeType == SpisumNames.NodeTypes.Concept)
                            {
                                await _auditLogService.Record(nodeId, SpisumNames.NodeTypes.Component, componentPid, NodeTypeCodes.Komponenta, EventCodes.VyjmutiZDokumentu,
                                                              TransactinoHistoryMessages.ConceptComponentDeleteDocument);
                            }
                            else if (parentInfo?.Entry?.NodeType == SpisumNames.NodeTypes.Document)
                            {
                                await _auditLogService.Record(nodeId, SpisumNames.NodeTypes.Component, componentPid, NodeTypeCodes.Komponenta, EventCodes.VyjmutiZDokumentu,
                                                              TransactinoHistoryMessages.DocumentComponentDeleteDocument);
                            }

                            var documentFileParent = await _alfrescoHttpClient.GetNodeParents(nodeId, ImmutableList <Parameter> .Empty
                                                                                              .Add(new Parameter(AlfrescoNames.Headers.Include, AlfrescoNames.Includes.Properties, ParameterType.QueryString))
                                                                                              .Add(new Parameter(AlfrescoNames.Headers.Where, $"(assocType='{SpisumNames.Associations.Documents}')", ParameterType.QueryString))
                                                                                              .Add(new Parameter(AlfrescoNames.Headers.MaxItems, "1", ParameterType.QueryString)));

                            var fileId = documentFileParent?.List?.Entries?.FirstOrDefault()?.Entry?.Id;

                            if (fileId != null)
                            {
                                await _auditLogService.Record(fileId, SpisumNames.NodeTypes.Component, componentPid, NodeTypeCodes.Komponenta, EventCodes.VyjmutiZDokumentu,
                                                              TransactinoHistoryMessages.DocumentComponentDeleteFile);
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.Logger?.Error(ex, "Audit log failed");
                        }
                    }
                    catch
                    {
                        unprocessedId.Add(componentId);
                    }
                }

                ;

                return(unprocessedId);
            }

            return(await DeleteComponent(componentsId));
        }
Ejemplo n.º 3
0
        public async Task <NodeEntry> ShreddingProposalCreate(string name, List <string> ids)
        {
            var nodes = new List <NodeEntry>();

            await ids.ForEachAsync(async x =>
            {
                #region Validations

                var nodeInfo = await _alfrescoHttpClient.GetNodeInfo(x);
                nodes.Add(nodeInfo);

                var properties    = nodeInfo.Entry.Properties.As <JObject>().ToDictionary();
                var discardReason = properties.GetNestedValueOrDefault(SpisumNames.Properties.DiscardReason)?.ToString();
                var discardTo     = properties.GetNestedValueOrDefault(SpisumNames.Properties.DiscardTo)?.ToString();
                var discardDate   = properties.GetNestedValueOrDefault(SpisumNames.Properties.DiscardDate)?.ToString();
                var borrower      = properties.GetNestedValueOrDefault(SpisumNames.Properties.Borrower)?.ToString();
                var proposalName  = properties.GetNestedValueOrDefault(SpisumNames.Properties.ProposalName)?.ToString();

                if (!string.IsNullOrWhiteSpace(proposalName))
                {
                    throw new BadRequestException("", "One or more of the ids cannot be used because they were used previously.");
                }

                var parentRm = await _nodesService.GetParentsByAssociation(x, new List <string>
                {
                    SpisumNames.Associations.DocumentInRepository,
                    SpisumNames.Associations.FileInRepository
                });

                var rmRef = parentRm.FirstOrDefault()?.Entry?.Id;

                if (string.IsNullOrWhiteSpace(rmRef))
                {
                    throw new BadRequestException("", "One or more of the ids are not in record management.");
                }

                var rmNodeInfo = await _alfrescoHttpClient.GetNodeInfo(rmRef);

                var propertiesRm = rmNodeInfo.Entry.Properties.As <JObject>().ToDictionary();
                var cutOffDate   = propertiesRm.GetNestedValueOrDefault(AlfrescoNames.ContentModel.CutOffDate)?.ToString();

                if (string.IsNullOrWhiteSpace(cutOffDate))
                {
                    throw new BadRequestException("", "One or more of the ids has not been cut off yet.");
                }

                if (!string.IsNullOrWhiteSpace(discardReason) ||
                    !string.IsNullOrWhiteSpace(discardTo) ||
                    !string.IsNullOrWhiteSpace(discardDate) ||
                    !string.IsNullOrWhiteSpace(borrower))
                {
                    throw new BadRequestException("", "One or more of ids is borrowed or removed of shredding plan");
                }

                #endregion
            });

            var shreddingPlanCreate = await _alfrescoHttpClient.CreateNode(AlfrescoNames.Aliases.Root, new FormDataParam(new byte[] { 01 }),
                                                                           ImmutableList <Parameter> .Empty
                                                                           .Add(new Parameter(AlfrescoNames.Headers.NodeType, SpisumNames.NodeTypes.ShreddingProposal, ParameterType.GetOrPost))
                                                                           .Add(new Parameter(AlfrescoNames.Headers.Name, IdGenerator.GenerateId(), ParameterType.GetOrPost))
                                                                           .Add(new Parameter(AlfrescoNames.Headers.RelativePath, SpisumNames.Paths.RepositoryShreddingProposal, ParameterType.GetOrPost))
                                                                           .Add(new Parameter(AlfrescoNames.Headers.Include, AlfrescoNames.Includes.Properties, ParameterType.QueryString))
                                                                           .Add(new Parameter(SpisumNames.Properties.Name, name, ParameterType.GetOrPost))
                                                                           .Add(new Parameter(SpisumNames.Properties.AssociationCount, nodes.Count, ParameterType.GetOrPost))
                                                                           .Add(new Parameter(SpisumNames.Properties.CreatedDate, DateTime.UtcNow.ToAlfrescoDateTimeString(), ParameterType.GetOrPost))
                                                                           .Add(new Parameter(SpisumNames.Properties.Author, _identityUser.Id, ParameterType.GetOrPost))
                                                                           );

            var shreddingPlan = await _alfrescoHttpClient.GetNodeInfo(shreddingPlanCreate?.Entry?.Id);

            var shredding = shreddingPlan?.Entry?.Properties.As <JObject>().ToDictionary();
            var pid       = shredding.GetNestedValueOrDefault(SpisumNames.Properties.Pid)?.ToString();

            await nodes.ForEachAsync(async x =>
            {
                await _nodesService.TryUnlockNode(x?.Entry?.Id);

                await _alfrescoHttpClient.CreateNodeSecondaryChildren(shreddingPlan?.Entry?.Id, new ChildAssociationBody
                {
                    AssocType = SpisumNames.Associations.ShreddingObjects,
                    ChildId   = x?.Entry?.Id
                });

                await _alfrescoHttpClient.UpdateNode(x?.Entry?.Id, new NodeBodyUpdate()
                                                     .AddProperty(SpisumNames.Properties.ProposalName, pid)
                                                     );

                await _alfrescoHttpClient.NodeLock(x?.Entry?.Id, new NodeBodyLock
                {
                    Type = NodeBodyLockType.FULL
                });
            });

            return(shreddingPlan);
        }