public async Task LogForSignature(string nodeId, string fileId, string nextGroup, string nextOwner)
        {
            try
            {
                var nodeEntry = await _alfrescoHttpClient.GetNodeInfo(nodeId);

                var personEntry = await _alfrescoHttpClient.GetPerson(nextOwner);

                var groupEntry = await _alfrescoHttpClient.GetGroup(nextGroup);

                var pid = nodeEntry?.GetPid();

                // Audit log for a document
                await _auditLogService.Record(nodeId, SpisumNames.NodeTypes.Document, pid, NodeTypeCodes.Dokument, EventCodes.PostoupeniAgende,
                                              string.Format(TransactinoHistoryMessages.DocumentForSignature, personEntry?.Entry?.DisplayName, groupEntry?.Entry?.DisplayName));

                // Audit log for a file
                if (fileId != null)
                {
                    await _auditLogService.Record(fileId, SpisumNames.NodeTypes.Document, pid, NodeTypeCodes.Dokument, EventCodes.PostoupeniAgende,
                                                  string.Format(TransactinoHistoryMessages.DocumentForSignature, personEntry?.Entry?.DisplayName, groupEntry?.Entry?.DisplayName));
                }
            }
            catch (Exception ex)
            {
                Log.Logger?.Error(ex, "Audit log failed");
            }
        }
        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");
            });
        }
Exemple #3
0
        public async Task DontRegister(DontRegister parameters, EmailOrDataboxEnum type)
        {
            var emlNode = await _alfrescoHttpClient.GetNodeInfo(parameters.NodeId, ImmutableList <Parameter> .Empty
                                                                .Add(new Parameter(AlfrescoNames.Headers.Include, AlfrescoNames.Includes.Path, ParameterType.QueryString)));

            if (parameters.Body.Reason.Length < 4)
            {
                throw new BadRequestException(ErrorCodes.V_MIN_TEXT);
            }

            if (parameters.Body.Reason.Length > 30)
            {
                parameters.Body.Reason = parameters.Body.Reason.Substring(0, 30);
            }

            var body = new NodeBodyUpdate();
            var path = string.Empty;

            switch (type)
            {
            case EmailOrDataboxEnum.Email:

                if (emlNode?.Entry?.Path?.Name.StartsWith(AlfrescoNames.Prefixes.Path + SpisumNames.Paths.MailRoomEmail, StringComparison.OrdinalIgnoreCase) == false)
                {
                    throw new BadRequestException("", "Node is not in Mailbox");
                }

                body = new NodeBodyUpdate
                {
                    Properties = new Dictionary <string, object>
                    {
                        { SpisumNames.Properties.EmailNotRegisteredReason, parameters.Body.Reason }
                    }
                };
                path = SpisumNames.Paths.MailRoomEmailNotRegistered;
                break;

            case EmailOrDataboxEnum.Databox:
                if (emlNode?.Entry?.Path?.Name.StartsWith(AlfrescoNames.Prefixes.Path + SpisumNames.Paths.MailRoomDataBox, StringComparison.OrdinalIgnoreCase) == false)
                {
                    throw new BadRequestException("", "Node is not in Databox");
                }

                body = new NodeBodyUpdate
                {
                    Properties = new Dictionary <string, object>
                    {
                        { SpisumNames.Properties.DataBoxNotRegisteredReason, parameters.Body.Reason }
                    }
                };
                path = SpisumNames.Paths.MailRoomDataBoxNotRegistered;
                break;
            }

            await _alfrescoHttpClient.UpdateNode(parameters.NodeId, body);

            await _nodesService.MoveChildrenByPath(parameters.NodeId, path);
        }
        public DocumentFromSignatureValidator(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);

                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(x => $"Provided nodeId must be NodeType {SpisumNames.NodeTypes.Document}");

                RuleFor(x => x.NodeId)
                .Must(x => _nodeEntry.Entry.Path.Name.EndsWith(SpisumNames.Paths.DocumentsForSignature) ||
                      _nodeEntry.Entry.Path.Name.EndsWith(SpisumNames.Paths.FilesDocumentsForSignature))
                .WithMessage(
                    $"NodeId must be in path {SpisumNames.Paths.EvidenceDocumentsForProcessingForSignature(identityUser.RequestGroup)} or " +
                    $"{SpisumNames.Paths.EvidenceFilesDocumentsForProcessingForSignature(identityUser.RequestGroup)}.");
            });
        }
Exemple #5
0
        public async Task SendEmail([FromRoute] EmailSend parameters)
        {
            var emlNode = await _alfrescoHttpClient.GetNodeInfo(parameters.NodeId, ImmutableList <Parameter> .Empty
                                                                .Add(new Parameter(AlfrescoNames.Headers.Include, AlfrescoNames.Includes.Path, ParameterType.QueryString)));

            if (emlNode?.Entry?.Path?.Name.StartsWith(AlfrescoNames.Prefixes.Path + SpisumNames.Paths.MailRoomEmail, StringComparison.OrdinalIgnoreCase) == false)
            {
                throw new BadRequestException("", "Node is not in Mailroom");
            }

            var emailProperties = emlNode.Entry.Properties.As <JObject>().ToDictionary();

            if (emailProperties.GetNestedValueOrDefault(SpisumNames.Properties.EmailSender) == null)
            {
                throw new BadRequestException(ErrorCodes.V_EMAIL_NO_SENDER);
            }

            if (emailProperties.GetNestedValueOrDefault(SpisumNames.Properties.EmailRecipient) == null)
            {
                throw new BadRequestException(ErrorCodes.V_EMAIL_NO_RECIPIENT);
            }

            string senderEmail    = emailProperties.GetNestedValueOrDefault(SpisumNames.Properties.EmailSender).ToString();
            string recipientEmail = emailProperties.GetNestedValueOrDefault(SpisumNames.Properties.EmailRecipient).ToString();

            if (!EmailUtils.IsValidEmail(senderEmail))
            {
                throw new BadRequestException(ErrorCodes.V_EMAIL_INVALID_SENDER);
            }
            if (!EmailUtils.IsValidEmail(recipientEmail))
            {
                throw new BadRequestException(ErrorCodes.V_EMAIL_INVALID_RECIPIENT);
            }

            var emailConfiguration = (await _emailHttpClient.Accounts())?.FirstOrDefault(x => x?.Username?.ToLower() == recipientEmail?.ToLower());

            if (emailConfiguration == null)
            {
                throw new BadRequestException(ErrorCodes.V_EMAIL_NO_CONFIGURATION);
            }

            if (emlNode?.Entry?.Path?.Name?.Equals(AlfrescoNames.Prefixes.Path + SpisumNames.Paths.MailRoomEmailUnprocessed) != true)
            {
                throw new BadRequestException("", "Node is not in expected path");
            }

            await _emailHttpClient.Send(senderEmail, emailConfiguration.Username, parameters.Subject, parameters.Body, parameters.Files);

            // Move eml and children
            await _nodesService.MoveChildrenByPath(emlNode.Entry.Id, SpisumNames.Paths.MailRoomEmailNotRegistered);

            await _alfrescoHttpClient.UpdateNode(parameters.NodeId, new NodeBodyUpdate
            {
                Properties = new Dictionary <string, object>
                {
                    { SpisumNames.Properties.EmailNotRegisteredReason, "EM_VAL_01" }
                }
            }
                                                 );
        }
        public DocumentForSignatureValidator(
            IAlfrescoHttpClient alfrescoHttpClient,
            IIdentityUser identityUser,
            IAlfrescoConfiguration alfrescoConfiguration,
            ISimpleMemoryCache simpleMemoryCache,
            ISystemLoginService systemLoginService)
        {
            var adminHttpClient = new AlfrescoHttpClient(alfrescoConfiguration, new AdminAuthentification(simpleMemoryCache, alfrescoConfiguration, systemLoginService));

            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)));
                _groupPagingCurrentUser = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);
                _groupPagingNextOwner   = await adminHttpClient.GetPersonGroups(context.Body.User);

                return(_nodeEntry?.Entry?.Id != null && _groupPagingCurrentUser != null && _groupPagingNextOwner != null);
            })
            .WithName(x => nameof(x.NodeId))
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(y => _groupPagingCurrentUser?.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)
                .Must(y => _groupPagingNextOwner?.List?.Entries?.Any(q => q.Entry.Id == $"{y.Body.Group}_Sign") ?? false)
                .WithName(x => "Group")
                .WithMessage("User for signing isn't member of group with postfix _Sign.");

                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(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.NodeId)
                .Must(x => _nodeEntry.Entry.Path.Name.Equals(AlfrescoNames.Prefixes.Path + SpisumNames.Paths.EvidenceDocumentsForProcessing(identityUser.RequestGroup)) ||
                      _nodeEntry.Entry.Path.Name.Equals(AlfrescoNames.Prefixes.Path + SpisumNames.Paths.EvidenceFilesDocumentsForProcessing(identityUser.RequestGroup)))
                .WithMessage($"NodeId must be in path {SpisumNames.Paths.EvidenceDocumentsForProcessing(identityUser.RequestGroup)} or {SpisumNames.Paths.EvidenceFilesDocumentsForProcessing(identityUser.RequestGroup)}.");
            });

            RuleFor(x => x)
            .Must(x => !string.IsNullOrEmpty(x?.Body?.User))
            .When(x => x?.Body != null)
            .WithName(x => nameof(x.Body.User))
            .WithMessage("You have to fill user.");

            RuleFor(x => x)
            .Must(x => !string.IsNullOrEmpty(x?.Body?.Group))
            .When(x => x?.Body != null)
            .WithName(x => nameof(x.Body.Group))
            .WithMessage("You have to fill group.");
        }
        public SignerCreateValidator(IAlfrescoHttpClient alfrescoHttpClient)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _nodeEntry = await alfrescoHttpClient.GetNodeInfo(context.DocumentId);

                return(_nodeEntry?.Entry?.Id != null);
            })
            .WithName(x => nameof(x.DocumentId))
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x.DocumentId)
                .Must(x => _nodeEntry?.Entry?.NodeType == SpisumNames.NodeTypes.Document)
                .OnAnyFailure(x => throw new BadRequestException($"NodeId {x.DocumentId} must be type of {SpisumNames.NodeTypes.Document}"));
            });

            RuleFor(x => x)
            .Must(x => x.ComponentId != null && x.ComponentId.All(x => !string.IsNullOrEmpty(x)))
            .When(x => x != null)
            .OnAnyFailure(x => throw new BadRequestException("Component id's can't be null."));

            RuleFor(x => x)
            .Must(x => !string.IsNullOrEmpty(x.DocumentId))
            .When(x => x != null)
            .OnAnyFailure(x => throw new BadRequestException("Document id can't be null."));
        }
Exemple #8
0
        public FileDocumentAddValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _nodeEntry   = await alfrescoHttpClient.GetNodeInfo(context.NodeId);
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);

                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.File)
                .WithMessage(x => $"Provided nodeId must be NodeType {SpisumNames.NodeTypes.File}");
            });
        }
        public DocumentChangeFileMarkValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser, INodesService nodesService)
        {
            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);


                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}.");
            });
        }
        public DocumentReturnForReworkValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);
                _nodeEntry   = await alfrescoHttpClient.GetNodeInfo(context.NodeId, ImmutableList <Parameter> .Empty
                                                                    .Add(new Parameter(AlfrescoNames.Headers.Include, $"{AlfrescoNames.Includes.Path}", ParameterType.QueryString)));

                return(_groupPaging != null && _nodeEntry?.Entry?.Id != 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.Path.Name.Equals(AlfrescoNames.Prefixes.Path + SpisumNames.Paths.EvidenceDocumentsForProcessingForSignature(identityUser.RequestGroup)) ||
                      _nodeEntry.Entry.Path.Name.Equals(AlfrescoNames.Prefixes.Path + SpisumNames.Paths.EvidenceFilesDocumentsForProcessingForSignature(identityUser.RequestGroup)))
                .WithMessage($"NodeId must be in path {SpisumNames.Paths.EvidenceDocumentsForProcessing(identityUser.RequestGroup)} or {SpisumNames.Paths.EvidenceFilesDocumentsForProcessing(identityUser.RequestGroup)}.");
            });

            RuleFor(x => x.Body.Reason)
            .MinimumLength(4)
            .MaximumLength(30)
            .When(x => x.Body != null)
            .WithMessage("Reason must be at least 4 characters long but maximum 30 characters long");
        }
        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.");
            });
        }
Exemple #12
0
        public async Task <NodeEntry> ConvertToOutputFormat(string documentId, string componentId, string reason, string organization)
        {
            var nodeEntry = await _alfrescoHttpClient.GetNodeInfo(componentId, ImmutableList <Parameter> .Empty
                                                                  .Add(new Parameter(AlfrescoNames.Headers.Include, $"{AlfrescoNames.Includes.Properties}, {AlfrescoNames.Includes.Path}", ParameterType.QueryString)));

            var extension = Path.GetExtension(nodeEntry?.Entry?.Name);

            if (!_fileExtensions.Any(x => extension.Contains(x)))
            {
                return(await _alfrescoHttpClient.UpdateNode(componentId, new NodeBodyUpdate()
                                                            .AddProperty(SpisumNames.Properties.FileIsInOutputFormat, "impossible")));
            }

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

            var componentPid = pid.Split('/');

            FormDataParam pdf = null;

            if (nodeEntry?.Entry?.Content.MimeType != MediaTypeNames.Application.Pdf)
            {
                pdf = await _alfrescoHttpClient.GetThumbnailPdf(componentId, ImmutableList <Parameter> .Empty
                                                                .Add(new Parameter("c", "force", ParameterType.QueryString)));
            }
            else
            {
                pdf = await _alfrescoHttpClient.NodeContent(componentId);
            }

            var data = await _pdfService.ConvertToPdfA2B(new MemoryStream(pdf.File));

            if (_signerConfiguration.Base != null || _signerConfiguration.Url != null)
            {
                SealResponse signer = await _signerClient.Seal(data);

                await _signerService.CheckAndUpdateComponent(componentId, signer.Output);

                data = signer.Output;
            }

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

            return(await _alfrescoHttpClient.UpdateNode(componentId, new NodeBodyUpdate()
                                                        .AddProperty(SpisumNames.Properties.FileIsInOutputFormat, "yes")
                                                        .AddProperty(SpisumNames.Properties.FinalVersion, true)
                                                        .AddProperty(SpisumNames.Properties.SettleReason, reason)
                                                        .AddProperty(SpisumNames.Properties.KeepForm, SpisumNames.KeepForm.Original_InOutputFormat)
                                                        .AddProperty(SpisumNames.Properties.LinkRendering, int.Parse(componentPid[1]) + 1)
                                                        .AddProperty(SpisumNames.Properties.ListOriginalComponent, int.Parse(componentPid[1]))
                                                        .AddProperty(SpisumNames.Properties.CompanyImplementingDataFormat, organization)
                                                        .AddProperty(SpisumNames.Properties.AuthorChangeOfDataFormat, $"{_identityUser.FirstName} {_identityUser.LastName}")
                                                        .AddProperty(SpisumNames.Properties.OriginalDataFormat, nodeEntry?.Entry?.Content?.MimeType)
                                                        .AddProperty(SpisumNames.Properties.ImprintFile, Hashes.Sha256CheckSum(new MemoryStream(data)))
                                                        .AddProperty(SpisumNames.Properties.DataCompleteVerificationItem, DateTime.Now)
                                                        .AddProperty(SpisumNames.Properties.UsedAlgorithm, "SHA-256")));
        }
Exemple #13
0
        public ShipmentCreatePublishValidator(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);

                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(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.Body.Components)
            .Must(y => y?.Count > 0)
            .When(x => x.Body != null)
            .WithName(x => "Components")
            .WithMessage("Components cannot be empty");

            RuleFor(x => x.Body.DateFrom)
            .Must(y => y.HasValue && CompareDateTime(y.Value))
            .When(x => x.Body != null)
            .WithName(x => "DateFrom")
            .WithMessage("DateFrom cannot be in past");

            RuleFor(x => x.Body.Days)
            .Must(y => y.HasValue ? y.Value > 0 : true)
            .When(x => x.Body != null)
            .WithName(x => "Days")
            .WithMessage("Days must be greater than 0");

            RuleFor(x => x.Body.Note)
            .MaximumLength(255)
            .When(x => x.Body != null)
            .WithName(x => "Note")
            .WithMessage("Message cannot be longer than 255 characters");
        }
        public FileCloseValidator(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},{AlfrescoNames.Includes.Properties}", ParameterType.QueryString)));
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);

                return(_groupPaging != null && _nodeEntry?.Entry?.Id != null);
            })
            .WithName("Document")
            .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 =>
            {
                if (x?.Body?.SettleMethod != "jinyZpusob")
                {
                    return(true);
                }

                if (x?.Body?.CustomSettleMethod == null || x?.Body?.SettleReason == null)
                {
                    return(false);
                }

                if (x.Body.CustomSettleMethod.Length < 4 || x.Body.SettleReason.Length < 4)
                {
                    throw new BadRequestException(ErrorCodes.V_MIN_TEXT);
                }

                x.Body.CustomSettleMethod = x.Body.CustomSettleMethod.CutLength(30);
                x.Body.SettleReason       = x.Body.SettleReason.CutLength(30);

                return(true);
            })
            .WithName(x => nameof(x.Body.SettleMethod))
            .WithMessage("You have to fill CustomSettleMethod and SettleReason.");
        }
        public DocumentToRepositoryDocumentValidator(IAlfrescoHttpClient alfrescoHttpClient, INodesService nodesService)
        {
            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},{AlfrescoNames.Includes.Properties}", ParameterType.QueryString)));

                _secondaryChildren = await nodesService.GetSecondaryChildren(context.NodeId, new List <string>
                {
                    SpisumNames.Associations.ShipmentsCreated,
                    SpisumNames.Associations.ShipmentsToDispatch,
                    SpisumNames.Associations.ShipmentsToReturn
                });

                return(_nodeEntry?.Entry?.Id != null && _secondaryChildren != null);
            })
            .WithName("Document")
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x.NodeId)
                .Must(x => _nodeEntry.Entry.NodeType == SpisumNames.NodeTypes.Document)
                .OnAnyFailure(x => throw new Exception($"Provided nodeId must be NodeType of {SpisumNames.NodeTypes.Document}"));

                RuleFor(x => x.NodeId)
                .Must(x => _secondaryChildren.Count == 0)
                .OnAnyFailure(x => throw new Exception($"Not all shipments are dispatched for nodeId {x.NodeId}"));

                RuleFor(x => x.NodeId)
                .Must(x =>
                {
                    var nodeProperties = _nodeEntry.Entry.Properties.As <JObject>().ToDictionary();
                    if (nodeProperties.GetNestedValueOrDefault(SpisumNames.Properties.Form)?.ToString() == "analog" &&
                        nodeProperties.GetNestedValueOrDefault(SpisumNames.Properties.ListCount)?.ToString() == null)
                    {
                        return(false);
                    }

                    if (_oneOfThemNotNull.All(property => nodeProperties.GetNestedValueOrDefault(property)?.ToString() == null))
                    {
                        return(false);
                    }

                    return(_notNullProperties.All(property => nodeProperties.GetNestedValueOrDefault(property)?.ToString() != null));
                })
                .OnAnyFailure(x => throw new Exception($"Missing properties in metadata {string.Join(", ", _notNullProperties)}"));
            });
        }
Exemple #16
0
        private async Task <string> getNodeId(string path)
        {
            try
            {
                var response = await _alfrescoHttpClient.GetNodeInfo(AlfrescoNames.Aliases.Root, ImmutableList <Parameter> .Empty
                                                                     /*.Add(new Parameter(AlfrescoNames.Headers.Fields, "id", ParameterType.QueryString))*/
                                                                     .Add(new Parameter(AlfrescoNames.Headers.RelativePath, $"Sites/{path}", ParameterType.QueryString)));

                return(response?.Entry?.Id);
            }
            catch
            {
            }

            return(null);
        }
        public DocumentComponentOutputFormatValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _nodeEntry = await alfrescoHttpClient.GetNodeInfo(context.ComponentId, ImmutableList <Parameter> .Empty
                                                                  .Add(new Parameter(AlfrescoNames.Headers.Include, AlfrescoNames.Includes.Properties, ParameterType.QueryString)));
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);

                return(_nodeEntry?.Entry?.Id != null && _groupPaging != null);
            })
            .WithName(x => nameof(x.ComponentId))
            .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.ComponentId)
                .Must(x => _nodeEntry?.Entry?.NodeType == SpisumNames.NodeTypes.Component ||
                      _nodeEntry?.Entry?.NodeType == SpisumNames.NodeTypes.Email ||
                      _nodeEntry?.Entry?.NodeType == AlfrescoNames.ContentModel.Content ||
                      _nodeEntry?.Entry?.NodeType == SpisumNames.NodeTypes.EmailComponent ||
                      _nodeEntry?.Entry?.NodeType == SpisumNames.NodeTypes.DataBoxComponent)
                .WithMessage($"NodeId must be type of {SpisumNames.NodeTypes.Component}.");

                RuleFor(x => x)
                .Must(x =>
                {
                    var properties           = _nodeEntry?.Entry?.Properties?.As <JObject>().ToDictionary();
                    var fileIsInOutputFormat = properties.GetNestedValueOrDefault(SpisumNames.Properties.FileIsInOutputFormat)?.ToString();

                    return(fileIsInOutputFormat != "yes");
                })
                .WithMessage("Component is already in output format.");
            });

            RuleFor(x => x.Body.Reason)
            .MinimumLength(4)
            .MaximumLength(30)
            .NotNull()
            .When(x => x.Body != null)
            .WithName(x => nameof(x.Body.Reason));
        }
Exemple #18
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);
        }
Exemple #19
0
        public async Task <NodeEntry> GetFile([FromRoute] string nodeId, [FromQuery] BasicNodeQueryParamsWithRelativePath queryParams)
        {
            var nodeInfo = await _alfrescoHttpClient.GetNodeInfo(nodeId, ImmutableList <Parameter> .Empty.AddQueryParams(queryParams));

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

                await _auditLogService.Record(nodeInfo?.Entry?.Id, SpisumNames.NodeTypes.File, componentPid, NodeTypeCodes.Spis, EventCodes.Zobrazeni,
                                              TransactinoHistoryMessages.File);
            }
            catch (Exception ex)
            {
                Log.Logger?.Error(ex, "Audit log failed");
            }

            return(nodeInfo);
        }
        public FileShipmentSendValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser, INodesService nodesService)
        {
            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)));

                await context.ShipmentsId?.ForEachAsync(async x =>
                {
                    _parents.Add(new ParentShipmentInfo
                    {
                        ShipmentId = x,
                        Parents    = await nodesService.GetParentsByAssociation(x, new List <string>
                        {
                            SpisumNames.Associations.ShipmentsCreated, SpisumNames.Associations.ShipmentsToReturn
                        })
                    });
                });

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

                return(_groupPaging != null && _nodeEntry != null && _parents != 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(y => _parents.All(p => p.Parents.Any(c => c.Entry.Id == y.NodeId)))
                .WithName(x => "Shipments")
                .WithMessage($"Not all shipments are type of {SpisumNames.Associations.ShipmentsCreated} or {SpisumNames.Associations.ShipmentsToReturn} or not all shipments are not associated with nodeId");
            });
        }
        public FileToRepositoryFileValidator(IAlfrescoHttpClient alfrescoHttpClient)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _nodeEntry = await alfrescoHttpClient.GetNodeInfo(context.NodeId);

                return(_nodeEntry?.Entry?.Id != null);
            })
            .WithName("File")
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x.NodeId)
                .Must(x => _nodeEntry.Entry.NodeType == SpisumNames.NodeTypes.File)
                .OnAnyFailure(x => throw new Exception($"Provided nodeId must be NodeType of {SpisumNames.NodeTypes.File}"));
            });
        }
Exemple #22
0
        public ComponentValidator(IAlfrescoHttpClient alfrescoHttpClient)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _nodeEntry = await alfrescoHttpClient.GetNodeInfo(context.NodeId);

                return(_nodeEntry?.Entry?.Id != null);
            })
            .WithName(x => nameof(x.NodeId))
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x.NodeId)
                .Must(x => _nodeEntry?.Entry?.NodeType == SpisumNames.NodeTypes.Component)
                .OnAnyFailure(x => throw new BadRequestException($"NodeId {x.NodeId} must be type of {SpisumNames.NodeTypes.Component}"));
            });
        }
        public DocumentShreddingSValidator(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)));
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);

                return(_nodeEntry != 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(x =>
                      _nodeEntry?.Entry?.Path?.Name?.StartsWith(AlfrescoNames.Prefixes.Path + SpisumNames.Paths.RepositoryDocumentsStored, StringComparison.OrdinalIgnoreCase) == true ||
                      _nodeEntry?.Entry?.Path?.Name?.StartsWith(AlfrescoNames.Prefixes.Path + SpisumNames.Paths.RepositoryDocumentsRented, StringComparison.OrdinalIgnoreCase) == true)
                .OnAnyFailure(x => throw new BadRequestException($"Document must be in {SpisumNames.Paths.RepositoryDocumentsStored} or {SpisumNames.Paths.RepositoryDocumentsRented} path."));

                RuleFor(x => x.NodeId)
                .Must(x =>
                {
                    var nodeProperties = _nodeEntry.Entry.Properties.As <JObject>().ToDictionary();
                    var retentionMark  = nodeProperties.GetNestedValueOrDefault(SpisumNames.Properties.RetentionMark)?.ToString();

                    return(retentionMark == "A" || retentionMark == "V");
                })
                .WithMessage(x => "RetentionMark isn't A or V.");
            });
        }
Exemple #24
0
        public ConceptCancelValidator(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);

                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(x => _nodeEntry?.Entry?.Path?.Name?.StartsWith(AlfrescoNames.Prefixes.Path + SpisumNames.Paths.Evidence, StringComparison.OrdinalIgnoreCase) == true)
                .OnAnyFailure(x => throw new BadRequestException("Concept must be in evidence site."));

                RuleFor(x => x)
                .Must(x => _nodeEntry?.Entry?.Path?.Name?.StartsWith(AlfrescoNames.Prefixes.Path + SpisumNames.Paths.EvidenceConcepts(identityUser.RequestGroup), StringComparison.OrdinalIgnoreCase) == true)
                .OnAnyFailure(x => throw new BadRequestException("Concept can't be cancelled"));

                RuleFor(x => x.NodeId)
                .Must(IsNodePathAllowed);

                RuleFor(x => x)
                .Must(CheckReasonLength);
            });
        }
Exemple #25
0
        public ShipmentDispatchPostValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser, INodesService nodesService)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);
                _nodeEntry   = await alfrescoHttpClient.GetNodeInfo(context.NodeId, ImmutableList <Parameter> .Empty
                                                                    .Add(new Parameter(AlfrescoNames.Headers.Include, AlfrescoNames.Includes.Path, ParameterType.QueryString)));
                _nodeParents = await nodesService.GetParentsByAssociation(context.NodeId, new List <string> {
                    SpisumNames.Associations.ShipmentsToDispatch
                });

                return(_groupPaging != null && _nodeEntry != null && _nodeParents != null);
            })
            .WithName("Document")
            .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(q => _nodeEntry?.Entry?.NodeType == SpisumNames.NodeTypes.ShipmentPost)
                .WithName("NodeId")
                .WithMessage($"Provided node must be type of {SpisumNames.NodeTypes.ShipmentPost}.");

                RuleFor(x => x.NodeId)
                .Must(q => _nodeEntry?.Entry?.Path?.Name == AlfrescoNames.Prefixes.Path + SpisumNames.Paths.DispatchToDispatch)
                .WithName("NodeId")
                .WithMessage($"Provided node must be located in {AlfrescoNames.Prefixes.Path + SpisumNames.Paths.DispatchToDispatch}.");

                RuleFor(x => x.NodeId)
                .Must(q => _nodeParents?.Count > 0)
                .WithName("NodeId")
                .WithMessage($"Provided node is not child type of {SpisumNames.Associations.ShipmentsToDispatch}");
            });
        }
        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");
            });
        }
Exemple #27
0
        public DocumentOwnerAcceptValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser)
        {
            _identityUser = 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.Permissions}, {AlfrescoNames.Includes.Path}",
                                                                                     ParameterType.QueryString)));
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);

                return(_nodeEntry != 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(HasAction)
                .WithMessage("NodeIs has no accept action.");

                RuleFor(x => x.NodeId)
                .Must(CanUserMakeAction)
                .WithMessage("User has no access to this action.");

                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."));
            });
        }
        public ConceptToDocumentValidator(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);

                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.Body.SettleTo)
            .Must(x => x.HasValue ? x.Value.Date >= DateTime.UtcNow.Date : true)
            .When(w => w.Body != null)
            .WithMessage("SettleTo can't be in the past");

            RuleFor(x => x.Body.AttachmentsCount)
            .GreaterThanOrEqualTo(0)
            .When(w => w.Body != null)
            .WithMessage("AttachmentCount can't be negative number");
        }
        public DocumentBorrowValidator(IAlfrescoHttpClient alfrescoHttpClient,
                                       IIdentityUser identityUser,
                                       IAlfrescoConfiguration alfrescoConfiguration,
                                       ISimpleMemoryCache simpleMemoryCache,
                                       ISystemLoginService systemLoginService)
        {
            var adminHttpClient = new AlfrescoHttpClient(alfrescoConfiguration, new AdminAuthentification(simpleMemoryCache, alfrescoConfiguration, systemLoginService));

            _identityUser = 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)));

                var documentProperties = _nodeEntry?.Entry?.Properties?.As <JObject>().ToDictionary();
                _borrowedUser          = documentProperties.GetNestedValueOrDefault(SpisumNames.Properties.Borrower)?.ToString();

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

                _groupRepository = await alfrescoHttpClient.GetGroupMembers(SpisumNames.Groups.RepositoryGroup,
                                                                            ImmutableList <Parameter> .Empty.Add(new Parameter(AlfrescoNames.Headers.Where, AlfrescoNames.MemberType.Group, ParameterType.QueryString)));

                _groupPagingNextOwner = await adminHttpClient.GetPersonGroups(context.Body.User);

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

                RuleFor(x => x)
                .Must(y =>
                {
                    return(_groupRepository?.List?.Entries?.Any(x => x.Entry.Id == identityUser.RequestGroup) ?? false);
                })
                .WithName(x => "User")
                .WithMessage("User isn't member of repository group");

                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(x => _nodeEntry?.Entry?.Path?.Name?.StartsWith(AlfrescoNames.Prefixes.Path + SpisumNames.Paths.RepositoryDocuments, StringComparison.OrdinalIgnoreCase) == true)
                .OnAnyFailure(x => throw new BadRequestException("Document must be in repository site."));

                RuleFor(x => x)
                .Must(x => string.IsNullOrWhiteSpace(_borrowedUser))
                .WithMessage("Document is already borrowed");
            });
        }
Exemple #30
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."));
            });
        }