Skip to content

Commit a4ce2f2

Browse files
committed
- adds a method to add batch steps from http requests
1 parent 9dfb9e5 commit a4ce2f2

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/main/java/com/microsoft/graph/content/MSBatchRequestContent.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.microsoft.graph.content;
22

33
import java.io.IOException;
4+
import java.util.Arrays;
45
import java.util.HashMap;
56
import java.util.List;
67
import java.util.Map;
8+
import java.util.concurrent.ThreadLocalRandom;
79

810
import com.google.gson.JsonArray;
911
import com.google.gson.JsonObject;
@@ -50,12 +52,27 @@ public MSBatchRequestContent() {
5052
* given
5153
*/
5254
public boolean addBatchRequestStep(final MSBatchRequestStep batchRequestStep) {
53-
if (batchRequestStepsHashMap.containsKey(batchRequestStep.getRequestId()))
55+
if (batchRequestStepsHashMap.containsKey(batchRequestStep.getRequestId()) ||
56+
batchRequestStepsHashMap.size() >= MAX_NUMBER_OF_REQUESTS)
5457
return false;
5558
batchRequestStepsHashMap.put(batchRequestStep.getRequestId(), batchRequestStep);
5659
return true;
5760
}
5861

62+
/**
63+
* Add steps to batch from OkHttp.Request
64+
* @param request the request to add to the batch
65+
* @param arrayOfDependsOnIds ids of steps this step depends on
66+
* @return whether the step was added to the batch or not
67+
*/
68+
public boolean addBatchRequestStep(final Request request, final String... arrayOfDependsOnIds) {
69+
String requestId;
70+
do {
71+
requestId = Integer.toString(ThreadLocalRandom.current().nextInt());
72+
} while(batchRequestStepsHashMap.keySet().contains(requestId));
73+
return addBatchRequestStep(new MSBatchRequestStep(requestId, request, Arrays.asList(arrayOfDependsOnIds)));
74+
}
75+
5976
/*
6077
* @param requestId Id of Batch request step to be removed
6178
*

0 commit comments

Comments
 (0)