diff --git a/Apps/W1/EDocumentConnectors/Logiq/app/src/Auth.Codeunit.al b/Apps/W1/EDocumentConnectors/Logiq/app/src/Auth.Codeunit.al index 48aa4a75da..4508f4e8e9 100644 --- a/Apps/W1/EDocumentConnectors/Logiq/app/src/Auth.Codeunit.al +++ b/Apps/W1/EDocumentConnectors/Logiq/app/src/Auth.Codeunit.al @@ -1,5 +1,5 @@ namespace Microsoft.EServices.EDocumentConnector.Logiq; -codeunit 6380 Auth +codeunit 6383 Auth { internal procedure SetIsolatedStorageValue(var ValueKey: Guid; Value: SecretText; TokenDataScope: DataScope) begin diff --git a/Apps/W1/EDocumentConnectors/Logiq/app/src/ConnectionSetup.Table.al b/Apps/W1/EDocumentConnectors/Logiq/app/src/ConnectionSetup.Table.al index 369cbf9d2a..72a0332141 100644 --- a/Apps/W1/EDocumentConnectors/Logiq/app/src/ConnectionSetup.Table.al +++ b/Apps/W1/EDocumentConnectors/Logiq/app/src/ConnectionSetup.Table.al @@ -4,6 +4,8 @@ table 6380 "Connection Setup" { Caption = 'Logiq Connection Setup'; DataClassification = CustomerContent; + Access = Internal; + fields { field(1; PK; Code[20]) diff --git a/Apps/W1/EDocumentConnectors/Logiq/app/src/ConnectionUserSetup.Table.al b/Apps/W1/EDocumentConnectors/Logiq/app/src/ConnectionUserSetup.Table.al index b68e93be7d..e12c2f3cb2 100644 --- a/Apps/W1/EDocumentConnectors/Logiq/app/src/ConnectionUserSetup.Table.al +++ b/Apps/W1/EDocumentConnectors/Logiq/app/src/ConnectionUserSetup.Table.al @@ -6,6 +6,7 @@ table 6381 "Connection User Setup" { Caption = 'Logiq Connection User Setup'; DataClassification = CustomerContent; + Access = Internal; fields { diff --git a/Apps/W1/EDocumentConnectors/Logiq/app/src/EDocumentIntegration.Codeunit.al b/Apps/W1/EDocumentConnectors/Logiq/app/src/EDocumentIntegration.Codeunit.al index 6d50bda2fa..4340feb709 100644 --- a/Apps/W1/EDocumentConnectors/Logiq/app/src/EDocumentIntegration.Codeunit.al +++ b/Apps/W1/EDocumentConnectors/Logiq/app/src/EDocumentIntegration.Codeunit.al @@ -2,51 +2,35 @@ namespace Microsoft.EServices.EDocumentConnector.Logiq; using Microsoft.eServices.EDocument; using System.Utilities; +using Microsoft.eServices.EDocument.Integration.Interfaces; +using Microsoft.eServices.EDocument.Integration.Send; +using Microsoft.eServices.EDocument.Integration.Receive; -codeunit 6381 "E-Document Integration" implements "E-Document Integration" +codeunit 6381 "E-Document Integration" implements IDocumentSender, IDocumentReceiver { Access = Internal; - procedure Send(var EDocument: Record "E-Document"; var TempBlob: Codeunit "Temp Blob"; var IsAsync: Boolean; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage) + procedure Send(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service"; SendContext: Codeunit SendContext); begin - this.LogiqEDocumentManagement.Send(EDocument, TempBlob, IsAsync, HttpRequest, HttpResponse); + this.LogiqEDocumentManagement.Send(EDocument, EDocumentService, SendContext); end; -#pragma warning disable AA0150 - procedure SendBatch(var EDocuments: Record "E-Document"; var TempBlob: Codeunit "Temp Blob"; var IsAsync: Boolean; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage) + procedure ReceiveDocuments(var EDocumentService: Record "E-Document Service"; DocumentsMetadata: Codeunit "Temp Blob List"; ReceiveContext: Codeunit ReceiveContext) begin - Error('Batch sending is not supported'); - end; -#pragma warning restore AA0150 - procedure GetResponse(var EDocument: Record "E-Document"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage): Boolean - begin - Error('Getting response is not supported'); - end; - - procedure GetApproval(var EDocument: Record "E-Document"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage): Boolean - begin - Error('Approval is not supported'); + this.LogiqEDocumentManagement.ReceiveDocuments(EDocumentService, DocumentsMetadata, ReceiveContext); end; - procedure Cancel(var EDocument: Record "E-Document"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage): Boolean + procedure DownloadDocument(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service"; DocumentMetadata: Codeunit "Temp Blob"; ReceiveContext: Codeunit ReceiveContext) begin - Error('Cancelling sent document is not supported'); + this.LogiqEDocumentManagement.DownloadDocument(EDocument, EDocumentService, DocumentMetadata, ReceiveContext); end; - procedure ReceiveDocument(var TempBlob: Codeunit "Temp Blob"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage) - begin - this.LogiqEDocumentManagement.DownloadDocuments(TempBlob, HttpRequest, HttpResponse); - end; - - procedure GetDocumentCountInBatch(var TempBlob: Codeunit "Temp Blob"): Integer - begin - exit(this.LogiqEDocumentManagement.GetDocumentCountInBatch(TempBlob)); - end; - procedure GetIntegrationSetup(var SetupPage: Integer; var SetupTable: Integer) + [EventSubscriber(ObjectType::Page, Page::"E-Document Service", OnBeforeOpenServiceIntegrationSetupPage, '', false, false)] + local procedure OnBeforeOpenServiceIntegrationSetupPage(EDocumentService: Record "E-Document Service"; var SetupPage: Integer) begin - SetupTable := Database::"Connection Setup"; - SetupPage := Page::"Connection Setup"; + if EDocumentService."Service Integration V2" = EDocumentService."Service Integration V2"::Logiq then + SetupPage := Page::"Connection Setup"; end; var diff --git a/Apps/W1/EDocumentConnectors/Logiq/app/src/EDocumentIntegration.EnumExt.al b/Apps/W1/EDocumentConnectors/Logiq/app/src/EDocumentIntegration.EnumExt.al index ae3794ae78..53845b243c 100644 --- a/Apps/W1/EDocumentConnectors/Logiq/app/src/EDocumentIntegration.EnumExt.al +++ b/Apps/W1/EDocumentConnectors/Logiq/app/src/EDocumentIntegration.EnumExt.al @@ -1,12 +1,13 @@ namespace Microsoft.EServices.EDocumentConnector.Logiq; -using Microsoft.eServices.EDocument; +using Microsoft.eServices.EDocument.Integration; +using Microsoft.eServices.EDocument.Integration.Interfaces; -enumextension 6381 "E-Document Integration" extends "E-Document Integration" +enumextension 6381 "E-Document Integration" extends "Service Integration" { value(6381; "Logiq") { Caption = 'Logiq'; - Implementation = "E-Document Integration" = "E-Document Integration"; + Implementation = IDocumentSender = "E-Document Integration", IDocumentReceiver = "E-Document Integration"; } -} +} \ No newline at end of file diff --git a/Apps/W1/EDocumentConnectors/Logiq/app/src/EDocumentManagement.Codeunit.al b/Apps/W1/EDocumentConnectors/Logiq/app/src/EDocumentManagement.Codeunit.al index d01732d395..490e6fd6d0 100644 --- a/Apps/W1/EDocumentConnectors/Logiq/app/src/EDocumentManagement.Codeunit.al +++ b/Apps/W1/EDocumentConnectors/Logiq/app/src/EDocumentManagement.Codeunit.al @@ -1,6 +1,8 @@ namespace Microsoft.EServices.EDocumentConnector.Logiq; using Microsoft.eServices.EDocument; +using Microsoft.eServices.EDocument.Integration.Send; +using Microsoft.eServices.EDocument.Integration.Receive; using System.Utilities; using System.Xml; @@ -10,7 +12,7 @@ codeunit 6382 "E-Document Management" Permissions = tabledata "E-Document" = m; #pragma warning disable AA0150 - internal procedure Send(var EDocument: Record "E-Document"; var TempBlob: Codeunit "Temp Blob"; var IsAsync: Boolean; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage) + internal procedure Send(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service"; SendContext: Codeunit SendContext) var LogiqConnectionUserSetup: Record "Connection User Setup"; LogiqAuth: Codeunit Auth; @@ -18,6 +20,8 @@ codeunit 6382 "E-Document Management" Headers: HttpHeaders; Content: HttpContent; ContentHeaders: HttpHeaders; + HttpRequest: HttpRequestMessage; + HttpResponse: HttpResponseMessage; BodyText: Text; FileNameText: Text; Boundary: Text; @@ -37,7 +41,7 @@ codeunit 6382 "E-Document Management" FileNameText := StrSubstNo(this.FileNameTok, EDocument."Document No."); Boundary := DelChr(Format(CreateGuid()), '<>=', '{}&[]*()!@#$%^+=;:"''<>,.?/|\\~`'); - BodyText := this.GetFileContentAsMultipart(TempBlob, FileNameText, Boundary); + BodyText := this.GetFileContentAsMultipart(SendContext.GetTempBlob(), FileNameText, Boundary); Content.WriteFrom(BodyText); Content.GetHeaders(ContentHeaders); @@ -71,7 +75,7 @@ codeunit 6382 "E-Document Management" HttpResponse: HttpResponseMessage; RequestSuccessful: Boolean; begin - if EDocumentService."Service Integration" <> EDocumentService."Service Integration"::Logiq then + if EDocumentService."Service Integration v2" <> EDocumentService."Service Integration v2"::Logiq then exit; RequestSuccessful := this.GetStatus(EDocument, HttpRequest, HttpResponse); @@ -114,15 +118,13 @@ codeunit 6382 "E-Document Management" exit(HttpResponse.IsSuccessStatusCode()); end; - internal procedure DownloadDocuments(var TempBlob: Codeunit "Temp Blob"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage) + internal procedure DownloadDocuments(var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage) var LogiqConnectionUserSetup: Record "Connection User Setup"; LogiqConnectionSetup: Record "Connection Setup"; LogiqAuth: Codeunit Auth; Client: HttpClient; Headers: HttpHeaders; - InStr: InStream; - OutStr: OutStream; begin HttpRequest.Method('GET'); @@ -139,25 +141,73 @@ codeunit 6382 "E-Document Management" Client.Send(HttpRequest, HttpResponse); - if HttpResponse.IsSuccessStatusCode() then begin - HttpResponse.Content.ReadAs(InStr); - TempBlob.CreateOutStream(OutStr, TextEncoding::UTF8); - CopyStream(OutStr, InStr); - end else + if not HttpResponse.IsSuccessStatusCode() then Error(this.DownloadDocumentsErr, HttpResponse.HttpStatusCode, HttpResponse.ReasonPhrase); end; - internal procedure GetDocumentCountInBatch(var TempBlob: Codeunit "Temp Blob"): Integer + internal procedure ReceiveDocuments(var EDocumentService: Record "E-Document Service"; Documents: Codeunit "Temp Blob List"; ReceiveContext: Codeunit ReceiveContext) var - JsonArray: JsonArray; + LogiqConnectionUserSetup: Record "Connection User Setup"; + LogiqConnectionSetup: Record "Connection Setup"; + LogiqAuth: Codeunit Auth; + TempBlob: Codeunit "Temp Blob"; + HttpRequest: HttpRequestMessage; + HttpResponse: HttpResponseMessage; + DocumentsArray: JsonArray; InStr: InStream; + OutStr: OutStream; + i: Integer; begin - TempBlob.CreateInStream(InStr, TextEncoding::UTF8); + HttpRequest.Method('GET'); + + LogiqAuth.CheckSetup(LogiqConnectionSetup); + LogiqAuth.CheckUserSetup(LogiqConnectionUserSetup); + LogiqAuth.CheckUpdateTokens(); - if not JsonArray.ReadFrom(InStr) then - exit(0); + this.DownloadDocuments(HttpRequest, HttpResponse); - exit(JsonArray.Count()); + HttpResponse.Content.ReadAs(InStr); + DocumentsArray.ReadFrom(InStr); + for i := 0 to DocumentsArray.Count() - 1 do begin + Clear(TempBlob); + TempBlob.CreateOutStream(OutStr, TextEncoding::UTF8); + DocumentsArray.GetObject(i).WriteTo(OutStr); + Documents.Add(TempBlob); + end; + + ReceiveContext.Http().SetHttpRequestMessage(HttpRequest); + ReceiveContext.Http().SetHttpResponseMessage(HttpResponse); + end; + + internal procedure DownloadDocument(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service"; Document: Codeunit "Temp Blob"; ReceiveContext: Codeunit ReceiveContext) + var + HttpRequest: HttpRequestMessage; + HttpResponse: HttpResponseMessage; + InStr: InStream; + OutStr: OutStream; + DocumentData, FileName : Text; + begin + Document.CreateInStream(InStr, TextEncoding::UTF8); + InStr.ReadText(DocumentData); + if not this.ParseReceivedFileName(DocumentData, FileName) then begin + this.EDocumentErrorHelper.LogSimpleErrorMessage(EDocument, this.FileNameNotFoundErr); + exit; + end; + + this.DownloadFile(FileName, HttpRequest, HttpResponse); + this.EDocumentLogHelper.InsertIntegrationLog(EDocument, EDocumentService, HttpRequest, HttpResponse); + + HttpResponse.Content.ReadAs(DocumentData); + if DocumentData = '' then + this.EDocumentErrorHelper.LogSimpleErrorMessage(EDocument, StrSubstNo(this.FileNotFoundErr, FileName)); + + ReceiveContext.GetTempBlob().CreateOutStream(OutStr, TextEncoding::UTF8); + OutStr.WriteText(DocumentData); + + this.EDocumentLogHelper.InsertLog(EDocument, EDocumentService, Document, "E-Document Service Status"::Imported); + + ReceiveContext.Http().SetHttpRequestMessage(HttpRequest); + ReceiveContext.Http().SetHttpResponseMessage(HttpResponse); end; internal procedure DownloadFile(FileName: Text; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage) @@ -265,26 +315,14 @@ codeunit 6382 "E-Document Management" EDocumentsErrorHelper.LogSimpleErrorMessage(EDocument, StrSubstNo(this.SendingFailedErr, ResponseMessage.HttpStatusCode(), ResponseMessage.ReasonPhrase())); end; - local procedure ParseReceivedFileName(ContentTxt: Text; Index: Integer; var FileName: Text): Boolean + local procedure ParseReceivedFileName(ContentTxt: Text; var FileName: Text): Boolean var - JsonArray: JsonArray; JsonObj: JsonObject; JsonTok: JsonToken; begin - if not JsonArray.ReadFrom(ContentTxt) then - exit(false); - - if Index > JsonArray.Count() then + if not JsonObj.ReadFrom(ContentTxt) then exit(false); - if Index = 0 then - JsonArray.Get(Index, JsonTok) - else - JsonArray.Get(Index - 1, JsonTok); - if not JsonTok.IsObject() then - exit(false); - - JsonObj := JsonTok.AsObject(); if not JsonObj.Get('fileName', JsonTok) then exit(false); @@ -318,52 +356,6 @@ codeunit 6382 "E-Document Management" end; end; - [EventSubscriber(ObjectType::Codeunit, Codeunit::"E-Doc. Import", OnAfterInsertImportedEdocument, '', false, false)] - local procedure OnAfterInsertEdocument(var EDocument: Record "E-Document"; EDocumentService: Record "E-Document Service"; var TempBlob: Codeunit "Temp Blob"; EDocCount: Integer; HttpRequest: HttpRequestMessage; HttpResponse: HttpResponseMessage) - var - LocalHttpRequest: HttpRequestMessage; - LocalHttpResponse: HttpResponseMessage; - DocumentOutStream: OutStream; - ContentData, FileName : Text; - begin - if EDocumentService."Service Integration" <> EDocumentService."Service Integration"::Logiq then - exit; - - HttpResponse.Content.ReadAs(ContentData); - if not this.ParseReceivedFileName(ContentData, EDocument."Index In Batch", FileName) then begin - this.EDocumentErrorHelper.LogSimpleErrorMessage(EDocument, this.FileNameNotFoundErr); - exit; - end; - - this.DownloadFile(FileName, LocalHttpRequest, LocalHttpResponse); - this.EDocumentLogHelper.InsertIntegrationLog(EDocument, EDocumentService, LocalHttpRequest, LocalHttpResponse); - - LocalHttpResponse.Content.ReadAs(ContentData); - if ContentData = '' then - this.EDocumentErrorHelper.LogSimpleErrorMessage(EDocument, StrSubstNo(this.FileNotFoundErr, FileName)); - - Clear(TempBlob); - TempBlob.CreateOutStream(DocumentOutStream, TextEncoding::UTF8); - DocumentOutStream.WriteText(ContentData); - - this.EDocumentLogHelper.InsertLog(EDocument, EDocumentService, TempBlob, "E-Document Service Status"::Imported); - end; - - [EventSubscriber(ObjectType::Codeunit, Codeunit::"E-Document Log", OnUpdateEDocumentStatus, '', false, false)] - local procedure OnUpdateEDocumentStatus(var EDocument: Record "E-Document"; var IsHandled: Boolean) - var - EDocumentServiceStatus: Record "E-Document Service Status"; - begin - EDocumentServiceStatus.SetRange("E-Document Entry No", EDocument."Entry No"); - EDocumentServiceStatus.SetRange(Status, EDocumentServiceStatus.Status::"Failed Logiq"); - - if not EDocumentServiceStatus.IsEmpty() then begin - EDocument.Validate(Status, EDocument.Status::Error); - EDocument.Modify(false); - IsHandled := true; - end; - end; - // copied from standard codeunit 6108 "E-Document Processing" because it is internal /// /// Updates existing service status record. Throws runtime error if record does not exists. diff --git a/Apps/W1/EDocumentConnectors/Logiq/test/src/IntegrationTests.Codeunit.al b/Apps/W1/EDocumentConnectors/Logiq/test/src/IntegrationTests.Codeunit.al index 24c53c6469..8cb3297a86 100644 --- a/Apps/W1/EDocumentConnectors/Logiq/test/src/IntegrationTests.Codeunit.al +++ b/Apps/W1/EDocumentConnectors/Logiq/test/src/IntegrationTests.Codeunit.al @@ -1,6 +1,7 @@ namespace Microsoft.EServices.EDocumentConnector.Logiq; using Microsoft.eServices.EDocument; +using Microsoft.eServices.EDocument.Integration; using Microsoft.Foundation.Company; using Microsoft.Sales.Customer; using Microsoft.Purchases.Vendor; @@ -367,8 +368,8 @@ codeunit 148201 "Integration Tests" exit; this.LibraryEDocument.SetupStandardVAT(); - this.LibraryEDocument.SetupStandardSalesScenario(this.Customer, this.EDocumentService, Enum::"E-Document Format"::"PEPPOL BIS 3.0", Enum::"E-Document Integration"::Logiq); - this.LibraryEDocument.SetupStandardPurchaseScenario(this.Vendor, this.EDocumentService, Enum::"E-Document Format"::"PEPPOL BIS 3.0", Enum::"E-Document Integration"::Logiq); + this.LibraryEDocument.SetupStandardSalesScenario(this.Customer, this.EDocumentService, Enum::"E-Document Format"::"PEPPOL BIS 3.0", Enum::"Service Integration"::Logiq); + this.LibraryEDocument.SetupStandardPurchaseScenario(this.Vendor, this.EDocumentService, Enum::"E-Document Format"::"PEPPOL BIS 3.0", Enum::"Service Integration"::Logiq); this.Vendor."VAT Registration No." := 'NO 777 777 777'; this.Vendor."Receive E-Document To" := Enum::"E-Document Type"::"Purchase Invoice";