Skip to content

Commit f914128

Browse files
SDK regenerated by CI server [ci skip]
1 parent a3fdc80 commit f914128

File tree

5 files changed

+179
-34
lines changed

5 files changed

+179
-34
lines changed

src/main/java/com/aspose/words/cloud/ApiClient.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
package com.aspose.words.cloud;
2929

30-
import com.aspose.words.cloud.model.requests.RequestIfc;
30+
import com.aspose.words.cloud.model.requests.*;
3131
import com.squareup.okhttp.*;
3232
import com.squareup.okhttp.internal.http.HttpMethod;
3333
import com.squareup.okhttp.logging.HttpLoggingInterceptor;
@@ -1226,18 +1226,24 @@ public String addParameterToPath(String path, String paramName, Object paramValu
12261226
/**
12271227
* Build batch request
12281228
*/
1229-
public Request buildBatchRequest(RequestIfc[] requests) throws ApiException, IOException {
1229+
public Request buildBatchRequest(BatchPartRequest[] requests, Boolean displayIntermediateResults) throws ApiException, IOException {
12301230
Headers multipartHeaders = Headers.of("Content-Disposition", "form-data");
12311231
MultipartBuilder builder = new MultipartBuilder().type(MultipartBuilder.FORM);
1232-
for (RequestIfc request : requests) {
1233-
Request httpRequest = request.buildHttpRequest(this, null, null, false);
1234-
builder.addPart(multipartHeaders, new ChildRequestContent(httpRequest, basePath + "/words/"));
1232+
for (BatchPartRequest request : requests) {
1233+
builder.addPart(multipartHeaders, new ChildRequestContent(this, request, basePath + "/words/"));
12351234
}
12361235

12371236
RequestBody requestBody = builder.build();
12381237
Map<String, String> headers = new HashMap<>();
12391238
headers.put("Content-Type", requestBody.contentType().toString());
1240-
return buildRequest("/words/batch", "PUT", new ArrayList<>(), new ArrayList<>(), requestBody, headers, new HashMap<>(), true, null);
1239+
1240+
String url = "/words/batch";
1241+
if (!displayIntermediateResults)
1242+
{
1243+
url += "?displayIntermediateResults=false";
1244+
}
1245+
1246+
return buildRequest(url, "PUT", new ArrayList<>(), new ArrayList<>(), requestBody, headers, new HashMap<>(), true, null);
12411247
}
12421248

12431249
/**
@@ -1334,7 +1340,8 @@ public Object parseBatchPart(Request masterRequest, BodyPart bodyPart, Type retu
13341340
Headers headers = headersBuilder.build();
13351341
byte[] rawBody = buffer.toByteArray();
13361342
if (rawBody.length != lastSplitIndex + 2) {
1337-
byte[] responseBytes = Arrays.copyOfRange(rawBody, lastSplitIndex + 2, rawBody.length);
1343+
byte[] responseBytes = new byte[rawBody.length - (lastSplitIndex + 2)];
1344+
System.arraycopy(rawBody, lastSplitIndex + 2, responseBytes, 0, responseBytes.length);
13381345
responseBody = ResponseBody.create(MediaType.parse(headers.get("Content-Type")), responseBytes);
13391346
}
13401347

src/main/java/com/aspose/words/cloud/ChildRequestContent.java

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
package com.aspose.words.cloud;
2929

30+
import com.aspose.words.cloud.model.requests.*;
3031
import com.squareup.okhttp.MediaType;
3132
import com.squareup.okhttp.Request;
3233
import com.squareup.okhttp.RequestBody;
@@ -37,10 +38,12 @@
3738

3839
public class ChildRequestContent extends RequestBody {
3940
private static final String CRLF = "\r\n";
40-
private Request request;
41+
private ApiClient apiClient;
42+
private BatchPartRequest request;
4143
private URI baseUri;
4244

43-
public ChildRequestContent(Request request, String rootUrl) {
45+
public ChildRequestContent(ApiClient apiClient, BatchPartRequest request, String rootUrl) {
46+
this.apiClient = apiClient;
4447
this.request = request;
4548
this.baseUri = URI.create(rootUrl);
4649
}
@@ -52,22 +55,43 @@ public MediaType contentType() {
5255

5356
@Override
5457
public void writeTo(BufferedSink bufferedSink) throws IOException {
55-
bufferedSink.writeUtf8(request.method());
58+
Request httpRequest;
59+
try
60+
{
61+
httpRequest = request.getRequest().buildHttpRequest(this.apiClient, null, null, false);
62+
}
63+
catch (ApiException ex)
64+
{
65+
throw new IOException(ex.getMessage());
66+
}
67+
68+
bufferedSink.writeUtf8(httpRequest.method());
5669
bufferedSink.writeUtf8(" ");
57-
bufferedSink.writeUtf8(baseUri.relativize(request.uri()).toString());
70+
bufferedSink.writeUtf8(baseUri.relativize(httpRequest.uri()).toString());
5871
bufferedSink.writeUtf8(" ");
5972
bufferedSink.writeUtf8(CRLF);
6073

61-
for (String key : request.headers().names()) {
74+
bufferedSink.writeUtf8("RequestId: ");
75+
bufferedSink.writeUtf8(request.getRequestId());
76+
bufferedSink.writeUtf8(CRLF);
77+
78+
if (request.getParentRequestId() != null)
79+
{
80+
bufferedSink.writeUtf8("DependsOn: ");
81+
bufferedSink.writeUtf8(request.getParentRequestId());
82+
bufferedSink.writeUtf8(CRLF);
83+
}
84+
85+
for (String key : httpRequest.headers().names()) {
6286
bufferedSink.writeUtf8(key);
6387
bufferedSink.writeUtf8(": ");
64-
bufferedSink.writeUtf8(request.headers().get(key));
88+
bufferedSink.writeUtf8(httpRequest.headers().get(key));
6589
bufferedSink.writeUtf8(CRLF);
6690
}
6791

6892
bufferedSink.writeUtf8(CRLF);
69-
if (request.body() != null) {
70-
request.body().writeTo(bufferedSink);
93+
if (httpRequest.body() != null) {
94+
httpRequest.body().writeTo(bufferedSink);
7195
}
7296
}
7397
}

src/main/java/com/aspose/words/cloud/api/WordsApi.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import com.squareup.okhttp.Response;
3636
import java.io.IOException;
3737
import javax.crypto.NoSuchPaddingException;
38+
import javax.mail.BodyPart;
3839
import javax.mail.MessagingException;
3940
import java.io.File;
4041
import java.lang.reflect.Type;
@@ -23055,24 +23056,32 @@ public void onRequestProgress(long bytesWritten, long contentLength, boolean don
2305523056
return call;
2305623057
}
2305723058

23058-
public Object[] batch(RequestIfc... requests) throws ApiException, IOException {
23059+
public Object[] batch(BatchPartRequest... requests) throws ApiException, IOException {
23060+
return this.batch(true, requests);
23061+
}
23062+
23063+
public Object[] batch(Boolean displayIntermediateResults, BatchPartRequest... requests) throws ApiException, IOException {
2305923064
if (requests == null || requests.length == 0) {
2306023065
return null;
2306123066
}
2306223067

23063-
com.squareup.okhttp.Request masterRequest = apiClient.buildBatchRequest(requests);
23068+
com.squareup.okhttp.Request masterRequest = apiClient.buildBatchRequest(requests, displayIntermediateResults);
2306423069
com.squareup.okhttp.Call call = apiClient.buildCall(masterRequest);
2306523070
ApiResponse<javax.mail.internet.MimeMultipart> response = apiClient.execute(call, javax.mail.internet.MimeMultipart.class);
2306623071

2306723072
try {
23068-
int count = response.getData().getCount();
23069-
if (count != requests.length) {
23070-
throw new ApiException(400, "The number of responses does not match the number of requests.");
23071-
}
23072-
23073-
Object[] result = new Object[count];
23074-
for (int i = 0; i < count; i++) {
23075-
result[i] = apiClient.parseBatchPart(masterRequest, response.getData().getBodyPart(i), requests[i].getResponseType());
23073+
Object[] result = new Object[response.getData().getCount()];
23074+
for (int i = 0; i < result.length; i++) {
23075+
BodyPart part = response.getData().getBodyPart(i);
23076+
String[] requestId = part.getHeader("RequestId");
23077+
if (requestId != null && requestId.length == 1) {
23078+
for (BatchPartRequest batchPartRequest : requests) {
23079+
if (batchPartRequest.getRequestId().equals(requestId[0])) {
23080+
result[i] = apiClient.parseBatchPart(masterRequest, part, batchPartRequest.getRequest().getResponseType());
23081+
break;
23082+
}
23083+
}
23084+
}
2307623085
}
2307723086

2307823087
return result;
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* --------------------------------------------------------------------------------
3+
* <copyright company="Aspose" file="BatchPartRequest.java">
4+
* Copyright (c) 2021 Aspose.Words for Cloud
5+
* </copyright>
6+
* <summary>
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in all
15+
* copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
* SOFTWARE.
24+
* </summary>
25+
* --------------------------------------------------------------------------------
26+
*/
27+
28+
package com.aspose.words.cloud.model.requests;
29+
30+
import com.aspose.words.cloud.*;
31+
import com.squareup.okhttp.Request;
32+
33+
import java.io.*;
34+
35+
/*
36+
* A batch part request wrapper to add batch part features.
37+
*/
38+
public class BatchPartRequest
39+
{
40+
private RequestIfc request;
41+
42+
private String requestId;
43+
44+
private String parentRequestId;
45+
46+
/*
47+
* Initializes a new instance of the BatchPartRequest class.
48+
*
49+
* @param request RequestIfc inner request
50+
*/
51+
public BatchPartRequest(RequestIfc request) {
52+
this.request = request;
53+
this.requestId = java.util.UUID.randomUUID().toString();
54+
this.parentRequestId = null;
55+
}
56+
57+
/*
58+
* Get request object.
59+
*/
60+
public RequestIfc getRequest() {
61+
return this.request;
62+
}
63+
64+
/*
65+
* Get request ID.
66+
*/
67+
public String getRequestId() {
68+
return this.requestId;
69+
}
70+
71+
/*
72+
* Get parent request ID.
73+
*/
74+
public String getParentRequestId() {
75+
return this.parentRequestId;
76+
}
77+
78+
/*
79+
* Set parent request.
80+
*
81+
* @param parentRequest BatchPartRequest a parent request.
82+
*/
83+
public BatchPartRequest dependsOn(BatchPartRequest parentRequest) {
84+
this.parentRequestId = parentRequest.getRequestId();
85+
return this;
86+
}
87+
88+
/*
89+
* Use a binary response of the request as an input for another request.
90+
*/
91+
public byte[] resultOf() throws UnsupportedEncodingException {
92+
return ("resultOf(" + this.requestId + ")").getBytes("UTF8");
93+
}
94+
}

src/test/java/com/aspose/words/cloud/TestBatch.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,23 @@ public void testBatch() throws ApiException, MessagingException, IOException {
6262
String remote_path = PathUtil.get(remoteFolder, remoteName).replace("\\", "/");
6363
UploadFileRequest request0 = new UploadFileRequest(Files.readAllBytes(new File(file).toPath()), remote_path, null);
6464

65-
GetParagraphsRequest request1 = new GetParagraphsRequest(remoteName,"sections/0", remoteFolder, null, null, null);
65+
BatchPartRequest request1 = new BatchPartRequest(
66+
new GetParagraphsRequest(remoteName,"sections/0", remoteFolder, null, null, null)
67+
);
6668

67-
GetParagraphRequest request2 = new GetParagraphRequest(remoteName, 0, "sections/0", remoteFolder, null, null, null);
69+
BatchPartRequest request2 = new BatchPartRequest(
70+
new GetParagraphRequest(remoteName, 0, "sections/0", remoteFolder, null, null, null)
71+
);
6872

6973
ParagraphInsert request3body = new ParagraphInsert();
7074
request3body.setText("This is a new paragraph for your document");
71-
InsertParagraphRequest request3 = new InsertParagraphRequest(remoteName, request3body, "sections/0", remoteFolder, null, null, null, null, null, null, null);
75+
BatchPartRequest request3 = new BatchPartRequest(
76+
new InsertParagraphRequest(remoteName, request3body, "sections/0", remoteFolder, null, null, null, null, null, null, null)
77+
);
7278

73-
DeleteParagraphRequest request4 = new DeleteParagraphRequest(remoteName, 0, "", remoteFolder, null, null, null, null, null, null);
79+
BatchPartRequest request4 = new BatchPartRequest(
80+
new DeleteParagraphRequest(remoteName, 0, "", remoteFolder, null, null, null, null, null, null)
81+
);
7482

7583
String localDocumentFile = "ReportTemplate.docx";
7684
String localDataFile = new String(Files.readAllBytes(Paths.get(TestInitializer.LocalTestFolder, reportingFolder + "/ReportData.json")), "utf8");
@@ -79,12 +87,15 @@ public void testBatch() throws ApiException, MessagingException, IOException {
7987
requestReportEngineSettings.setDataSourceType(ReportEngineSettings.DataSourceTypeEnum.JSON);
8088
requestReportEngineSettings.setDataSourceName("persons");
8189

82-
BuildReportOnlineRequest request5 = new BuildReportOnlineRequest(
83-
Files.readAllBytes(Paths.get(TestInitializer.LocalTestFolder, reportingFolder + "/" + localDocumentFile).toAbsolutePath()),
84-
localDataFile,
85-
requestReportEngineSettings,
86-
null
90+
BatchPartRequest request5 = new BatchPartRequest(
91+
new BuildReportOnlineRequest(
92+
Files.readAllBytes(Paths.get(TestInitializer.LocalTestFolder, reportingFolder + "/" + localDocumentFile).toAbsolutePath()),
93+
localDataFile,
94+
requestReportEngineSettings,
95+
null
96+
)
8797
);
98+
8899
TestInitializer.wordsApi.uploadFile(request0);
89100

90101
Object[] result = TestInitializer.wordsApi.batch(request1, request2, request3, request4, request5);

0 commit comments

Comments
 (0)