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