|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
8 n! {' u) {9 ~- b, G- | n
Teamenter SOA开发源码:通过user ID 找 User
/ @3 H9 l7 j f K4 G( R! l4 J+ Q1 \$ E3 R* m0 y8 ~3 ]; p
[mw_shl_code=applescript,true]import com.Teamcenter.services.strong.query.SavedQueryService;
& H/ }, w! G- R% T- p* |import com.teamcenter.services.strong.query._2006_03.SavedQuery.GetSavedQueriesResponse;
& J. S3 k1 U* S: Y. kimport com.teamcenter.services.strong.query._2007_09.SavedQuery.SavedQueriesResponse;
9 b. G4 Y: O: Z- |import com.teamcenter.services.strong.query._2008_06.SavedQuery.QueryInput;
8 S+ D" Q( t Nimport com.teamcenter.services.strong.query._2007_09.SavedQuery.QueryResults;
2 _+ \$ _8 w. ?& ?/ J9 qimport com.teamcenter.services.strong.core.DataManagementService;( M, S, w7 ]4 {
import com.teamcenter.soa.client.model.ModelObject;
[1 c+ S6 z* b' r0 jimport com.teamcenter.soa.client.model.ServiceData;# B7 `, E a3 K) Z9 Z Z1 f
import com.teamcenter.soa.client.model.strong.ImanQuery;* i z7 [6 D6 Y4 X
; c6 x4 l+ I7 H
import com.teamcenter.soa.client.model.strong.User;
|5 D/ C9 L8 m
* n6 G5 x, ]! N4 V# H' C0 m! N/ I) {: |9 G
public User findUser(String userId)
( N# X2 }6 D7 b( H& K {
! D6 _: a* X9 z, o A6 K+ s ImanQuery query = null;
9 Z( j0 L6 I9 x% | User user = null;' K" o L$ |, B) ~
2 v7 B1 t. ]4 Y, Q% m2 F$ K/ t/ q0 a7 v9 c
SavedQueryService queryService = SavedQueryService.getService(AppXSession.geTConnection());% {9 T) c0 A$ {; Q2 {/ o* B
DataManagementService dmService= DataManagementService.getService(AppXSession.getConnection());
$ K6 _5 o3 }' i3 L; i8 M
8 E% J! }" ?3 v$ f8 R2 l try6 [& j" g. ]: `+ H, j
{
) s/ @$ _, t/ q) m+ y1 x5 d& k GetSavedQueriesResponse savedQueries = queryService.getSavedQueries();
- q; Y7 B; T- W' {0 Q2 {+ w; O- b if (savedQueries.queries.length == 0)9 U2 h# z4 A) d
{
+ D$ {9 j% N! W% v+ I: A System.out.println("There are no saved queries in the system.");
. Q5 H* k8 O a$ L2 j" t return user;8 Y+ R8 f( s9 v+ c3 o( Y, _2 V
}
: k' H& x1 w2 L0 p 2 T% J6 C, R' T1 L2 C; M
for (int i = 0; i < savedQueries.queries.length; i++)! x2 n, I/ U1 T: w0 s4 F. Y: _
{
& @# F9 ?( D: b; w9 Q9 T3 p! k8 j8 r* H
if (savedQueries.queries.name.equals("__WEB_find_user"))" G/ a# y9 k' Y0 t' |9 T
{
- ?: R9 k v! J5 H- E3 v# G3 k query = savedQueries.queries.query;
5 Q% p) U/ K8 z1 W- x break;
- d* D; F. Z. Y& n* ] }) t) k' }; |$ ?
}
% u$ E; j# R8 `$ ? }2 u; x4 i6 H$ m) m* S' I5 ^) b1 i
catch (ServiceException e)
+ V2 J+ h& j6 f4 f- \7 m* Q {
' Y0 Q1 G8 I" G; v* t6 u System.out.println("GetSavedQueries service request failed.");
3 }: H/ {4 |3 ]; ^% H2 D System.out.println(e.getMessage());
4 c; Z! |3 A) J1 A5 P return user;
7 |5 L0 i" `4 ~. {$ h6 U: l }1 J+ K" ~, L* g# X# O r' m( }
/ e+ v' C. X2 T; v% S, b9 e
if (query == null)
) {8 ~' j+ D0 W {$ N. d1 p" s1 L j, W6 X, ]
System.out.println("There is not an '__WEB_find_user' query.");( X$ a7 I' T7 y2 E' Z5 h4 N2 w; \
return user;; ], a6 l- d7 c
}, k+ l7 E2 u7 j) w; s' V, o5 a
; Y5 m* p: f: w* j/ @
try$ P$ o" ]1 s- {# q) ~1 b% J
{1 F' A) S' w& `- Y8 y }
QueryInput savedQueryInput[] = new QueryInput[1];
! G6 v, t' }- l$ b7 Q6 Y savedQueryInput[0] = new QueryInput();
3 J! l- Q; F0 L$ ^) x0 |3 n0 g savedQueryInput[0].query = query;( q5 D$ L, M7 m4 d+ \( `4 I
savedQueryInput[0].entries = new String[1];4 v/ F* I$ ^2 L. b/ `- f
savedQueryInput[0].values = new String[1];
; l, L' h2 {2 Y3 i" L1 U savedQueryInput[0].entries[0] = "User ID" ;
: {1 N3 m0 I2 N savedQueryInput[0].values[0] = userId;8 g* z6 P* ^* C+ H5 O, R3 b- K
savedQueryInput[0].maxNumToReturn = 25;; R3 v. [) e+ ~
4 n( ^3 ^% V/ V/ c SavedQueriesResponse savedQueryResult = queryService.executeSavedQueries(savedQueryInput); r6 c2 W. V4 H- P2 l T# v
QueryResults found = savedQueryResult.arrayOfResults[0];* r V# e" l+ A7 c% H
9 M @1 l7 z. [1 Q( n6 t/ v
int length = found.objectUIDS.length;1 K/ a9 f# ^4 U! E# i
R% V3 b/ a V+ h String[] uids = new String[length];
2 {1 c& ~1 V2 t5 \1 n for( int ii = 0; ii < length; ii++)
+ W+ v: d7 y; b! H* T {
3 | x" h; v+ v' L$ s uids[ii]= found.objectUIDS[ii];
5 n$ K* S5 t5 y/ c; g3 N" p7 j }- o1 S, E8 t) N( P9 F n6 H9 H
ServiceData sd = dmService.loadObjects(uids);
; l. r4 p' Q- P/ U" b7 K6 ~& D3 _ ModelObject[] foundObjs = new ModelObject[ sd.sizeOfPlainObjects()];" y5 R1 |2 w: P7 @& W/ }
for( int k =0; k< sd.sizeOfPlainObjects(); k++)2 A% X, V1 `5 ]% l8 `4 t0 G
{
$ p7 n/ }7 b$ Y" w foundObjs[k] = sd.getPlainObject(k);
: Q/ o* f( X! }+ L }+ k$ L0 e" q% v
user = (User) foundObjs[0];
' K) B, d( ?2 G }% f# p# w6 }1 p( z, M& j/ ]! r
catch (Exception e)
; e) ]1 h+ b8 M {
$ M1 T0 ~) u7 G: R System.out.println("ExecuteSavedQuery service request failed.");) M' w% v9 S+ D( q0 P: o$ x- }0 y
System.out.println(e.getMessage());& n/ ]/ C+ Q9 d# ]0 r) j
}
2 b. w! a& X" l8 @ return user;
) n( S, {; j8 L0 S4 k/ w+ z }/ |/ X! B3 E( {5 [+ u- J/ e; ~$ o+ a
[/mw_shl_code]
, I$ Q! B" e: D3 J9 N |
|