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