-
Notifications
You must be signed in to change notification settings - Fork 29
GraphClient and GraphRequestAdapter #555
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
Merged
+410
−65
Merged
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
726b7f6
BaseGraphRequestAdapter
ramsessanchez e05c636
BaseGraphRequestAdapter
ramsessanchez 1765be9
Kiota-Core IBaseClient & BaseClient
ramsessanchez 215dcae
adding GraphClientFactory
ramsessanchez e03c48b
BaseClient, BaseGraphRequestAdapter, GraphClientFactory updates
ramsessanchez 069cb8e
Update src/main/java/com/microsoft/graph/Requests/BaseGraphRequestAda…
ramsessanchez ad3226d
Add overloads to BaseGraphRequestAdapter
ramsessanchez d01363d
method chaining
ramsessanchez ef2b4bd
Use snapshot dependencies.
ramsessanchez d7425c8
GraphClientFactory will not add CompressionHandler
ramsessanchez d163ed0
Finalized BaseClient and BaseGraphRequestAdapter constructors
ramsessanchez c84ac74
Update BaseClient.java
ramsessanchez 2a0549a
JavaDocs, adapter, factory, client constructor updates.
ramsessanchez 1115722
Add Interceptor only constructor
ramsessanchez 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
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
63 changes: 63 additions & 0 deletions
63
src/main/java/com/microsoft/graph/Requests/BaseClient.java
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,63 @@ | ||
| package com.microsoft.graph.Requests; | ||
|
|
||
| import com.microsoft.graph.content.BatchRequestBuilder; | ||
| import com.microsoft.kiota.RequestAdapter; | ||
| import com.microsoft.kiota.authentication.AuthenticationProvider; | ||
| import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
| import okhttp3.OkHttpClient; | ||
|
|
||
| import javax.annotation.Nonnull; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| @SuppressFBWarnings | ||
| class BaseClient implements IBaseClient{ | ||
|
|
||
| private RequestAdapter requestAdapter; | ||
| public BatchRequestBuilder batchRequestBuilder; | ||
|
|
||
| BaseClient(@Nonnull RequestAdapter requestAdapter) { | ||
| setRequestAdapter(requestAdapter); | ||
| } | ||
|
|
||
| BaseClient(@Nonnull AuthenticationProvider authenticationProvider) { | ||
| this(new BaseGraphRequestAdapter(authenticationProvider)); | ||
| } | ||
|
|
||
| BaseClient(@Nonnull AuthenticationProvider authenticationProvider, @Nonnull String baseUrl) { | ||
| this(new BaseGraphRequestAdapter(authenticationProvider, baseUrl)); | ||
| } | ||
|
|
||
| BaseClient(@Nonnull AuthenticationProvider authenticationProvider, @Nullable BaseGraphRequestAdapter.Clouds nationalCloud, @Nullable String version){ | ||
| this(new BaseGraphRequestAdapter(authenticationProvider, nationalCloud, version)); | ||
| } | ||
|
|
||
| BaseClient(@Nonnull AuthenticationProvider authenticationProvider, @Nonnull OkHttpClient client, @Nullable GraphClientOptions graphClientOptions) { | ||
| this(new BaseGraphRequestAdapter(authenticationProvider,client, graphClientOptions)); | ||
| } | ||
|
|
||
| BaseClient(@Nonnull AuthenticationProvider authenticationProvider, @Nonnull OkHttpClient client, @Nullable GraphClientOptions graphClientOptions, @Nonnull String baseUrl) { | ||
| this(new BaseGraphRequestAdapter(authenticationProvider, client, graphClientOptions, baseUrl)); | ||
| } | ||
|
|
||
| BaseClient(@Nonnull AuthenticationProvider authenticationProvider, @Nonnull OkHttpClient client, @Nullable GraphClientOptions graphClientOptions, @Nullable BaseGraphRequestAdapter.Clouds nationalCloud, @Nullable String version) { | ||
| this(new BaseGraphRequestAdapter(authenticationProvider,client, graphClientOptions, nationalCloud, version)); | ||
| } | ||
|
|
||
| @Override | ||
| public void setRequestAdapter(RequestAdapter requestAdapter) { | ||
| this.requestAdapter = requestAdapter; | ||
| } | ||
|
|
||
| @Override | ||
| public RequestAdapter getRequestAdapter() { | ||
| return this.requestAdapter; | ||
| } | ||
|
|
||
| @Override | ||
| public BatchRequestBuilder getBatchRequestBuilder() { | ||
| //TODO: Refactor BatchRequestBuilder so that it accepts a request adapter as the param | ||
| //return this.batchRequestBuilder != null ? this.batchRequestBuilder : new BatchRequestBuilder(this.requestAdapter) | ||
| return this.batchRequestBuilder; | ||
| } | ||
|
|
||
| } |
80 changes: 80 additions & 0 deletions
80
src/main/java/com/microsoft/graph/Requests/BaseGraphRequestAdapter.java
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 @@ | ||
| package com.microsoft.graph.Requests; | ||
|
|
||
| import com.microsoft.graph.core.ClientException; | ||
| import com.microsoft.kiota.authentication.AnonymousAuthenticationProvider; | ||
| import com.microsoft.kiota.authentication.AuthenticationProvider; | ||
| import com.microsoft.kiota.http.OkHttpRequestAdapter; | ||
| import com.microsoft.kiota.serialization.ParseNodeFactory; | ||
| import com.microsoft.kiota.serialization.SerializationWriterFactory; | ||
| import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
| import okhttp3.OkHttpClient; | ||
|
|
||
| import javax.annotation.Nonnull; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| import java.util.HashMap; | ||
|
|
||
| @SuppressFBWarnings | ||
| public class BaseGraphRequestAdapter extends OkHttpRequestAdapter { | ||
|
|
||
| public enum Clouds { | ||
| GLOBAL_CLOUD, | ||
| USGOV_CLOUD, | ||
| CHINA_CLOUD, | ||
| GERMANY_CLOUD, | ||
| USGOV_DOD_CLOUD | ||
| } | ||
|
|
||
| private static final HashMap<Clouds, String> cloudList = new HashMap<Clouds, String>() {{ | ||
| put( Clouds.GLOBAL_CLOUD, "https://graph.microsoft.com" ); | ||
| put( Clouds.USGOV_CLOUD, "https://graph.microsoft.us"); | ||
| put( Clouds.CHINA_CLOUD, "https://microsoftgraph.chinacloudapi.cn"); | ||
| put( Clouds.GERMANY_CLOUD, "https://graph.microsoft.de"); | ||
| put( Clouds.USGOV_DOD_CLOUD, "https://dod-graph.microsoft.us"); | ||
| }}; | ||
|
|
||
|
|
||
| /** Base Constructor */ | ||
| public BaseGraphRequestAdapter(@Nonnull final AuthenticationProvider authenticationProvider, @Nullable final ParseNodeFactory parseNodeFactory, @Nullable final SerializationWriterFactory serializationWriterFactory, @Nullable final OkHttpClient client, @Nullable final GraphClientOptions graphClientOptions, @Nullable String baseUrl) { | ||
| super(authenticationProvider, parseNodeFactory, serializationWriterFactory, client != null ? client : GraphClientFactory.create(graphClientOptions).build()); | ||
| if (baseUrl != null && !baseUrl.isEmpty()) { | ||
| setBaseUrl(baseUrl); | ||
| } else { | ||
| setBaseUrl(determineBaseAddress(null, null)); | ||
| } | ||
| } | ||
|
|
||
| BaseGraphRequestAdapter(@Nonnull final AuthenticationProvider authenticationProvider){ | ||
| this(authenticationProvider, null, null, null, null, null); | ||
| } | ||
|
|
||
| public BaseGraphRequestAdapter(@Nonnull final AuthenticationProvider authenticationProvider, @Nonnull String baseUrl) { | ||
| this(authenticationProvider, null, null, null, null, baseUrl); | ||
| } | ||
|
|
||
| public BaseGraphRequestAdapter(@Nonnull final AuthenticationProvider authenticationProvider, @Nullable Clouds nationalCloud, @Nullable String version) { | ||
| this(authenticationProvider, determineBaseAddress(nationalCloud, version)); | ||
| } | ||
|
|
||
| BaseGraphRequestAdapter(@Nonnull AuthenticationProvider authenticationProvider, @Nonnull OkHttpClient client, @Nullable GraphClientOptions graphClientOptions) { | ||
| this(authenticationProvider, client, graphClientOptions, null, null); | ||
| } | ||
|
|
||
| public BaseGraphRequestAdapter(@Nonnull AuthenticationProvider authenticationProvider, @Nonnull OkHttpClient client, @Nullable GraphClientOptions graphClientOptions, @Nonnull String baseUrl) { | ||
| this(authenticationProvider, null, null, client,graphClientOptions, baseUrl); | ||
| } | ||
|
|
||
| public BaseGraphRequestAdapter(@Nonnull final AuthenticationProvider authenticationProvider, @Nonnull OkHttpClient client, @Nullable GraphClientOptions graphClientOptions, @Nullable Clouds nationalCloud, @Nullable String version) { | ||
| this(authenticationProvider, client, graphClientOptions , determineBaseAddress(nationalCloud, version)); | ||
| } | ||
|
|
||
| private static String determineBaseAddress(@Nullable Clouds nationalCloud, @Nullable String version) throws IllegalArgumentException { | ||
| String cloud = nationalCloud == null ? cloudList.get(Clouds.GLOBAL_CLOUD) : cloudList.get(nationalCloud); | ||
| if(cloud == null) { | ||
| throw new IllegalArgumentException(String.format("%s is an unexpected national cloud.", nationalCloud)); | ||
| } | ||
| String baseAddress = version == null ? String.format("%s/%s/",cloud,"v1.0") : String.format("%s/%s/",cloud,version); | ||
| return baseAddress; | ||
| } | ||
|
|
||
| } |
47 changes: 47 additions & 0 deletions
47
src/main/java/com/microsoft/graph/Requests/GraphClientFactory.java
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,47 @@ | ||
| package com.microsoft.graph.Requests; | ||
|
|
||
| import com.microsoft.graph.httpcore.CompressionHandler; | ||
| import com.microsoft.graph.httpcore.GraphTelemetryHandler; | ||
| import com.microsoft.kiota.RequestInformation; | ||
| import com.microsoft.kiota.http.KiotaClientFactory; | ||
| import edu.umd.cs.findbugs.annotations.Nullable; | ||
| import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
| import okhttp3.Interceptor; | ||
| import okhttp3.OkHttpClient; | ||
|
|
||
| import java.net.URI; | ||
| import java.net.URISyntaxException; | ||
| import java.text.Format; | ||
| import java.time.temporal.ChronoUnit; | ||
| import java.util.*; | ||
|
|
||
| @SuppressFBWarnings | ||
| public class GraphClientFactory { | ||
| private GraphClientFactory() { } | ||
|
|
||
| public static OkHttpClient.Builder create() { | ||
| return create((GraphClientOptions) null); | ||
| } | ||
|
|
||
| public static OkHttpClient.Builder create(Interceptor[] interceptors, @Nullable GraphClientOptions graphClientOptions) { | ||
| OkHttpClient.Builder builder = create((GraphClientOptions) null); | ||
| for(Interceptor interceptor : interceptors) { | ||
| builder.addInterceptor(interceptor); | ||
| } | ||
| return builder; | ||
| } | ||
|
|
||
| public static OkHttpClient.Builder create(@Nullable GraphClientOptions options) { | ||
| OkHttpClient.Builder builder = KiotaClientFactory.Create(createDefaultGraphInterceptors(options)); | ||
| return builder; | ||
| } | ||
|
|
||
| public static Interceptor[] createDefaultGraphInterceptors(@Nullable GraphClientOptions graphClientOptions) { | ||
| List<Interceptor> handlers = new ArrayList<>(); | ||
| handlers.add(new GraphTelemetryHandler(graphClientOptions)); | ||
| for(final Interceptor interceptor: KiotaClientFactory.CreateDefaultInterceptors()) { | ||
| handlers.add(interceptor); | ||
| } | ||
| return (Interceptor[]) handlers.toArray(); | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/microsoft/graph/Requests/IBaseClient.java
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,15 @@ | ||
| package com.microsoft.graph.Requests; | ||
|
|
||
| import com.microsoft.graph.content.BatchRequestBuilder; | ||
| import com.microsoft.kiota.RequestAdapter; | ||
| import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
|
|
||
| @SuppressFBWarnings | ||
| public interface IBaseClient { | ||
|
|
||
| public void setRequestAdapter(RequestAdapter requestAdapter); | ||
|
|
||
| public RequestAdapter getRequestAdapter(); | ||
|
|
||
| public BatchRequestBuilder getBatchRequestBuilder(); | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.