|
3 | 3 | import com.qiniu.common.QiniuException;
|
4 | 4 | import com.qiniu.http.Client;
|
5 | 5 | import com.qiniu.http.Response;
|
| 6 | +import com.qiniu.media.apis.ApiPfop; |
| 7 | +import com.qiniu.storage.Api; |
6 | 8 | import com.qiniu.storage.Configuration;
|
7 | 9 | import com.qiniu.util.Auth;
|
8 | 10 | import com.qiniu.util.StringMap;
|
@@ -86,19 +88,59 @@ public String pfop(String bucket, String key, String fops) throws QiniuException
|
86 | 88 | * <a href="http://developer.qiniu.com/dora/api/persistent-data-processing-pfop"> 相关链接 </a>
|
87 | 89 | */
|
88 | 90 | public String pfop(String bucket, String key, String fops, StringMap params) throws QiniuException {
|
89 |
| - params = params == null ? new StringMap() : params; |
90 |
| - params.put("bucket", bucket).put("key", key).put("fops", fops); |
91 |
| - byte[] data = StringUtils.utf8Bytes(params.formString()); |
92 |
| - String url = configuration.apiHost(auth.accessKey, bucket) + "/pfop/"; |
93 |
| - StringMap headers = auth.authorizationV2(url, "POST", data, Client.FormMime); |
94 |
| - Response response = client.post(url, data, headers, Client.FormMime); |
| 91 | + Integer force = null; |
| 92 | + if (params.get("force") != null) { |
| 93 | + if (params.get("force") instanceof Integer) { |
| 94 | + force = (Integer) params.get("force"); |
| 95 | + } else { |
| 96 | + throw QiniuException.unrecoverable("force type error, should be Integer"); |
| 97 | + } |
| 98 | + } |
| 99 | + String pipeline = null; |
| 100 | + if (params.get("pipeline") != null) { |
| 101 | + if (params.get("pipeline") instanceof Integer) { |
| 102 | + pipeline = (String) params.get("pipeline"); |
| 103 | + } else { |
| 104 | + throw QiniuException.unrecoverable("pipeline type error, String be Integer"); |
| 105 | + } |
| 106 | + } |
| 107 | + String notifyUrl = null; |
| 108 | + if (params.get("notifyURL") != null) { |
| 109 | + if (params.get("notifyURL") instanceof String) { |
| 110 | + notifyUrl = (String) params.get("notifyURL"); |
| 111 | + } else { |
| 112 | + throw QiniuException.unrecoverable("notifyURL type error, should be String"); |
| 113 | + } |
| 114 | + } |
| 115 | + Integer type = null; |
| 116 | + if (params.get("type") != null) { |
| 117 | + if (params.get("type") instanceof Integer) { |
| 118 | + type = (Integer) params.get("type"); |
| 119 | + } else { |
| 120 | + throw QiniuException.unrecoverable("type type error, should be Integer"); |
| 121 | + } |
| 122 | + } |
| 123 | + |
| 124 | + String url = configuration.apiHost(auth.accessKey, bucket); |
| 125 | + ApiPfop.Request request = new ApiPfop.Request(url, bucket, key, fops) |
| 126 | + .setPipeline(pipeline) |
| 127 | + .setForce(force) |
| 128 | + .setNotifyUrl(notifyUrl) |
| 129 | + .setType(type); |
| 130 | + ApiPfop api = new ApiPfop(client, new Api.Config.Builder() |
| 131 | + .setRequestDebugLevel(Api.Config.DebugLevelDetail) |
| 132 | + .setResponseDebugLevel(Api.Config.DebugLevelDetail) |
| 133 | + .build()); |
| 134 | + ApiPfop.Response response = api.request(request); |
| 135 | + if (response == null) { |
| 136 | + throw QiniuException.unrecoverable("unknown error"); |
| 137 | + } |
95 | 138 | if (!response.isOK()) {
|
96 |
| - throw new QiniuException(response); |
| 139 | + throw new QiniuException(response.getResponse()); |
97 | 140 | }
|
98 |
| - PfopResult status = response.jsonToObject(PfopResult.class); |
99 |
| - response.close(); |
| 141 | + ApiPfop.Response.PfopId status = response.getData(); |
100 | 142 | if (status != null) {
|
101 |
| - return status.persistentId; |
| 143 | + return status.getPersistentId(); |
102 | 144 | }
|
103 | 145 | return null;
|
104 | 146 | }
|
@@ -254,8 +296,4 @@ public <T> T prefop(String bucket, String persistentId, Class<T> retClass) throw
|
254 | 296 | response.close();
|
255 | 297 | return object;
|
256 | 298 | }
|
257 |
| - |
258 |
| - private class PfopResult { |
259 |
| - public String persistentId; |
260 |
| - } |
261 | 299 | }
|
0 commit comments