public ConceptComponentUpdateContentValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _nodeEntry = await alfrescoHttpClient.GetNodeInfo(context.NodeId, ImmutableList <Parameter> .Empty
                                                                  .Add(new Parameter(AlfrescoNames.Headers.Include, AlfrescoNames.Includes.Path, ParameterType.QueryString)));
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);
                _nodeParents = await alfrescoHttpClient.GetNodeParents(context.ComponentId, ImmutableList <Parameter> .Empty
                                                                       .Add(new Parameter(AlfrescoNames.Headers.Include, AlfrescoNames.Includes.Properties, ParameterType.QueryString))
                                                                       .Add(new Parameter(AlfrescoNames.Headers.Where,
                                                                                          $"(assocType='{SpisumNames.Associations.Components}')"
                                                                                          , ParameterType.QueryString)));

                return(_nodeEntry?.Entry?.Id != null && _groupPaging != null);
            })
            .WithName(x => nameof(x.NodeId))
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(y => _groupPaging?.List?.Entries?.Any(q => q.Entry.Id == identityUser.RequestGroup) ?? false)
                .WithName(x => "Group")
                .WithMessage($"User isn't member of group {identityUser.RequestGroup}.");

                RuleFor(x => x.NodeId)
                .Must(x => _nodeEntry?.Entry?.NodeType == SpisumNames.NodeTypes.Concept)
                .WithMessage($"NodeId must be type of {SpisumNames.NodeTypes.Concept}.");

                RuleFor(x => x)
                .Must(c => _nodeParents?.List?.Entries?.Any(y => y?.Entry?.Id == c.NodeId) ?? false)
                .WithMessage("Provided component is not associated with nodeId or cannot be canceled.");
            });
        }
        public DocumentShreddingCancelDiscardValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _nodeEntry = await alfrescoHttpClient.GetNodeInfo(context.NodeId, ImmutableList <Parameter> .Empty
                                                                  .Add(new Parameter(AlfrescoNames.Headers.Include, $"{AlfrescoNames.Includes.Properties}, {AlfrescoNames.Includes.Path}",
                                                                                     ParameterType.QueryString)));
                _parentRM = await alfrescoHttpClient.GetNodeParents(context.NodeId, ImmutableList <Parameter> .Empty
                                                                    .Add(new Parameter(AlfrescoNames.Headers.Include, AlfrescoNames.Includes.Properties, ParameterType.QueryString))
                                                                    .Add(new Parameter(AlfrescoNames.Headers.Where, $"(assocType='{SpisumNames.Associations.DocumentInRepository}')", ParameterType.QueryString))
                                                                    .Add(new Parameter(AlfrescoNames.Headers.MaxItems, "1", ParameterType.QueryString)));



                if (_parentRM?.List?.Entries?.Count == 1)
                {
                    var documentInfoRM       = await alfrescoHttpClient.GetNodeInfo(_parentRM?.List?.Entries?.FirstOrDefault()?.Entry?.Id);
                    var rmdocumentProperties = documentInfoRM?.Entry?.Properties?.As <JObject>().ToDictionary();
                    _cutOffDate = rmdocumentProperties.GetNestedValueOrDefault(AlfrescoNames.ContentModel.CutOffDate)?.ToString();
                }

                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);

                return(_nodeEntry != null && _groupPaging != null && _parentRM != null);
            })
            .WithName(x => nameof(x.NodeId))
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(y => _groupPaging?.List?.Entries?.Any(q => q.Entry.Id == identityUser.RequestGroup) ?? false)
                .WithName(x => "Group")
                .WithMessage($"User isn't member of group {identityUser.RequestGroup}.");

                RuleFor(x => x.NodeId)
                .Must(x => _nodeEntry?.Entry?.NodeType == SpisumNames.NodeTypes.Document)
                .WithMessage($"NodeId must be type of {SpisumNames.NodeTypes.Document}.");

                RuleFor(x => x.NodeId)
                .Must(x => _parentRM?.List?.Entries.Count == 1)
                .WithMessage(x => "Document is not in record management");

                RuleFor(x => x.NodeId)
                .Must(x => !string.IsNullOrWhiteSpace(_cutOffDate))
                .WithMessage(x => "Cut off date is not set yet");

                RuleFor(x => x.NodeId)
                .Must(x =>
                {
                    var documentProperties = _nodeEntry?.Entry?.Properties?.As <JObject>().ToDictionary();
                    _discardTo             = documentProperties.GetNestedValueOrDefault(SpisumNames.Properties.DiscardTo)?.ToString();

                    return(!string.IsNullOrWhiteSpace(_discardTo));
                })
                .WithMessage(x => $"{SpisumNames.Properties.DiscardTo} property is not set");
            });
        }
Exemplo n.º 3
0
        public async Task UploadFile(string token, string documentId, string componentId, byte[] newComponent)
        {
            var alfrescoClient   = new AlfrescoHttpClient(_alfrescoConfiguration, new SignerAuthentification(_simpleMemoryCache, token));
            var nodeService      = new NodesService(_alfrescoConfiguration, alfrescoClient, _auditLogService, _identityUser, _mapper, _simpleMemoryCache, _transactionHistoryService, _systemLoginService, _repositoryService);
            var componentService = new ComponentService(alfrescoClient, nodeService, _personService, _identityUser, _auditLogService);

            var nodeEntry = await alfrescoClient.GetNodeInfo(componentId, ImmutableList <Parameter> .Empty
                                                             .Add(new Parameter(AlfrescoNames.Headers.Include, $"{AlfrescoNames.Includes.Properties}, {AlfrescoNames.Includes.Path}", ParameterType.QueryString)));

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

            var pdfValidation = await _signerClient.Validate(newComponent);

            var certValidation = await _signerClient.ValidateCertificate(pdfValidation?.Report?.sigInfos[0]?.signCert.Data);

            await UnlockNode(alfrescoClient, documentId);
            await UnlockNode(alfrescoClient, componentId);

            await componentService.UploadNewVersionComponent(documentId, componentId, newComponent,
                                                             Path.ChangeExtension(properties.GetNestedValueOrDefault(SpisumNames.Properties.FileName)?.ToString(), ".pdf"), MediaTypeNames.Application.Pdf);

            var node = await alfrescoClient.UpdateNode(componentId, GetSignerProperties(pdfValidation, certValidation, true));

            await LockNode(alfrescoClient, documentId);
            await LockNode(alfrescoClient, componentId);

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

                // Audit log for a document
                if (node?.Entry?.NodeType == SpisumNames.NodeTypes.Document)
                {
                    await _auditLogService.Record(documentId, SpisumNames.NodeTypes.Component, componentPid, NodeTypeCodes.Komponenta, EventCodes.PripojeniPodpisu,
                                                  TransactinoHistoryMessages.DocumentSignComponent);
                }

                // Audit log for a file
                var documentFileParent = await _alfrescoHttpClient.GetNodeParents(documentId, 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.PripojeniPodpisu,
                                                  TransactinoHistoryMessages.DocumentSignComponent);
                }
            }
            catch (Exception ex)
            {
                Log.Logger?.Error(ex, "Audit log failed");
            }
        }
Exemplo n.º 4
0
        private async Task <bool> CheckMainComponent(NodeUpdate body, CancellationToken cancellation)
        {
            if (body.Body.Properties == null)
            {
                return(true);
            }

            if (body.Body.Properties.ContainsKey(SpisumNames.Properties.ComponentType))
            {
                var inputValue = body.Body.Properties.GetNestedValueOrDefault(SpisumNames.Properties.ComponentType)?.ToString();
                if (!inputValue.Equals("main"))
                {
                    return(true);
                }

                var response = await _alfrescoHttpClient.GetNodeParents(body.NodeId, ImmutableList <Parameter> .Empty
                                                                        .Add(new Parameter(AlfrescoNames.Headers.Where, $"(assocType='{SpisumNames.Associations.Components}')", ParameterType.QueryString)));

                foreach (var parent in response.List.Entries)
                {
                    var childrens = await _documentService.GetComponents(parent.Entry.Id, false, true);

                    foreach (var children in childrens)
                    {
                        if (children.Entry.Id == body.NodeId)
                        {
                            continue;
                        }

                        var properties   = children.Entry.Properties?.As <JObject>().ToDictionary();
                        var fileMetaType = properties.GetNestedValueOrDefault(SpisumNames.Properties.ComponentType)?.ToString();

                        if (fileMetaType != null && fileMetaType == SpisumNames.Component.Main)
                        {
                            throw new BadRequestException(ErrorCodes.V_COMPONENT_TYPE);
                        }
                    }
                }
            }

            return(true);
        }
Exemplo n.º 5
0
        public FileCreateValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _nodeEntry = await alfrescoHttpClient.GetNodeInfo(context.DocumentId, ImmutableList <Parameter> .Empty
                                                                  .Add(new Parameter(AlfrescoNames.Headers.Include, $"{AlfrescoNames.Includes.Properties},{AlfrescoNames.Includes.Permissions},{AlfrescoNames.Includes.Path}", ParameterType.QueryString)));
                _associationPaging = await alfrescoHttpClient.GetNodeParents(context.DocumentId, 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)));
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);

                return(_nodeEntry?.Entry?.Id != null && _associationPaging != null && _groupPaging != null);
            })
            .WithName(x => nameof(x.DocumentId))
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(y => _groupPaging?.List?.Entries?.Any(q => q.Entry.Id == identityUser.RequestGroup) ?? false)
                .WithName(x => "Group")
                .WithMessage($"User isn't member of group {identityUser.RequestGroup}.");

                RuleFor(x => x.DocumentId)
                .Must(x => _nodeEntry.Entry.NodeType == SpisumNames.NodeTypes.Document)
                .WithMessage(x => $"Provided nodeId must be NodeType {SpisumNames.NodeTypes.Document}");

                RuleFor(x => x)
                .Must(x => _nodeEntry?.Entry?.Path?.Name?.StartsWith(AlfrescoNames.Prefixes.Path + SpisumNames.Paths.Evidence, StringComparison.OrdinalIgnoreCase) == true)
                .OnAnyFailure(x => throw new BadRequestException("Document must be in evidence site."));

                RuleFor(x => x.DocumentId)
                .Must(x => _associationPaging.List.Entries.Count == 0)
                .WithMessage(x => "Provided document is already in file");
            });
        }
Exemplo n.º 6
0
        public DocumentComponentUpdateContentValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _nodeEntry = await alfrescoHttpClient.GetNodeInfo(context.NodeId, ImmutableList <Parameter> .Empty
                                                                  .Add(new Parameter(AlfrescoNames.Headers.Include, AlfrescoNames.Includes.Path, ParameterType.QueryString)));
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);
                _nodeParents = await alfrescoHttpClient.GetNodeParents(context.ComponentId, ImmutableList <Parameter> .Empty
                                                                       .Add(new Parameter(AlfrescoNames.Headers.Include, AlfrescoNames.Includes.Properties, ParameterType.QueryString))
                                                                       .Add(new Parameter(AlfrescoNames.Headers.Where,
                                                                                          $"(assocType='{SpisumNames.Associations.Components}')"
                                                                                          , ParameterType.QueryString)));

                return(_nodeEntry?.Entry?.Id != null && _groupPaging != null);
            })
            .WithName(x => nameof(x.NodeId))
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(y => _groupPaging?.List?.Entries?.Any(q => q.Entry.Id == identityUser.RequestGroup) ?? false)
                .WithName(x => "Group")
                .WithMessage($"User isn't member of group {identityUser.RequestGroup}.");

                RuleFor(x => x.NodeId)
                .Must(x => _nodeEntry?.Entry?.NodeType == SpisumNames.NodeTypes.Document)
                .WithMessage($"NodeId must be type of {SpisumNames.NodeTypes.Document}.");

                RuleFor(x => x)
                .Must(c => _nodeParents?.List?.Entries?.Any(y => y?.Entry?.Id == c.NodeId) ?? false)
                .WithMessage("Provided component is not associated with nodeId or cannot be canceled.");

                RuleFor(x => x)
                .Must(x =>
                {
                    if (_nodeEntry.Entry.NodeType == SpisumNames.NodeTypes.Concept)
                    {
                        return(true);
                    }

                    if (_nodeEntry?.Entry?.IsLocked == true)
                    {
                        return(false);
                    }

                    var properties   = _nodeEntry?.Entry?.Properties?.As <JObject>().ToDictionary();
                    var form         = properties.GetNestedValueOrDefault(SpisumNames.Properties.Form)?.ToString();
                    var senderType   = properties.GetNestedValueOrDefault(SpisumNames.Properties.SenderType)?.ToString();
                    var documentType = properties.GetNestedValueOrDefault(SpisumNames.Properties.DocumentType)?.ToString();

                    if (form == "analog" || documentType == "technicalDataCarries" || form == "digital" && senderType == SpisumNames.SenderType.Own)
                    {
                        return(true);
                    }

                    return(false);
                })
                .OnAnyFailure(x => throw new BadRequestException("Adding component is not allowed."));
            });
        }
Exemplo n.º 7
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));
        }