|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
% V6 D5 J4 {& J' w2 z
Teamenter SOA开发源码:通过user ID 找 User
6 |3 ~9 u8 U' m }$ W& C2 Z1 q9 s8 A* D3 p2 V$ y* z0 `6 k
[mw_shl_code=applescript,true]import com.Teamcenter.services.strong.query.SavedQueryService;
, B6 X6 \! i& ]$ eimport com.teamcenter.services.strong.query._2006_03.SavedQuery.GetSavedQueriesResponse; a" q& x# f( a9 P# U9 a3 M6 v* R, Y. w2 M
import com.teamcenter.services.strong.query._2007_09.SavedQuery.SavedQueriesResponse;, U7 a; l/ b( u8 X
import com.teamcenter.services.strong.query._2008_06.SavedQuery.QueryInput;5 \# F9 O& w" I* y
import com.teamcenter.services.strong.query._2007_09.SavedQuery.QueryResults;' K* g. `& m. {: b/ q
import com.teamcenter.services.strong.core.DataManagementService;# C9 g# W0 B1 b: H) j* W3 n
import com.teamcenter.soa.client.model.ModelObject;
. n6 x" i$ q7 i0 mimport com.teamcenter.soa.client.model.ServiceData;& W/ r' T3 |' h0 O5 z7 D4 H
import com.teamcenter.soa.client.model.strong.ImanQuery;& o- Q4 D' S- y$ B
2 x+ c1 v1 S- v9 n- B' d" q7 Kimport com.teamcenter.soa.client.model.strong.User;
; O% [5 \ W# n" M3 A+ ?+ x, a* F) e0 p( `' \/ r5 U. M
! N+ S+ w6 c, V+ j' B( R
public User findUser(String userId)
& m8 r% y4 R7 ~7 ~) S8 O2 r {! w1 M; c0 r9 i2 x m5 m& T; h
ImanQuery query = null;
0 p x& P9 i6 S% ^/ H User user = null;
8 l: i1 H" C7 u2 p6 B+ R2 \5 g8 b & A1 C8 [9 m5 ?- Y x7 w! j8 ^1 |
! ]) G9 ?% t. P* M; {# ^ SavedQueryService queryService = SavedQueryService.getService(AppXSession.geTConnection());% I7 L, |8 Q/ [' u; \4 w
DataManagementService dmService= DataManagementService.getService(AppXSession.getConnection());
8 _$ y, x2 D* q0 j
8 |! A Y, g- P& g. \6 m, w try9 @ o1 r2 M& t
{
6 x7 o) r% D# \8 T GetSavedQueriesResponse savedQueries = queryService.getSavedQueries();$ }2 {, Y5 X& b
if (savedQueries.queries.length == 0)
& P+ E7 y4 q+ z8 R4 {7 D$ G4 x {1 F! r( g( p- |- t; o% R, U
System.out.println("There are no saved queries in the system.");. W( E! `" k3 i* V
return user;# H* R; u, r* p7 \, P
}; _9 |: h% c5 _) b8 }8 F
/ }; F1 `6 Y5 j& P# P: w% L4 N
for (int i = 0; i < savedQueries.queries.length; i++)
+ R. J4 N+ A' h4 ?1 K, C3 _2 A3 ? {
0 _: r, h6 [; d% }0 x. \$ R. c/ Q( V* g7 `
if (savedQueries.queries.name.equals("__WEB_find_user"))
" z$ y$ _: k) g) G2 _& R/ T {8 @1 Y6 P5 l2 H/ Y# {8 ~& g
query = savedQueries.queries.query;0 V* A/ u+ c6 S2 v6 \# Z
break;5 l3 W" _7 s- J f6 y" c0 a
}
. W2 t9 l) S. f$ r, b( s, ] }; E; }8 A v( ~, s. s6 ?
}
- t) O) z0 U& B1 } catch (ServiceException e)
6 h' F9 U# M: e$ e8 W4 U {
6 H7 t0 I0 L/ w, Y0 z! h System.out.println("GetSavedQueries service request failed.");
8 N" b' F3 U& y6 y* S System.out.println(e.getMessage());
% U `0 F s! O; S, A return user;- e+ R J2 x* `5 Q4 p* N
}
`( c- w. \6 Z R! X# q* V+ g% c; N6 Z" a7 s
if (query == null)
# T+ P/ g5 \. A+ @& [& L: m {
/ ~. _; \- y: E$ r) V% B System.out.println("There is not an '__WEB_find_user' query.");$ W4 p' D2 `- L% N( w; P5 l/ W
return user;& R, _4 Y( G. Y6 s6 M6 p: m4 o
}" b1 N; o( S% _6 d5 ^+ Q; ?
0 H' V$ o8 X5 a try
! F4 F0 d) x8 x! g4 M: D {/ U4 q' E* S I1 |6 ^
QueryInput savedQueryInput[] = new QueryInput[1];: J# y# M* y$ D4 K6 k) X
savedQueryInput[0] = new QueryInput();" n% [: d$ e N$ ~
savedQueryInput[0].query = query;: N6 k/ w, ` t: i4 C9 w
savedQueryInput[0].entries = new String[1];
- F% p- ^. T. m9 _# _+ [ savedQueryInput[0].values = new String[1];
[. p9 I* j. j% Y5 l! N7 D savedQueryInput[0].entries[0] = "User ID" ;
) o( p6 b* B! x- P# ` savedQueryInput[0].values[0] = userId;% W& @/ ?# @/ L7 n
savedQueryInput[0].maxNumToReturn = 25;
( |9 O- e' y5 l 8 U1 `' ~: N$ t
SavedQueriesResponse savedQueryResult = queryService.executeSavedQueries(savedQueryInput);% a% j- P( V8 ~0 \9 T6 F5 ~
QueryResults found = savedQueryResult.arrayOfResults[0];3 D. Y' S- y% }4 R2 |7 H5 H! v9 A
" [0 }9 P9 n; g& c, G
int length = found.objectUIDS.length;( J; G" f. E; a9 i8 N4 ]5 f
E2 H0 t! X% l& o! T- i String[] uids = new String[length];: J( F/ |3 v0 W! Q
for( int ii = 0; ii < length; ii++)
. Z2 ]( N: M( ]- ?7 p6 ~$ ^ {
# Q7 C. h. L1 q( r, S' }/ x( E uids[ii]= found.objectUIDS[ii];
. f0 `7 e' n& S! Z: D. F1 t }0 J+ w. J9 V( K
ServiceData sd = dmService.loadObjects(uids);
, s5 A4 J# @# _5 R ModelObject[] foundObjs = new ModelObject[ sd.sizeOfPlainObjects()];
. d5 ~9 e8 @8 @) D Q# ]; M2 P for( int k =0; k< sd.sizeOfPlainObjects(); k++)
- a$ Q+ Q! H% S5 e7 Y {
* a1 s1 B$ e* ?( q( W foundObjs[k] = sd.getPlainObject(k);1 `3 i9 w: F4 R1 Z, H4 a
}2 o) B6 ^" h* o E
user = (User) foundObjs[0]; 2 P2 ]0 k( ]: a) G! O: j
}
* c9 X4 Q" t) Y- s3 S/ `% U catch (Exception e)& F( A7 V2 R* j& Y) {
{7 D$ P9 x8 _5 {6 b7 w
System.out.println("ExecuteSavedQuery service request failed.");
* q. M; ?; ]7 K$ c& P5 x System.out.println(e.getMessage());3 w4 a6 r9 y3 A- y( ], i
} 3 Q: Z9 \0 I9 W* y9 s
return user;: @" r! X9 n% D! B6 \+ `, O$ ?
}0 A7 h2 ^4 X: ?. V( \
[/mw_shl_code]/ W i% L9 N t. h7 [5 I* c8 {+ h
|
|