Skip to content

Commit eae74b9

Browse files
author
YangSen-qn
committed
fop
1 parent 5743546 commit eae74b9

File tree

1 file changed

+52
-14
lines changed

1 file changed

+52
-14
lines changed

src/main/java/com/qiniu/processing/OperationManager.java

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.qiniu.common.QiniuException;
44
import com.qiniu.http.Client;
55
import com.qiniu.http.Response;
6+
import com.qiniu.media.apis.ApiPfop;
7+
import com.qiniu.storage.Api;
68
import com.qiniu.storage.Configuration;
79
import com.qiniu.util.Auth;
810
import com.qiniu.util.StringMap;
@@ -86,19 +88,59 @@ public String pfop(String bucket, String key, String fops) throws QiniuException
8688
* <a href="http://developer.qiniu.com/dora/api/persistent-data-processing-pfop"> 相关链接 </a>
8789
*/
8890
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+
}
95138
if (!response.isOK()) {
96-
throw new QiniuException(response);
139+
throw new QiniuException(response.getResponse());
97140
}
98-
PfopResult status = response.jsonToObject(PfopResult.class);
99-
response.close();
141+
ApiPfop.Response.PfopId status = response.getData();
100142
if (status != null) {
101-
return status.persistentId;
143+
return status.getPersistentId();
102144
}
103145
return null;
104146
}
@@ -254,8 +296,4 @@ public <T> T prefop(String bucket, String persistentId, Class<T> retClass) throw
254296
response.close();
255297
return object;
256298
}
257-
258-
private class PfopResult {
259-
public String persistentId;
260-
}
261299
}

0 commit comments

Comments
 (0)