Skip to content

Commit

Permalink
Merge pull request #2 from CristianMocanuContinia/continiaeDocConnector
Browse files Browse the repository at this point in the history
Code changes based on feedback comments
  • Loading branch information
CristianMocanuContinia authored Oct 9, 2024
2 parents 40246b7 + bbbb645 commit b37612a
Show file tree
Hide file tree
Showing 20 changed files with 379 additions and 398 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,66 +5,66 @@
namespace Microsoft.EServices.EDocumentConnector.Continia;
using System.Environment;

codeunit 6392 "API URL Mgt."
codeunit 6392 "Api Url Mgt."
{
Access = Internal;
internal procedure NetworkProfilesURL(Network: Enum "Network"; Page: Integer; PageSize: Integer): Text
internal procedure NetworkProfilesUrl(Network: Enum "E-Delivery Network"; Page: Integer; PageSize: Integer): Text
var
ProfilesUrlLbl: Label '%1/networks/%2/profiles.xml?page=%3&page_size=%4', Locked = true;
begin
exit(StrSubstNo(ProfilesUrlLbl, CDNBaseURL(), GetNetworkNameAsText(Network), Page, PageSize));
exit(StrSubstNo(ProfilesUrlLbl, CdnBaseUrl(), GetNetworkNameAsText(Network), Page, PageSize));
end;

internal procedure NetworkIdentifiersURL(Network: Enum "Network"; Page: Integer; PageSize: Integer): Text
internal procedure NetworkIdentifiersUrl(Network: Enum "E-Delivery Network"; Page: Integer; PageSize: Integer): Text
var
IdentifiersUrlLbl: Label '%1/networks/%2/id_types.xml?page=%3&page_size=%4', Locked = true;
begin
exit(StrSubstNo(IdentifiersUrlLbl, CDNBaseURL(), GetNetworkNameAsText(Network), Page, PageSize));
exit(StrSubstNo(IdentifiersUrlLbl, CdnBaseUrl(), GetNetworkNameAsText(Network), Page, PageSize));
end;

internal procedure ParticipationURL(Network: Enum "Network"): Text
internal procedure ParticipationUrl(Network: Enum "E-Delivery Network"): Text
var
ParticipationUrlLbl: Label '%1/networks/%2/participations.xml', Locked = true;
begin
exit(StrSubstNo(ParticipationUrlLbl, CDNBaseURL(), GetNetworkNameAsText(Network)))
exit(StrSubstNo(ParticipationUrlLbl, CdnBaseUrl(), GetNetworkNameAsText(Network)))
end;

internal procedure SingleParticipationURL(Network: Enum "Network"; ParticipationGUID: Guid): Text
internal procedure SingleParticipationUrl(Network: Enum "E-Delivery Network"; ParticipationGuid: Guid): Text
var
SingleParticipationUrlLbl: Label '%1/networks/%2/participations/%3.xml', Locked = true;
begin
exit(StrSubstNo(SingleParticipationUrlLbl, CDNBaseURL(), GetNetworkNameAsText(Network), GetGUIDAsText(ParticipationGUID)))
exit(StrSubstNo(SingleParticipationUrlLbl, CdnBaseUrl(), GetNetworkNameAsText(Network), GetGuidAsText(ParticipationGuid)))
end;

internal procedure ParticipationProfilesURL(Network: Enum "Network"; ParticipationGUID: Guid): Text
internal procedure ParticipationProfilesUrl(Network: Enum "E-Delivery Network"; ParticipationGuid: Guid): Text
var
ParticipationProfilesUrlLbl: Label '%1/networks/%2/participations/%3/profiles.xml', Locked = true;
begin
exit(StrSubstNo(ParticipationProfilesUrlLbl, CDNBaseURL(), GetNetworkNameAsText(Network), GetGUIDAsText(ParticipationGUID)))
exit(StrSubstNo(ParticipationProfilesUrlLbl, CdnBaseUrl(), GetNetworkNameAsText(Network), GetGuidAsText(ParticipationGuid)))
end;

internal procedure ParticipationProfilesURL(Network: Enum "Network"; ParticipationGUID: Guid; Page: Integer; PageSize: Integer): Text
internal procedure ParticipationProfilesUrl(Network: Enum "E-Delivery Network"; ParticipationGuid: Guid; Page: Integer; PageSize: Integer): Text
var
ParticipationProfilesUrlPagesLbl: Label '%1/networks/%2/participations/%3/profiles.xml?page=%4&page_size=%5', Locked = true;
begin
exit(StrSubstNo(ParticipationProfilesUrlPagesLbl, CDNBaseURL(), GetNetworkNameAsText(Network), GetGUIDAsText(ParticipationGUID), Page, PageSize))
exit(StrSubstNo(ParticipationProfilesUrlPagesLbl, CdnBaseUrl(), GetNetworkNameAsText(Network), GetGuidAsText(ParticipationGuid), Page, PageSize))
end;

internal procedure SingleParticipationProfileURL(Network: Enum "Network"; ParticipationGUID: Guid; ProfileGUID: Guid): Text
internal procedure SingleParticipationProfileUrl(Network: Enum "E-Delivery Network"; ParticipationGuid: Guid; ProfileGuid: Guid): Text
var
SingleParticipationProfileUrlLbl: Label '%1/networks/%2/participations/%3/profiles/%4.xml', Locked = true;
begin
exit(StrSubstNo(SingleParticipationProfileUrlLbl, CDNBaseURL(), GetNetworkNameAsText(Network), GetGUIDAsText(ParticipationGUID), GetGUIDAsText(ProfileGUID)))
exit(StrSubstNo(SingleParticipationProfileUrlLbl, CdnBaseUrl(), GetNetworkNameAsText(Network), GetGuidAsText(ParticipationGuid), GetGuidAsText(ProfileGuid)))
end;

internal procedure ParticipationLookupURL(Network: Enum "Network"; IdType: Text[4]; IdValue: Text[50]): Text
internal procedure ParticipationLookupUrl(Network: Enum "E-Delivery Network"; IdType: Text[4]; IdValue: Text[50]): Text
var
ParticipationLookupUrlLbl: Label '%1/networks/%2/participation_lookups.xml?id_type=%3&id_value=%4', Locked = true;
begin
exit(StrSubstNo(ParticipationLookupUrlLbl, CDNBaseURL(), GetNetworkNameAsText(Network), IdType, IdValue))
exit(StrSubstNo(ParticipationLookupUrlLbl, CdnBaseUrl(), GetNetworkNameAsText(Network), IdType, IdValue))
end;

internal procedure DocumentsForCompanyURL(CompanyGUID: Guid; Page: Integer; PageSize: Integer; Incoming: Boolean): Text
internal procedure DocumentsForCompanyUrl(CompanyGuid: Guid; Page: Integer; PageSize: Integer; Incoming: Boolean): Text
var
DirectionQueryTxt: Text;
DocumentsForCompanyUrlLbl: Label '%1/documents.xml?business_central_company_code=%2&page=%3&page_size=%4&direction=%5', Locked = true;
Expand All @@ -73,35 +73,35 @@ codeunit 6392 "API URL Mgt."
DirectionQueryTxt := 'IncomingEnum'
else
DirectionQueryTxt := 'OutgoingEnum';
exit(StrSubstNo(DocumentsForCompanyUrlLbl, CDNBaseURL(), GetGUIDAsText(CompanyGUID), Page, PageSize, DirectionQueryTxt))
exit(StrSubstNo(DocumentsForCompanyUrlLbl, CdnBaseUrl(), GetGuidAsText(CompanyGuid), Page, PageSize, DirectionQueryTxt))
end;

internal procedure DocumentActionUrl(DocumentGUID: Guid): Text
internal procedure DocumentActionUrl(DocumentGuid: Guid): Text
var
DocumentActionUrlLbl: Label '%1/documents/%2/action.xml', Locked = true;
begin
exit(StrSubstNo(DocumentActionUrlLbl, CDNBaseURL(), GetGUIDAsText(DocumentGUID)))
exit(StrSubstNo(DocumentActionUrlLbl, CdnBaseUrl(), GetGuidAsText(DocumentGuid)))
end;

internal procedure PostDocumentsUrl(CompanyGUID: Guid): Text
internal procedure PostDocumentsUrl(CompanyGuid: Guid): Text
var
PostDocumentsUrlLbl: Label '%1/documents.xml?business_central_company_code=%2', Locked = true;
begin
exit(StrSubstNo(PostDocumentsUrlLbl, CDNBaseURL(), GetGUIDAsText(CompanyGUID)))
exit(StrSubstNo(PostDocumentsUrlLbl, CdnBaseUrl(), GetGuidAsText(CompanyGuid)))
end;

internal procedure TechnicalResponseURL(DocumentGUID: Guid): Text
internal procedure TechnicalResponseUrl(DocumentGuid: Guid): Text
var
TechnicalResponseUrlLbl: Label '%1/documents/%2/technical_response.xml', Locked = true;
begin
exit(StrSubstNo(TechnicalResponseUrlLbl, CDNBaseURL(), GetGUIDAsText(DocumentGUID)))
exit(StrSubstNo(TechnicalResponseUrlLbl, CdnBaseUrl(), GetGuidAsText(DocumentGuid)))
end;

internal procedure BusinessResponseURL(DocumentGUID: Guid): Text
internal procedure BusinessResponseUrl(DocumentGuid: Guid): Text
var
BusinessResponseUrlLbl: Label '%1/documents/%2/business_responses.xml', Locked = true;
begin
exit(StrSubstNo(BusinessResponseUrlLbl, CDNBaseURL(), GetGUIDAsText(DocumentGUID)))
exit(StrSubstNo(BusinessResponseUrlLbl, CdnBaseUrl(), GetGuidAsText(DocumentGuid)))
end;

internal procedure PartnerAccessTokenUrl(): Text
Expand Down Expand Up @@ -160,27 +160,27 @@ codeunit 6392 "API URL Mgt."
exit(StrSubstNo(GetUpdateCompanyInfoUrlLbl, COBaseUrl()));
end;

local procedure COBaseUrl() URL: Text
local procedure COBaseUrl() Url: Text
var
Handled: Boolean;
begin
OnGetCOBaseUrl(URL, Handled);
OnGetCOBaseUrl(Url, Handled);
if Handled then
exit(URL);
exit(Url);

exit('https://auth.continiaonline.com/api/v1');
end;


internal procedure CDNBaseURL() URL: Text
internal procedure CdnBaseUrl() Url: Text
var
EnvironmentInformation: Codeunit "Environment Information";
Handled: Boolean;
LocalizedBaseUrl: Text;
begin
OnGetCDNBaseUrl(URL, Handled);
OnGetCdnBaseUrl(Url, Handled);
if Handled then
exit(URL);
exit(Url);

LocalizedBaseUrl := GetBaseUrlForLocalization(EnvironmentInformation.GetApplicationFamily());
if LocalizedBaseUrl <> '' then
Expand All @@ -202,12 +202,12 @@ codeunit 6392 "API URL Mgt."
end;
end;

internal procedure GetNetworkNameAsText(NetworkName: Enum "Network"): Text
internal procedure GetNetworkNameAsText(NetworkName: Enum "E-Delivery Network"): Text
begin
exit(NetworkName.Names.Get(NetworkName.Ordinals.IndexOf(NetworkName.AsInteger())));
end;

internal procedure GetGUIDAsText(Value: Guid): Text[36]
internal procedure GetGuidAsText(Value: Guid): Text[36]
begin
exit(CopyStr(DelChr(Value, '<>', '{}'), 1, 36))
end;
Expand All @@ -219,7 +219,7 @@ codeunit 6392 "API URL Mgt."
end;

[IntegrationEvent(false, false)]
local procedure OnGetCDNBaseUrl(var ReturnUrl: Text; var Handled: Boolean)
local procedure OnGetCdnBaseUrl(var ReturnUrl: Text; var Handled: Boolean)
begin
end;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ table 6390 "Connection Setup"
{
DataClassification = CustomerContent;
}
field(3; "Client ID"; Guid)
field(3; "Client Id"; Guid)
{
Caption = 'Client ID';
Caption = 'Client Id';
DataClassification = EndUserIdentifiableInformation;
}
field(4; "Client Secret"; Guid)
Expand Down Expand Up @@ -70,7 +70,7 @@ table 6390 "Connection Setup"
var
CredentialManagement: Codeunit "Credential Management";
begin
exit(CredentialManagement.GetIsolatedStorageValue("Client ID", DataScope::Module));
exit(CredentialManagement.GetIsolatedStorageValue("Client Id", DataScope::Module));
end;

internal procedure GetClientSecret(): SecretText
Expand All @@ -84,7 +84,7 @@ table 6390 "Connection Setup"
var
CredentialManagement: Codeunit "Credential Management";
begin
exit(CredentialManagement.SetIsolatedStorageValue("Client ID", Value, DataScope::Module));
exit(CredentialManagement.SetIsolatedStorageValue("Client Id", Value, DataScope::Module));
end;

internal procedure SetClientSecret(Value: SecretText) UsedNewKey: Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// ------------------------------------------------------------------------------------------------
namespace Microsoft.EServices.EDocumentConnector.Continia;
using Microsoft.eServices.EDocument;
using Microsoft.EServices.EDocumentConnector;
using System.Utilities;
using System.Telemetry;

Expand All @@ -15,7 +14,7 @@ codeunit 6391 "EDocument Processing"
var
EdocumentService: Record "E-Document Service";
EDocumentServiceStatus: Record "E-Document Service Status";
APIRequests: Codeunit "API Requests";
ApiRequests: Codeunit "Api Requests";
EDocumentHelper: Codeunit "E-Document Helper";
FeatureTelemetry: Codeunit "Feature Telemetry";
begin
Expand All @@ -25,33 +24,33 @@ codeunit 6391 "EDocument Processing"

case EDocumentServiceStatus.Status of
EDocumentServiceStatus.Status::Exported:
APIRequests.SendDocument(EDocument, TempBlob, HttpRequest, HttpResponse);
ApiRequests.SendDocument(EDocument, TempBlob, HttpRequest, HttpResponse);
EDocumentServiceStatus.Status::"Sending Error":
if EDocument."Document Id" = '' then
APIRequests.SendDocument(EDocument, TempBlob, HttpRequest, HttpResponse);
ApiRequests.SendDocument(EDocument, TempBlob, HttpRequest, HttpResponse);
end;

FeatureTelemetry.LogUptake('', ExternalServiceTok, Enum::"Feature Uptake Status"::Used);
end;

internal procedure GetTechnicalResponse(var EDocument: Record "E-Document"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage): Boolean
var
APIRequests: Codeunit "API Requests";
ApiRequests: Codeunit "Api Requests";
begin
APIRequests.SetSupressError(true);
ApiRequests.SetSupressError(true);

exit(APIRequests.GetTechnicalResponse(EDocument, HttpRequest, HttpResponse));
exit(ApiRequests.GetTechnicalResponse(EDocument, HttpRequest, HttpResponse));
end;

internal procedure GetLastDocumentBusinessResponses(var EDocument: Record "E-Document"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage): Boolean
var
APIRequests: Codeunit "API Requests";
DocumentGUID: Guid;
ApiRequests: Codeunit "Api Requests";
DocumentGuid: Guid;
begin
Evaluate(DocumentGUID, EDocument."Document Id");
Evaluate(DocumentGuid, EDocument."Document Id");

APIRequests.SetSupressError(true);
if not APIRequests.GetBusinessResponses(DocumentGUID, HttpRequest, HttpResponse) then
ApiRequests.SetSupressError(true);
if not ApiRequests.GetBusinessResponses(DocumentGuid, HttpRequest, HttpResponse) then
exit(false);

exit(IsDocumentApproved(HttpResponse));
Expand Down Expand Up @@ -168,7 +167,7 @@ codeunit 6391 "EDocument Processing"
[EventSubscriber(ObjectType::Codeunit, Codeunit::"E-Doc. Import", 'OnAfterInsertImportedEdocument', '', false, false)]
local procedure OnAfterInsertImportedEdocument(var EDocument: Record "E-Document"; EDocumentService: Record "E-Document Service"; var TempBlob: Codeunit "Temp Blob"; EDocCount: Integer; HttpRequest: HttpRequestMessage; HttpResponse: HttpResponseMessage)
var
APIRequests: Codeunit "API Requests";
ApiRequests: Codeunit "Api Requests";
EDocumentLogHelper: Codeunit "E-Document Log Helper";
ContentData: Text;
XMLFileToken: Text;
Expand Down Expand Up @@ -200,13 +199,13 @@ codeunit 6391 "EDocument Processing"
XMLFileToken := XMLFileTokenNode.AsXmlElement().InnerText;

// Download XML file from XMLFileToken and save to TempBlob
APIRequests.DownloadFileFromURL(XMLFileToken, TempBlob);
ApiRequests.DownloadFileFromUrl(XMLFileToken, TempBlob);

EDocumentLogHelper.InsertLog(EDocument, EDocumentService, TempBlob, "E-Document Service Status"::Imported);

// Mark document as processed in Continia Online
Evaluate(DocumentId, EDocument."Document Id");
APIRequests.MarkDocumentAsProcessed(DocumentId);
ApiRequests.MarkDocumentAsProcessed(DocumentId);
end;

[EventSubscriber(ObjectType::Codeunit, Codeunit::"E-Doc. Import", 'OnBeforeInsertImportedEdocument', '', false, false)]
Expand All @@ -232,7 +231,7 @@ codeunit 6391 "EDocument Processing"
DocumentXMLPathLbl: Label '/documents/document[%1]', Locked = true;
CurrentEDocumentNode: XmlNode;
ParticipationProfileIdNode: XmlNode;
ParticipationNetworkProfileID: Guid;
ParticipationNetworkProfileId: Guid;
begin
HttpResponse.Content.ReadAs(ContentData);

Expand All @@ -243,14 +242,14 @@ codeunit 6391 "EDocument Processing"
DocumentResponse.SelectSingleNode(StrSubstNo(DocumentXMLPathLbl, EDocument."Index In Batch"), CurrentEDocumentNode);

CurrentEDocumentNode.SelectSingleNode('participation_profile_id', ParticipationProfileIdNode);
Evaluate(ParticipationNetworkProfileID, ParticipationProfileIdNode.AsXmlElement().InnerText);
Evaluate(ParticipationNetworkProfileId, ParticipationProfileIdNode.AsXmlElement().InnerText);

ParticipationNetworkProfile.SetCurrentKey("CDN GUID");
ParticipationNetworkProfile.SetRange("CDN GUID", ParticipationNetworkProfileID);
ParticipationNetworkProfile.SetCurrentKey(Id);
ParticipationNetworkProfile.SetRange(Id, ParticipationNetworkProfileId);
if not ParticipationNetworkProfile.FindFirst() then
exit(false);

NetworkProfile.Get(ParticipationNetworkProfile."Network Profile ID");
NetworkProfile.Get(ParticipationNetworkProfile."Network Profile Id");
if not ProfileSupportedByEDocumentService(EDocumentService, NetworkProfile) then
exit(false);
exit(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ page 6390 "Ext. Connection Setup"
trigger OnDrillDown()
var
Participation: Record "Participation";
APIRequests: Codeunit "API Requests";
ApiRequests: Codeunit "Api Requests";
Participations: Page "Participations";
ProgressWindow: Dialog;
begin
ProgressWindow.Open(ProcessingWindowMsg);
if Participation.FindSet() then
repeat
APIRequests.GetParticipation(Participation);
APIRequests.GetAllParticipationProfiles(Participation);
ApiRequests.GetParticipation(Participation);
ApiRequests.GetAllParticipationProfiles(Participation);
until Participation.Next() = 0;

ProgressWindow.Close();
Expand Down Expand Up @@ -132,13 +132,13 @@ page 6390 "Ext. Connection Setup"
trigger OnAction()
var
Participation: Record "Participation";
APIRequests: Codeunit "API Requests";
ApiRequests: Codeunit "Api Requests";
ActivationMgt: Codeunit "Subscription Mgt.";
begin
if Confirm(UnsubscribeQst) then begin
if Participation.FindSet() then
repeat
APIRequests.DeleteParticipation(Participation);
ApiRequests.DeleteParticipation(Participation);
until Participation.Next() = 0;
ActivationMgt.Unsubscribe(true);
CurrPage.Update(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@ codeunit 6390 "Integration Impl." implements "E-Document Integration"

procedure Cancel(var EDocument: Record "E-Document"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage): Boolean
var
APIRequests: Codeunit "API Requests";
DocumentCDNGUID: Guid;
ApiRequests: Codeunit "Api Requests";
DocumentId: Guid;
begin
Evaluate(DocumentCDNGUID, EDocument."Document Id");
APIRequests.CancelDocument(DocumentCDNGUID, HttpRequest, HttpResponse);
Evaluate(DocumentId, EDocument."Document Id");
ApiRequests.CancelDocument(DocumentId, HttpRequest, HttpResponse);
end;

procedure ReceiveDocument(var TempBlob: Codeunit "Temp Blob"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage)
var
APIRequests: Codeunit "API Requests";
ApiRequests: Codeunit "Api Requests";
OutStream: OutStream;
ContentData: Text;
begin
if not APIRequests.GetDocumentsForCompany(HttpRequest, HttpResponse) then
if not ApiRequests.GetDocumentsForCompany(HttpRequest, HttpResponse) then
exit;

HttpResponse.Content.ReadAs(ContentData);
Expand Down
Loading

0 comments on commit b37612a

Please sign in to comment.