-
Notifications
You must be signed in to change notification settings - Fork 213
[DRAFT] Pagination for microsoft graph module #3940
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Drakonian
wants to merge
2
commits into
microsoft:main
Choose a base branch
from
Drakonian:PaginationForMicrosoftGraphModule
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,7 +54,7 @@ | |
"idRanges": [ | ||
{ | ||
"from": 9350, | ||
"to": 9359 | ||
"to": 9361 | ||
} | ||
], | ||
"target": "OnPrem", | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
src/System Application/App/MicrosoftGraph/src/GraphPaginationData.Codeunit.al
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// ------------------------------------------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
// ------------------------------------------------------------------------------------------------ | ||
namespace System.Integration.Graph; | ||
|
||
/// <summary> | ||
/// Holder for pagination data when working with Microsoft Graph API responses. | ||
/// </summary> | ||
codeunit 9360 "Graph Pagination Data" | ||
{ | ||
Access = Public; | ||
InherentEntitlements = X; | ||
InherentPermissions = X; | ||
|
||
var | ||
GraphPaginationDataImpl: Codeunit "Graph Pagination Data Impl."; | ||
|
||
/// <summary> | ||
/// Sets the next link URL for retrieving the next page of results. | ||
/// </summary> | ||
/// <param name="NewNextLink">The @odata.nextLink value from the Graph response.</param> | ||
procedure SetNextLink(NewNextLink: Text) | ||
begin | ||
GraphPaginationDataImpl.SetNextLink(NewNextLink); | ||
end; | ||
|
||
/// <summary> | ||
/// Gets the current next link URL. | ||
/// </summary> | ||
/// <returns>The URL to retrieve the next page of results.</returns> | ||
procedure GetNextLink(): Text | ||
begin | ||
exit(GraphPaginationDataImpl.GetNextLink()); | ||
end; | ||
|
||
/// <summary> | ||
/// Checks if there are more pages available. | ||
/// </summary> | ||
/// <returns>True if more pages are available; otherwise false.</returns> | ||
procedure HasMorePages(): Boolean | ||
begin | ||
exit(GraphPaginationDataImpl.HasMorePages()); | ||
end; | ||
|
||
/// <summary> | ||
/// Sets the page size for pagination requests. | ||
/// </summary> | ||
/// <param name="NewPageSize">The number of items to retrieve per page (max 999).</param> | ||
procedure SetPageSize(NewPageSize: Integer) | ||
begin | ||
GraphPaginationDataImpl.SetPageSize(NewPageSize); | ||
end; | ||
|
||
/// <summary> | ||
/// Gets the current page size. | ||
/// </summary> | ||
/// <returns>The number of items per page.</returns> | ||
procedure GetPageSize(): Integer | ||
begin | ||
exit(GraphPaginationDataImpl.GetPageSize()); | ||
end; | ||
|
||
/// <summary> | ||
/// Gets the default page size. | ||
/// </summary> | ||
/// <returns>The default number of items per page.</returns> | ||
procedure GetDefaultPageSize(): Integer | ||
begin | ||
exit(GraphPaginationDataImpl.GetDefaultPageSize()); | ||
end; | ||
|
||
/// <summary> | ||
/// Resets the pagination data to initial state. | ||
/// </summary> | ||
procedure Reset() | ||
begin | ||
GraphPaginationDataImpl.Reset(); | ||
end; | ||
} |
59 changes: 59 additions & 0 deletions
59
src/System Application/App/MicrosoftGraph/src/GraphPaginationDataImpl.Codeunit.al
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor
9E81
that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// ------------------------------------------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
// ------------------------------------------------------------------------------------------------ | ||
namespace System.Integration.Graph; | ||
|
||
codeunit 9361 "Graph Pagination Data Impl." | ||
{ | ||
Access = Internal; | ||
InherentEntitlements = X; | ||
InherentPermissions = X; | ||
|
||
var | ||
NextLink: Text; | ||
PageSize: Integer; | ||
DefaultPageSizeErr: Label 'Page size must be between 1 and 999.'; | ||
|
||
procedure SetNextLink(NewNextLink: Text) | ||
begin | ||
NextLink := NewNextLink; | ||
end; | ||
|
||
procedure GetNextLink(): Text | ||
begin | ||
exit(NextLink); | ||
end; | ||
|
||
procedure HasMorePages(): Boolean | ||
begin | ||
exit(NextLink <> ''); | ||
end; | ||
|
||
procedure SetPageSize(NewPageSize: Integer) | ||
begin | ||
if not (NewPageSize in [1 .. 999]) then | ||
Error(DefaultPageSizeErr); | ||
|
||
PageSize := NewPageSize; | ||
end; | ||
|
||
procedure GetPageSize(): Integer | ||
begin | ||
if PageSize = 0 then | ||
exit(GetDefaultPageSize()); | ||
|
||
exit(PageSize); | ||
end; | ||
|
||
procedure Reset() | ||
begin | ||
Clear(NextLink); | ||
Clear(PageSize); | ||
end; | ||
|
||
procedure GetDefaultPageSize(): Integer | ||
begin | ||
exit(100); | ||
end; | ||
} |
101 changes: 101 additions & 0 deletions
101
src/System Application/App/MicrosoftGraph/src/helper/GraphPaginationHelper.Codeunit.al
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// ------------------------------------------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
// ------------------------------------------------------------------------------------------------ | ||
namespace System.Integration.Graph; | ||
|
||
using System.RestClient; | ||
|
||
codeunit 9359 "Graph Pagination Helper" | ||
{ | ||
Access = Internal; | ||
InherentEntitlements = X; | ||
InherentPermissions = X; | ||
|
||
procedure ExtractNextLink(HttpResponseMessage: Codeunit "Http Response Message"; var GraphPaginationData: Codeunit "Graph Pagination Data") | ||
var | ||
ResponseJson: JsonObject; | ||
JsonToken: JsonToken; | ||
NextLink: Text; | ||
ResponseText: Text; | ||
begin | ||
if not HttpResponseMessage.GetIsSuccessStatusCode() then begin | ||
GraphPaginationData.SetNextLink(''); | ||
exit; | ||
end; | ||
|
||
ResponseText := HttpResponseMessage.GetContent().AsText(); | ||
|
||
// Parse JSON response | ||
if not ResponseJson.ReadFrom(ResponseText) then begin | ||
GraphPaginationData.SetNextLink(''); | ||
exit; | ||
end; | ||
|
||
// Extract nextLink | ||
if ResponseJson.Get('@odata.nextLink', JsonToken) then | ||
NextLink := JsonToken.AsValue().AsText(); | ||
|
||
GraphPaginationData.SetNextLink(NextLink); | ||
end; | ||
|
||
procedure ExtractValueArray(HttpResponseMessage: Codeunit "Http Response Message"; var ValueArray: JsonArray): Boolean | ||
var | ||
ResponseJson: JsonObject; | ||
JsonToken: JsonToken; | ||
ResponseText: Text; | ||
begin | ||
Clear(ValueArray); | ||
|
||
if not HttpResponseMessage.GetIsSuccessStatusCode() then | ||
exit(false); | ||
|
||
ResponseText := HttpResponseMessage.GetContent().AsText(); | ||
|
||
// Parse JSON response | ||
if not ResponseJson.ReadFrom(ResponseText) then | ||
exit(false); | ||
|
||
// Extract value array | ||
if not ResponseJson.Get('value', JsonToken) then | ||
exit(false); | ||
|
||
ValueArray := JsonToken.AsArray(); | ||
exit(true); | ||
end; | ||
|
||
procedure ApplyPageSize(var GraphOptionalParameters: Codeunit "Graph Optional Parameters"; GraphPaginationData: Codeunit "Graph Pagination Data") | ||
begin | ||
if GraphPaginationData.GetPageSize() > 0 then | ||
GraphOptionalParameters.SetODataQueryParameter(Enum::"Graph OData Query Parameter"::top, Format(GraphPaginationData.GetPageSize())); | ||
end; | ||
|
||
procedure CombineValueArrays(HttpResponseMessage: Codeunit "Http Response Message"; var JsonResults: JsonArray): Boolean | ||
var | ||
ValueArray: JsonArray; | ||
JsonItem: JsonToken; | ||
begin | ||
if not ExtractValueArray(HttpResponseMessage, ValueArray) then | ||
exit(false); | ||
|
||
foreach JsonItem in ValueArray do | ||
JsonResults.Add(JsonItem); | ||
|
||
exit(true); | ||
end; | ||
|
||
procedure IsWithinIterationLimit(var IterationCount: Integer; MaxIterations: Integer): Boolean | ||
begin | ||
if IterationCount >= MaxIterations then | ||
exit(false); | ||
|
||
IterationCount += 1; | ||
|
||
exit(true); | ||
end; | ||
|
||
procedure GetMaxIterations(): Integer | ||
begin | ||
exit(1000); // Safety limit to prevent infinite loops | ||
end; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we maybe be able to specify the value
$skip
for skip here, too?Following scenario:
Someone wants to call the GetWithPagination but it should return only all results after the first record.
Technically I think that we don't need this, since we can specify the value for
$skip
in the optional parameters.Maybe we should provide a Readme with some examples how to use those new procedures instead?