Skip to content

Commit 9d10dc8

Browse files
committed
update Version1.2.4
1 parent c6ce853 commit 9d10dc8

File tree

6 files changed

+290
-107
lines changed

6 files changed

+290
-107
lines changed

sample/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<dependency>
1717
<groupId>com.compdf</groupId>
1818
<artifactId>compdfkit-pdf-api-java</artifactId>
19-
<version>0.0.1</version>
19+
<version>0.0.3</version>
2020
</dependency>
2121
</dependencies>
2222

src/main/java/cn/kdan/compdfkit/client/CHttpClient.java

Lines changed: 110 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
import java.util.Map;
3131
import java.util.Objects;
3232

33-
33+
/**
34+
* HttpClient
35+
*/
3436
public class CHttpClient {
3537

3638
private final RestTemplate restTemplate;
@@ -41,39 +43,71 @@ public class CHttpClient {
4143
private final String publicKey;
4244
private final String secretKey;
4345

44-
CHttpClient(RestTemplate restTemplate, String publicKey, String secretKey){
46+
/**
47+
* CHttpClient
48+
*
49+
* @param restTemplate restTemplate
50+
* @param publicKey publicKey
51+
* @param secretKey secretKey
52+
*/
53+
CHttpClient(RestTemplate restTemplate, String publicKey, String secretKey) {
4554
this.address = "https://api-server.compdf.com/server/";
4655
this.restTemplate = restTemplate;
4756
this.publicKey = publicKey;
4857
this.secretKey = secretKey;
4958
this.refreshAccessToken();
5059
}
5160

61+
/**
62+
* basicHeaders
63+
*
64+
* @return HttpHeaders
65+
*/
5266
private HttpHeaders basicHeaders() {
5367
HttpHeaders headers = new HttpHeaders();
5468
headers.set("Authorization", "Bearer " + this.getAccessToken());
5569
return headers;
5670
}
5771

58-
public String getAccessToken() {
72+
/**
73+
* getAccessToken
74+
*
75+
* @return toke
76+
*/
77+
String getAccessToken() {
5978
if (ObjectUtils.isEmpty(expireTime) || System.currentTimeMillis() > expireTime) {
6079
refreshAccessToken();
6180
}
6281
return accessToken;
6382
}
6483

65-
public void setAccessToken(String token, long expiresIn) {
84+
/**
85+
* setAccessToken
86+
*
87+
* @param token token
88+
* @param expiresIn expiresIn
89+
*/
90+
void setAccessToken(String token, long expiresIn) {
6691
accessToken = token;
6792
expireTime = System.currentTimeMillis() + expiresIn * 1000L;
6893
}
6994

95+
/**
96+
* refreshAccessToken
97+
*/
7098
void refreshAccessToken() {
7199
// Call the API to refresh the token
72100
ComPdfKitOauthResult newToken = getComPdfKitAuth(this.publicKey, this.secretKey);
73101
setAccessToken(newToken.getAccessToken(), Long.parseLong(newToken.getExpiresIn()));
74102
}
75103

76-
104+
/**
105+
* getComPdfKitAuth
106+
*
107+
* @param publicKey publicKey
108+
* @param secretKey secretKey
109+
* @return ComPdfKitOauthResult
110+
*/
77111
ComPdfKitOauthResult getComPdfKitAuth(String publicKey, String secretKey) {
78112
HttpHeaders headers = new HttpHeaders();
79113
headers.setContentType(MediaType.APPLICATION_JSON);
@@ -100,6 +134,11 @@ ComPdfKitOauthResult getComPdfKitAuth(String publicKey, String secretKey) {
100134
return responseEntity.getBody().getData();
101135
}
102136

137+
/**
138+
* getTools
139+
*
140+
* @return List<CTool>
141+
*/
103142
List<CTool> getTools() {
104143
String url = address.concat(ComPDFKitConstant.API_V1_TOOL_SUPPORT);
105144
ResponseEntity<ComPdfKitResult<List<CTool>>> response;
@@ -122,7 +161,13 @@ List<CTool> getTools() {
122161
return response.getBody().getData();
123162
}
124163

125-
CFileInfo queryFileInfo(String fileKey) {
164+
/**
165+
* getFileInfo
166+
*
167+
* @param fileKey fileKey
168+
* @return CFileInfo
169+
*/
170+
CFileInfo getFileInfo(String fileKey) {
126171
String url = address.concat(ComPDFKitConstant.API_V1_FILE_INFO).concat("?fileKey=").concat(fileKey);
127172
ResponseEntity<ComPdfKitResult<CFileInfo>> response;
128173
ParameterizedTypeReference<ComPdfKitResult<CFileInfo>> typeRef = new ParameterizedTypeReference<ComPdfKitResult<CFileInfo>>() {
@@ -144,7 +189,12 @@ CFileInfo queryFileInfo(String fileKey) {
144189
return response.getBody().getData();
145190
}
146191

147-
CTenantAssetResult queryAssetInfo() {
192+
/**
193+
* getAssetInfo
194+
*
195+
* @return CTenantAssetResult
196+
*/
197+
CTenantAssetResult getAssetInfo() {
148198
String url = address.concat(ComPDFKitConstant.API_V1_ASSET_INFO);
149199
ResponseEntity<ComPdfKitResult<CTenantAssetResult>> response;
150200
ParameterizedTypeReference<ComPdfKitResult<CTenantAssetResult>> typeRef = new ParameterizedTypeReference<ComPdfKitResult<CTenantAssetResult>>() {
@@ -166,7 +216,14 @@ CTenantAssetResult queryAssetInfo() {
166216
return response.getBody().getData();
167217
}
168218

169-
CTaskRecordsResult queryTaskList(String page, String size) {
219+
/**
220+
* getTaskList
221+
*
222+
* @param page page
223+
* @param size size
224+
* @return CTaskRecordsResult
225+
*/
226+
CTaskRecordsResult getTaskList(String page, String size) {
170227
if (StringUtils.isEmpty(page)) {
171228
page = "1";
172229
}
@@ -194,6 +251,12 @@ CTaskRecordsResult queryTaskList(String page, String size) {
194251
return response.getBody().getData();
195252
}
196253

254+
/**
255+
* createTask
256+
*
257+
* @param executeTypeUrl executeTypeUrl
258+
* @return CCreateTaskResult
259+
*/
197260
CCreateTaskResult createTask(String executeTypeUrl) {
198261
String url = address.concat(ComPDFKitConstant.API_V1_CREATE_TASK).replace("{executeTypeUrl}", executeTypeUrl);
199262
ResponseEntity<ComPdfKitResult<CCreateTaskResult>> response;
@@ -216,15 +279,34 @@ CCreateTaskResult createTask(String executeTypeUrl) {
216279
return response.getBody().getData();
217280
}
218281

219-
CUploadFileResult getUploadFileResult(File file, String taskId, String password, CFileParameter CFileParameter) {
282+
/**
283+
* getUploadFileResult
284+
*
285+
* @param file file
286+
* @param taskId taskId
287+
* @param password password
288+
* @param fileParameter fileParameter
289+
* @return CUploadFileResult
290+
*/
291+
CUploadFileResult getUploadFileResult(File file, String taskId, String password, CFileParameter fileParameter) {
220292
try {
221-
return this.getUploadFileResult(new FileInputStream(file),taskId,password, CFileParameter,file.getName());
293+
return this.getUploadFileResult(new FileInputStream(file), taskId, password, fileParameter, file.getName());
222294
} catch (FileNotFoundException e) {
223-
throw new ComPDFKitException(e.getMessage(),e);
295+
throw new ComPDFKitException(e.getMessage(), e);
224296
}
225297
}
226298

227-
CUploadFileResult getUploadFileResult(InputStream fileInputStream, String taskId, String password, CFileParameter CFileParameter, String fileName) {
299+
/**
300+
* getUploadFileResult
301+
*
302+
* @param fileInputStream fileInputStream
303+
* @param taskId taskId
304+
* @param password password
305+
* @param fileParameter fileParameter
306+
* @param fileName fileName
307+
* @return return CUploadFileResult
308+
*/
309+
CUploadFileResult getUploadFileResult(InputStream fileInputStream, String taskId, String password, CFileParameter fileParameter, String fileName) {
228310
log.info("Start uploading files, task Id: {}, password: {}", taskId, password);
229311
String url = address.concat(ComPDFKitConstant.API_V1_UPLOAD_FILE);
230312
MultiValueMap<String, Object> param = new LinkedMultiValueMap<>();
@@ -233,6 +315,7 @@ CUploadFileResult getUploadFileResult(InputStream fileInputStream, String taskId
233315
public long contentLength() throws IOException {
234316
return fileInputStream.available();
235317
}
318+
236319
@Override
237320
public String getFilename() {
238321
return fileName;
@@ -243,8 +326,8 @@ public String getFilename() {
243326
if (!StringUtils.isEmpty(password)) {
244327
param.add("password", password);
245328
}
246-
if (!ObjectUtils.isEmpty(CFileParameter)) {
247-
param.add("parameter", JSON.toJSONString(CFileParameter));
329+
if (!ObjectUtils.isEmpty(fileParameter)) {
330+
param.add("parameter", JSON.toJSONString(fileParameter));
248331
}
249332
HttpHeaders headers = basicHeaders();
250333
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
@@ -274,7 +357,12 @@ public String getFilename() {
274357
return response.getBody().getData();
275358
}
276359

277-
360+
/**
361+
* executeTask
362+
*
363+
* @param taskId taskId
364+
* @return CCreateTaskResult
365+
*/
278366
CCreateTaskResult executeTask(String taskId) {
279367
log.info("Start executing task transfer, taskId: {}", taskId);
280368
String url = address.concat(ComPDFKitConstant.API_V1_EXECUTE_TASK).concat("?taskId=").concat(taskId);
@@ -298,7 +386,13 @@ CCreateTaskResult executeTask(String taskId) {
298386
return response.getBody().getData();
299387
}
300388

301-
CTaskInfoResult queryTaskInfo(String taskId) {
389+
/**
390+
* getTaskInfo
391+
*
392+
* @param taskId taskId
393+
* @return CTaskInfoResult
394+
*/
395+
CTaskInfoResult getTaskInfo(String taskId) {
302396
log.info("Start to query the transfer status, taskId: {}", taskId);
303397
String url = address.concat(ComPDFKitConstant.API_V1_TASK_INFO).concat("?taskId=").concat(taskId);
304398
ResponseEntity<ComPdfKitResult<CTaskInfoResult>> response;

0 commit comments

Comments
 (0)