@@ -27,124 +27,199 @@ public class GraphServiceClient extends BaseGraphServiceClient implements IGraph
2727 */
2828 protected GraphServiceClient () {
2929 }
30-
30+
3131 /**
3232 * Send a custom request to Graph
3333 *
34- * @param url the full URL to make a request with
35- * @param responseType the response class to deserialize the response into
34+ * @param url
35+ * the full URL to make a request with
36+ * @param responseType
37+ * the response class to deserialize the response into
3638 * @return the instance of this builder
3739 */
38- public CustomRequestBuilder customRequest (final String url , final Class responseType ) {
39- return new CustomRequestBuilder (getServiceRoot () + url , (IGraphServiceClient )this , null , responseType );
40+ public < T > CustomRequestBuilder < T > customRequest (final String url , final Class < T > responseType ) {
41+ return new CustomRequestBuilder < T > (getServiceRoot () + url , (IGraphServiceClient ) this , null , responseType );
4042 }
41-
43+
4244 /**
4345 * Send a custom request to Graph
4446 *
45- * @param url the full URL to make a request with
47+ * @param url
48+ * the full URL to make a request with
4649 * @return the instance of this builder
4750 */
48- public CustomRequestBuilder customRequest (final String url ) {
49- return new CustomRequestBuilder (getServiceRoot () + url , (IGraphServiceClient )this , null , JsonObject .class );
50- }
51-
52- public static Builder builder () {
53- return new Builder ();
51+ public CustomRequestBuilder <JsonObject > customRequest (final String url ) {
52+ return new CustomRequestBuilder <JsonObject >(getServiceRoot () + url , (IGraphServiceClient ) this , null ,
53+ JsonObject .class );
5454 }
5555
5656 /**
57- * The builder for this GraphServiceClient
57+ * Returns a Graph service client using the given configuration.
58+ *
59+ * @param config
60+ * the client configuration
61+ * @return a Graph service client
5862 */
59- public static class Builder {
63+ public static IGraphServiceClient fromConfig (final IClientConfig config ) {
64+ GraphServiceClient client = new GraphServiceClient ();
65+ client .setAuthenticationProvider (config .getAuthenticationProvider ());
66+ client .setExecutors (config .getExecutors ());
67+ client .setHttpProvider (config .getHttpProvider ());
68+ client .setLogger (config .getLogger ());
69+ client .setSerializer (config .getSerializer ());
70+ client .validate ();
71+ return client ;
72+ }
73+
74+ public static Builder builder () {
75+ return new Builder ();
76+ }
77+
78+ public static final class Builder {
6079
6180 Builder () {
62- // ensure instantiation only from static factory method
81+ // restrict instantiation
6382 }
6483
6584 /**
66- * The client under construction
67- */
68- private final GraphServiceClient client = new GraphServiceClient ();
69-
70- /**
71- * Sets the serializer
85+ * Sets the authentication provider
7286 *
73- * @param serializer the serializer
74- * @return the instance of this builder
87+ * @param authenticationProvider
88+ * the authentication provider
89+ * @return a new builder that allows specification of other aspects of the GraphServiceClient
7590 */
76- public Builder serializer (final ISerializer serializer ) {
77- client .setSerializer (serializer );
78- return this ;
91+ public Builder2 authenticationProvider (IAuthenticationProvider authenticationProvider ) {
92+ checkNotNull (authenticationProvider , "authenticationProvider" );
93+ return new Builder2 (authenticationProvider );
94+ }
95+ }
96+
97+ /**
98+ * The builder for this GraphServiceClient
99+ */
100+ public static final class Builder2 {
101+
102+ private final IAuthenticationProvider authenticationProvider ;
103+ private ISerializer serializer ;
104+ private IHttpProvider httpProvider ;
105+ private IExecutors executors ;
106+ private ILogger logger ;
107+
108+
109+ Builder2 (IAuthenticationProvider authenticationProvider ) {
110+ this .authenticationProvider = authenticationProvider ;
79111 }
80112
81113 /**
82- * Sets the httpProvider
114+ * Sets the serializer.
83115 *
84- * @param httpProvider the httpProvider
116+ * @param serializer
117+ * the serializer
85118 * @return the instance of this builder
86119 */
87- public Builder httpProvider (final IHttpProvider httpProvider ) {
88- client .setHttpProvider (httpProvider );
120+ public Builder2 serializer (final ISerializer serializer ) {
121+ checkNotNull (serializer , "serializer" );
122+ this .serializer = serializer ;
89123 return this ;
90124 }
91125
92126 /**
93- * Sets the authentication provider
127+ * Sets the httpProvider
94128 *
95- * @param authenticationProvider the authentication provider
129+ * @param httpProvider
130+ * the httpProvider
96131 * @return the instance of this builder
97132 */
98- public Builder authenticationProvider (final IAuthenticationProvider authenticationProvider ) {
99- client .setAuthenticationProvider (authenticationProvider );
133+ public Builder2 httpProvider (final IHttpProvider httpProvider ) {
134+ checkNotNull (httpProvider , "httpProvider" );
135+ this .httpProvider = httpProvider ;
100136 return this ;
101137 }
102138
103139 /**
104140 * Sets the executors
105141 *
106- * @param executors the executors
142+ * @param executors
143+ * the executors
107144 * @return the instance of this builder
108145 */
109- public Builder executors (final IExecutors executors ) {
110- client .setExecutors (executors );
146+ public Builder2 executors (final IExecutors executors ) {
147+ checkNotNull (executors , "executors" );
148+ this .executors = executors ;
111149 return this ;
112150 }
113151
114152 /**
115153 * Sets the logger
116154 *
117- * @param logger the logger
155+ * @param logger
156+ * the logger
118157 * @return the instance of this builder
119158 */
120- public Builder logger (final ILogger logger ) {
121- client .setLogger (logger );
159+ public Builder2 logger (final ILogger logger ) {
160+ checkNotNull (logger , "logger" );
161+ this .logger = logger ;
122162 return this ;
123163 }
124164
125165 /**
126- * Set this builder based on the client configuration
166+ * Builds and returns the Graph service client.
127167 *
128- * @param clientConfig the client configuration
129- * @return the instance of this builder
168+ * @return the Graph service client object
169+ * @throws ClientException
170+ * if there was an exception creating the client
130171 */
131- public Builder fromConfig (final IClientConfig clientConfig ) {
132- return this .authenticationProvider (clientConfig .getAuthenticationProvider ())
133- .executors (clientConfig .getExecutors ())
134- .httpProvider (clientConfig .getHttpProvider ())
135- .logger (clientConfig .getLogger ())
136- .serializer (clientConfig .getSerializer ());
137- }
172+ public IGraphServiceClient buildClient () throws ClientException {
173+ DefaultClientConfig config = new DefaultClientConfig () {
138174
139- /**
140- * Builds and returns the GraphServiceClient
141- *
142- * @return the GraphServiceClient object
143- * @throws ClientException if there was an exception creating the client
144- */
145- public IGraphServiceClient buildClient () throws ClientException {
146- client .validate ();
147- return client ;
175+ @ Override
176+ public IAuthenticationProvider getAuthenticationProvider () {
177+ return authenticationProvider ;
178+ }
179+
180+ @ Override
181+ public IHttpProvider getHttpProvider () {
182+ if (httpProvider != null ) {
183+ return httpProvider ;
184+ } else {
185+ return super .getHttpProvider ();
186+ }
187+ }
188+
189+ @ Override
190+ public IExecutors getExecutors () {
191+ if (executors != null ) {
192+ return executors ;
193+ } else {
194+ return super .getExecutors ();
195+ }
196+ }
197+
198+ @ Override
199+ public ILogger getLogger () {
200+ if (logger !=null ) {
201+ return logger ;
202+ } else {
203+ return super .getLogger ();
204+ }
205+ }
206+
207+ @ Override
208+ public ISerializer getSerializer () {
209+ if (serializer != null ) {
210+ return serializer ;
211+ } else {
212+ return super .getSerializer ();
213+ }
214+ }
215+ };
216+ return GraphServiceClient .fromConfig (config );
217+ }
218+ }
219+
220+ private static void checkNotNull (Object o , String name ) {
221+ if (o ==null ) {
222+ throw new NullPointerException (name + " cannot be null" );
148223 }
149224 }
150225}
0 commit comments