|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
6 E& [6 a0 ~0 `0 n D. u5 C: z) j
Teamenter SOA开发源码:通过user ID 找 User
* \' O0 J. i' V, F$ U; t
# |- ~. i, n0 `5 V/ P[mw_shl_code=applescript,true]import com.Teamcenter.services.strong.query.SavedQueryService;
+ L" H: H- p( \6 fimport com.teamcenter.services.strong.query._2006_03.SavedQuery.GetSavedQueriesResponse;
5 V* T3 T/ [5 ^import com.teamcenter.services.strong.query._2007_09.SavedQuery.SavedQueriesResponse;
& w4 ?% ]! l2 Q, y- dimport com.teamcenter.services.strong.query._2008_06.SavedQuery.QueryInput;
' c- n) s) i9 q) C1 Pimport com.teamcenter.services.strong.query._2007_09.SavedQuery.QueryResults;* p0 N8 T) u; Q" l- R
import com.teamcenter.services.strong.core.DataManagementService;& K4 v" F( N4 s' ~9 p( [
import com.teamcenter.soa.client.model.ModelObject;- s* }$ `4 c( Y! Z
import com.teamcenter.soa.client.model.ServiceData;
4 D$ F/ L4 j0 g3 f3 ], H& t# simport com.teamcenter.soa.client.model.strong.ImanQuery;
9 J+ R' y7 k5 r+ n% t+ t- `. ^) s0 V! }( g1 `* b: E
import com.teamcenter.soa.client.model.strong.User; M$ N: f% \9 m4 {( V% l
3 `+ `1 T* U' _+ p# ^, r: t0 l+ |% ~9 S" O o" P* t) J* i
public User findUser(String userId)0 I" M+ M; z- a" i" R' i
{& n1 I2 g! f! U: |, i4 T
ImanQuery query = null;2 L' P5 m+ S7 z' L/ t
User user = null;9 d0 i4 p. f G2 }- C1 L& l
* }2 M* N8 S b0 o( J& q( T+ ~! Z
3 r9 v% ~5 r) e& V& E& F- G SavedQueryService queryService = SavedQueryService.getService(AppXSession.geTConnection());
+ G9 {% J- d! r L/ Y3 C" r# \/ L DataManagementService dmService= DataManagementService.getService(AppXSession.getConnection());7 l0 \5 O; Y" a1 Q. u
3 @1 u3 G4 ^ f- O |. \9 r1 G try
. n. h6 v( B$ m* @5 O9 L {3 f* i4 R2 m, ^: V/ n# }! k
GetSavedQueriesResponse savedQueries = queryService.getSavedQueries();7 F. Y# c& T8 Y% |) ^
if (savedQueries.queries.length == 0)
- T8 X- M6 C/ F; w1 X) F+ } {
" t3 y2 ?1 B' a# l3 B' X3 c w/ U System.out.println("There are no saved queries in the system.");
i3 S/ F Y! K2 b return user;
. W5 _! ]7 n! x X6 S' r }) U3 R, o1 N3 l
* d$ O$ z$ k7 r) `
for (int i = 0; i < savedQueries.queries.length; i++)& f3 j* V+ i `3 D ?% Q
{) Z9 F! h- J# A. E
6 H& S& A: i* g) g; R9 K; |
if (savedQueries.queries.name.equals("__WEB_find_user"))8 j: d# t3 Y4 @: p' }! y3 w0 {
{% v; A% A# Y7 |% v9 O5 ^' Y) N2 z0 j
query = savedQueries.queries.query;* z+ G! d M. n5 L9 n
break;
1 i& G" U6 E; H0 u5 M# h7 s }
9 R7 B# G8 J% }* o2 P; l }
; |# z5 R" d w }0 |& X3 K2 L* l& L7 ~: Y. K! Q
catch (ServiceException e)
; }* k3 \4 B8 |6 A* C {: U) d" G. z3 I' a9 |
System.out.println("GetSavedQueries service request failed.");
+ b; Y' f- F. F. R3 k System.out.println(e.getMessage());
) `6 O; G: h/ x0 A5 s- k- z return user;
9 ~: _3 F6 M# E+ l0 V }+ _- c% N* r, s/ `
" Q1 M* m/ Q7 K# A- N$ D5 @3 ^ if (query == null)- H" n s2 J) M$ H! _7 h# b
{
( T, L) V$ S! t; p2 K System.out.println("There is not an '__WEB_find_user' query.");
2 H9 ]. ^. [6 T9 e$ b7 q return user;# w/ n5 S; L6 [/ d: B ?: d1 q. Q
}
3 U7 q/ y3 N, v1 U* N8 ~9 c5 B9 C$ H! S9 N# U* {" _9 H3 l
try9 d. v8 K2 |8 a: Z
{
4 y, D0 S! R2 j0 N S5 [- @ n QueryInput savedQueryInput[] = new QueryInput[1];/ j9 o* t( I9 D+ q1 j- A
savedQueryInput[0] = new QueryInput();
, N. D8 U7 V! w7 a$ M; V savedQueryInput[0].query = query;6 X, |4 {* p$ `! {, M
savedQueryInput[0].entries = new String[1];
% ]/ [; ?( H( b* o8 `: H7 X# M savedQueryInput[0].values = new String[1];
7 N: i& e9 u* T5 _' `! v savedQueryInput[0].entries[0] = "User ID" ;1 p, G, @7 i: |% w4 C# E0 {
savedQueryInput[0].values[0] = userId;
! B1 c; K, [7 X) Q" u3 E; k; J savedQueryInput[0].maxNumToReturn = 25;
$ u4 y" J7 z8 q T) J( r, F; ^/ n. C
SavedQueriesResponse savedQueryResult = queryService.executeSavedQueries(savedQueryInput);
8 J, m: [7 d+ {0 B* H QueryResults found = savedQueryResult.arrayOfResults[0];
1 b5 _' p. l8 n% ~
# p* k" {0 h3 y L% v; B int length = found.objectUIDS.length;
) |+ |+ ~4 o! c, y6 |
, C% f: B# G$ ?& |- U String[] uids = new String[length];
~4 S7 n5 y/ _6 G9 r for( int ii = 0; ii < length; ii++)/ K' P+ x% q& O( u! ?7 n
{
' L/ j- { F8 J) F; o6 F- D8 u/ k uids[ii]= found.objectUIDS[ii];7 L" D% t6 M* [
}
; T9 |2 z: M. ]& c0 b1 x% l: b* D ServiceData sd = dmService.loadObjects(uids);
+ j$ ^0 p% `6 F4 G ModelObject[] foundObjs = new ModelObject[ sd.sizeOfPlainObjects()];
4 }3 P$ Y" F" r1 l for( int k =0; k< sd.sizeOfPlainObjects(); k++)
4 O5 ^8 c$ Q. D/ d$ {8 E% A9 _ g8 N {) Z$ @5 M R# I0 |, U+ c; B" S
foundObjs[k] = sd.getPlainObject(k);
! A( } l! c! V, @4 H }* A7 F% s7 h5 P2 i" w4 u
user = (User) foundObjs[0]; 9 P5 G) A: x6 G: K* W; N9 Z+ M- c
}. Y* U( Y2 L* @2 S* d
catch (Exception e)
/ f/ z) y! Y# B {8 f& N, K9 Y) g4 `4 U
System.out.println("ExecuteSavedQuery service request failed.");
& U9 b3 {, b& J. a5 c( v y2 E System.out.println(e.getMessage());
* J9 z% J! w' S, { } / Q% m0 r2 L* h! C' |9 |
return user;
2 u. o( j, ^! R: w& ]2 h9 N" G }
x$ N7 Z) X5 T( f3 w @" J[/mw_shl_code]9 L. P2 R9 l* G& l6 c
|
|