Skip to content
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

Add Support to specifiy ODataQuery Parameters in Microsoft Graph Client #827

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ codeunit 9351 "Graph Client Impl."
GraphUriBuilder: Codeunit "Graph Uri Builder";
begin
Clear(HttpResponseMessage);
GraphUriBuilder.Initialize(MicrosoftGraphBaseUrl, GraphAPIVersion, RelativeUriToResource, GraphOptionalParameters.GetQueryParameters());
GraphUriBuilder.Initialize(MicrosoftGraphBaseUrl, GraphAPIVersion, RelativeUriToResource, GraphOptionalParameters.GetQueryParameters(), GraphOptionalParameters.GetODataQueryParameters());
GraphRequestHelper.SetRestClient(RestClient);
HttpResponseMessage := GraphRequestHelper.Get(GraphUriBuilder, GraphOptionalParameters);
exit(HttpResponseMessage.GetIsSuccessStatusCode());
Expand All @@ -63,7 +63,7 @@ codeunit 9351 "Graph Client Impl."
var
GraphUriBuilder: Codeunit "Graph Uri Builder";
begin
GraphUriBuilder.Initialize(MicrosoftGraphBaseUrl, GraphAPIVersion, RelativeUriToResource, GraphOptionalParameters.GetQueryParameters());
GraphUriBuilder.Initialize(MicrosoftGraphBaseUrl, GraphAPIVersion, RelativeUriToResource, GraphOptionalParameters.GetQueryParameters(), GraphOptionalParameters.GetODataQueryParameters());
GraphRequestHelper.SetRestClient(RestClient);
HttpResponseMessage := GraphRequestHelper.Post(GraphUriBuilder, GraphOptionalParameters, RequestHttpContent);
exit(HttpResponseMessage.GetIsSuccessStatusCode());
Expand All @@ -73,7 +73,7 @@ codeunit 9351 "Graph Client Impl."
var
GraphUriBuilder: Codeunit "Graph Uri Builder";
begin
GraphUriBuilder.Initialize(MicrosoftGraphBaseUrl, GraphAPIVersion, RelativeUriToResource, GraphOptionalParameters.GetQueryParameters());
GraphUriBuilder.Initialize(MicrosoftGraphBaseUrl, GraphAPIVersion, RelativeUriToResource, GraphOptionalParameters.GetQueryParameters(), GraphOptionalParameters.GetODataQueryParameters());
GraphRequestHelper.SetRestClient(RestClient);
HttpResponseMessage := GraphRequestHelper.Patch(GraphUriBuilder, GraphOptionalParameters, RequestHttpContent);
exit(HttpResponseMessage.GetIsSuccessStatusCode());
Expand All @@ -83,7 +83,7 @@ codeunit 9351 "Graph Client Impl."
var
GraphUriBuilder: Codeunit "Graph Uri Builder";
begin
GraphUriBuilder.Initialize(MicrosoftGraphBaseUrl, GraphAPIVersion, RelativeUriToResource, GraphOptionalParameters.GetQueryParameters());
GraphUriBuilder.Initialize(MicrosoftGraphBaseUrl, GraphAPIVersion, RelativeUriToResource, GraphOptionalParameters.GetQueryParameters(), GraphOptionalParameters.GetODataQueryParameters());
GraphRequestHelper.SetRestClient(RestClient);
HttpResponseMessage := GraphRequestHelper.Put(GraphUriBuilder, GraphOptionalParameters, RequestHttpContent);
exit(HttpResponseMessage.GetIsSuccessStatusCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ codeunit 9353 "Graph Optional Parameters"
InherentEntitlements = X;
InherentPermissions = X;

var
GraphOptionalParametersImpl: Codeunit "Graph Optional Parameters Impl";

#region Headers

/// <summary>
Expand All @@ -21,7 +24,7 @@ codeunit 9353 "Graph Optional Parameters"
/// <param name="Value">Text value specifying the HttpHeader value</param>
procedure SetIfMatch("Value": Text)
begin
SetRequestHeader('IF-Match', "Value");
GraphOptionalParametersImpl.SetIfMatch("Value");
end;

/// <summary>
Expand All @@ -30,7 +33,7 @@ codeunit 9353 "Graph Optional Parameters"
/// <param name="Value">Text value specifying the HttpHeader value</param>
procedure SetIfNoneMatchRequestHeader("Value": Text)
begin
SetRequestHeader('If-None-Match', "Value");
GraphOptionalParametersImpl.SetIfNoneMatchRequestHeader("Value");
end;

/// <summary>
Expand All @@ -39,7 +42,7 @@ codeunit 9353 "Graph Optional Parameters"
/// <param name="Value">Text value specifying the HttpHeader value</param>
procedure SetPreferRequestHeader("Value": Text)
begin
SetRequestHeader('Prefer', "Value");
GraphOptionalParametersImpl.SetPreferRequestHeader("Value");
end;

/// <summary>
Expand All @@ -48,18 +51,12 @@ codeunit 9353 "Graph Optional Parameters"
/// <param name="Value">Text value specifying the HttpHeader value</param>
procedure SetConsistencyLevelRequestHeader("Value": Text)
begin
SetRequestHeader('ConsistencyLevel', "Value");
end;

local procedure SetRequestHeader(Header: Text; HeaderValue: Text)
begin
RequestHeaders.Remove(Header);
RequestHeaders.Add(Header, HeaderValue);
GraphOptionalParametersImpl.SetConsistencyLevelRequestHeader("Value");
end;

internal procedure GetRequestHeaders(): Dictionary of [Text, Text]
begin
exit(RequestHeaders);
exit(GraphOptionalParametersImpl.GetRequestHeaders());
end;

#endregion
Expand All @@ -72,23 +69,120 @@ codeunit 9353 "Graph Optional Parameters"
/// <param name="GraphConflictBehavior">Enum "Graph ConflictBehavior" value specifying the HttpHeader value</param>
procedure SetMicrosftGraphConflictBehavior(GraphConflictBehavior: Enum "Graph ConflictBehavior")
begin
SetQueryParameter('@microsoft.graph.conflictBehavior', Format(GraphConflictBehavior));
GraphOptionalParametersImpl.SetMicrosftGraphConflictBehavior(GraphConflictBehavior);
end;

internal procedure GetQueryParameters(): Dictionary of [Text, Text]
begin
exit(GraphOptionalParametersImpl.GetQueryParameters());
end;
#endregion

#region ODataQueryParameters

local procedure SetQueryParameter(Header: Text; HeaderValue: Text)

/// <summary>
/// Sets the value for the OData Query Parameter '$count'.
/// see: https://learn.microsoft.com/en-us/graph/query-parameters?tabs=http#count-parameter
/// </summary>
procedure SetODataQueryParameterCount()
begin
QueryParameters.Remove(Header);
QueryParameters.Add(Header, HeaderValue);
GraphOptionalParametersImpl.SetODataQueryParameterCount(true);
end;

internal procedure GetQueryParameters(): Dictionary of [Text, Text]
/// <summary>
/// Sets the value for the OData Query Parameter '$expand'.
/// see: https://learn.microsoft.com/en-us/graph/query-parameters?tabs=http#expand-parameter
/// </summary>
/// <param name="Value">Text value specifying the query parameter</param>
procedure SetODataQueryParameterExpand("Value": Text)
begin
exit(QueryParameters);
GraphOptionalParametersImpl.SetODataQueryParameterExpand("Value");
end;
#endregion

var
QueryParameters: Dictionary of [Text, Text];
RequestHeaders: Dictionary of [Text, Text];
/// <summary>
/// Sets the value for the OData Query Parameter '$filter'.
/// see: https://learn.microsoft.com/en-us/graph/query-parameters?tabs=http#filter-parameter
/// </summary>
/// <param name="Value">Text value specifying the query parameter</param>
procedure SetODataQueryParameterFilter("Value": Text)
JesperSchulz marked this conversation as resolved.
Show resolved Hide resolved
begin
GraphOptionalParametersImpl.SetODataQueryParameterFilter("Value");
end;

/// <summary>
/// Sets the value for the OData Query Parameter '$format'.
/// see: https://learn.microsoft.com/en-us/graph/query-parameters?tabs=http#format-parameter
/// </summary>
/// <param name="Value">Text value specifying the query parameter</param>
procedure SetODataQueryParameterFormat("Value": Text)
begin
GraphOptionalParametersImpl.SetODataQueryParameterFormat("Value");
end;

/// <summary>
/// Sets the value for the OData Query Parameter '$orderBy'.
/// see: https://learn.microsoft.com/en-us/graph/query-parameters?tabs=http#orderby-parameter
/// </summary>
/// <param name="Value">Text value specifying the query parameter</param>
procedure SetODataQueryParameterOrderBy("Value": Text)
begin
GraphOptionalParametersImpl.SetODataQueryParameterOrderBy("Value");
end;

/// <summary>
/// Sets the value for the OData Query Parameter '$search'.
/// see: https://learn.microsoft.com/en-us/graph/query-parameters?tabs=http#search-parameter
/// </summary>
/// <param name="Value">Text value specifying the query parameter</param>
procedure SetODataQueryParameterSearch("Value": Text)
begin
GraphOptionalParametersImpl.SetODataQueryParameterSearch("Value");
end;

/// <summary>
/// Sets the value for the OData Query Parameter '$select'.
/// see: https://learn.microsoft.com/en-us/graph/query-parameters?tabs=http#select-parameter
/// </summary>
/// <param name="Value">Text value specifying the query parameter</param>
procedure SetODataQueryParameterSelect("Value": Text)
begin
GraphOptionalParametersImpl.SetODataQueryParameterSelect("Value");
end;

/// <summary>
/// Sets the value for the OData Query Parameter '$skip'.
/// see: https://learn.microsoft.com/en-us/graph/query-parameters?tabs=http#skip-parameter
/// </summary>
/// <param name="Value">Text value specifying the query parameter</param>
procedure SetODataQueryParameterSkip("Value": Integer)
begin
GraphOptionalParametersImpl.SetODataQueryParameterSkip("Value");
end;

/// <summary>
/// Sets the value for the OData Query Parameter '$skipToken'.
/// see: https://learn.microsoft.com/en-us/graph/query-parameters?tabs=http#skiptoken-parameter
/// </summary>
/// <param name="Value">Text value specifying the query parameter</param>
procedure SetODataQueryParameterSkipToken("Value": Text)
begin
GraphOptionalParametersImpl.SetODataQueryParameterSkipToken("Value");
end;

/// <summary>
/// Sets the value for the OData Query Parameter '$top'.
/// see: https://learn.microsoft.com/en-us/graph/query-parameters?tabs=http#top-parameter
/// </summary>
/// <param name="Value">Text value specifying the query parameter</param>
procedure SetODataQueryParameterTop("Value": Integer)
begin
GraphOptionalParametersImpl.SetODataQueryParameterTop("Value");
end;

internal procedure GetODataQueryParameters(): Dictionary of [Text, Text]
begin
exit(GraphOptionalParametersImpl.GetODataQueryParameters());
end;
#endregion
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
// ------------------------------------------------------------------------------------------------
// 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 9358 "Graph Optional Parameters Impl"
{
Access = Internal;
InherentEntitlements = X;
InherentPermissions = X;

#region Headers
procedure SetIfMatch("Value": Text)
begin
SetRequestHeader('IF-Match', "Value");
end;

procedure SetIfNoneMatchRequestHeader("Value": Text)
begin
SetRequestHeader('If-None-Match', "Value");
end;

procedure SetPreferRequestHeader("Value": Text)
begin
SetRequestHeader('Prefer', "Value");
end;

procedure SetConsistencyLevelRequestHeader("Value": Text)
begin
SetRequestHeader('ConsistencyLevel', "Value");
end;

local procedure SetRequestHeader(Header: Text; HeaderValue: Text)
begin
RequestHeaders.Remove(Header);
RequestHeaders.Add(Header, HeaderValue);
end;

internal procedure GetRequestHeaders(): Dictionary of [Text, Text]
begin
exit(RequestHeaders);
end;

#endregion

#region Parameters

procedure SetMicrosftGraphConflictBehavior(GraphConflictBehavior: Enum "Graph ConflictBehavior")
begin
SetQueryParameter('@microsoft.graph.conflictBehavior', Format(GraphConflictBehavior));
end;


local procedure SetQueryParameter(Header: Text; HeaderValue: Text)
begin
QueryParameters.Remove(Header);
QueryParameters.Add(Header, HeaderValue);
end;

procedure GetQueryParameters(): Dictionary of [Text, Text]
begin
exit(QueryParameters);
end;
#endregion

#region ODataQueryParameters

procedure SetODataQueryParameterCount(RetrieveCount: Boolean)
begin
if RetrieveCount then
SetODataQueryParameter('$count', 'true');
end;

procedure SetODataQueryParameterExpand("Value": Text)
begin
SetODataQueryParameter('$expand', "Value");
end;

procedure SetODataQueryParameterFilter("Value": Text)
begin
SetODataQueryParameter('$filter', "Value");
end;

procedure SetODataQueryParameterFormat("Value": Text)
begin
SetODataQueryParameter('$format', "Value");
end;

procedure SetODataQueryParameterOrderBy("Value": Text)
begin
SetODataQueryParameter('$orderby ', "Value");
end;

procedure SetODataQueryParameterSearch("Value": Text)
begin
SetODataQueryParameter('$search ', "Value");
end;

procedure SetODataQueryParameterSelect("Value": Text)
begin
SetODataQueryParameter('$select', "Value");
end;

procedure SetODataQueryParameterSkip("Value": Integer)
begin
SetODataQueryParameter('$skip', Format("Value", 0, 9));
end;

procedure SetODataQueryParameterSkipToken("Value": Text)
begin
SetODataQueryParameter('$skipToken', "Value");
end;

procedure SetODataQueryParameterTop("Value": Integer)
begin
SetODataQueryParameter('$top', Format("Value", 0, 9));
end;

local procedure SetODataQueryParameter(ODataQueryParameterKey: Text; ODataQueryParameterValue: Text)
begin
ODataQueryParameters.Remove(ODataQueryParameterKey);
ODataQueryParameters.Add(ODataQueryParameterKey, ODataQueryParameterValue);
end;

procedure GetODataQueryParameters(): Dictionary of [Text, Text]
begin
exit(ODataQueryParameters);
end;

#endregion

var
QueryParameters: Dictionary of [Text, Text];
ODataQueryParameters: Dictionary of [Text, Text];
RequestHeaders: Dictionary of [Text, Text];
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ codeunit 9352 "Graph Uri Builder"
procedure Initialize(MicrosoftGraphBaseUrl: Text; NewGraphAPIVersion: Enum "Graph API Version"; RelativeUriToResource: Text)
var
QueryParameters: Dictionary of [Text, Text];
ODataQueryParameters: Dictionary of [Text, Text];
begin
Initialize(MicrosoftGraphBaseUrl, NewGraphAPIVersion, RelativeUriToResource, QueryParameters);
Initialize(MicrosoftGraphBaseUrl, NewGraphAPIVersion, RelativeUriToResource, QueryParameters, ODataQueryParameters);
end;

procedure Initialize(MicrosoftGraphBaseUrl: Text; NewGraphAPIVersion: Enum "Graph API Version"; RelativeUriToResource: Text; QueryParameters: Dictionary of [Text, Text])
procedure Initialize(MicrosoftGraphBaseUrl: Text; NewGraphAPIVersion: Enum "Graph API Version"; RelativeUriToResource: Text; QueryParameters: Dictionary of [Text, Text]; ODataQueryParameters: Dictionary of [Text, Text])
var
UriBuilder: Codeunit "Uri Builder";
BaseUri: Text;
Expand All @@ -42,6 +43,9 @@ codeunit 9352 "Graph Uri Builder"
UriBuilder.Init(Uri.GetAbsoluteUri());
foreach QueryParameterKey in QueryParameters.Keys() do
UriBuilder.AddQueryParameter(QueryParameterKey, QueryParameters.Get(QueryParameterKey));
foreach QueryParameterKey in ODataQueryParameters.Keys() do
UriBuilder.AddODataQueryParameter(QueryParameterKey, ODataQueryParameters.Get(QueryParameterKey));
UriBuilder.GetUri(Uri);
end;

procedure GetUri(): Text
Expand Down
Loading
Loading