1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.apache.ws.scout.registry; |
18 | |
|
19 | |
import java.io.Serializable; |
20 | |
import java.net.PasswordAuthentication; |
21 | |
import java.util.ArrayList; |
22 | |
import java.util.Collection; |
23 | |
import java.util.HashSet; |
24 | |
import java.util.Hashtable; |
25 | |
import java.util.Iterator; |
26 | |
import java.util.LinkedHashSet; |
27 | |
import java.util.List; |
28 | |
import java.util.Set; |
29 | |
import java.util.Vector; |
30 | |
|
31 | |
import javax.xml.registry.BulkResponse; |
32 | |
import javax.xml.registry.BusinessLifeCycleManager; |
33 | |
import javax.xml.registry.DeleteException; |
34 | |
import javax.xml.registry.InvalidRequestException; |
35 | |
import javax.xml.registry.JAXRException; |
36 | |
import javax.xml.registry.JAXRResponse; |
37 | |
import javax.xml.registry.LifeCycleManager; |
38 | |
import javax.xml.registry.RegistryService; |
39 | |
import javax.xml.registry.SaveException; |
40 | |
import javax.xml.registry.UnexpectedObjectException; |
41 | |
import javax.xml.registry.infomodel.Association; |
42 | |
import javax.xml.registry.infomodel.ClassificationScheme; |
43 | |
import javax.xml.registry.infomodel.Concept; |
44 | |
import javax.xml.registry.infomodel.Key; |
45 | |
import javax.xml.registry.infomodel.Organization; |
46 | |
import javax.xml.registry.infomodel.RegistryObject; |
47 | |
import javax.xml.registry.infomodel.Service; |
48 | |
import javax.xml.registry.infomodel.ServiceBinding; |
49 | |
|
50 | |
import org.apache.commons.logging.Log; |
51 | |
import org.apache.commons.logging.LogFactory; |
52 | |
import org.apache.ws.scout.model.uddi.v2.AssertionStatusItem; |
53 | |
import org.apache.ws.scout.model.uddi.v2.AssertionStatusReport; |
54 | |
import org.apache.ws.scout.model.uddi.v2.AuthToken; |
55 | |
import org.apache.ws.scout.model.uddi.v2.BindingDetail; |
56 | |
import org.apache.ws.scout.model.uddi.v2.BindingTemplate; |
57 | |
import org.apache.ws.scout.model.uddi.v2.BusinessDetail; |
58 | |
import org.apache.ws.scout.model.uddi.v2.BusinessEntity; |
59 | |
import org.apache.ws.scout.model.uddi.v2.BusinessInfo; |
60 | |
import org.apache.ws.scout.model.uddi.v2.BusinessService; |
61 | |
import org.apache.ws.scout.model.uddi.v2.Description; |
62 | |
import org.apache.ws.scout.model.uddi.v2.DispositionReport; |
63 | |
import org.apache.ws.scout.model.uddi.v2.ErrInfo; |
64 | |
import org.apache.ws.scout.model.uddi.v2.KeyedReference; |
65 | |
import org.apache.ws.scout.model.uddi.v2.Name; |
66 | |
import org.apache.ws.scout.model.uddi.v2.ObjectFactory; |
67 | |
import org.apache.ws.scout.model.uddi.v2.PublisherAssertion; |
68 | |
import org.apache.ws.scout.model.uddi.v2.PublisherAssertions; |
69 | |
import org.apache.ws.scout.model.uddi.v2.Result; |
70 | |
import org.apache.ws.scout.model.uddi.v2.ServiceDetail; |
71 | |
import org.apache.ws.scout.model.uddi.v2.ServiceInfo; |
72 | |
import org.apache.ws.scout.model.uddi.v2.TModel; |
73 | |
import org.apache.ws.scout.model.uddi.v2.TModelDetail; |
74 | |
import org.apache.ws.scout.registry.infomodel.ConceptImpl; |
75 | |
import org.apache.ws.scout.registry.infomodel.InternationalStringImpl; |
76 | |
import org.apache.ws.scout.registry.infomodel.KeyImpl; |
77 | |
import org.apache.ws.scout.registry.infomodel.OrganizationImpl; |
78 | |
import org.apache.ws.scout.registry.infomodel.ServiceImpl; |
79 | |
import org.apache.ws.scout.util.ScoutJaxrUddiHelper; |
80 | |
import org.apache.ws.scout.util.ScoutUddiJaxrHelper; |
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
public class BusinessLifeCycleManagerImpl extends LifeCycleManagerImpl |
91 | |
implements BusinessLifeCycleManager, Serializable { |
92 | |
|
93 | |
private static final long serialVersionUID = -4533264314909343311L; |
94 | |
|
95 | 0 | private Log log = LogFactory.getLog(this.getClass()); |
96 | |
|
97 | 0 | private transient ObjectFactory objectFactory = new ObjectFactory(); |
98 | |
|
99 | |
public BusinessLifeCycleManagerImpl(RegistryService registry) { |
100 | 0 | super(registry); |
101 | |
|
102 | 0 | if(objectFactory == null) |
103 | 0 | objectFactory = new ObjectFactory(); |
104 | 0 | } |
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
public BulkResponse deleteObjects(Collection keys, String objectType) throws JAXRException { |
116 | 0 | BulkResponse bulk = null; |
117 | |
|
118 | 0 | if (objectType == LifeCycleManager.ASSOCIATION) { |
119 | 0 | bulk = this.deleteAssociations(keys); |
120 | |
} |
121 | 0 | else if (objectType == LifeCycleManager.CLASSIFICATION_SCHEME) { |
122 | 0 | bulk = this.deleteClassificationSchemes(keys); |
123 | |
} |
124 | 0 | else if (objectType == LifeCycleManager.CONCEPT) { |
125 | 0 | bulk = this.deleteConcepts(keys); |
126 | |
} |
127 | 0 | else if (objectType == LifeCycleManager.ORGANIZATION) { |
128 | 0 | bulk = this.deleteOrganizations(keys); |
129 | |
} |
130 | 0 | else if (objectType == LifeCycleManager.SERVICE) { |
131 | 0 | bulk = this.deleteServices(keys); |
132 | |
} |
133 | 0 | else if (objectType == LifeCycleManager.SERVICE_BINDING) { |
134 | 0 | bulk = this.deleteServiceBindings(keys); |
135 | |
} |
136 | |
else { |
137 | 0 | throw new JAXRException("Delete Operation for " + objectType + " not implemented by Scout"); |
138 | |
} |
139 | |
|
140 | 0 | return bulk; |
141 | |
} |
142 | |
|
143 | |
public BulkResponse deleteAssociations(Collection associationKeys) throws JAXRException { |
144 | 0 | return this.deleteOperation(associationKeys, "DELETE_ASSOCIATION"); |
145 | |
} |
146 | |
|
147 | |
public BulkResponse deleteClassificationSchemes(Collection schemeKeys) throws JAXRException { |
148 | 0 | return this.deleteOperation(schemeKeys, "DELETE_CLASSIFICATIONSCHEME"); |
149 | |
} |
150 | |
|
151 | |
public BulkResponse deleteConcepts(Collection conceptKeys) throws JAXRException { |
152 | 0 | return this.deleteOperation(conceptKeys, "DELETE_CONCEPT"); |
153 | |
} |
154 | |
|
155 | |
public BulkResponse deleteOrganizations(Collection orgkeys) throws JAXRException { |
156 | 0 | return this.deleteOperation(orgkeys, "DELETE_ORG"); |
157 | |
} |
158 | |
|
159 | |
public BulkResponse deleteServiceBindings(Collection bindingKeys) throws JAXRException { |
160 | 0 | return this.deleteOperation(bindingKeys, "DELETE_SERVICEBINDING"); |
161 | |
} |
162 | |
|
163 | |
public BulkResponse deleteServices(Collection serviceKeys) throws JAXRException { |
164 | 0 | return this.deleteOperation(serviceKeys, "DELETE_SERVICE"); |
165 | |
} |
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
|
186 | |
|
187 | |
public BulkResponse saveObjects(Collection col) throws JAXRException { |
188 | |
|
189 | 0 | Iterator iter = col.iterator(); |
190 | |
|
191 | 0 | LinkedHashSet<Object> suc = new LinkedHashSet<Object>(); |
192 | 0 | Collection<Exception> exc = new ArrayList<Exception>(); |
193 | |
|
194 | 0 | while (iter.hasNext()) { |
195 | 0 | RegistryObject reg = (RegistryObject) iter.next(); |
196 | |
|
197 | 0 | BulkResponse br = null; |
198 | |
|
199 | 0 | Collection<RegistryObject> c = new ArrayList<RegistryObject>(); |
200 | 0 | c.add(reg); |
201 | |
|
202 | 0 | if (reg instanceof javax.xml.registry.infomodel.Association) { |
203 | 0 | br = saveAssociations(c, true); |
204 | |
} |
205 | 0 | else if (reg instanceof javax.xml.registry.infomodel.ClassificationScheme) { |
206 | 0 | br = saveClassificationSchemes(c); |
207 | |
} |
208 | 0 | else if (reg instanceof javax.xml.registry.infomodel.Concept) { |
209 | 0 | br = saveConcepts(c); |
210 | |
} |
211 | 0 | else if (reg instanceof javax.xml.registry.infomodel.Organization) { |
212 | 0 | br = saveOrganizations(c); |
213 | |
} |
214 | 0 | else if (reg instanceof javax.xml.registry.infomodel.Service) { |
215 | 0 | br = saveServices(c); |
216 | |
} |
217 | 0 | else if (reg instanceof javax.xml.registry.infomodel.ServiceBinding) { |
218 | 0 | br = saveServiceBindings(c); |
219 | |
} |
220 | |
else { |
221 | 0 | throw new JAXRException("Delete Operation for " + reg.getClass() |
222 | |
+ " not implemented by Scout"); |
223 | |
} |
224 | |
|
225 | 0 | if (br.getCollection() != null) { |
226 | 0 | suc.addAll(br.getCollection()); |
227 | |
} |
228 | |
|
229 | 0 | if (br.getExceptions() != null) { |
230 | 0 | exc.addAll(br.getExceptions()); |
231 | |
} |
232 | 0 | } |
233 | |
|
234 | 0 | BulkResponseImpl bulk = new BulkResponseImpl(); |
235 | |
|
236 | |
|
237 | |
|
238 | |
|
239 | 0 | bulk.setStatus(JAXRResponse.STATUS_SUCCESS); |
240 | |
|
241 | 0 | bulk.setCollection(suc); |
242 | 0 | bulk.setExceptions(exc); |
243 | |
|
244 | 0 | return bulk; |
245 | |
} |
246 | |
|
247 | |
|
248 | |
public BulkResponse saveAssociations(Collection associations, boolean replace) throws JAXRException { |
249 | 0 | BulkResponseImpl bulk = new BulkResponseImpl(); |
250 | 0 | PublisherAssertion[] sarr = new PublisherAssertion[associations.size()]; |
251 | |
|
252 | 0 | Collection<Key> coll = new ArrayList<Key>(); |
253 | 0 | Collection<Exception> exceptions = new ArrayList<Exception>(); |
254 | |
|
255 | 0 | Iterator iter = associations.iterator(); |
256 | 0 | int currLoc = 0; |
257 | 0 | while (iter.hasNext()) { |
258 | |
|
259 | 0 | Association association = (Association) iter.next(); |
260 | 0 | association.getSourceObject(); |
261 | 0 | PublisherAssertion pa = ScoutJaxrUddiHelper.getPubAssertionFromJAXRAssociation(association); |
262 | 0 | sarr[currLoc] = pa; |
263 | 0 | currLoc++; |
264 | |
|
265 | |
|
266 | 0 | PublisherAssertions bd = null; |
267 | |
try { |
268 | 0 | bd = (PublisherAssertions) executeOperation(sarr, "SAVE_ASSOCIATION"); |
269 | |
} |
270 | 0 | catch (RegistryException e) { |
271 | 0 | exceptions.add(new SaveException(e)); |
272 | 0 | bulk.setExceptions(exceptions); |
273 | 0 | bulk.setStatus(JAXRResponse.STATUS_FAILURE); |
274 | 0 | return bulk; |
275 | 0 | } |
276 | 0 | if(bd != null) |
277 | |
{ |
278 | 0 | List<PublisherAssertion> publisherAssertionList = bd.getPublisherAssertion(); |
279 | 0 | PublisherAssertion[] keyarr = new PublisherAssertion[publisherAssertionList.size()]; |
280 | 0 | publisherAssertionList.toArray(keyarr); |
281 | |
|
282 | 0 | for (int i = 0; keyarr != null && i < keyarr.length; i++) { |
283 | 0 | PublisherAssertion result = (PublisherAssertion) keyarr[i]; |
284 | 0 | KeyedReference keyr = result.getKeyedReference(); |
285 | 0 | Concept c = new ConceptImpl(getRegistryService().getBusinessLifeCycleManager()); |
286 | 0 | c.setName(new InternationalStringImpl(keyr.getKeyName())); |
287 | 0 | c.setKey( new KeyImpl(keyr.getTModelKey()) ); |
288 | 0 | c.setValue(keyr.getKeyValue()); |
289 | 0 | association.setAssociationType(c); |
290 | 0 | coll.add(association.getKey()); |
291 | |
} |
292 | |
} |
293 | 0 | } |
294 | 0 | bulk.setCollection(coll); |
295 | 0 | bulk.setExceptions(exceptions); |
296 | |
|
297 | 0 | return bulk; |
298 | |
} |
299 | |
|
300 | |
public BulkResponse saveClassificationSchemes(Collection schemes) throws JAXRException { |
301 | |
|
302 | 0 | BulkResponseImpl bulk = new BulkResponseImpl(); |
303 | 0 | TModel[] entityarr = new TModel[schemes.size()]; |
304 | |
|
305 | 0 | LinkedHashSet<Key> coll = new LinkedHashSet<Key>(); |
306 | 0 | Collection<Exception> exceptions = new ArrayList<Exception>(); |
307 | |
|
308 | 0 | Iterator iter = schemes.iterator(); |
309 | 0 | int currLoc = 0; |
310 | 0 | while (iter.hasNext()) { |
311 | |
try { |
312 | 0 | TModel en = |
313 | |
ScoutJaxrUddiHelper.getTModelFromJAXRClassificationScheme((ClassificationScheme) iter.next()); |
314 | 0 | entityarr[currLoc] = en; |
315 | 0 | currLoc++; |
316 | |
} |
317 | 0 | catch (ClassCastException ce) { |
318 | 0 | throw new UnexpectedObjectException(); |
319 | 0 | } |
320 | |
} |
321 | 0 | log.debug("Method:save_classificationscheme: ENlength=" + entityarr.length); |
322 | |
|
323 | 0 | TModelDetail td = null; |
324 | |
try { |
325 | 0 | td = (TModelDetail) executeOperation(entityarr, "SAVE_TMODEL"); |
326 | |
} |
327 | 0 | catch (RegistryException e) { |
328 | 0 | exceptions.add(new SaveException(e.getLocalizedMessage())); |
329 | 0 | bulk.setStatus(JAXRResponse.STATUS_FAILURE); |
330 | 0 | return bulk; |
331 | 0 | } |
332 | |
|
333 | 0 | List<TModel> tmodelList = td.getTModel(); |
334 | 0 | entityarr = new TModel[tmodelList.size()]; |
335 | 0 | tmodelList.toArray(entityarr); |
336 | 0 | log.debug("After Saving TModel. Obtained vector size:" + entityarr != null ? entityarr.length : 0); |
337 | 0 | for (int i = 0; entityarr != null && i < entityarr.length; i++) { |
338 | 0 | TModel tm = (TModel) entityarr[i]; |
339 | 0 | coll.add(new KeyImpl(tm.getTModelKey())); |
340 | |
} |
341 | |
|
342 | 0 | bulk.setCollection(coll); |
343 | 0 | bulk.setExceptions(exceptions); |
344 | |
|
345 | 0 | return bulk; |
346 | |
} |
347 | |
|
348 | |
public BulkResponse saveConcepts(Collection concepts) throws JAXRException { |
349 | |
|
350 | 0 | BulkResponseImpl bulk = new BulkResponseImpl(); |
351 | 0 | TModel[] entityarr = new TModel[concepts.size()]; |
352 | |
|
353 | 0 | LinkedHashSet<Key> coll = new LinkedHashSet<Key>(); |
354 | 0 | Collection<Exception> exceptions = new ArrayList<Exception>(); |
355 | |
|
356 | 0 | Iterator iter = concepts.iterator(); |
357 | 0 | int currLoc = 0; |
358 | 0 | while (iter.hasNext()) { |
359 | |
try { |
360 | 0 | TModel en = |
361 | |
ScoutJaxrUddiHelper.getTModelFromJAXRConcept((Concept) iter.next()); |
362 | 0 | entityarr[currLoc] = en; |
363 | 0 | currLoc++; |
364 | |
} |
365 | 0 | catch (ClassCastException ce) { |
366 | 0 | throw new UnexpectedObjectException(); |
367 | 0 | } |
368 | |
} |
369 | 0 | log.debug("Method:save_concept: ENlength=" + entityarr.length); |
370 | |
|
371 | 0 | TModelDetail td = null; |
372 | |
try { |
373 | 0 | td = (TModelDetail) executeOperation(entityarr, "SAVE_TMODEL"); |
374 | |
} |
375 | 0 | catch (RegistryException e) { |
376 | 0 | exceptions.add(new SaveException(e.getLocalizedMessage())); |
377 | 0 | bulk.setStatus(JAXRResponse.STATUS_FAILURE); |
378 | 0 | return bulk; |
379 | 0 | } |
380 | |
|
381 | 0 | List<TModel> tmodelList = td.getTModel(); |
382 | 0 | entityarr = new TModel[tmodelList.size()]; |
383 | 0 | tmodelList.toArray(entityarr); |
384 | |
|
385 | 0 | log.debug("After Saving TModel. Obtained vector size:" + entityarr != null ? entityarr.length : 0); |
386 | 0 | for (int i = 0; entityarr != null && i < entityarr.length; i++) { |
387 | 0 | TModel tm = (TModel) entityarr[i]; |
388 | 0 | coll.add(new KeyImpl(tm.getTModelKey())); |
389 | |
} |
390 | |
|
391 | 0 | bulk.setCollection(coll); |
392 | 0 | bulk.setExceptions(exceptions); |
393 | |
|
394 | 0 | return bulk; |
395 | |
} |
396 | |
|
397 | |
public BulkResponse saveOrganizations(Collection organizations) throws JAXRException { |
398 | |
|
399 | 0 | BulkResponseImpl bulk = new BulkResponseImpl(); |
400 | 0 | BusinessEntity[] entityarr = new BusinessEntity[organizations.size()]; |
401 | |
|
402 | 0 | LinkedHashSet<Key> coll = new LinkedHashSet<Key>(); |
403 | 0 | Collection<Exception> exceptions = new ArrayList<Exception>(); |
404 | |
|
405 | 0 | Iterator iter = organizations.iterator(); |
406 | 0 | int currLoc = 0; |
407 | 0 | while (iter.hasNext()) { |
408 | |
try { |
409 | 0 | BusinessEntity en = |
410 | |
ScoutJaxrUddiHelper.getBusinessEntityFromJAXROrg((Organization) iter.next()); |
411 | 0 | entityarr[currLoc] = en; |
412 | 0 | currLoc++; |
413 | |
} |
414 | 0 | catch (ClassCastException ce) { |
415 | 0 | throw new UnexpectedObjectException(); |
416 | 0 | } |
417 | |
} |
418 | 0 | log.debug("Method:save_business: ENlength=" + entityarr.length); |
419 | |
|
420 | 0 | BusinessDetail bd = null; |
421 | |
try { |
422 | 0 | bd = (BusinessDetail) executeOperation(entityarr, "SAVE_ORG"); |
423 | |
} |
424 | 0 | catch (RegistryException e) { |
425 | 0 | exceptions.add(new SaveException(e.getLocalizedMessage())); |
426 | 0 | bulk.setStatus(JAXRResponse.STATUS_FAILURE); |
427 | 0 | bulk.setExceptions(exceptions); |
428 | 0 | return bulk; |
429 | 0 | } |
430 | |
|
431 | 0 | List<BusinessEntity> bizEntityList = bd.getBusinessEntity(); |
432 | |
|
433 | 0 | entityarr = new BusinessEntity[bizEntityList.size()]; |
434 | 0 | bizEntityList.toArray(entityarr); |
435 | |
|
436 | 0 | log.debug("After Saving Business. Obtained vector size:" + entityarr != null ? entityarr.length : 0); |
437 | 0 | for (int i = 0; entityarr != null && i < entityarr.length; i++) { |
438 | 0 | BusinessEntity entity = (BusinessEntity) entityarr[i]; |
439 | 0 | coll.add(new KeyImpl(entity.getBusinessKey())); |
440 | |
} |
441 | |
|
442 | 0 | bulk.setCollection(coll); |
443 | 0 | bulk.setExceptions(exceptions); |
444 | |
|
445 | 0 | return bulk; |
446 | |
} |
447 | |
|
448 | |
public BulkResponse saveServiceBindings(Collection bindings) throws JAXRException { |
449 | 0 | BulkResponseImpl bulk = new BulkResponseImpl(); |
450 | 0 | BindingTemplate[] sbarr = new BindingTemplate[bindings.size()]; |
451 | |
|
452 | 0 | LinkedHashSet<Key> coll = new LinkedHashSet<Key>(); |
453 | 0 | Collection<Exception> exceptions = new ArrayList<Exception>(); |
454 | |
|
455 | 0 | Iterator iter = bindings.iterator(); |
456 | 0 | int currLoc = 0; |
457 | 0 | while (iter.hasNext()) { |
458 | |
try { |
459 | 0 | BindingTemplate bs = ScoutJaxrUddiHelper.getBindingTemplateFromJAXRSB((ServiceBinding) iter.next()); |
460 | 0 | sbarr[currLoc] = bs; |
461 | 0 | currLoc++; |
462 | |
} |
463 | 0 | catch (ClassCastException ce) { |
464 | 0 | throw new UnexpectedObjectException(); |
465 | 0 | } |
466 | |
} |
467 | |
|
468 | 0 | BindingDetail bd = null; |
469 | |
try { |
470 | 0 | bd = (BindingDetail) executeOperation(sbarr, "SAVE_SERVICE_BINDING"); |
471 | |
} |
472 | 0 | catch (RegistryException e) { |
473 | 0 | exceptions.add(new SaveException(e.getLocalizedMessage())); |
474 | 0 | bulk.setStatus(JAXRResponse.STATUS_FAILURE); |
475 | 0 | return bulk; |
476 | 0 | } |
477 | |
|
478 | 0 | List<BindingTemplate> bindingTemplateList = bd.getBindingTemplate(); |
479 | 0 | sbarr = new BindingTemplate[bindingTemplateList.size()]; |
480 | 0 | bindingTemplateList.toArray(sbarr); |
481 | |
|
482 | 0 | for (int i = 0; sbarr != null && i < sbarr.length; i++) { |
483 | 0 | BindingTemplate bt = (BindingTemplate) sbarr[i]; |
484 | 0 | coll.add(new KeyImpl(bt.getBindingKey())); |
485 | |
} |
486 | 0 | if (coll.size()>0) { |
487 | 0 | bulk.setCollection(coll); |
488 | |
} |
489 | 0 | bulk.setExceptions(exceptions); |
490 | |
|
491 | 0 | return bulk; |
492 | |
} |
493 | |
|
494 | |
public BulkResponse saveServices(Collection services) throws JAXRException { |
495 | 0 | BulkResponseImpl bulk = new BulkResponseImpl(); |
496 | 0 | BusinessService[] sarr = new BusinessService[services.size()]; |
497 | |
|
498 | 0 | LinkedHashSet<Key> coll = new LinkedHashSet<Key>(); |
499 | 0 | Collection<Exception> exceptions = new ArrayList<Exception>(); |
500 | |
|
501 | |
|
502 | 0 | Iterator iter = services.iterator(); |
503 | 0 | int currLoc = 0; |
504 | 0 | while (iter.hasNext()) { |
505 | |
try { |
506 | 0 | BusinessService bs = ScoutJaxrUddiHelper.getBusinessServiceFromJAXRService((Service) iter.next()); |
507 | 0 | sarr[currLoc] = bs; |
508 | 0 | currLoc++; |
509 | |
} |
510 | 0 | catch (ClassCastException ce) { |
511 | 0 | throw new UnexpectedObjectException(); |
512 | 0 | } |
513 | |
} |
514 | |
|
515 | 0 | ServiceDetail sd = null; |
516 | |
try { |
517 | 0 | sd = (ServiceDetail) executeOperation(sarr, "SAVE_SERVICE"); |
518 | |
} |
519 | 0 | catch (RegistryException e) { |
520 | 0 | exceptions.add(new SaveException(e.getLocalizedMessage())); |
521 | 0 | bulk.setStatus(JAXRResponse.STATUS_FAILURE); |
522 | 0 | return bulk; |
523 | 0 | } |
524 | |
|
525 | 0 | List<BusinessService> bizServiceList = sd.getBusinessService(); |
526 | 0 | sarr = new BusinessService[bizServiceList.size()]; |
527 | 0 | bizServiceList.toArray(sarr); |
528 | |
|
529 | 0 | for (int i = 0; sarr != null && i < sarr.length; i++) { |
530 | 0 | BusinessService entity = (BusinessService) sarr[i]; |
531 | 0 | coll.add(new KeyImpl(entity.getServiceKey())); |
532 | |
} |
533 | 0 | bulk.setCollection(coll); |
534 | 0 | bulk.setExceptions(exceptions); |
535 | |
|
536 | 0 | return bulk; |
537 | |
} |
538 | |
|
539 | |
public void confirmAssociation(Association assoc) throws JAXRException, InvalidRequestException { |
540 | |
|
541 | 0 | HashSet<Association> col = new HashSet<Association>(); |
542 | 0 | col.add(assoc); |
543 | 0 | BulkResponse br = this.saveAssociations(col, true); |
544 | 0 | if(br.getExceptions()!= null) |
545 | 0 | throw new JAXRException("Confiming the Association Failed"); |
546 | 0 | } |
547 | |
|
548 | |
public void unConfirmAssociation(Association assoc) throws JAXRException, InvalidRequestException { |
549 | |
|
550 | |
|
551 | 0 | Collection<Key> col = new ArrayList<Key>(); |
552 | 0 | col.add(assoc.getKey()); |
553 | 0 | BulkResponse br = this.deleteAssociations(col); |
554 | 0 | if(br.getExceptions()!= null) |
555 | 0 | throw new JAXRException("UnConfiming the Association Failed"); |
556 | 0 | } |
557 | |
|
558 | |
|
559 | |
protected Object executeOperation(Object dataarray, String op) |
560 | |
throws RegistryException, JAXRException { |
561 | 0 | if (registry == null) { |
562 | 0 | throw new IllegalStateException("No registry"); |
563 | |
} |
564 | |
|
565 | 0 | IRegistry ireg = (IRegistry) registry.getRegistry(); |
566 | |
|
567 | 0 | ConnectionImpl connection = registry.getConnection(); |
568 | 0 | AuthToken token = getAuthToken(connection, ireg); |
569 | 0 | if (token == null) { |
570 | 0 | throw new IllegalStateException("No auth token returned"); |
571 | |
} |
572 | |
|
573 | |
Object regobj; |
574 | 0 | if(op.equalsIgnoreCase("SAVE_ASSOCIATION")) |
575 | |
{ |
576 | |
try { |
577 | 0 | regobj = ireg.setPublisherAssertions(token.getAuthInfo(), (PublisherAssertion[]) dataarray); |
578 | 0 | } catch (RegistryException rve) { |
579 | 0 | String username = getUsernameFromCredentials(connection.getCredentials()); |
580 | 0 | if (AuthTokenSingleton.getToken(username) != null) { |
581 | 0 | AuthTokenSingleton.deleteAuthToken(username); |
582 | |
} |
583 | 0 | token = getAuthToken(connection, ireg); |
584 | 0 | regobj = ireg.setPublisherAssertions(token.getAuthInfo(), (PublisherAssertion[]) dataarray); |
585 | 0 | } |
586 | |
} |
587 | 0 | else if (op.equalsIgnoreCase("SAVE_SERVICE")) { |
588 | |
try { |
589 | 0 | regobj = ireg.saveService(token.getAuthInfo(), (BusinessService[])dataarray); |
590 | 0 | } catch (RegistryException rve) { |
591 | 0 | String username = getUsernameFromCredentials(connection.getCredentials()); |
592 | 0 | if (AuthTokenSingleton.getToken(username) != null) { |
593 | 0 | AuthTokenSingleton.deleteAuthToken(username); |
594 | |
} |
595 | 0 | token = getAuthToken(connection, ireg); |
596 | 0 | regobj = ireg.saveService(token.getAuthInfo(), (BusinessService[])dataarray); |
597 | 0 | } |
598 | |
} |
599 | 0 | else if (op.equalsIgnoreCase("SAVE_SERVICE_BINDING")) { |
600 | |
try { |
601 | 0 | regobj = ireg.saveBinding(token.getAuthInfo(), (BindingTemplate[]) dataarray); |
602 | 0 | } catch (RegistryException rve) { |
603 | 0 | String username = getUsernameFromCredentials(connection.getCredentials()); |
604 | 0 | if (AuthTokenSingleton.getToken(username) != null) { |
605 | 0 | AuthTokenSingleton.deleteAuthToken(username); |
606 | |
} |
607 | 0 | token = getAuthToken(connection, ireg); |
608 | 0 | regobj = ireg.saveBinding(token.getAuthInfo(), (BindingTemplate[]) dataarray); |
609 | 0 | } |
610 | |
} |
611 | 0 | else if (op.equalsIgnoreCase("SAVE_ORG")) { |
612 | |
try { |
613 | 0 | regobj = ireg.saveBusiness(token.getAuthInfo(), (BusinessEntity[]) dataarray); |
614 | 0 | } catch (RegistryException rve) { |
615 | 0 | String username = getUsernameFromCredentials(connection.getCredentials()); |
616 | 0 | if (AuthTokenSingleton.getToken(username) != null) { |
617 | 0 | AuthTokenSingleton.deleteAuthToken(username); |
618 | |
} |
619 | 0 | token = getAuthToken(connection, ireg); |
620 | 0 | regobj = ireg.saveBusiness(token.getAuthInfo(), (BusinessEntity[]) dataarray); |
621 | 0 | } |
622 | |
} |
623 | 0 | else if (op.equalsIgnoreCase("SAVE_TMODEL")) { |
624 | |
try { |
625 | 0 | regobj = ireg.saveTModel(token.getAuthInfo(), (TModel[]) dataarray); |
626 | 0 | } catch (RegistryException rve) { |
627 | 0 | String username = getUsernameFromCredentials(connection.getCredentials()); |
628 | 0 | if (AuthTokenSingleton.getToken(username) != null) { |
629 | 0 | AuthTokenSingleton.deleteAuthToken(username); |
630 | |
} |
631 | 0 | token = getAuthToken(connection, ireg); |
632 | 0 | regobj = ireg.saveTModel(token.getAuthInfo(), (TModel[]) dataarray); |
633 | 0 | } |
634 | |
} |
635 | 0 | else if (op.equalsIgnoreCase("DELETE_ORG")) { |
636 | |
try { |
637 | 0 | clearPublisherAssertions(token.getAuthInfo(), ireg); |
638 | 0 | regobj = ireg.deleteBusiness(token.getAuthInfo(), (String[]) dataarray); |
639 | 0 | } catch (RegistryException rve) { |
640 | 0 | String username = getUsernameFromCredentials(connection.getCredentials()); |
641 | 0 | if (AuthTokenSingleton.getToken(username) != null) { |
642 | 0 | AuthTokenSingleton.deleteAuthToken(username); |
643 | |
} |
644 | 0 | token = getAuthToken(connection, ireg); |
645 | 0 | clearPublisherAssertions(token.getAuthInfo(), ireg); |
646 | 0 | regobj = ireg.deleteBusiness(token.getAuthInfo(), (String[]) dataarray); |
647 | 0 | } |
648 | |
} |
649 | 0 | else if (op.equalsIgnoreCase("DELETE_SERVICE")) { |
650 | |
try { |
651 | 0 | regobj = ireg.deleteService(token.getAuthInfo(), (String[]) dataarray); |
652 | 0 | } catch (RegistryException rve) { |
653 | 0 | String username = getUsernameFromCredentials(connection.getCredentials()); |
654 | 0 | if (AuthTokenSingleton.getToken(username) != null) { |
655 | 0 | AuthTokenSingleton.deleteAuthToken(username); |
656 | |
} |
657 | 0 | token = getAuthToken(connection, ireg); |
658 | |
|
659 | 0 | regobj = ireg.deleteService(token.getAuthInfo(), (String[]) dataarray); |
660 | 0 | } |
661 | |
} |
662 | 0 | else if (op.equalsIgnoreCase("DELETE_SERVICEBINDING")) { |
663 | |
try { |
664 | 0 | regobj = ireg.deleteBinding(token.getAuthInfo(), (String[]) dataarray); |
665 | 0 | } catch (RegistryException rve) { |
666 | 0 | String username = getUsernameFromCredentials(connection.getCredentials()); |
667 | 0 | if (AuthTokenSingleton.getToken(username) != null) { |
668 | 0 | AuthTokenSingleton.deleteAuthToken(username); |
669 | |
} |
670 | 0 | token = getAuthToken(connection, ireg); |
671 | |
|
672 | 0 | regobj = ireg.deleteBinding(token.getAuthInfo(), (String[]) dataarray); |
673 | 0 | } |
674 | |
} |
675 | 0 | else if (op.equalsIgnoreCase("DELETE_CONCEPT")) { |
676 | |
try { |
677 | 0 | regobj = ireg.deleteTModel(token.getAuthInfo(), (String[]) dataarray); |
678 | 0 | } catch (RegistryException rve) { |
679 | 0 | String username = getUsernameFromCredentials(connection.getCredentials()); |
680 | 0 | if (AuthTokenSingleton.getToken(username) != null) { |
681 | 0 | AuthTokenSingleton.deleteAuthToken(username); |
682 | |
} |
683 | 0 | token = getAuthToken(connection, ireg); |
684 | 0 | clearPublisherAssertions(token.getAuthInfo(), ireg); |
685 | 0 | regobj = ireg.deleteTModel(token.getAuthInfo(), (String[]) dataarray); |
686 | 0 | } |
687 | |
} |
688 | 0 | else if (op.equalsIgnoreCase("DELETE_ASSOCIATION")) { |
689 | 0 | int len = ((String[]) dataarray).length; |
690 | 0 | PublisherAssertion[] paarr = new PublisherAssertion[len]; |
691 | 0 | for(int i=0;i<len;i++) |
692 | |
{ |
693 | 0 | String keystr = ((String[])dataarray)[i]; |
694 | 0 | paarr[i] = ScoutJaxrUddiHelper.getPubAssertionFromJAXRAssociationKey(keystr); |
695 | |
} |
696 | |
try { |
697 | 0 | regobj = ireg.deletePublisherAssertions(token.getAuthInfo(), paarr); |
698 | 0 | } catch (RegistryException rve) { |
699 | 0 | String username = getUsernameFromCredentials(connection.getCredentials()); |
700 | 0 | if (AuthTokenSingleton.getToken(username) != null) { |
701 | 0 | AuthTokenSingleton.deleteAuthToken(username); |
702 | |
} |
703 | 0 | token = getAuthToken(connection, ireg); |
704 | 0 | clearPublisherAssertions(token.getAuthInfo(), ireg); |
705 | 0 | regobj = ireg.deletePublisherAssertions(token.getAuthInfo(), paarr); |
706 | 0 | } |
707 | 0 | } |
708 | 0 | else if (op.equalsIgnoreCase("DELETE_CLASSIFICATIONSCHEME")) { |
709 | |
try { |
710 | 0 | regobj = ireg.deleteTModel(token.getAuthInfo(), (String[]) dataarray); |
711 | 0 | } catch (RegistryException rve) { |
712 | 0 | String username = getUsernameFromCredentials(connection.getCredentials()); |
713 | 0 | if (AuthTokenSingleton.getToken(username) != null) { |
714 | 0 | AuthTokenSingleton.deleteAuthToken(username); |
715 | |
} |
716 | 0 | token = getAuthToken(connection, ireg); |
717 | 0 | clearPublisherAssertions(token.getAuthInfo(), ireg); |
718 | 0 | regobj = ireg.deleteTModel(token.getAuthInfo(), (String[]) dataarray); |
719 | 0 | } |
720 | |
} |
721 | |
else { |
722 | 0 | throw new JAXRException("Unsupported operation:" + op); |
723 | |
} |
724 | |
|
725 | 0 | return regobj; |
726 | |
} |
727 | |
|
728 | |
private void clearPublisherAssertions( String authinfo,IRegistry ireg) |
729 | |
{ |
730 | 0 | Vector<PublisherAssertion> pasvect = new Vector<PublisherAssertion>(); |
731 | |
|
732 | |
try |
733 | |
{ |
734 | 0 | AssertionStatusReport report = ireg.getAssertionStatusReport(authinfo,"status:complete"); |
735 | 0 | List<AssertionStatusItem> assertionStatusItemList = report.getAssertionStatusItem(); |
736 | 0 | for (AssertionStatusItem assertionStatusItem : assertionStatusItemList) { |
737 | 0 | pasvect.add(this.getPublisherAssertion(assertionStatusItem)); |
738 | |
} |
739 | |
|
740 | 0 | report = ireg.getAssertionStatusReport(authinfo,"status:toKey_incomplete"); |
741 | 0 | assertionStatusItemList = report.getAssertionStatusItem(); |
742 | 0 | for (AssertionStatusItem assertionStatusItem : assertionStatusItemList) { |
743 | 0 | pasvect.add(this.getPublisherAssertion(assertionStatusItem)); |
744 | |
} |
745 | |
|
746 | 0 | report = ireg.getAssertionStatusReport(authinfo,"status:fromKey_incomplete"); |
747 | 0 | assertionStatusItemList = report.getAssertionStatusItem(); |
748 | 0 | for (AssertionStatusItem assertionStatusItem : assertionStatusItemList) { |
749 | 0 | pasvect.add(this.getPublisherAssertion(assertionStatusItem)); |
750 | |
} |
751 | |
|
752 | 0 | if (pasvect.size() > 0) { |
753 | 0 | PublisherAssertion[] pasarr = new PublisherAssertion[pasvect.size()]; |
754 | 0 | int i=0; |
755 | 0 | for (PublisherAssertion publisherAssertion : pasvect) { |
756 | 0 | pasarr[i++] = publisherAssertion; |
757 | |
} |
758 | 0 | ireg.deletePublisherAssertions(authinfo, pasarr); |
759 | |
} |
760 | |
} |
761 | 0 | catch (RegistryException e) |
762 | |
{ |
763 | 0 | ConnectionImpl connection = registry.getConnection(); |
764 | 0 | String username = getUsernameFromCredentials(connection.getCredentials()); |
765 | 0 | if (AuthTokenSingleton.getToken(username) != null) { |
766 | 0 | AuthTokenSingleton.deleteAuthToken(username); |
767 | |
} |
768 | 0 | AuthToken token = null; |
769 | |
try { |
770 | 0 | token = getAuthToken(connection, ireg); |
771 | 0 | } catch (JAXRException je) { |
772 | 0 | } |
773 | 0 | clearPublisherAssertions( token.getAuthInfo(), ireg); |
774 | 0 | } |
775 | 0 | } |
776 | |
|
777 | |
|
778 | |
|
779 | |
protected BulkResponse deleteOperation(Collection<Key> keys, String op) |
780 | |
throws JAXRException { |
781 | 0 | if(keys == null) |
782 | 0 | throw new JAXRException("Keys provided to "+op+" are null"); |
783 | |
|
784 | |
|
785 | 0 | BulkResponseImpl bulk = new BulkResponseImpl(); |
786 | 0 | String[] keyarr = new String[keys.size()]; |
787 | |
Result[] keyResultArr; |
788 | |
|
789 | 0 | LinkedHashSet<Key> coll = new LinkedHashSet<Key>(); |
790 | 0 | Collection<Exception> exceptions = new ArrayList<Exception>(); |
791 | |
|
792 | |
try { |
793 | 0 | Iterator iter = keys.iterator(); |
794 | 0 | int currLoc = 0; |
795 | 0 | while (iter.hasNext()) { |
796 | 0 | Key key = (Key) iter.next(); |
797 | 0 | keyarr[currLoc] = key.getId(); |
798 | 0 | currLoc++; |
799 | 0 | } |
800 | |
|
801 | 0 | DispositionReport bd = (DispositionReport) executeOperation(keyarr, op); |
802 | 0 | List<Result> resultList = bd.getResult(); |
803 | 0 | keyResultArr = new Result[resultList.size()]; |
804 | 0 | resultList.toArray(keyResultArr); |
805 | |
|
806 | 0 | log.debug("After deleting Business. Obtained vector size:" + keyResultArr != null ? keyResultArr.length : 0); |
807 | 0 | for (int i = 0; keyResultArr != null && i < keyResultArr.length; i++) { |
808 | 0 | Result result = (Result) keyResultArr[i]; |
809 | 0 | int errno = result.getErrno(); |
810 | 0 | if (errno == 0) { |
811 | 0 | coll.addAll(keys); |
812 | |
} |
813 | |
else { |
814 | 0 | ErrInfo errinfo = result.getErrInfo(); |
815 | 0 | DeleteException de = new DeleteException(errinfo.getErrCode() + ":" + errinfo.getValue()); |
816 | 0 | bulk.setStatus(JAXRResponse.STATUS_FAILURE); |
817 | 0 | exceptions.add(de); |
818 | |
} |
819 | |
} |
820 | |
} |
821 | 0 | catch (RegistryException regExcept) { |
822 | |
|
823 | |
|
824 | |
|
825 | |
|
826 | |
|
827 | |
|
828 | 0 | DeleteException de = new DeleteException(regExcept.getFaultCode() |
829 | |
+ ":" + regExcept.getFaultString(), regExcept); |
830 | |
|
831 | 0 | bulk.setStatus(JAXRResponse.STATUS_FAILURE); |
832 | 0 | exceptions.add(de); |
833 | |
} |
834 | 0 | catch (JAXRException tran) { |
835 | 0 | exceptions.add(new JAXRException("Apache JAXR Impl:", tran)); |
836 | 0 | bulk.setStatus(JAXRResponse.STATUS_FAILURE); |
837 | 0 | } |
838 | |
|
839 | 0 | bulk.setCollection(coll); |
840 | 0 | bulk.setExceptions(exceptions); |
841 | |
|
842 | 0 | return bulk; |
843 | |
} |
844 | |
|
845 | |
private String getUsernameFromCredentials(Set credentials) { |
846 | 0 | String username = "", pwd = ""; |
847 | |
|
848 | 0 | if (credentials != null) { |
849 | 0 | Iterator it = credentials.iterator(); |
850 | 0 | while (it.hasNext()) { |
851 | 0 | PasswordAuthentication pass = (PasswordAuthentication) it.next(); |
852 | 0 | username = pass.getUserName(); |
853 | 0 | } |
854 | |
} |
855 | 0 | return username; |
856 | |
} |
857 | |
|
858 | |
|
859 | |
|
860 | |
|
861 | |
|
862 | |
|
863 | |
|
864 | |
|
865 | |
|
866 | |
private AuthToken getAuthToken(ConnectionImpl connection, IRegistry ireg) |
867 | |
throws JAXRException { |
868 | 0 | Set creds = connection.getCredentials(); |
869 | 0 | String username = "", pwd = ""; |
870 | 0 | if (creds != null) { |
871 | 0 | Iterator it = creds.iterator(); |
872 | 0 | while (it.hasNext()) { |
873 | 0 | PasswordAuthentication pass = (PasswordAuthentication) it.next(); |
874 | 0 | username = pass.getUserName (); |
875 | 0 | pwd = new String(pass.getPassword()); |
876 | 0 | } |
877 | |
} |
878 | |
|
879 | 0 | if (AuthTokenSingleton.getToken(username) != null) { |
880 | 0 | return (AuthToken) AuthTokenSingleton.getToken(username); |
881 | |
} |
882 | |
|
883 | 0 | AuthToken token = null; |
884 | |
try { |
885 | 0 | token = ireg.getAuthToken(username, pwd); |
886 | |
} |
887 | 0 | catch (Exception e) |
888 | |
{ |
889 | 0 | throw new JAXRException(e); |
890 | 0 | } |
891 | 0 | AuthTokenSingleton.addAuthToken(username, token); |
892 | 0 | return token; |
893 | |
} |
894 | |
|
895 | |
private PublisherAssertion getPublisherAssertion(AssertionStatusItem asi) |
896 | |
{ |
897 | 0 | PublisherAssertion pa = this.objectFactory.createPublisherAssertion(); |
898 | |
|
899 | 0 | if(asi != null) |
900 | |
{ |
901 | 0 | String sourceKey = asi.getFromKey(); |
902 | 0 | String targetKey = asi.getToKey(); |
903 | |
|
904 | 0 | if (sourceKey != null) { |
905 | 0 | pa.setFromKey(sourceKey); |
906 | |
} |
907 | |
|
908 | 0 | if (targetKey != null) { |
909 | 0 | pa.setToKey(targetKey); |
910 | |
} |
911 | |
|
912 | 0 | KeyedReference keyr = asi.getKeyedReference(); |
913 | |
|
914 | 0 | if (keyr != null) { |
915 | 0 | pa.setKeyedReference(keyr); |
916 | |
} |
917 | |
|
918 | |
|
919 | |
|
920 | |
|
921 | 0 | }return pa; |
922 | |
} |
923 | |
|
924 | |
Organization createOrganization(BusinessDetail bizDetail) throws JAXRException { |
925 | 0 | return ScoutUddiJaxrHelper.getOrganization(bizDetail, this); |
926 | |
} |
927 | |
|
928 | |
Organization createOrganization(BusinessInfo bizInfo) throws JAXRException { |
929 | 0 | String key = bizInfo.getBusinessKey(); |
930 | 0 | List<Name> names = bizInfo.getName(); |
931 | |
|
932 | 0 | List<Description> descriptions = bizInfo.getDescription(); |
933 | 0 | List<ServiceInfo> serviceInfos = bizInfo.getServiceInfos().getServiceInfo(); |
934 | |
|
935 | 0 | OrganizationImpl org = new OrganizationImpl(this); |
936 | 0 | org.setKey(createKey(key)); |
937 | 0 | if (names != null && names.size() > 0) { |
938 | 0 | org.setName(createInternationalString(names.get(0).getValue())); |
939 | |
} |
940 | 0 | if (descriptions != null && descriptions.size() > 0) { |
941 | 0 | org.setDescription(createInternationalString(descriptions.get(0).getValue())); |
942 | |
} |
943 | 0 | if (serviceInfos != null && serviceInfos.size() > 0) { |
944 | 0 | List<Service> services = new ArrayList<Service>(serviceInfos.size()); |
945 | 0 | for (int i = 0; i < serviceInfos.size(); i++) { |
946 | 0 | ServiceInfo serviceInfo = serviceInfos.get(i); |
947 | 0 | services.add(createService(serviceInfo)); |
948 | |
} |
949 | 0 | org.addServices(services); |
950 | |
} |
951 | |
|
952 | 0 | return org; |
953 | |
} |
954 | |
|
955 | |
Service createService(ServiceInfo serviceInfo) throws JAXRException { |
956 | 0 | String key = serviceInfo.getServiceKey(); |
957 | 0 | List<Name> names = serviceInfo.getName(); |
958 | 0 | ServiceImpl service = new ServiceImpl(this); |
959 | 0 | service.setKey(createKey(key)); |
960 | 0 | if (names != null && names.size() > 0) { |
961 | 0 | service.setName(createInternationalString(names.get(0).getValue())); |
962 | |
} |
963 | 0 | return service; |
964 | |
} |
965 | |
|
966 | |
} |