Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
T
TDPIMS-SDK
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhengfunan
TDPIMS-SDK
Commits
b56158ae
Commit
b56158ae
authored
Jul 18, 2023
by
zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
16b2dead
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
324 additions
and
18 deletions
+324
-18
SaAuth.java
src/main/java/com/tongda/tdpimssdk/auth/SaAuth.java
+6
-14
LoginSamples.java
...main/java/com/tongda/tdpimssdk/examples/LoginSamples.java
+20
-0
QuerySamples.java
...main/java/com/tongda/tdpimssdk/examples/QuerySamples.java
+94
-0
PimHttpUtil.java
src/main/java/com/tongda/tdpimssdk/http/PimHttpUtil.java
+43
-4
RemoteAppService.java
...in/java/com/tongda/tdpimssdk/remote/RemoteAppService.java
+7
-0
RemoteAsset.java
src/main/java/com/tongda/tdpimssdk/remote/RemoteAsset.java
+4
-0
RemoteDocument.java
...main/java/com/tongda/tdpimssdk/remote/RemoteDocument.java
+4
-0
RemoteQueryHelper.java
...n/java/com/tongda/tdpimssdk/remote/RemoteQueryHelper.java
+100
-0
RemoteSaAuthHandler.java
...java/com/tongda/tdpimssdk/remote/RemoteSaAuthHandler.java
+46
-0
No files found.
src/main/java/com/tongda/tdpimssdk/auth/SaAuth.java
View file @
b56158ae
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
.
loginGetSa
t
oken
(
url
,
user
,
password
);
satoken
=
PimHttpUtil
.
loginGetSa
T
oken
(
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));
}
...
...
src/main/java/com/tongda/tdpimssdk/examples/LoginSamples.java
0 → 100644
View file @
b56158ae
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
);
}
}
src/main/java/com/tongda/tdpimssdk/examples/QuerySamples.java
0 → 100644
View file @
b56158ae
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
());
}
}
}
src/main/java/com/tongda/tdpimssdk/http/PimHttpUtil.java
View file @
b56158ae
...
...
@@ -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
loginGetSa
token
(
String
url
,
String
user
,
String
password
){
public
static
String
loginGetSa
Token
(
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实例
...
...
src/main/java/com/tongda/tdpimssdk/remote/RemoteAppService.java
0 → 100644
View file @
b56158ae
package
com
.
tongda
.
tdpimssdk
.
remote
;
import
lombok.Data
;
@Data
public
class
RemoteAppService
{
}
src/main/java/com/tongda/tdpimssdk/remote/RemoteAsset.java
0 → 100644
View file @
b56158ae
package
com
.
tongda
.
tdpimssdk
.
remote
;
public
class
RemoteAsset
{
}
src/main/java/com/tongda/tdpimssdk/remote/RemoteDocument.java
0 → 100644
View file @
b56158ae
package
com
.
tongda
.
tdpimssdk
.
remote
;
public
class
RemoteDocument
{
}
src/main/java/com/tongda/tdpimssdk/remote/RemoteQueryHelper.java
0 → 100644
View file @
b56158ae
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
);
}
}
}
src/main/java/com/tongda/tdpimssdk/remote/RemoteSaAuthHandler.java
0 → 100644
View file @
b56158ae
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"
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment