Skip to content

Commit a5bdd2b

Browse files
author
Caitlin Bales (MSFT)
authored
Merge pull request #51 from davidmoten/custom-request-fixes
CustomRequest fixes
2 parents 9661186 + 3f64dd8 commit a5bdd2b

File tree

3 files changed

+29
-39
lines changed

3 files changed

+29
-39
lines changed

src/main/java/com/microsoft/graph/http/CustomRequest.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,21 @@
2929
import com.microsoft.graph.options.Option;
3030
import com.microsoft.graph.options.QueryOption;
3131

32-
public class CustomRequest extends BaseRequest {
32+
public class CustomRequest<T> extends BaseRequest {
3333

34-
public CustomRequest(final String requestUrl, final IBaseClient client, final java.util.List<? extends Option> requestOptions, final Class<?> responseClass) {
34+
public CustomRequest(final String requestUrl, final IBaseClient client, final java.util.List<? extends Option> requestOptions, final Class<T> responseClass) {
3535
super(requestUrl, client, requestOptions, responseClass);
3636
}
3737

38-
public CustomRequest(final String requestUrl, final IBaseClient client, final java.util.List<? extends Option> requestOptions) {
39-
super(requestUrl, client, requestOptions, JsonObject.class);
38+
public static CustomRequest<JsonObject> create(final String requestUrl, final IBaseClient client, final java.util.List<? extends Option> requestOptions) {
39+
return new CustomRequest<JsonObject>(requestUrl, client, requestOptions, JsonObject.class);
4040
}
4141

42-
public <T> T get() throws ClientException {
42+
public T get() throws ClientException {
4343
return send(HttpMethod.GET, null);
4444
}
4545

46-
public <T> void get(final ICallback<T> callback) {
46+
public void get(final ICallback<T> callback) {
4747
send(HttpMethod.GET, callback, null);
4848
}
4949

@@ -68,8 +68,8 @@ public void delete() throws ClientException {{
6868
* @param sourceItem The source object with updates
6969
* @param callback The callback to be called after success or failure.
7070
*/
71-
public <T> void patch(final Class<?> sourceObject, final ICallback<T> callback) {
72-
send(HttpMethod.PATCH, callback, sourceObject);
71+
public void patch(final ICallback<T> callback) {
72+
send(HttpMethod.PATCH, callback, super.getResponseType());
7373
}
7474

7575
/**
@@ -78,26 +78,26 @@ public <T> void patch(final Class<?> sourceObject, final ICallback<T> callback)
7878
* @return The updated item
7979
* @throws ClientException This exception occurs if the request was unable to complete for any reason.
8080
*/
81-
public <T> T patch(final Class<?> sourceObject) throws ClientException {
81+
public T patch(final T sourceObject) throws ClientException {
8282
return send(HttpMethod.PATCH, sourceObject);
8383
}
8484

8585
/**
86-
* Creates an item with a new object
87-
* @param newObject The new object to create
86+
* Creates a new object
87+
* @param newAttachment The new object to create
8888
* @param callback The callback to be called after success or failure.
8989
*/
90-
public <T> void post(final Class<?> newObject, final ICallback<T> callback) {
90+
public void post(final T newObject, final ICallback<T> callback) {
9191
send(HttpMethod.POST, callback, newObject);
9292
}
9393

9494
/**
95-
* Creates an item with a new object
96-
* @param newObject The new object to create
97-
* @return The created item
95+
* Creates a new object
96+
* @param newAttachment The new object to create
97+
* @return The created Attachment
9898
* @throws ClientException This exception occurs if the request was unable to complete for any reason.
9999
*/
100-
public <T> T post(final Class<?> newObject) throws ClientException {
100+
public T post(final T newObject) throws ClientException {
101101
return send(HttpMethod.POST, newObject);
102102
}
103103

@@ -107,7 +107,7 @@ public <T> T post(final Class<?> newObject) throws ClientException {
107107
* @param value The select clause
108108
* @return The updated request
109109
*/
110-
public CustomRequest select(final String value) {
110+
public CustomRequest<T> select(final String value) {
111111
getQueryOptions().add(new QueryOption("$select", value));
112112
return this;
113113
}
@@ -118,7 +118,7 @@ public CustomRequest select(final String value) {
118118
* @param value The expand clause
119119
* @return The updated request
120120
*/
121-
public CustomRequest expand(final String value) {
121+
public CustomRequest<T> expand(final String value) {
122122
getQueryOptions().add(new QueryOption("$expand", value));
123123
return this;
124124
}

src/main/java/com/microsoft/graph/models/extensions/IGraphServiceClient.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,9 @@
44

55
package com.microsoft.graph.models.extensions;
66

7-
import com.microsoft.graph.concurrency.*;
8-
import com.microsoft.graph.core.*;
9-
import com.microsoft.graph.models.extensions.*;
10-
import com.microsoft.graph.models.generated.*;
11-
import com.microsoft.graph.http.*;
12-
import com.microsoft.graph.requests.extensions.*;
13-
import com.microsoft.graph.requests.generated.*;
14-
import com.microsoft.graph.options.*;
15-
import com.microsoft.graph.serializer.*;
16-
17-
import java.util.Arrays;
18-
import java.util.EnumSet;
7+
import com.google.gson.JsonObject;
8+
import com.microsoft.graph.models.generated.IBaseGraphServiceClient;
9+
import com.microsoft.graph.requests.extensions.CustomRequestBuilder;
1910

2011
// This file is available for extending, afterwards please submit a pull request.
2112

@@ -24,7 +15,7 @@
2415
*/
2516
public interface IGraphServiceClient extends IBaseGraphServiceClient {
2617

27-
CustomRequestBuilder customRequest(final String url, final Class<?> responseType);
18+
<T> CustomRequestBuilder<T> customRequest(final String url, final Class<T> responseType);
2819

29-
CustomRequestBuilder customRequest(final String url);
20+
CustomRequestBuilder<JsonObject> customRequest(final String url);
3021
}

src/main/java/com/microsoft/graph/requests/extensions/CustomRequestBuilder.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,26 @@
55
import com.microsoft.graph.core.IBaseClient;
66
import com.microsoft.graph.http.BaseRequestBuilder;
77
import com.microsoft.graph.http.CustomRequest;
8-
import com.microsoft.graph.requests.extensions.GraphServiceClient;
98
import com.microsoft.graph.options.Option;
109

1110
/**
1211
* The class for the CustomRequestBuilder
1312
*
1413
* @throws ClientException If the provided URL is malformed, the client exception will contain a MalformedURLException
1514
*/
16-
public class CustomRequestBuilder extends BaseRequestBuilder {
17-
public final Class<?> responseType;
15+
public class CustomRequestBuilder<T> extends BaseRequestBuilder {
16+
public final Class<T> responseType;
1817

19-
public CustomRequestBuilder(final String requestUrl, final IBaseClient client, final List<? extends Option> requestOptions, final Class<?> responseType) {
18+
public CustomRequestBuilder(final String requestUrl, final IBaseClient client, final List<? extends Option> requestOptions, final Class<T> responseType) {
2019
super(requestUrl, client, requestOptions);
2120
this.responseType = responseType;
2221
}
2322

24-
public CustomRequest buildRequest() {
23+
public CustomRequest<T> buildRequest() {
2524
return buildRequest(getOptions());
2625
}
2726

28-
public CustomRequest buildRequest(final List<? extends Option> requestOptions) {
29-
return new CustomRequest(getRequestUrl(), getClient(), requestOptions, responseType);
27+
public CustomRequest<T> buildRequest(final List<? extends Option> requestOptions) {
28+
return new CustomRequest<T>(getRequestUrl(), getClient(), requestOptions, responseType);
3029
}
3130
}

0 commit comments

Comments
 (0)