forked from microsoftgraph/msgraph-sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphServiceClient.java
More file actions
124 lines (119 loc) · 5.54 KB
/
GraphServiceClient.java
File metadata and controls
124 lines (119 loc) · 5.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package com.microsoft.graph.serviceclient;
import com.microsoft.graph.core.CoreConstants;
import com.microsoft.graph.core.requests.BaseGraphRequestAdapter;
import com.microsoft.graph.core.requests.BaseGraphRequestAdapter.Clouds;
import com.microsoft.graph.core.requests.BatchRequestBuilder;
import com.microsoft.graph.core.requests.options.GraphClientOption;
import com.microsoft.graph.core.requests.IBaseClient;
import com.microsoft.graph.BaseGraphServiceClient;
import com.microsoft.graph.users.UsersRequestBuilder;
import com.microsoft.graph.users.item.UserItemRequestBuilder;
import com.microsoft.graph.info.Constants;
import com.microsoft.kiota.RequestAdapter;
import com.microsoft.kiota.authentication.AnonymousAuthenticationProvider;
import com.microsoft.kiota.authentication.AuthenticationProvider;
import com.microsoft.graph.core.authentication.AzureIdentityAuthenticationProvider;
import com.microsoft.kiota.store.InMemoryBackingStoreFactory;
import com.azure.core.credential.TokenCredential;
import okhttp3.OkHttpClient;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
public class GraphServiceClient extends BaseGraphServiceClient implements IBaseClient {
private RequestAdapter graphServiceClientRequestAdapter;
/**
* Sets a few basic values for the GraphClientOptions to pass to the client.
* @return the GraphClientOptions instance for the GraphServiceClient.
*/
@Nonnull
public static GraphClientOption getGraphClientOptions() {
GraphClientOption graphClientOptions = new GraphClientOption();
graphClientOptions.setGraphServiceTargetVersion("v1.0");
graphClientOptions.setClientLibraryVersion(Constants.VERSION_NAME);
return graphClientOptions;
}
/**
* Instantiates a new GraphServiceClient and sets the default values.
* @param requestAdapter The request adapter to use to execute the requests.
*/
public GraphServiceClient(@Nonnull RequestAdapter requestAdapter) {
super(requestAdapter, new InMemoryBackingStoreFactory());
this.graphServiceClientRequestAdapter = requestAdapter;
}
/**
* Instantiate the GraphServiceClient using an AuthenticationProvider.
* @param authenticationProvider The AuthenticationProvider for this GraphServiceClient.
*/
public GraphServiceClient(@Nonnull AuthenticationProvider authenticationProvider) {
this(new BaseGraphRequestAdapter(authenticationProvider, null, "v1.0" , getGraphClientOptions()));
}
/**
* Instantiate the GraphServiceClient using an AuthenticationProvider, Cloud and OkHttpClient.
* @param authenticationProvider The AuthenticationProvider for this GraphServiceClient.
* @param client The OkHttpClient for the GraphServiceClient.
* @param clouds The Clouds for the GraphServiceClient.
*
*/
@SuppressWarnings("LambdaLast")
public GraphServiceClient(@Nonnull AuthenticationProvider authenticationProvider, @Nonnull OkHttpClient client, @Nonnull Clouds clouds) {
this(new BaseGraphRequestAdapter(authenticationProvider, clouds, "v1.0", client));
}
/**
* Instantiate the GraphServiceClient using an AuthenticationProvider and OkHttpClient.
* @param authenticationProvider The AuthenticationProvider for this GraphServiceClient.
* @param client The OkHttpClient for the GraphServiceClient.
*/
@SuppressWarnings("LambdaLast")
public GraphServiceClient(@Nonnull AuthenticationProvider authenticationProvider, @Nonnull OkHttpClient client) {
this(new BaseGraphRequestAdapter(authenticationProvider, null, "v1.0", client));
}
/**
* Instantiate the GraphServiceClient using an OkHttpClient
* @param client The OkHttpClient for the GraphServiceClient.
*/
public GraphServiceClient(@Nonnull OkHttpClient client) {
this(new AnonymousAuthenticationProvider(), client);
}
/**
* Instantiate the GraphServiceClient using a TokenCredential and Scopes.
* @param tokenCredential The TokenCredential for this GraphServiceClient.
* @param scopes The Scopes for this GraphServiceClient.
*/
@SuppressWarnings("LambdaLast")
public GraphServiceClient(@Nonnull TokenCredential tokenCredential, @Nullable String... scopes) {
this(new AzureIdentityAuthenticationProvider(tokenCredential, new String[] {}, scopes));
}
/**
* Sets the RequestAdapter for the GraphServiceClient.
* @param requestAdapter the request adapter to use to execute the requests.
*/
@Override
public void setRequestAdapter(@Nonnull RequestAdapter requestAdapter) {
this.graphServiceClientRequestAdapter = requestAdapter;
}
/**
* Gets the RequestAdapter for the GraphServiceClient.
* @return the request adapter to use to execute the requests.
*/
@Nonnull
@Override
public RequestAdapter getRequestAdapter() {
return this.graphServiceClientRequestAdapter;
}
/**
* Gets the BatchRequestBuilder for the GraphServiceClient.
* @return the BatchRequestBuilder for the GraphServiceClient.
*/
@Nonnull
@Override
public BatchRequestBuilder getBatchRequestBuilder() {
return new CustomBatchRequestBuilder(this.graphServiceClientRequestAdapter);
}
/**
* Provides operations to manage the user singleton.
* @return the request builder for the user singleton.
*/
@Nonnull
public UserItemRequestBuilder me() {
return new UsersRequestBuilder(pathParameters, graphServiceClientRequestAdapter).byUserId(CoreConstants.ReplacementConstants.USER_ID_TOKEN_TO_REPLACE);
}
}