Skip to content

Commit

Permalink
Main 98840 reset data azure data lake (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bertverbeek4PS authored Jan 24, 2025
2 parents fe8842f + e636a51 commit 968d646
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 14 deletions.
15 changes: 12 additions & 3 deletions businessCentral/app/src/Communication.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,11 @@ codeunit 82562 "ADLSE Communication"
end;

procedure ResetTableExport(ltableId: Integer)
begin
ResetTableExport(ltableId, false);
end;

procedure ResetTableExport(ltableId: Integer; AllCompanies: Boolean)
var
ADLSESetup: Record "ADLSE Setup";
ADLSEUtil: Codeunit "ADLSE Util";
Expand All @@ -368,13 +373,17 @@ codeunit 82562 "ADLSE Communication"
begin
ADLSESetup.GetSingleton();
ADLSECredentials.Init();

if not AllCompanies then
if ADLSESetup."Export Company Database Tables" in ['', CompanyName()] then
if not ADLSEUtil.IsTablePerCompany(ltableId) then
AllCompanies := true;

case ADLSESetup."Storage Type" of
"ADLSE Storage Type"::"Microsoft Fabric":
ADLSEGen2Util.CreateOrUpdateJsonBlob(GetBaseUrl() + StrSubstNo(ResetTableExportTxt, ADLSEUtil.GetDataLakeCompliantTableName(ltableId)), ADLSECredentials, '', Body);
"ADLSE Storage Type"::"Azure Data Lake":
ADLSEGen2Util.RemoveDeltasFromDataLake(ADLSEUtil.GetDataLakeCompliantTableName(ltableId), ADLSECredentials);
ADLSEGen2Util.RemoveDeltasFromDataLake(ADLSEUtil.GetDataLakeCompliantTableName(ltableId), ADLSECredentials, AllCompanies);
end;
end;


}
31 changes: 25 additions & 6 deletions businessCentral/app/src/Gen2Util.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -297,23 +297,37 @@ codeunit 82568 "ADLSE Gen 2 Util"
end;

procedure RemoveDeltasFromDataLake(ADLSEntityName: Text; ADLSECredentials: Codeunit "ADLSE Credentials")
begin
RemoveDeltasFromDataLake(ADLSEntityName, ADLSECredentials, false);
end;

procedure RemoveDeltasFromDataLake(ADLSEntityName: Text; ADLSECredentials: Codeunit "ADLSE Credentials"; AllCompanies: Boolean)
var
ADLSESetup: Record "ADLSE Setup";
ADLSEHttp: Codeunit "ADLSE Http";
IsHandled: Boolean;
Response: Text;
Url: Text;
ADLSEContainerUrlTxt: Label 'https://%1.dfs.core.windows.net/%2', Comment = '%1: Account name, %2: Container Name', Locked = true;
begin
// DELETE https://{accountName}.{dnsSuffix}/{filesystem}/{path}
// https://learn.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path/delete?view=rest-storageservices-datalakestoragegen2-2019-12-12
ADLSESetup.GetSingleton();
Url := StrSubstNo(ADLSEContainerUrlTxt, ADLSESetup."Account Name", ADLSESetup.Container);
Url += '/deltas/' + ADLSEntityName + '?recursive=true';

ADLSEHttp.SetMethod("ADLSE Http Method"::Delete);
ADLSEHttp.SetUrl(Url);
ADLSEHttp.SetAuthorizationCredentials(ADLSECredentials);
ADLSEHttp.InvokeRestApi(Response)
OnBeforeRemoveDeltasFromDataLake(ADLSEntityName, ADLSECredentials, AllCompanies, IsHandled);
if IsHandled then
exit;


if AllCompanies then begin
Url := StrSubstNo(ADLSEContainerUrlTxt, ADLSESetup."Account Name", ADLSESetup.Container);
Url += '/deltas/' + ADLSEntityName + '?recursive=true';

ADLSEHttp.SetMethod("ADLSE Http Method"::Delete);
ADLSEHttp.SetUrl(Url);
ADLSEHttp.SetAuthorizationCredentials(ADLSECredentials);
ADLSEHttp.InvokeRestApi(Response)
end;
end;

[IntegrationEvent(false, false)]
Expand All @@ -340,4 +354,9 @@ codeunit 82568 "ADLSE Gen 2 Util"
local procedure OnBeforeCommitAllBlocksOnDataBlob(BlobPath: Text; BlockIDList: List of [Text]; var IsHandled: Boolean)
begin
end;

[Integrationevent(false, false)]
local procedure OnBeforeRemoveDeltasFromDataLake(ADLSEntityName: Text; ADLSECredentials: Codeunit "ADLSE Credentials"; AllCompanies: Boolean; var IsHandled: Boolean)
begin
end;
}
16 changes: 15 additions & 1 deletion businessCentral/app/src/SetupTables.Page.al
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,23 @@ page 82561 "ADLSE Setup Tables"
trigger OnAction()
var
SelectedADLSETable: Record "ADLSE Table";
Options: Text[30];
OptionStringLbl: Label 'Current Company,All Companies';
ChosenOption: Integer;
begin
Options := OptionStringLbl;
ChosenOption := Dialog.StrMenu(Options, 1, 'Do you want to reset the selected tables for the current company or all companies?');
CurrPage.SetSelectionFilter(SelectedADLSETable);
SelectedADLSETable.ResetSelected();
case ChosenOption of
0:
exit;
1:
SelectedADLSETable.ResetSelected(false);
2:
SelectedADLSETable.ResetSelected(true);
else
Error('Chosen option is not valid');
end;
CurrPage.Update();
end;
}
Expand Down
21 changes: 17 additions & 4 deletions businessCentral/app/src/Table.Table.al
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ table 82561 "ADLSE Table"

[InherentPermissions(PermissionObjectType::TableData, Database::"ADLSE Table", 'rm')]
procedure ResetSelected()
begin
ResetSelected(false);
end;

[InherentPermissions(PermissionObjectType::TableData, Database::"ADLSE Table", 'rm')]
procedure ResetSelected(AllCompanies: Boolean)
var
ADLSEDeletedRecord: Record "ADLSE Deleted Record";
ADLSETableLastTimestamp: Record "ADLSE Table Last Timestamp";
Expand All @@ -204,15 +210,21 @@ table 82561 "ADLSE Table"
Rec.Modify(true);
end;

ADLSETableLastTimestamp.SaveUpdatedLastTimestamp(Rec."Table ID", 0);
ADLSETableLastTimestamp.SaveDeletedLastEntryNo(Rec."Table ID", 0);

if not AllCompanies then begin
ADLSETableLastTimestamp.SaveUpdatedLastTimestamp(Rec."Table ID", 0);
ADLSETableLastTimestamp.SaveDeletedLastEntryNo(Rec."Table ID", 0);
end else begin
ADLSETableLastTimestamp.SetRange("Table ID", rec."Table ID");
ADLSETableLastTimestamp.ModifyAll("Updated Last Timestamp", 0);
ADLSETableLastTimestamp.ModifyAll("Deleted Last Entry No.", 0);
ADLSETableLastTimestamp.SetRange("Table ID");
end;
ADLSEDeletedRecord.SetRange("Table ID", Rec."Table ID");
ADLSEDeletedRecord.DeleteAll(false);

ADLSESetup.GetSingleton();
if (ADLSESetup."Delete Table") then
ADLSECommunication.ResetTableExport(Rec."Table ID");
ADLSECommunication.ResetTableExport(Rec."Table ID", AllCompanies);

OnAfterResetSelected(Rec);

Expand Down Expand Up @@ -300,6 +312,7 @@ table 82561 "ADLSE Table"
end;
until Field.Next() = 0;
end;

[IntegrationEvent(false, false)]
local procedure OnAfterResetSelected(ADLSETable: Record "ADLSE Table")
begin
Expand Down

0 comments on commit 968d646

Please sign in to comment.