Skip to content

Commit 040760c

Browse files
author
codezhang
committed
支持ocr.GetUAIOcrAvailResourceType
1 parent 30bb1db commit 040760c

8 files changed

Lines changed: 298 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package cn.ucloud.ocr.client;
2+
3+
import cn.ucloud.common.client.DefaultUcloudClient;
4+
import cn.ucloud.common.handler.UcloudHandler;
5+
import cn.ucloud.common.http.UcloudHttp;
6+
import cn.ucloud.common.http.UcloudHttpImpl;
7+
import cn.ucloud.common.pojo.UcloudConfig;
8+
import cn.ucloud.ocr.model.GetUAIOcrAvailResourceTypeParam;
9+
import cn.ucloud.ocr.model.GetUAIOcrAvailResourceTypeResult;
10+
11+
/**
12+
* @Description : 默认ocr 客户端
13+
* @Author : codezhang
14+
* @Date : 2019-04-19 15:25
15+
**/
16+
public class DefaultOcrClient extends DefaultUcloudClient implements OcrClient {
17+
18+
public DefaultOcrClient(UcloudConfig config) {
19+
super(config);
20+
}
21+
22+
@Override
23+
public GetUAIOcrAvailResourceTypeResult
24+
getUAIOcrAvailResourceType(GetUAIOcrAvailResourceTypeParam param) throws Exception {
25+
UcloudHttp http = new UcloudHttpImpl(GetUAIOcrAvailResourceTypeResult.class);
26+
return (GetUAIOcrAvailResourceTypeResult) http.doGet(param, config, null);
27+
}
28+
29+
@Override
30+
public void getUAIOcrAvailResourceType(GetUAIOcrAvailResourceTypeParam param,
31+
UcloudHandler<GetUAIOcrAvailResourceTypeResult> handler,
32+
Boolean... asyncFlag) {
33+
UcloudHttp http = new UcloudHttpImpl(GetUAIOcrAvailResourceTypeResult.class);
34+
try {
35+
http.doGet(param, config, handler, asyncFlag);
36+
} catch (Exception e) {
37+
}
38+
}
39+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package cn.ucloud.ocr.client;
2+
3+
import cn.ucloud.common.client.UcloudClient;
4+
import cn.ucloud.common.handler.UcloudHandler;
5+
import cn.ucloud.ocr.model.GetUAIOcrAvailResourceTypeParam;
6+
import cn.ucloud.ocr.model.GetUAIOcrAvailResourceTypeResult;
7+
8+
/**
9+
* @Description : ocr 客户端接口
10+
* @Author : codezhang
11+
* @Date : 2019-04-19 15:24
12+
**/
13+
public interface OcrClient extends UcloudClient {
14+
15+
/**
16+
* 获取可用UAI-OCR资源类型
17+
*
18+
* @param param 参数对象
19+
* @return 结果对象
20+
* @throws Exception
21+
*/
22+
GetUAIOcrAvailResourceTypeResult
23+
getUAIOcrAvailResourceType(GetUAIOcrAvailResourceTypeParam param) throws Exception;
24+
25+
/**
26+
* 获取可用UAI-OCR资源类型 (回调)
27+
*
28+
* @param param 参数对象
29+
* @param handler 回调接口
30+
* @param asyncFlag 是否异步
31+
*/
32+
void getUAIOcrAvailResourceType(GetUAIOcrAvailResourceTypeParam param,
33+
UcloudHandler<GetUAIOcrAvailResourceTypeResult> handler,
34+
Boolean... asyncFlag);
35+
36+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package cn.ucloud.ocr.model;
2+
3+
import cn.ucloud.common.annotation.UcloudParam;
4+
import cn.ucloud.common.pojo.BaseRequestParam;
5+
6+
import javax.validation.constraints.NotEmpty;
7+
8+
/**
9+
* @Description :获取可用UAI-OCR资源类型
10+
* @Author : codezhang
11+
* @Date : 2019-04-19 15:26
12+
**/
13+
public class GetUAIOcrAvailResourceTypeParam extends BaseRequestParam {
14+
15+
/**
16+
* 地域。 参见 [地域和可用区列表]
17+
*/
18+
@NotEmpty(message = "region can not be empty")
19+
@UcloudParam("Region")
20+
private String region;
21+
22+
/**
23+
* 可用区。参见 [可用区列表]
24+
*/
25+
@UcloudParam("Zone")
26+
private String zone;
27+
28+
public GetUAIOcrAvailResourceTypeParam(@NotEmpty(message = "region can not be empty") String region) {
29+
super("GetUAIOcrAvailResourceType");
30+
this.region = region;
31+
}
32+
33+
public String getRegion() {
34+
return region;
35+
}
36+
37+
public void setRegion(String region) {
38+
this.region = region;
39+
}
40+
41+
public String getZone() {
42+
return zone;
43+
}
44+
45+
public void setZone(String zone) {
46+
this.zone = zone;
47+
}
48+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package cn.ucloud.ocr.model;
2+
3+
import cn.ucloud.common.pojo.BaseResponseResult;
4+
import com.google.gson.annotations.SerializedName;
5+
6+
import java.util.List;
7+
8+
/**
9+
* @Description : 获取可用UAI-OCR资源类型
10+
* @Author : codezhang
11+
* @Date : 2019-04-19 15:28
12+
**/
13+
public class GetUAIOcrAvailResourceTypeResult extends BaseResponseResult {
14+
15+
/**
16+
* 可用资源类型总数
17+
*/
18+
@SerializedName("TotalCount")
19+
private Integer totalCount;
20+
21+
/**
22+
* OCR资源类型的具体信息
23+
*/
24+
@SerializedName("DataSet")
25+
private List<UAIOcrResourceTypeInfo> uaiOcrResourceTypeInfos;
26+
27+
public Integer getTotalCount() {
28+
return totalCount;
29+
}
30+
31+
public void setTotalCount(Integer totalCount) {
32+
this.totalCount = totalCount;
33+
}
34+
35+
public List<UAIOcrResourceTypeInfo> getUaiOcrResourceTypeInfos() {
36+
return uaiOcrResourceTypeInfos;
37+
}
38+
39+
public void setUaiOcrResourceTypeInfos(List<UAIOcrResourceTypeInfo> uaiOcrResourceTypeInfos) {
40+
this.uaiOcrResourceTypeInfos = uaiOcrResourceTypeInfos;
41+
}
42+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package cn.ucloud.ocr.model;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
5+
/**
6+
* @Description : UAI-OCR资源类型信息
7+
* @Author : codezhang
8+
* @Date : 2019-04-19 15:29
9+
**/
10+
public class UAIOcrResourceTypeInfo {
11+
12+
/**
13+
* UAI-OCR资源类型ID
14+
*/
15+
@SerializedName("ResourceTypeId")
16+
private Integer resourceTypeId;
17+
18+
/**
19+
* UAI-OCR资源类型名称
20+
*/
21+
@SerializedName("ResourceTypeName")
22+
private String resourceTypeName;
23+
24+
public Integer getResourceTypeId() {
25+
return resourceTypeId;
26+
}
27+
28+
public void setResourceTypeId(Integer resourceTypeId) {
29+
this.resourceTypeId = resourceTypeId;
30+
}
31+
32+
public String getResourceTypeName() {
33+
return resourceTypeName;
34+
}
35+
36+
public void setResourceTypeName(String resourceTypeName) {
37+
this.resourceTypeName = resourceTypeName;
38+
}
39+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package cn.ucloud.ocr.pojo;
2+
3+
import cn.ucloud.common.pojo.Account;
4+
import cn.ucloud.common.pojo.UcloudConfig;
5+
6+
/**
7+
* @Description : OCR 配置类
8+
* @Author : codezhang
9+
* @Date : 2019-04-19 15:23
10+
**/
11+
public class OcrConfig extends UcloudConfig {
12+
13+
public OcrConfig(Account account) {
14+
super(account);
15+
}
16+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package cn.ucloud.ocr.client;
2+
3+
import cn.ucloud.common.pojo.Account;
4+
import cn.ucloud.ocr.model.GetUAIOcrAvailResourceTypeParam;
5+
import cn.ucloud.ocr.model.GetUAIOcrAvailResourceTypeResult;
6+
import cn.ucloud.ocr.pojo.OcrConfig;
7+
import org.junit.Before;
8+
import org.junit.Test;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* @Description :
14+
* @Author : codezhang
15+
* @Date : 2019-04-19 15:33
16+
**/
17+
public class GetUAIOcrAvailResourceTypeTest {
18+
19+
20+
private OcrClient client;
21+
22+
private GetUAIOcrAvailResourceTypeParam param;
23+
24+
@Before
25+
public void setUp() throws Exception {
26+
client = new DefaultOcrClient(new OcrConfig(
27+
new Account(System.getenv("UCloudPrivateKey"),
28+
System.getenv("UCloudPublicKey"))));
29+
String projectId = System.getenv("ProjectId");
30+
String region = "cn-bj2";
31+
param = new GetUAIOcrAvailResourceTypeParam(region);
32+
param.setProjectId(projectId);
33+
}
34+
35+
@Test
36+
public void getUAICensorAvailResourceType() {
37+
try {
38+
GetUAIOcrAvailResourceTypeResult result =
39+
client.getUAIOcrAvailResourceType(param);
40+
JSONComparator.jsonComparator(result);
41+
} catch (Exception e) {
42+
assertNull(e);
43+
}
44+
}
45+
46+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package cn.ucloud.ocr.client;
2+
3+
import cn.ucloud.common.pojo.BaseResponseResult;
4+
import com.google.gson.Gson;
5+
import com.google.gson.GsonBuilder;
6+
import org.skyscreamer.jsonassert.JSONAssert;
7+
import org.skyscreamer.jsonassert.JSONCompareMode;
8+
import org.slf4j.Logger;
9+
import org.slf4j.LoggerFactory;
10+
11+
import static org.junit.Assert.assertNull;
12+
13+
/**
14+
* @Description :
15+
* @Author : codezhang
16+
* @Date : 2019-03-05 21:32
17+
**/
18+
public class JSONComparator {
19+
20+
private static final Logger logger = LoggerFactory.getLogger(JSONComparator.class.getName());
21+
22+
public static void jsonComparator(BaseResponseResult result) {
23+
try {
24+
Gson gson = new GsonBuilder().serializeNulls().create();
25+
logger.info("result 2 json:{}", gson.toJson(result));
26+
JSONAssert.assertEquals(result.getResponseContent(), gson.toJson(result), JSONCompareMode.LENIENT);
27+
} catch (Exception e) {
28+
assertNull(e);
29+
}
30+
}
31+
32+
}

0 commit comments

Comments
 (0)