forked from microsoftgraph/msgraph-sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomBatchRequestBuilder.java
More file actions
62 lines (57 loc) · 2.92 KB
/
Copy pathCustomBatchRequestBuilder.java
File metadata and controls
62 lines (57 loc) · 2.92 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
package com.microsoft.graph.serviceclient;
import com.microsoft.graph.core.content.BatchRequestContent;
import com.microsoft.graph.core.content.BatchRequestContentCollection;
import com.microsoft.graph.core.content.BatchResponseContent;
import com.microsoft.graph.core.content.BatchResponseContentCollection;
import com.microsoft.graph.core.requests.BatchRequestBuilder;
import com.microsoft.graph.models.odataerrors.ODataError;
import com.microsoft.kiota.RequestAdapter;
import com.microsoft.kiota.serialization.Parsable;
import com.microsoft.kiota.serialization.ParsableFactory;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
* CustomBatchRequestBuilder extends BatchRequestBuilder to include graph specific default error mappings.
*/
public class CustomBatchRequestBuilder extends BatchRequestBuilder {
/**
* Instantiates a new CustomBatchRequestBuilder
* @param requestAdapter the request adapter to use to execute the requests
*/
public CustomBatchRequestBuilder(@Nonnull RequestAdapter requestAdapter) {
super(requestAdapter);
}
/**
* Sends out the BatchRequestContent using the POST method.
* @param requestContent the BatchRequestContent to post.
* @param errorMappings the error mappings to use when parsing the response.
* @return the batchResponseContent.
*/
@Nonnull
@Override
public BatchResponseContent post(@Nonnull BatchRequestContent requestContent, @Nullable Map<String, ParsableFactory<? extends Parsable>> errorMappings) throws IOException {
Map<String, ParsableFactory<? extends Parsable>> batchErrorMappings = errorMappings == null ? getDefaultErrorMappings() : errorMappings;
return super.post(requestContent, batchErrorMappings);
}
/**
* Sends out the BatchRequestContentCollection using the POST method.
* @param requestContentCollection the BatchRequestContentCollection to post.
* @param errorMappings the error mappings to use when parsing the response.
* @return the responseContentCollection.
*/
@Nonnull
@Override
public BatchResponseContentCollection post(@Nonnull BatchRequestContentCollection requestContentCollection, @Nullable Map<String, ParsableFactory<? extends Parsable>> errorMappings) throws IOException {
Map<String, ParsableFactory<? extends Parsable>> batchErrorMappings = errorMappings == null ? getDefaultErrorMappings() : errorMappings;
return super.post(requestContentCollection, batchErrorMappings);
}
private Map<String, ParsableFactory<? extends Parsable>> getDefaultErrorMappings() {
Map<String, ParsableFactory<? extends Parsable>> errorMappings = new HashMap<>();
errorMappings.put("4XX", ODataError::createFromDiscriminatorValue);
errorMappings.put("5XX", ODataError::createFromDiscriminatorValue);
return errorMappings;
}
}