1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 package org.ogf.graap.wsag.wsrf.impl;
36
37 import java.util.Calendar;
38 import java.util.GregorianCalendar;
39
40 import javax.xml.namespace.QName;
41
42 import org.apache.log4j.Logger;
43 import org.apache.muse.ws.addressing.soap.SoapFault;
44 import org.apache.muse.ws.resource.faults.ResourceUnavailableFault;
45 import org.apache.muse.ws.resource.faults.ResourceUnknownFault;
46 import org.apache.ws.security.WSSecurityException;
47 import org.ogf.graap.wsag.api.Agreement;
48 import org.ogf.graap.wsag.api.WsagConstants;
49 import org.ogf.graap.wsag.api.exceptions.ResourceUnavailableException;
50 import org.ogf.graap.wsag.api.exceptions.ResourceUnknownException;
51 import org.ogf.graap.wsag.api.exceptions.WSAgreementException;
52 import org.ogf.graap.wsag.server.api.WsagSession;
53 import org.ogf.graap.wsag.server.engine.WsagEngine;
54 import org.ogf.graap.wsag.wsrf.WSAG4JCapability;
55 import org.ogf.schemas.graap.wsAgreement.AgreementContextType;
56 import org.ogf.schemas.graap.wsAgreement.AgreementIdDocument;
57 import org.ogf.schemas.graap.wsAgreement.AgreementRoleType;
58 import org.ogf.schemas.graap.wsAgreement.AgreementStateDocument;
59 import org.ogf.schemas.graap.wsAgreement.GuaranteeTermStateDocument;
60 import org.ogf.schemas.graap.wsAgreement.GuaranteeTermStateType;
61 import org.ogf.schemas.graap.wsAgreement.ServiceTermStateDocument;
62 import org.ogf.schemas.graap.wsAgreement.ServiceTermStateType;
63 import org.ogf.schemas.graap.wsAgreement.TemplateDocument;
64 import org.ogf.schemas.graap.wsAgreement.TermTreeType;
65 import org.ogf.schemas.graap.wsAgreement.TerminateInputDocument;
66 import org.ogf.schemas.graap.wsAgreement.TerminateOutputType;
67 import org.ogf.schemas.graap.wsAgreement.TerminateResponseDocument;
68 import org.w3c.dom.Element;
69
70
71
72
73
74
75
76 public class AgreementCapability extends WSAG4JCapability
77 {
78
79 @SuppressWarnings( "unused" )
80 private static Logger log = Logger.getLogger( AgreementCapability.class );
81
82 private Agreement getAgreement() throws WSSecurityException
83 {
84 return ( (AgreementWsResource) getResource() ).getAgreement();
85 }
86
87 private WsagSession getSession()
88 {
89 return ( (AgreementWsResource) getResource() ).getSession();
90 }
91
92
93
94
95 public QName[] getPropertyNames()
96 {
97 return WsagConstants.WSAG_AGREEMENT_PROPERTIES;
98 }
99
100
101
102
103
104
105
106
107
108
109
110
111 public TerminateOutputType terminate( TerminateInputDocument input ) throws SoapFault
112 {
113 try
114 {
115 WsagEngine.getWsagMessageContext().setSession( getSession() );
116
117 TerminateResponseDocument response = TerminateResponseDocument.Factory.newInstance();
118 getAgreement().terminate( input.getTerminateInput() );
119 response.addNewTerminateResponse();
120
121 return response.getTerminateResponse();
122
123 }
124 catch ( Exception e )
125 {
126 throw new SoapFault( e );
127 }
128 }
129
130
131
132
133
134
135
136
137
138
139
140 public String getName() throws ResourceUnknownFault, ResourceUnavailableFault
141 {
142 WsagEngine.getWsagMessageContext().setSession( getSession() );
143
144 try
145 {
146 return getAgreement().getName();
147 }
148 catch ( WSSecurityException e )
149 {
150 throw new ResourceUnavailableFault( e );
151 }
152 }
153
154
155
156
157
158
159
160
161
162
163
164 public Element getAgreementId() throws ResourceUnknownFault, ResourceUnavailableFault
165 {
166 try
167 {
168 WsagEngine.getWsagMessageContext().setSession( getSession() );
169
170 String id = getAgreement().getAgreementId();
171 AgreementIdDocument doc = AgreementIdDocument.Factory.newInstance();
172 doc.setAgreementId( id );
173
174 return toElement( doc );
175
176 }
177 catch ( ResourceUnknownException e )
178 {
179 throw new ResourceUnknownFault( e );
180 }
181 catch ( ResourceUnavailableException e )
182 {
183 throw new ResourceUnavailableFault( e );
184 }
185 catch ( WSAgreementException e )
186 {
187 throw new ResourceUnavailableFault( e );
188 }
189 catch ( WSSecurityException e )
190 {
191 throw new ResourceUnavailableFault( e );
192 }
193 }
194
195
196
197
198
199
200
201
202
203
204 public Element getContext() throws ResourceUnknownFault, ResourceUnavailableFault
205 {
206 try
207 {
208 WsagEngine.getWsagMessageContext().setSession( getSession() );
209
210 AgreementContextType context = getAgreement().getContext();
211 if ( context == null )
212 {
213 context = TemplateDocument.Factory.newInstance().addNewTemplate().addNewContext();
214
215 Calendar expire = new GregorianCalendar();
216 expire.add( Calendar.DAY_OF_YEAR, 1 );
217
218 context.setExpirationTime( expire );
219 context.setServiceProvider( AgreementRoleType.AGREEMENT_RESPONDER );
220 }
221
222 return toElement( context );
223 }
224 catch ( ResourceUnknownException e )
225 {
226 throw new ResourceUnknownFault( e );
227 }
228 catch ( ResourceUnavailableException e )
229 {
230 throw new ResourceUnavailableFault( e );
231 }
232 catch ( WSAgreementException e )
233 {
234 throw new ResourceUnavailableFault( e );
235 }
236 catch ( WSSecurityException e )
237 {
238 throw new ResourceUnavailableFault( e );
239 }
240 }
241
242
243
244
245
246
247
248
249
250
251 public Element getTerms() throws ResourceUnknownFault, ResourceUnavailableFault
252 {
253 try
254 {
255 WsagEngine.getWsagMessageContext().setSession( getSession() );
256
257 TermTreeType terms = getAgreement().getTerms();
258
259 if ( terms == null )
260 {
261 terms = TemplateDocument.Factory.newInstance().addNewTemplate().addNewTerms();
262 terms.addNewAll();
263 }
264
265 return toElement( terms );
266 }
267 catch ( ResourceUnknownException e )
268 {
269 throw new ResourceUnknownFault( e );
270 }
271 catch ( ResourceUnavailableException e )
272 {
273 throw new ResourceUnavailableFault( e );
274 }
275 catch ( WSAgreementException e )
276 {
277 throw new ResourceUnavailableFault( e );
278 }
279 catch ( WSSecurityException e )
280 {
281 throw new ResourceUnavailableFault( e );
282 }
283 }
284
285
286
287
288
289
290
291
292
293
294 public Element getAgreementState() throws ResourceUnknownFault, ResourceUnavailableFault
295 {
296 try
297 {
298 WsagEngine.getWsagMessageContext().setSession( getSession() );
299
300 AgreementStateDocument state = AgreementStateDocument.Factory.newInstance();
301 state.addNewAgreementState();
302
303 if ( getAgreement().getState() != null )
304 {
305 state.getAgreementState().set( getAgreement().getState() );
306 }
307
308 return toElement( state );
309 }
310 catch ( ResourceUnknownException e )
311 {
312 throw new ResourceUnknownFault( e );
313 }
314 catch ( ResourceUnavailableException e )
315 {
316 throw new ResourceUnavailableFault( e );
317 }
318 catch ( WSAgreementException e )
319 {
320 throw new ResourceUnavailableFault( e );
321 }
322 catch ( WSSecurityException e )
323 {
324 throw new ResourceUnavailableFault( e );
325 }
326 }
327
328
329
330
331
332
333
334
335
336
337 public Element[] getGuaranteeTermState() throws ResourceUnknownFault, ResourceUnavailableFault
338 {
339 try
340 {
341 WsagEngine.getWsagMessageContext().setSession( getSession() );
342
343 GuaranteeTermStateType[] currentStates = getAgreement().getGuaranteeTermStates();
344
345 if ( currentStates == null )
346 {
347 currentStates = new GuaranteeTermStateType[0];
348 }
349
350 GuaranteeTermStateDocument[] states = new GuaranteeTermStateDocument[currentStates.length];
351 for ( int i = 0; i < states.length; i++ )
352 {
353 states[i] = GuaranteeTermStateDocument.Factory.newInstance();
354 states[i].setGuaranteeTermState( currentStates[i] );
355 }
356
357 return toElementArray( states );
358 }
359 catch ( ResourceUnknownException e )
360 {
361 throw new ResourceUnknownFault( e );
362 }
363 catch ( ResourceUnavailableException e )
364 {
365 throw new ResourceUnavailableFault( e );
366 }
367 catch ( WSAgreementException e )
368 {
369 throw new ResourceUnavailableFault( e );
370 }
371 catch ( WSSecurityException e )
372 {
373 throw new ResourceUnavailableFault( e );
374 }
375 }
376
377
378
379
380
381
382
383
384
385
386 public Element[] getServiceTermState() throws ResourceUnknownFault, ResourceUnavailableFault
387 {
388 try
389 {
390 WsagEngine.getWsagMessageContext().setSession( getSession() );
391
392 ServiceTermStateType[] currentStates = getAgreement().getServiceTermStates();
393 if ( currentStates == null )
394 {
395 currentStates = new ServiceTermStateType[0];
396 }
397
398 ServiceTermStateDocument[] states = new ServiceTermStateDocument[currentStates.length];
399 for ( int i = 0; i < states.length; i++ )
400 {
401 states[i] = ServiceTermStateDocument.Factory.newInstance();
402 states[i].setServiceTermState( currentStates[i] );
403 }
404
405 return toElementArray( states );
406
407 }
408 catch ( ResourceUnknownException e )
409 {
410 throw new ResourceUnknownFault( e );
411 }
412 catch ( ResourceUnavailableException e )
413 {
414 throw new ResourceUnavailableFault( e );
415 }
416 catch ( WSAgreementException e )
417 {
418 throw new ResourceUnavailableFault( e );
419 }
420 catch ( WSSecurityException e )
421 {
422 throw new ResourceUnavailableFault( e );
423 }
424 }
425
426 }