Skip to content

Commit e5a3aef

Browse files
authored
Merge branch 'dev' into release/1.0.3
2 parents ca1dbbb + 8c51f4b commit e5a3aef

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

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

Lines changed: 21 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,30 @@ 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 the step id
67+
*/
68+
public String 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+
if(addBatchRequestStep(new MSBatchRequestStep(requestId, request, Arrays.asList(arrayOfDependsOnIds))))
74+
return requestId;
75+
else
76+
throw new IllegalArgumentException("unable to add step to batch. Number of batch request steps cannot exceed " + MAX_NUMBER_OF_REQUESTS);
77+
}
78+
5979
/*
6080
* @param requestId Id of Batch request step to be removed
6181
*

0 commit comments

Comments
 (0)