public ConceptComponentCancelValidator(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);
                _nodeChildrens = await alfrescoHttpClient.GetNodeSecondaryChildren(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.Components}')"
                                                                                                      , ParameterType.QueryString)));

                return(_nodeEntry?.Entry?.Id != null && _groupPaging != null && _nodeChildrens != 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 => c.ComponentsId.All(x => _nodeChildrens?.List?.Entries?.Any(y => y?.Entry?.Id == x) ?? false))
                .WithMessage("Not all components are associated with nodeId");
            });
        }
Ejemplo n.º 2
0
        public async Task UpdateAssociationCount(string nodeId)
        {
            var childrens = await _alfrescoHttpClient.GetNodeSecondaryChildren(nodeId, ImmutableList <Parameter> .Empty
                                                                               .Add(new Parameter(AlfrescoNames.Headers.MaxItems, "1", ParameterType.QueryString))
                                                                               .Add(new Parameter(AlfrescoNames.Headers.Where, $"(assocType='{SpisumNames.Associations.Components}')", ParameterType.QueryString)));

            await _alfrescoHttpClient.UpdateNode(nodeId, new NodeBodyUpdate()
                                                 .AddProperty(SpisumNames.Properties.AssociationCount, childrens?.List.Pagination?.TotalItems ?? 0));
        }
Ejemplo n.º 3
0
        public FileCancelValidator(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)));
                _secondaryChildren = await alfrescoHttpClient.GetNodeSecondaryChildren(context.NodeId, ImmutableList <Parameter> .Empty
                                                                                       .Add(new Parameter(AlfrescoNames.Headers.Where, $"(assocType='{SpisumNames.Associations.Documents}')", ParameterType.QueryString)));
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);

                return(_nodeEntry?.Entry?.Id != null && _secondaryChildren != 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.File)
                .WithMessage(x => $"Provided nodeId must be NodeType {SpisumNames.NodeTypes.File}");

                RuleFor(x => x)
                .Must(x => _secondaryChildren?.List?.Entries?.Count == null || !_secondaryChildren.List.Entries.Any())
                .OnAnyFailure(x => throw new BadRequestException(ErrorCodes.V_FILE_CANCEL_CHILDREN));

                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)
                .Must(x => _nodeEntry?.Entry?.Path?.Name?.StartsWith(AlfrescoNames.Prefixes.Path + SpisumNames.Paths.EvidenceFilesOpen(identityUser.RequestGroup), StringComparison.OrdinalIgnoreCase) == true)
                .OnAnyFailure(x => throw new BadRequestException("File can't be cancelled"));

                RuleFor(x => x.NodeId)
                .Must(x => IsNodePathAllowed(x, identityUser.RequestGroup));
            });

            RuleFor(x => x)
            .Must(CheckReasonLength);
        }
Ejemplo n.º 4
0
 public async Task <NodeChildAssociationPagingFixed> GetSecondaryChildren([FromRoute] string nodeId, [FromQuery] BasicNodeQueryParams queryParams)
 {
     return(await _alfrescoHttpClient.GetNodeSecondaryChildren(nodeId, ImmutableList <Parameter> .Empty.AddQueryParams(queryParams)));
 }
Ejemplo n.º 5
0
        private async Task <NodeEntry> CreateArhiveAndMoveAllFiles(NodeUpdate body, string archiveFolder, string nodeType)
        {
            var copiedNodes  = new List <NodeEntry>();
            var updatedNodes = new List <NodeEntry>();
            var connections  = new List <Tuple <string, string> >();

            var alfrescoBody = _mapper.Map <NodeBodyUpdate>(body);
            var documentInfo = await _alfrescoHttpClient.UpdateNode(body.NodeId, alfrescoBody, ImmutableList <Parameter> .Empty
                                                                    .Add(new Parameter(AlfrescoNames.Headers.Include, AlfrescoNames.Includes.Path, ParameterType.QueryString)));

            var parentFolderInfo = await _alfrescoHttpClient.GetNodeInfo(documentInfo.Entry.ParentId);

            // create folder in archive because copy folder violation
            var copyFolderInfo = await _nodesService.CreateFolder(archiveFolder);

            AlfrescoPagingRequest <NodeChildAssociationPagingFixed, List19Fixed, NodeChildAssociationEntry> request;

            // copy and remove all associations - Copies .eml/.zfo and all it's children to the archive folder
            var entries = (await _alfrescoHttpClient.GetNodeChildren(body.NodeId, ImmutableList <Parameter> .Empty
                                                                     .Add(new Parameter(AlfrescoNames.Headers.MaxItems, 1, ParameterType.QueryString))
                                                                     .Add(new Parameter(AlfrescoNames.Headers.Where, $"(nodeType='{nodeType}')", ParameterType.QueryString))))
                          ?.List?.Entries?.ToList();

            if (entries?.Count > 0)
            {
                var nodeId = entries[0]?.Entry?.Id;

                request = new AlfrescoPagingRequest <NodeChildAssociationPagingFixed, List19Fixed, NodeChildAssociationEntry>(
                    parameters => _alfrescoHttpClient.GetNodeSecondaryChildren(nodeId, parameters)
                    );

                while (await request.Next())
                {
                    var response = request.Response();
                    if (!(response?.List?.Entries?.Count > 0))
                    {
                        break;
                    }

                    foreach (var item in response.List.Entries.ToList())
                    {
                        await _alfrescoHttpClient.DeleteSecondaryChildren(nodeId, item.Entry.Id);

                        var copyInfo = await _alfrescoHttpClient.NodeCopy(item.Entry.Id, new NodeBodyCopy
                        {
                            TargetParentId = copyFolderInfo.Entry.Id
                        });

                        var properties = copyInfo.Entry.Properties.As <JObject>().ToDictionary();
                        var pid        = properties.GetNestedValueOrDefault(SpisumNames.Properties.Pid)?.ToString();
                        await _alfrescoHttpClient.UpdateNode(copyInfo.Entry.Id, new NodeBodyUpdate()
                                                             .AddProperty(SpisumNames.Properties.Pid, null)
                                                             .AddProperty(SpisumNames.Properties.PidRef, pid)
                                                             .AddProperty(SpisumNames.Properties.Ref, item.Entry.Id));

                        copiedNodes.Add(copyInfo);
                    }
                }

                // Copy .eml / .zfo
                var copyEmlZfo = await _alfrescoHttpClient.NodeCopy(nodeId, new NodeBodyCopy
                {
                    TargetParentId = copyFolderInfo.Entry.Id
                });

                var propertiesEmlZfo = copyEmlZfo.Entry.Properties.As <JObject>().ToDictionary();
                var pidEmlZfo        = propertiesEmlZfo.GetNestedValueOrDefault(SpisumNames.Properties.Pid)?.ToString();

                await _alfrescoHttpClient.UpdateNode(copyEmlZfo?.Entry?.Id, new NodeBodyUpdate()
                                                     .AddProperty(SpisumNames.Properties.Pid, null)
                                                     .AddProperty(SpisumNames.Properties.PidRef, pidEmlZfo)
                                                     .AddProperty(SpisumNames.Properties.Ref, nodeId));

                copiedNodes.Add(copyEmlZfo);
            }

            // Take all files and move them to the new location
            // find all children and rename + change node type
            request = new AlfrescoPagingRequest <NodeChildAssociationPagingFixed, List19Fixed, NodeChildAssociationEntry>(
                parameters => _alfrescoHttpClient.GetNodeSecondaryChildren(body.NodeId, parameters)
                );

            while (await request.Next())
            {
                var response = request.Response();
                if (!(response?.List?.Entries?.Count > 0))
                {
                    break;
                }

                foreach (var item in response.List.Entries.ToList())
                {
                    if (item.Entry.NodeType == SpisumNames.NodeTypes.Component)
                    {
                        continue;
                    }

                    connections.Add(new Tuple <string, string>(item.Entry.Id, copiedNodes.FirstOrDefault(x => x.Entry.Name == item.Entry.Name)?.Entry?.Id));

                    var updateBody = new NodeBodyUpdate();

                    if (item.Entry.NodeType == AlfrescoNames.ContentModel.Content)
                    {
                        updateBody.NodeType = SpisumNames.NodeTypes.Component;
                    }
                    if (item.Entry.NodeType == SpisumNames.NodeTypes.Email)
                    {
                        updateBody.NodeType = SpisumNames.NodeTypes.EmailComponent;
                    }
                    if (item.Entry.NodeType == SpisumNames.NodeTypes.DataBox)
                    {
                        updateBody.NodeType = SpisumNames.NodeTypes.DataBoxComponent;
                    }

                    var personGroup = await GetCreateUserGroup();

                    updateBody.Permissions = _nodesService.SetPermissions(personGroup.GroupPrefix, _identityUser.Id).Permissions;

                    updateBody.Properties = new Dictionary <string, object>
                    {
                        { AlfrescoNames.ContentModel.Owner, _identityUser.Id },
                        { SpisumNames.Properties.Group, _identityUser.RequestGroup }
                    };

                    updatedNodes.Add(await _alfrescoHttpClient.UpdateNode(item.Entry.Id, updateBody));

                    if (item.Entry.NodeType == AlfrescoNames.ContentModel.Content)
                    {
                    }
                }
            }

            // Set PID to archive
            List <NodeEntry> movedNodes = new List <NodeEntry>();

            movedNodes.Add(await _nodesService.MoveByPath(body.NodeId, SpisumNames.Paths.EvidenceDocumentsForProcessing(_identityUser.RequestGroup)));
            movedNodes.AddRange(await _nodesService.MoveAllComponets(body.NodeId));

            foreach (var copy in copiedNodes)
            {
                var id = connections.First(x => x.Item2 == copy.Entry.Id);

                var node = movedNodes.FirstOrDefault(x => x.Entry.Id == id.Item1);

                if (node == null)
                {
                    continue;
                }

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

                if (string.IsNullOrWhiteSpace(pid))
                {
                    continue;
                }

                await _alfrescoHttpClient.UpdateNode(copy.Entry.Id, new NodeBodyUpdate
                {
                    Properties = new Dictionary <string, object>
                    {
                        { SpisumNames.Properties.PidArchive, pid }
                    }
                });
            }

            return(await _alfrescoHttpClient.GetNodeInfo(body.NodeId));
        }