예제 #1
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");
            }
        }
 public MainController(NodesService service)
 {
     _service = service;
 }