Exemplo n.º 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")));
        }