|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
% W% m! _2 Q; |+ K* R: X: aTeamenter SOA开发源码:通过user ID 找 User
& H- |2 V' u3 ^& P2 v6 p. {- i4 _% U9 d
[mw_shl_code=applescript,true]import com.Teamcenter.services.strong.query.SavedQueryService;$ C! ?& M( k2 F! b$ e! G
import com.teamcenter.services.strong.query._2006_03.SavedQuery.GetSavedQueriesResponse;
9 ?8 r" u3 k: H0 Bimport com.teamcenter.services.strong.query._2007_09.SavedQuery.SavedQueriesResponse;
8 L9 k3 H# h( m" p) S+ gimport com.teamcenter.services.strong.query._2008_06.SavedQuery.QueryInput;
9 E0 k. Z7 c) Q4 w7 o1 P, t* Rimport com.teamcenter.services.strong.query._2007_09.SavedQuery.QueryResults;
$ C, w s+ {4 N; e! x" Pimport com.teamcenter.services.strong.core.DataManagementService;
7 b. v& U0 a/ K+ D- Nimport com.teamcenter.soa.client.model.ModelObject;
6 w7 z3 L, B2 [9 g; e% Yimport com.teamcenter.soa.client.model.ServiceData;
7 I z) H* C1 t, d7 s" Fimport com.teamcenter.soa.client.model.strong.ImanQuery;4 _' E5 K4 A: H. u! J, V" N
( f" }: T0 J7 gimport com.teamcenter.soa.client.model.strong.User;
/ M: O2 L9 g7 Z1 S
: j* v3 D9 d3 b3 F% O" @: A% u! G- E
% l- R9 y: V$ B4 a m0 Z public User findUser(String userId)
; ?9 E' ?& ^( P0 l( r! z2 t) T& [ {
' ]: \9 O# Z$ z6 E ImanQuery query = null;1 @; C# Q! Z3 I. X
User user = null;
7 H( }# B' X' A" m6 i 1 K: J$ @& v4 {+ c% D: S3 l
7 O! C3 D6 N2 l1 k$ h, J" S3 t
SavedQueryService queryService = SavedQueryService.getService(AppXSession.geTConnection());$ Q! z" \7 }- {% N5 D: a+ e# o
DataManagementService dmService= DataManagementService.getService(AppXSession.getConnection());: Z! S$ X" I8 N9 p1 w6 u
7 g& x) a0 [/ W( Z; L
try+ Q0 f( K6 R& C" p* t
{
# q% S) b2 i/ ` GetSavedQueriesResponse savedQueries = queryService.getSavedQueries();
4 o) b/ j& ^' Q- e) v if (savedQueries.queries.length == 0)
0 ]5 h$ D$ C0 { {
4 J0 K% s( f; X System.out.println("There are no saved queries in the system.");) W3 d C5 A& i& _9 ]
return user;5 L7 x& l* h3 h# f
}
) U6 V6 c2 [; Z3 F' c i5 s8 s. X & u* v9 w! x. R
for (int i = 0; i < savedQueries.queries.length; i++)
$ \9 v& k! V1 k" a- W) Y. @( V {1 m( S+ z; j- ]; z; a
+ {! M1 q2 _: j I/ J if (savedQueries.queries.name.equals("__WEB_find_user"))
/ K/ [" K& c) j$ `; p# ` {
3 T9 G6 n- E" U z o query = savedQueries.queries.query;. z3 o% p; U/ V9 M/ x2 l# s. h) r/ Z
break;3 O' |5 K( `* [& [0 [5 e6 T
}
: f4 P1 g7 x) L }6 z% Z3 |5 w" A6 s
}( e' [9 K4 t+ c( ?
catch (ServiceException e)
D9 h7 {% J0 `0 _( ~& X1 O1 K {* r$ ] Y6 f# H' w
System.out.println("GetSavedQueries service request failed.");) E8 A9 Q; s# v1 `& R
System.out.println(e.getMessage());
% J7 s& {0 v' U; W return user;+ `* j! |, ]5 V4 F
}
/ b% L, ?' L- P/ S; q% Q; R) r) I
if (query == null)5 G( X+ l0 \4 ~; D2 u/ U' ?+ F
{
% X" x9 }3 s: n6 u( x: D4 r6 @6 f. U System.out.println("There is not an '__WEB_find_user' query.");2 U$ @8 |3 m* b' J! }! q
return user;
, H3 `6 \7 }; o0 [% ~, B }
( ^5 Q% ]0 A! f" n! Z$ s5 t. |9 B! ^- f) w$ Z: N7 B& A1 o% a
try ? G. v# S* M/ A% `
{
, \+ r) o. a! k( Z3 T) n7 R QueryInput savedQueryInput[] = new QueryInput[1];# `$ O' F5 x8 p! E0 k9 i
savedQueryInput[0] = new QueryInput();& V# \% B! J: l/ \& u1 O% U
savedQueryInput[0].query = query;6 z- [7 W# \- X0 k: Q j
savedQueryInput[0].entries = new String[1];
5 c. W! {9 o' l$ y2 S1 z savedQueryInput[0].values = new String[1];2 _" i G* h7 L) K8 F: E* `& y: ^; x
savedQueryInput[0].entries[0] = "User ID" ; n# g! u# X( a( k6 L6 I4 ?; U# `8 i
savedQueryInput[0].values[0] = userId;
2 q6 n/ v r+ _/ Q: y @ savedQueryInput[0].maxNumToReturn = 25;, z# K# y9 i0 \4 c1 y% @. j! [
6 i. Y9 G# P! T, k SavedQueriesResponse savedQueryResult = queryService.executeSavedQueries(savedQueryInput);1 C* n4 a) O8 B( Q5 B7 A& [0 }
QueryResults found = savedQueryResult.arrayOfResults[0];) }7 z9 G, C \! h- @2 ^, R
5 o6 `+ k: H) ]$ M
int length = found.objectUIDS.length;+ p. R/ O1 r$ T7 _* `
( J: A- w: Z3 z0 Z9 s) f
String[] uids = new String[length];( e# W: Q( _0 ]
for( int ii = 0; ii < length; ii++)
2 q# m6 W# L+ A {
5 a: o4 h3 C, ?$ } uids[ii]= found.objectUIDS[ii];
: r, m* V; y( k- } }
; j) F, G) q j( v* P" i7 s! N! a ServiceData sd = dmService.loadObjects(uids);
& @8 V4 @) l$ ^( ~, e- ?5 Y1 ` ModelObject[] foundObjs = new ModelObject[ sd.sizeOfPlainObjects()];4 e0 L- Y2 {" G4 l/ C
for( int k =0; k< sd.sizeOfPlainObjects(); k++)
% n' Q: r n7 L0 |. D {
1 A! ]. @ Z* @( y foundObjs[k] = sd.getPlainObject(k);
: a7 }4 S$ S Q; y: k: @ }
2 X8 Q& G) y7 z user = (User) foundObjs[0]; 6 \9 |6 H- g/ n
}
& i( X! S$ M6 T7 a( `6 o catch (Exception e)
6 m6 B. l, S5 N, O# S$ w {
% W4 n( q% [0 b System.out.println("ExecuteSavedQuery service request failed.");
8 s8 _/ `$ f- Y$ \' b System.out.println(e.getMessage());
2 J4 y# P% N% d' c0 G7 t: K7 \ }
) `# X) T: _9 R4 s' g8 ?9 I return user;3 j9 p' a& @5 Z+ P! O! q
}& g5 `$ _+ s ?' _2 d0 U$ R7 _
[/mw_shl_code]
8 c: j; D: R( X2 H: ` |
|