Skip to content

Commit

Permalink
use temporary table as parameter for batch processing
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanMaron committed Jan 19, 2024
1 parent a82205f commit 408f45f
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 50 deletions.
3 changes: 2 additions & 1 deletion MSDyn365BC.Ntfy.Test/doubles/DummyNtfyTypeNTSTM.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ codeunit 50006 DummyNtfyTypeNTSTM implements INtfyEventNTSTM
procedure DoCallNtfyEvent(NtfyEvent: Record NtfyEventNTSTM; Params: Dictionary of [Text, Text]) ReturnValue: Boolean;
begin
DoCallNtfyEventWasCalled := true;
exit(true);
end;

procedure GetMessage(Params: Dictionary of [Text, Text]) ReturnValue: Text[2048];
procedure GetMessage(NtfyEvent: Record NtfyEventNTSTM; Params: Dictionary of [Text, Text]) ReturnValue: Text[2048];
begin
GetMessageWasCalled := true;
end;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ codeunit 50009 MarkingTestRunBatchNTSTM implements IRunBatchNTSTM
{


procedure RunBatch(var Rec: Record NtfyEventNTSTM)
procedure RunBatch(var Rec: Record NtfyEventRequestNTSTM)
var
Assert: Codeunit "Library Assert";
begin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ codeunit 50008 MarkingTestTypeNTSTM implements INtfyEventNTSTM
Evaluate(ReturnValue, NtfyEvent.NtfyMessage);
end;

procedure GetMessage(Params: Dictionary of [Text, Text]) ReturnValue: Text[2048];
procedure GetMessage(NtfyEvent: Record NtfyEventNTSTM; Params: Dictionary of [Text, Text]) ReturnValue: Text[2048];
begin

end;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ codeunit 50007 RunBatchWrapperEmptyNTSTM implements IRunBatchNTSTM
var
RunBatchWasCalled: Boolean;

procedure RunBatch(var Rec: Record NtfyEventNTSTM)
procedure RunBatch(var Rec: Record NtfyEventRequestNTSTM)
begin
RunBatchWasCalled := true;
end;
Expand Down
32 changes: 16 additions & 16 deletions MSDyn365BC.Ntfy.Test/tests/TestBatchSend.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,44 @@ codeunit 50000 "TestBatchSend"
[Test]
procedure TestCreateBodyGetsCalled()
var
NtfyEvent: Record NtfyEventNTSTM temporary;
NtfyEventRequest: Record NtfyEventRequestNTSTM;
BatchSend: Codeunit BatchSendNtfysNTSTM;
RestWrapper: Codeunit RestWrapperTestBodyNTSTM;
begin
NtfyEvent.Init();
NtfyEvent.NtfyMessage := 'Hello World';
if not NtfyEvent.Insert() then;
asserterror BatchSend.SendRequests(NtfyEvent, RestWrapper);
NtfyEventRequest.Init();
NtfyEventRequest.NtfyMessage := 'Hello World';
if not NtfyEventRequest.Insert() then;
asserterror BatchSend.SendRequests(NtfyEventRequest, RestWrapper);

Assert.ExpectedError('CreateBody was called');
end;

[Test]
procedure TestPostGetsCalled()
var
NtfyEvent: Record NtfyEventNTSTM temporary;
NtfyEventRequest: Record NtfyEventRequestNTSTM;
BatchSend: Codeunit BatchSendNtfysNTSTM;
RestWrapper: Codeunit RestWrapperTestPostNTSTM;
begin
NtfyEvent.Init();
NtfyEvent.NtfyMessage := 'Hello World';
if not NtfyEvent.Insert() then;
asserterror BatchSend.SendRequests(NtfyEvent, RestWrapper);
NtfyEventRequest.Init();
NtfyEventRequest.NtfyMessage := 'Hello World';
if not NtfyEventRequest.Insert() then;
asserterror BatchSend.SendRequests(NtfyEventRequest, RestWrapper);

Assert.ExpectedError(StrSubstNo('Post was called with RequestUri: %1', StrSubstNo('https://ntfy.sh/%1', NtfyEvent.NtfyTopic)));
Assert.ExpectedError(StrSubstNo('Post was called with RequestUri: %1', StrSubstNo('https://ntfy.sh/%1', NtfyEventRequest.NtfyTopic)));
end;

[Test]
procedure TestBodyGetsPassedToPostCorrectly()
var
NtfyEvent: Record NtfyEventNTSTM temporary;
NtfyEventRequest: Record NtfyEventRequestNTSTM;
BatchSend: Codeunit BatchSendNtfysNTSTM;
RestWrapper: Codeunit RestWrapBodyPassNTSTM;
begin
NtfyEvent.Init();
NtfyEvent.NtfyMessage := 'Hello World';
if not NtfyEvent.Insert() then;
BatchSend.SendRequests(NtfyEvent, RestWrapper);
NtfyEventRequest.Init();
NtfyEventRequest.NtfyMessage := 'Hello World';
if not NtfyEventRequest.Insert() then;
BatchSend.SendRequests(NtfyEventRequest, RestWrapper);
end;


Expand Down
6 changes: 3 additions & 3 deletions MSDyn365BC.Ntfy/src/EventTypes/EmptyEvent.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ codeunit 71179876 EmptyEventNTSTM implements INtfyEventNTSTM

end;

procedure GetMessage(Params: Dictionary of [Text, Text]) ReturnValue: Text[2048]
procedure GetMessage(NtfyEvent: Record NtfyEventNTSTM; Params: Dictionary of [Text, Text]) ReturnValue: Text[2048]
begin

end;

procedure ResetSettings(NtfyEvent: Record NtfyEventNTSTM);
procedure ResetSettings(NtfyEvent: Record NtfyEventNTSTM)
begin

end;

procedure FilterNtfyEntriesBeforeBatchSend(var NtfyEvent: Record NtfyEventNTSTM; Params: Dictionary of [Text, Text]);
procedure FilterNtfyEntriesBeforeBatchSend(var NtfyEvent: Record NtfyEventNTSTM; Params: Dictionary of [Text, Text])
begin

end;
Expand Down
2 changes: 1 addition & 1 deletion MSDyn365BC.Ntfy/src/EventTypes/INtfyEvent.Interface.al
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ interface INtfyEventNTSTM
procedure ResetSettings(NtfyEvent: Record NtfyEventNTSTM)
procedure FilterNtfyEntriesBeforeBatchSend(var NtfyEvent: Record NtfyEventNTSTM; Params: Dictionary of [Text, Text])
procedure DoCallNtfyEvent(NtfyEvent: Record NtfyEventNTSTM; Params: Dictionary of [Text, Text]) ReturnValue: Boolean
procedure GetMessage(Params: Dictionary of [Text, Text]) ReturnValue: Text[2048]
procedure GetMessage(NtfyEvent: Record NtfyEventNTSTM; Params: Dictionary of [Text, Text]) ReturnValue: Text[2048]

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ codeunit 71179877 SalesDocumentReleasedNTSTM implements INtfyEventNTSTM
end;
end;

procedure ResetSettings(NtfyEvent: Record NtfyEventNTSTM);
procedure ResetSettings(NtfyEvent: Record NtfyEventNTSTM)
begin
NtfyEvent.Validate(FilterText, '');
NtfyEvent.Modify(true);
end;

procedure FilterNtfyEntriesBeforeBatchSend(var NtfyEvent: Record NtfyEventNTSTM; Params: Dictionary of [Text, Text]);
procedure FilterNtfyEntriesBeforeBatchSend(var NtfyEvent: Record NtfyEventNTSTM; Params: Dictionary of [Text, Text])
begin

end;
Expand All @@ -45,7 +45,7 @@ codeunit 71179877 SalesDocumentReleasedNTSTM implements INtfyEventNTSTM
end;
end;

procedure GetMessage(Params: Dictionary of [Text, Text]) ReturnValue: Text[2048]
procedure GetMessage(NtfyEvent: Record NtfyEventNTSTM; Params: Dictionary of [Text, Text]) ReturnValue: Text[2048]
begin
exit(StrSubstNo('Sales %1 - %2 - has been released', Params.Get('DocumentType'), Params.Get('No')));
end;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ codeunit 71179878 SalesDocumentReopenedNTSTM implements INtfyEventNTSTM
end;
end;

procedure GetMessage(Params: Dictionary of [Text, Text]) ReturnValue: Text[2048]
procedure GetMessage(NtfyEvent: Record NtfyEventNTSTM; Params: Dictionary of [Text, Text]) ReturnValue: Text[2048]
begin
exit(StrSubstNo('Sales %1 - %2 - has been reopened', Params.Get('DocumentType'), Params.Get('No')));
end;
Expand Down
4 changes: 2 additions & 2 deletions MSDyn365BC.Ntfy/src/foundation/BatchSendNtfys.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using System.RestClient;

codeunit 71179879 BatchSendNtfysNTSTM
{
TableNo = NtfyEventNTSTM;
TableNo = NtfyEventRequestNTSTM;

trigger OnRun()
var
Expand All @@ -13,7 +13,7 @@ codeunit 71179879 BatchSendNtfysNTSTM
SendRequests(Rec, RestWrapper);
end;

internal procedure SendRequests(var Rec: Record NtfyEventNTSTM; IRestWrapper: Interface IRestWrapperNTSTM)
internal procedure SendRequests(var Rec: Record NtfyEventRequestNTSTM; IRestWrapper: Interface IRestWrapperNTSTM)
var
Body: Codeunit "Http Content";
begin
Expand Down
4 changes: 2 additions & 2 deletions MSDyn365BC.Ntfy/src/foundation/NtfyEvent.Page.al
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace StefanMaron.Ntfy;
using StefanMaron.Ntfy;
page 71179875 NtfyEventNTSTM
page 71179875 NtfyEventsNTSTM
{
Caption = 'Ntfy Event';
Caption = 'Ntfy Events';
PageType = List;
ApplicationArea = All;
UsageCategory = Administration;
Expand Down
29 changes: 13 additions & 16 deletions MSDyn365BC.Ntfy/src/foundation/NtfyEvent.Table.al
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ using System.Security.AccessControl;
table 71179875 NtfyEventNTSTM
{
DataClassification = CustomerContent;
DrillDownPageId = NtfyEventNTSTM;
LookupPageId = NtfyEventNTSTM;
DrillDownPageId = NtfyEventsNTSTM;
LookupPageId = NtfyEventsNTSTM;
InherentEntitlements = RIMDX;
InherentPermissions = RIMDX;

Expand Down Expand Up @@ -70,14 +70,6 @@ table 71179875 NtfyEventNTSTM
INtfyEvent.ResetSettings(Rec);
end;

procedure RunBatch()
var
TempSessionId: Integer;
begin
if not StartSession(TempSessionId, Codeunit::BatchSendNtfysNTSTM, CompanyName, Rec) then
Codeunit.Run(Codeunit::BatchSendNtfysNTSTM, Rec);
end;

procedure SendNotifications(Type: Enum EventTypeNTSTM; Params: Dictionary of [Text, Text])
var
RunBatchWrapper: Codeunit RunBatchWrapperNTSTM;
Expand All @@ -86,20 +78,25 @@ table 71179875 NtfyEventNTSTM
end;

internal procedure SendNotifications(INtfyEvent: Interface INtfyEventNTSTM; Type: Enum EventTypeNTSTM; Params: Dictionary of [Text, Text]; RunBatchWrapper: Interface IRunBatchNTSTM)
var
NtfyEventRequest: Record NtfyEventRequestNTSTM;
begin
Rec.SetRange(EventType, Type);
Rec.SetFilter(NtfyTopic, '<>%1', '');
INtfyEvent.FilterNtfyEntriesBeforeBatchSend(Rec, Params);
if Rec.FindSet() then
repeat
if INtfyEvent.DoCallNtfyEvent(Rec, Params) then
Rec.Mark(true);
if INtfyEvent.DoCallNtfyEvent(Rec, Params) then begin
NtfyEventRequest.Init();
NtfyEventRequest.EntryNo += 1;
NtfyEventRequest.NtfyTopic := Rec.NtfyTopic;
// NtfyEventRequest.NtfyTitle := INtfyEvent.GetTitle(Params);
NtfyEventRequest.NtfyMessage := INtfyEvent.GetMessage(Rec, Params);
NtfyEventRequest.Insert(true);
end;
until Rec.Next() = 0;

Rec.NtfyMessage := INtfyEvent.GetMessage(Params);

Rec.MarkedOnly(true);

RunBatchWrapper.RunBatch(Rec);
RunBatchWrapper.RunBatch(NtfyEventRequest);
end;
}
46 changes: 46 additions & 0 deletions MSDyn365BC.Ntfy/src/foundation/NtfyEventRequest.Table.al
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
namespace StefanMaron.Ntfy;
using System.Security.AccessControl;


table 71179877 NtfyEventRequestNTSTM
{
TableType = Temporary;
InherentEntitlements = RIMDX;
InherentPermissions = RIMDX;

fields
{
field(1; EntryNo; Integer)
{
Caption = 'Entry No.';
}
field(2; NtfyTopic; Text[150])
{
Caption = 'Topic';
}
field(3; NtfyTitle; Text[150])
{
Caption = 'Title';
}
field(4; NtfyMessage; Text[2048])
{
Caption = 'Message';
}
}

keys
{
key(Key1; EntryNo)
{
Clustered = true;
}
}

procedure RunBatch()
var
TempSessionId: Integer;
begin
if not StartSession(TempSessionId, Codeunit::BatchSendNtfysNTSTM, CompanyName, Rec) then
Codeunit.Run(Codeunit::BatchSendNtfysNTSTM, Rec);
end;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
interface IRunBatchNTSTM
{
procedure RunBatch(var Rec: Record NtfyEventNTSTM)
procedure RunBatch(var Rec: Record NtfyEventRequestNTSTM)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
codeunit 71179881 RunBatchWrapperNTSTM implements IRunBatchNTSTM
{
procedure RunBatch(var Rec: Record NtfyEventNTSTM)
procedure RunBatch(var Rec: Record NtfyEventRequestNTSTM)
begin
Rec.RunBatch();
end;
Expand Down

0 comments on commit 408f45f

Please sign in to comment.