Example #1
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")));
        }
Example #2
0
        public async Task <FileContentResult> GetThumbnailPdf([FromRoute] string nodeId, [FromRoute] string componentId)
        {
            var fileContent = await _alfrescoHttpClient.GetThumbnailPdf(componentId, ImmutableList <Parameter> .Empty
                                                                        .Add(new Parameter("c", "force", ParameterType.QueryString))
                                                                        .Add(new Parameter("noCache", DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds, ParameterType.QueryString)));

            if (fileContent != null)
            {
                try
                {
                    var componentEntry = await _alfrescoHttpClient.GetNodeInfo(componentId);

                    var documentParent = await _nodesService.GetParentsByAssociation(componentId, new List <string> {
                        SpisumNames.Associations.Components
                    });

                    var documentEntry = await _alfrescoHttpClient.GetNodeInfo(documentParent?.FirstOrDefault()?.Entry?.Id);

                    var componentPid = componentEntry?.GetPid();

                    await _auditLogService.Record(documentEntry?.Entry?.Id, SpisumNames.NodeTypes.Component, componentPid, NodeTypeCodes.Komponenta, EventCodes.Zobrazeni, TransactinoHistoryMessages.DocumentComponentGetContentDocument);

                    var fileId = await _documentService.GetDocumentFileId(documentEntry?.Entry?.Id);

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

                return(new FileContentResult(fileContent.File, fileContent.ContentType)
                {
                    FileDownloadName = $"{fileContent.FileName}"
                });
            }

            throw new Exception();
        }