Commit b56158ae authored by zhang's avatar zhang

update

parent 16b2dead
package com.tongda.tdpimssdk.auth;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.tongda.tdpimssdk.api.PimsAsset;
import com.tongda.tdpimssdk.api.PimsBusiness;
import com.tongda.tdpimssdk.api.PimsDocument;
import com.tongda.tdpimssdk.api.PimsQuery;
import com.tongda.tdpimssdk.http.PimHttpUtil;
import com.tongda.tdpimssdk.resultVo.vo.AssetVo;
import com.tongda.tdpimssdk.resultVo.vo.CatalogItem;
import com.tongda.tdpimssdk.resultVo.vo.TeamVo;
import lombok.Data;
import java.io.File;
@Data
public class SaAuth {
......@@ -35,14 +28,13 @@ public class SaAuth {
public static String loginGetSatoken(){
String url="http://"+id+":"+port+"/sso/doLogin";
satoken=PimHttpUtil.loginGetSatoken(url,user,password);
satoken=PimHttpUtil.loginGetSaToken(url,user,password);
return satoken;
}
public static void main(String[] args) {
// SaAuth.serverId="150.158.75.213";
SaAuth.serverId="127.0.0.1";
SaAuth.serverId="150.158.75.213";
SaAuth.serverPort=8080;
SaAuth.dbName="TXPIMDB";
SaAuth saAuth=new SaAuth("guantiantian","q1w2e3r4","121.199.160.117",9000);
......@@ -53,11 +45,11 @@ public class SaAuth {
// //查询5个接口
// System.out.println(pimsQuery.pimsTemplate());
//
// System.out.println(pimsQuery.queryDocumentList());
// System.out.println(pimsQuery.queryDocumentList());
//
// System.out.println(pimsQuery.getBusinessList(""));
//
// System.out.println(pimsQuery.getLifeCycleDefinitionList("ResourceTemplate-1125740648473821184",1,20));
System.out.println(pimsQuery.getAssetByTemplate("ProductTemplate-1125744743611891712",1,20));
//
// System.out.println(pimsQuery.queryAssetAppViewPath("Product-1128330059979948032"));
......@@ -93,8 +85,8 @@ public class SaAuth {
//
// System.out.println(pimsBusiness.addAssetRefToTeam(JSONObject.parseObject(PimsBusiness.remove, CatalogItem.class)));
File file=new File("C:\\Users\\zfn\\Desktop\\新建 文本文档1.txt");
System.out.println(pimsDocument.uploadBinary("Resource-1126839993566756864",file));
// File file=new File("C:\\Users\\zfn\\Desktop\\新建 文本文档1.txt");
// System.out.println(pimsDocument.uploadBinary("Resource-1126839993566756864",file));
}
......
package com.tongda.tdpimssdk.examples;
import com.tongda.tdpimssdk.remote.RemoteSaAuthHandler;
public class LoginSamples {
public static void main(String[] args) {
RemoteSaAuthHandler rsh = new RemoteSaAuthHandler("guantiantian","q1w2e3r4","121.199.160.117",9000);
rsh.loginGetSaToken();
rsh.serverIP ="150.158.75.213";
rsh.serverPort=8080;
rsh.dbName="TXPIMDB";
System.out.println(rsh);
}
}
package com.tongda.tdpimssdk.examples;
import com.tongda.tdpimssdk.entities.AssetAbstract;
import com.tongda.tdpimssdk.entities.Entity;
import com.tongda.tdpimssdk.entities.common.Catalog;
import com.tongda.tdpimssdk.entities.common.CatalogRoot;
import com.tongda.tdpimssdk.remote.RemoteQueryHelper;
import com.tongda.tdpimssdk.remote.RemoteSaAuthHandler;
import com.tongda.tdpimssdk.resultVo.vo.GeneralPagerVo;
import java.util.List;
public class QuerySamples {
public static void main(String[] args) {
RemoteSaAuthHandler rsh = new RemoteSaAuthHandler("guantiantian","q1w2e3r4","121.199.160.117",9000);
rsh.loginGetSaToken();
rsh.serverIP ="150.158.75.213";
rsh.serverPort=8080;
rsh.dbName="TXPIMDB";
RemoteQueryHelper rqh = new RemoteQueryHelper(rsh);
CatalogRoot cr = rqh.fetchAssetTemplates();
System.out.println(
"-------------------------------------------" + "\n" +
"SDK queryAssetTemplates:" + "\n" +
"-------------------------------------------"
);
for( int i =0; i<cr.getCatalog().size();i++){
Catalog c = cr.getCatalog().get(i);
System.out.println(c.getLabel());
for(int j=0;j<c.getCatalog().size();j++){
Catalog t = c.getCatalog().get(j);
System.out.println("\t" + t.getLabel() + ", " + t.getIdRef());
}
}
CatalogRoot cr1 = rqh.fetchDocumentTemplates();
System.out.println(
"-------------------------------------------" + "\n" +
"SDK queryDocumentTemplates:" + "\n" +
"-------------------------------------------"
);
for( int i =0; i<cr1.getCatalog().size();i++){
Catalog c = cr1.getCatalog().get(i);
System.out.println(c.getLabel());
for(int j=0;j<c.getCatalog().size();j++){
Catalog t = c.getCatalog().get(j);
System.out.println("\t" + t.getLabel() + ", " + t.getIdRef() + ", " + t.getId());
}
}
List<Entity> le = rqh.fetchAppServiceList("");
System.out.println(
"-------------------------------------------" + "\n" +
"SDK getAppServiceList:" + "\n" +
"-------------------------------------------"
);
for( int i =0; i<le.size();i++){
Entity e = le.get(i);
System.out.println("\t" + e.getLabel() + ", " + e.getId());
}
GeneralPagerVo<AssetAbstract> ac = rqh.fetchAssetByTemplate("ProductTemplate-1125744743611891712",1,20);
System.out.println(
"-------------------------------------------" + "\n" +
"SDK queryAssetByTemplate:" + "\n" +
"-------------------------------------------"
);
System.out.println("total: " + ac.getTotal());
for( int i =0; i<ac.getData().size();i++){
AssetAbstract a = ac.getData().get(i);
System.out.println("\t" + a.getLabel() + ", " + a.getId());
}
List<Entity> le2 = rqh.queryAssetAppViewPath("Product-1126119026813042688");
System.out.println(
"-------------------------------------------" + "\n" +
"SDK queryAssetAppViewPath:" + "\n" +
"-------------------------------------------"
);
for( int i =0; i<le2.size();i++){
Entity e = le2.get(i);
System.out.println("\t" + e.getLabel() + ", " + e.getId() + ", " + e.getInfo());
}
}
}
......@@ -21,14 +21,11 @@ import org.apache.http.util.EntityUtils;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.HashMap;
public class PimHttpUtil {
public static String loginGetSatoken(String url ,String user ,String password){
public static String loginGetSaToken(String url , String user , String password){
try {
//创建httpClient实例
CloseableHttpClient client = HttpClients.createDefault();
......@@ -122,6 +119,48 @@ public class PimHttpUtil {
}
}
public static String sendGet(String token, String url){
try {
//创建httpClient实例
CloseableHttpClient client = HttpClients.createDefault();
//创建一个uri对象
URIBuilder uriBuilder = null;
uriBuilder = new URIBuilder(url);
//创建httpGet远程连接实例,这里传入目标的网络地址
HttpGet httpGet = new HttpGet(uriBuilder.build());
httpGet.setHeader("Satoken", token);
// 设置配置请求参数(没有可忽略)
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(60000)// 连接主机服务超时时间
.setConnectionRequestTimeout(60000)// 请求超时时间
.setSocketTimeout(60000)// 数据读取超时时间
.build();
// 为httpGet实例设置配置
httpGet.setConfig(requestConfig);
//执行请求
CloseableHttpResponse response = client.execute(httpGet);
//获取Response状态码
int statusCode = response.getStatusLine().getStatusCode();
// System.out.println(statusCode);
//获取响应实体, 响应内容
HttpEntity entity = response.getEntity();
//通过EntityUtils中的toString方法将结果转换为字符串
String str = EntityUtils.toString(entity);
System.out.println(str);
response.close();
client.close();
return str;
} catch (URISyntaxException e) {
throw new RuntimeException(e);
} catch (ClientProtocolException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static String sendPost(String url , JSONObject jsonObject){
try {
//创建httpClient实例
......
package com.tongda.tdpimssdk.remote;
import lombok.Data;
@Data
public class RemoteAppService {
}
package com.tongda.tdpimssdk.remote;
public class RemoteAsset {
}
package com.tongda.tdpimssdk.remote;
public class RemoteDocument {
}
package com.tongda.tdpimssdk.remote;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.tongda.tdpimssdk.entities.AssetAbstract;
import com.tongda.tdpimssdk.entities.Entity;
import com.tongda.tdpimssdk.entities.common.CatalogRoot;
import com.tongda.tdpimssdk.http.PimHttpUtil;
import com.tongda.tdpimssdk.resultVo.vo.GeneralPagerVo;
import java.util.List;
public class RemoteQueryHelper {
RemoteSaAuthHandler rsh;
public RemoteQueryHelper(RemoteSaAuthHandler rsh){
this.rsh = rsh;
}
/**
* 查询资产模型清单
* @return
*/
public CatalogRoot fetchAssetTemplates(){
String url="http://"+ this.rsh.serverIP +":"+ this.rsh.serverPort+"/pims/template?dbName="+ this.rsh.dbName;
String response= PimHttpUtil.sendGet(this.rsh.saToken, url);
String s=resultUtil(response);
List<CatalogRoot> catList = JSONObject.parseArray(s,CatalogRoot.class);
if(catList.size() == 1){
return catList.get(0);
}
return null;
}
/**
* 查询文档模型清单
* @return
*/
public CatalogRoot fetchDocumentTemplates(){
String url="http://"+ this.rsh.serverIP +":"+ this.rsh.serverPort+"/pims/template/document?dbName="+ this.rsh.dbName;
String response=PimHttpUtil.sendGet(this.rsh.saToken, url);
String s=resultUtil(response);
List<CatalogRoot> catList = JSONObject.parseArray(s,CatalogRoot.class);
if(catList.size() == 1){
return catList.get(0);
}
return null;
}
/**
* 根据模型ID查询资产/文档清单
* @param templateID
* @param page
* @param size
* @return
*/
public GeneralPagerVo<AssetAbstract> fetchAssetByTemplate(String templateID, int page, int size){
String url="http://"+ this.rsh.serverIP +":"+this.rsh.serverPort+"/pims/asset?dbName="+this.rsh.dbName+"&templateID="+templateID+"&page="+page+"&size="+size;
String response=PimHttpUtil.sendGet(this.rsh.saToken, url);
String s=resultUtil(response);
return JSONObject.parseObject(s,new TypeReference<GeneralPagerVo<AssetAbstract>>(){});
}
/**
* 查询资产所属业务
* @param id
* @return
*/
public List<Entity> queryAssetAppViewPath(String id){
String url="http://"+ this.rsh.serverIP +":"+ this.rsh.serverPort+"/pims/asset/business/path?dbName="+ this.rsh.dbName+"&id="+id;
String response=PimHttpUtil.sendGet(this.rsh.saToken,url);
String s=resultUtil(response);
return JSONObject.parseArray(s,Entity.class);
}
/**
* 查询业务清单
* @return
*/
public List<Entity> fetchAppServiceList(String label) {
String url="http://"+ this.rsh.serverIP +":"+ this.rsh.serverPort+"/pims/business?dbName="+ this.rsh.dbName+"&label="+label;
String response=PimHttpUtil.sendGet(this.rsh.saToken, url);
String s=resultUtil(response);
return JSONObject.parseArray(s,Entity.class);
}
public static String resultUtil(String re){
// System.out.println(re);
JSONObject jsonObject=JSONObject.parseObject(re);
if (jsonObject.get("code").toString().equals("200")){
return jsonObject.get("data").toString();
}else {
throw new RuntimeException("调用接口异常:"+re);
}
}
}
package com.tongda.tdpimssdk.remote;
import com.tongda.tdpimssdk.http.PimHttpUtil;
public class RemoteSaAuthHandler {
public String user;
public String password;
public String saServerIP;
public int saServerPort;
public String saToken;
public String serverIP;
public int serverPort;
public String dbName;
public RemoteSaAuthHandler(String user, String password, String saServerIP, int saServerPort) {
this.user = user;
this.password = password;
this.saServerIP = saServerIP;
this.saServerPort = saServerPort;
}
public String loginGetSaToken(){
String url="http://"+this.saServerIP +":"+this.saServerPort +"/sso/doLogin";
this.saToken = PimHttpUtil.loginGetSaToken(url,this.user,this.password);
return this.saToken;
}
@Override
public String toString(){
return "-------------------------------------------" + "\n" +
"SDK LOGIN INFO:" + "\n" +
"-------------------------------------------" + "\n" +
" user: " + this.user + "\n" +
" saServerIP: " + this.saServerIP + "\n" +
" saServerPort: " + this.saServerPort + "\n" +
" serverIP: " + this.serverIP + "\n" +
" serverPort: " + this.serverPort + "\n" +
" dbName: " + this.dbName + "\n" +
" saToken: " + this.saToken + "\n";
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment