View Javadoc
1 /* 2 * $Header: /cvsroot/ebxmlrr/ebxmlrr/src/share/com/sun/ebxml/registry/lcm/LifeCycleManagerImpl.java,v 1.79 2003/05/22 12:08:04 farrukh_najmi Exp $ 3 */ 4 5 package com.sun.ebxml.registry.lcm; 6 7 import org.oasis.ebxml.registry.bindings.rs.*; 8 import org.oasis.ebxml.registry.bindings.rs.types.*; 9 import org.oasis.ebxml.registry.bindings.rim.types.*; 10 import org.oasis.ebxml.registry.bindings.rim.*; 11 12 import com.sun.ebxml.registry.util.*; 13 14 import java.io.*; 15 import java.util.*; 16 import java.sql.*; 17 import javax.activation.*; 18 19 import com.sun.ebxml.registry.*; 20 import com.sun.ebxml.registry.lcm.quota.*; 21 import com.sun.ebxml.registry.persistence.*; 22 import com.sun.ebxml.registry.repository.*; 23 import com.sun.ebxml.registry.security.*; 24 25 import org.apache.commons.logging.*; 26 27 /*** 28 * Implementation of the LifeCycleManager interface 29 * @see 30 * @author Farrukh S. Najmi 31 * @author Adrian Chong 32 */ 33 public class LifeCycleManagerImpl implements LifeCycleManager { 34 35 /*** 36 * @link 37 * @shapeType PatternLink 38 * @pattern Singleton 39 * @supplierRole Singleton factory 40 */ 41 /*# private LifeCycleManagerImpl _objectManagerImpl; */ 42 private static LifeCycleManagerImpl instance = null; 43 44 /*** 45 * 46 * @associates <{com.sun.ebxml.registry.persistence.PersistenceManagerImpl}> 47 */ 48 PersistenceManager pm = PersistenceManagerImpl.getInstance(); 49 BindingUtility bu = BindingUtility.getInstance(); 50 QuotaServiceImpl qs = QuotaServiceImpl.getInstance(); 51 Utility util = Utility.getInstance(); 52 RepositoryManager rm = RepositoryManagerFactory.getInstance().getRepositoryManager(); 53 UUIDFactory uf = UUIDFactory.getInstance(); 54 55 /*** 56 * 57 * @associates <{com.sun.ebxml.registry.persistence.ContentIndexingManager}> 58 */ 59 ContentIndexingManager cim = ContentIndexingManager.getInstance(); 60 61 private org.apache.commons.logging.Log log = LogFactory.getLog(this.getClass()); 62 63 64 protected LifeCycleManagerImpl(){} 65 66 public static LifeCycleManagerImpl getInstance(){ 67 if (instance == null) { 68 synchronized(LifeCycleManagerImpl.class) { 69 if (instance == null) { 70 instance = new LifeCycleManagerImpl(); 71 } 72 } 73 } 74 return instance; 75 } 76 77 /*** 78 * Submits one or more RegistryObjects and one or more repository items. 79 * <br> 80 * <br> 81 * Note: One more special feature that is not in the RS spec. version 2. 82 * The SubmitObjectsRequest allows updating objects.If a object of a particular 83 * id already exist, it is updated instead of trying to be inserted. 84 * @param idToRepositoryItemMap is a HashMap with key that is id of a RegistryObject and value that is a RepositoryItem instance. 85 */ 86 public RegistryResponse submitObjects(User user, SubmitObjectsRequest req, HashMap idToRepositoryItemMap) throws RegistryException { 87 88 RegistryResponse resp = new RegistryResponse(); 89 RegistryErrorList el = new RegistryErrorList(); 90 try { 91 LeafRegistryObjectList objs = req.getLeafRegistryObjectList(); 92 ArrayList al = bu.getRegistryObjectList(objs); 93 94 //Replace temporary ids with proper UUID. 95 96 HashMap idMap = new HashMap(); 97 fixTemporaryIds(al, idMap); 98 99 /* 100 * check whether the referenced object for 101 * Association/Classification/ClassificationNode/Organization/ExternalIdentifier 102 * exist within the request document and whether REs has objectStatus, 103 * majorVersion or minorVersion. 104 */ 105 checkObjects(al, el); 106 107 if (idToRepositoryItemMap != null) { 108 qs.checkQuota(user.getId()); 109 110 //fix ri ID to match 111 //first ExtrinsicObject (in case where ri is submitted without id) 112 //only works for submission of one ri and one ExtrinsicObject 113 correctRepositoryItemId(al, idToRepositoryItemMap); 114 115 // It will select which repository items already exist and update 116 HashMap idToNotExistingItemsMap = updateExistingRepositoryItems( 117 idToRepositoryItemMap); 118 storeRepositoryItems(idMap, idToNotExistingItemsMap); 119 } 120 121 /* 122 * For RegistryObjects, the DAO will take care which objects already 123 * exist and update them instead 124 */ 125 log.info("Calling pm.insert at: " + System.currentTimeMillis()); 126 pm.insert(user, al); 127 log.info("Done Calling pm.insert at: " + System.currentTimeMillis()); 128 129 resp.setStatus(org.oasis.ebxml.registry.bindings.rs.types.StatusType.SUCCESS); 130 if (el.getRegistryErrorCount() > 0) { 131 // warning exists 132 resp.setRegistryErrorList(el); 133 } 134 135 //Now perform any content indexing for ExtrinsicObjects 136 log.info("Calling indexContent at: " + System.currentTimeMillis()); 137 indexContent(user, al, idToRepositoryItemMap, idMap); 138 log.info("Done Calling indexContent at: " + System.currentTimeMillis()); 139 140 } 141 catch (InvalidURLsException e) { 142 // We should have unified mapping in util to generate 143 // RegistryErrorList Later 144 145 Iterator roIter = e.getSourceRegistryObjects().iterator(); 146 while (roIter.hasNext()) { 147 Object ro = roIter.next(); 148 RegistryError re = new RegistryError(); 149 if (ro instanceof ExternalLink) { 150 ExternalLink extLink = (ExternalLink) ro; 151 re.setContent("The ExternalLink with id " + extLink.getId() 152 + " is not resolvable, the Http URL is " 153 + extLink.getExternalURI()); 154 } 155 else if (ro instanceof ServiceBinding) { 156 ServiceBinding serviceBinding = (ServiceBinding) ro; 157 re.setContent("The ServiceBinding with id " + serviceBinding 158 .getId() + " is not resolvable, the Http URL is " 159 + serviceBinding.getAccessURI()); 160 } 161 else { 162 re.setContent("Internal Error happens, unknown " 163 + "RegistryObjectType"); 164 } 165 re.setErrorCode("unknown"); 166 re.setCodeContext("LifeCycleManagerImpl.submitObjects"); 167 el.addRegistryError(re); 168 } 169 resp = new RegistryResponse(); 170 resp.setStatus(org.oasis.ebxml.registry.bindings.rs.types.StatusType 171 .FAILURE); 172 resp.setRegistryErrorList(el); 173 } 174 catch (ReferencesExistException e) { 175 RegistryError re = new RegistryError(); 176 re.setContent(e.getMessage()); 177 re.setErrorCode("unknown"); 178 re.setCodeContext("LifeCycleManagerImpl.submitObjects"); 179 el.addRegistryError(re); 180 resp = new RegistryResponse(); 181 resp.setStatus(org.oasis.ebxml.registry.bindings.rs.types.StatusType 182 .FAILURE); 183 resp.setRegistryErrorList(el); 184 } 185 catch (UUIDNotUniqueException e) { 186 RegistryError re = new RegistryError(); 187 re.setContent(e.getMessage()); 188 re.setErrorCode("unknown"); 189 re.setCodeContext("LifeCycleManagerImpl.submitObjects"); 190 el.addRegistryError(re); 191 resp = new RegistryResponse(); 192 resp.setStatus(org.oasis.ebxml.registry.bindings.rs.types.StatusType 193 .FAILURE); 194 resp.setRegistryErrorList(el); 195 } 196 catch (ReferencedObjectNotFoundException e) { 197 RegistryError re = new RegistryError(); 198 re.setContent(e.getMessage()); 199 re.setErrorCode("unknown"); 200 re.setCodeContext("LifeCycleManagerImpl.submitObjects"); 201 el.addRegistryError(re); 202 resp = new RegistryResponse(); 203 resp.setStatus(org.oasis.ebxml.registry.bindings.rs.types.StatusType 204 .FAILURE); 205 resp.setRegistryErrorList(el); 206 } 207 catch (AssociateToDeprecatedRegistryEntryException e) { 208 RegistryError re = new RegistryError(); 209 re.setContent(e.getMessage()); 210 re.setErrorCode("unknown"); 211 re.setCodeContext("LifeCycleManagerImpl.submitObjects"); 212 el.addRegistryError(re); 213 resp = new RegistryResponse(); 214 resp.setStatus(org.oasis.ebxml.registry.bindings.rs.types.StatusType 215 .FAILURE); 216 resp.setRegistryErrorList(el); 217 } 218 catch (RegistryObjectExistsException e) { 219 RegistryError re = new RegistryError(); 220 re.setContent(e.getMessage()); 221 re.setErrorCode("unknown"); 222 re.setCodeContext("LifeCycleManagerImpl.submitObjects"); 223 el.addRegistryError(re); 224 resp = new RegistryResponse(); 225 resp.setStatus(org.oasis.ebxml.registry.bindings.rs.types.StatusType 226 .FAILURE); 227 resp.setRegistryErrorList(el); 228 } 229 catch (QuotaExceededException e) { 230 RegistryError re = new RegistryError(); 231 re.setContent(e.getMessage()); 232 re.setErrorCode("unknown"); 233 re.setCodeContext("LifeCycleManagerImpl.submitObjects"); 234 el.addRegistryError(re); 235 resp = new RegistryResponse(); 236 resp.setStatus(org.oasis.ebxml.registry.bindings.rs.types.StatusType 237 .FAILURE); 238 resp.setRegistryErrorList(el); 239 } 240 catch (UnauthorizedRequestException e) { 241 // UnauthorizedRequestException will be thrown if updating objects through SubmitObjectsRequest but the user is not authorized 242 RegistryError re = new RegistryError(); 243 re.setContent(e.getMessage()); 244 re.setErrorCode("unknown"); 245 re.setCodeContext("LifeCycleManagerImpl.submitObjects"); 246 el.addRegistryError(re); 247 resp = new RegistryResponse(); 248 resp.setStatus(org.oasis.ebxml.registry.bindings.rs.types.StatusType 249 .FAILURE); 250 resp.setRegistryErrorList(el); 251 } 252 catch (RegistryException e) { 253 resp = util.createRegistryResponseFromThrowable(e, "LifeCycleManagerImpl.submitObjects", "Unknown"); 254 // Append any warnings 255 RegistryError [] errs = el.getRegistryError(); 256 RegistryErrorList newEl = resp.getRegistryErrorList(); 257 for (int i=0; i < errs.length ;i++) { 258 newEl.addRegistryError(errs[i]); 259 } 260 } 261 return resp; 262 } 263 264 265 /*** 266 * Stores the repository items in idToRepositoryItemMap in the repository 267 * @throws RegistryException when the items already exist 268 */ 269 private void storeRepositoryItems(HashMap idMap, HashMap idToRepositoryItemMap) throws RegistryException { 270 if (idToRepositoryItemMap != null) { 271 272 Collection keySet = idToRepositoryItemMap.keySet(); 273 274 if (keySet != null) { 275 276 Iterator iter = keySet.iterator(); 277 278 while (iter.hasNext()) { 279 280 String id = (String)iter.next(); 281 RepositoryItem ri = (RepositoryItem)idToRepositoryItemMap.get(id); 282 283 DataHandler dh = ri.getDataHandler(); 284 285 //Replace id if found in idMap 286 if (idMap.containsKey(id)) { 287 id = (String)idMap.get(id); 288 289 //Fix the id permanenetly within the repositoryItem 290 ri.setId(id); 291 } 292 293 // Inserting the repository item 294 rm.insert(ri); 295 } 296 } 297 } 298 } 299 300 /*** 301 * Check whether the id is a valid UUID. 302 * @return false if id is null, or id does not start with "urn:uuid:", or 303 * it is not valid. 304 */ 305 public boolean isValidRegistryId(String id) { 306 boolean isValid = false; 307 308 if (id !=null && id.startsWith("urn:uuid:")) { 309 String uuidStr = id.substring(9); 310 311 if (uf.isValidUUID(uuidStr)) { 312 isValid = true; 313 } 314 } 315 316 return isValid; 317 } 318 319 /*** 320 * It should be called by submitObjects() to update existing Repository Items 321 * @return HashMap of id To RepositoryItem, which are not exisitng 322 */ 323 private HashMap updateExistingRepositoryItems(HashMap idToRepositoryItemMap) throws RegistryException { 324 Iterator itemsIdsIter = idToRepositoryItemMap.keySet().iterator(); 325 326 // To find out which RI with a id does not exist 327 ArrayList itemsIds = new ArrayList(); 328 while(itemsIdsIter.hasNext()) { 329 String itemsId = (String)itemsIdsIter.next(); 330 itemsIds.add(itemsId); 331 } 332 ArrayList notExistItemsIds = rm.itemsExist(itemsIds); 333 //System.err.println((String)notExistItemsIds.get(0) + "!!!!!"); 334 335 // Create two maps to store existing and non-existing items 336 HashMap notExistItems = new HashMap(); 337 HashMap existingItems = new HashMap(); 338 339 for(int i=0; i < itemsIds.size(); i++) { 340 String id = (String) itemsIds.get(i); 341 String longId = null; 342 if (!id.startsWith("urn:uuid:")) { 343 longId = "urn:uuid:" + id; 344 } 345 else { 346 longId = id; 347 } 348 if (notExistItemsIds.contains(longId)) { 349 notExistItems.put(id, idToRepositoryItemMap.get(id)); 350 } 351 else { 352 existingItems.put(id, idToRepositoryItemMap.get(id)); 353 } 354 } 355 356 357 updateRepositoryItems(existingItems); 358 return notExistItems; 359 } 360 361 /*** 362 * Check if id is a proper UUID. If not make a proper UUID based URN and add 363 * a mapping in idMap between old and new Id. The parent attribute of ClassificationNode 364 * will be alo fixed here according to their hierarchy if the parent attributes are 365 * not provided explicitely by th clients. 366 * @param ids The ArrayList holding all the UUIDs in the SubmitObjectsRequest 367 * document 368 * @throws UUIDNotUniqueException if any UUID is not unique within a 369 * SubmitObjectsRequest 370 */ 371 private void checkId(ArrayList ids, HashMap idMap, RegistryObjectType ro) 372 throws RegistryException { 373 String id = ro.getId(); 374 375 // Check for uniqueness 376 if (ids != null && ids.contains(id)) { 377 throw new UUIDNotUniqueException(id); 378 } 379 380 if (id !=null) { 381 ids.add(id); 382 } 383 384 if (id == null || !id.startsWith("urn:uuid:")) { 385 // Generate UUID if the request does not provide ID for a RO 386 // or it does not start with urn:uuid: 387 UUID uuid = uf.newUUID(); 388 String newId = "urn:uuid:" + uuid; 389 ro.setId(newId); 390 idMap.put(id, newId); 391 } 392 else { 393 // id starts with "urn:uuid:" 394 String uuidStr = id.substring(9); 395 if (!uf.isValidUUID(uuidStr)) { 396 // but invalid 397 UUID uuid = uf.newUUID(); 398 String newId = "urn:uuid:" + uuid; 399 idMap.put(id, newId); 400 } 401 } 402 403 Classification[] classifications = ro.getClassification(); 404 for (int i=0; i<classifications.length; i++) { 405 checkId(ids, idMap, classifications[i]); 406 } 407 408 ExternalIdentifier[] eids = ro.getExternalIdentifier(); 409 for (int i=0; i<eids.length; i++) { 410 checkId(ids, idMap, eids[i]); 411 } 412 413 if (ro instanceof org.oasis.ebxml.registry.bindings.rim.Association) { 414 } else if (ro instanceof org.oasis.ebxml.registry.bindings.rim.AuditableEvent) { 415 } else if (ro instanceof org.oasis.ebxml.registry.bindings.rim.Classification) { 416 } else if (ro instanceof org.oasis.ebxml.registry.bindings.rim.ClassificationNode) { 417 ClassificationNode node = (ClassificationNode)ro; 418 419 //Recurse over children nodes 420 ClassificationNode[] children = node.getClassificationNode(); 421 for (int i=0; i<children.length; i++) { 422 if (children[i].getParent() == null) { 423 children[i].setParent(node); 424 } 425 checkId(ids, idMap, children[i]); 426 } 427 428 } else if (ro instanceof org.oasis.ebxml.registry.bindings.rim.ClassificationScheme) { 429 ClassificationScheme sch = (ClassificationScheme)ro; 430 431 //Recurse over children nodes 432 ClassificationNode[] children = sch.getClassificationNode(); 433 for (int i=0; i<children.length; i++) { 434 if (children[i].getParent() == null) { 435 children[i].setParent(sch); 436 } 437 checkId(ids, idMap, children[i]); 438 } 439 440 } else if (ro instanceof org.oasis.ebxml.registry.bindings.rim.ExternalIdentifier) { 441 } else if (ro instanceof org.oasis.ebxml.registry.bindings.rim.ExternalLink) { 442 } else if (ro instanceof org.oasis.ebxml.registry.bindings.rim.ExtrinsicObject) { 443 } else if (ro instanceof org.oasis.ebxml.registry.bindings.rim.Organization) { 444 } else if (ro instanceof org.oasis.ebxml.registry.bindings.rim.RegistryPackage) { 445 // Recusively check the RO under RegistryPackage 446 RegistryPackage pkg = (RegistryPackage) ro; 447 RegistryObjectList roList = pkg.getRegistryObjectList(); 448 ArrayList rosInPkg = bu.getRegistryObjectList(roList); 449 Iterator iter = rosInPkg.iterator(); 450 while (iter.hasNext()) { 451 RegistryObjectType roInPkg = (RegistryObjectType)iter.next(); 452 checkId(ids, idMap, roInPkg); 453 } 454 } else if (ro instanceof org.oasis.ebxml.registry.bindings.rim.Service) { 455 Service service = (Service)ro; 456 457 ServiceBinding[] bindings = service.getServiceBinding(); 458 for (int i=0; i<bindings.length; i++) { 459 checkId(ids, idMap, bindings[i]); 460 } 461 } else if (ro instanceof org.oasis.ebxml.registry.bindings.rim.ServiceBinding) { 462 ServiceBinding bind = (ServiceBinding)ro; 463 SpecificationLink[] specLinks = bind.getSpecificationLink(); 464 for (int i=0; i<specLinks.length; i++) { 465 checkId(ids, idMap, specLinks[i]); 466 } 467 } else if (ro instanceof org.oasis.ebxml.registry.bindings.rim.SpecificationLink) { 468 } else if (ro instanceof org.oasis.ebxml.registry.bindings.rim.User) { 469 } else { 470 throw new RegistryException("Unexpected object: " + ro); 471 } 472 } 473 474 /*** 475 * Fix those ids that are not proper UUID based URNs using idMap produced by checkId. 476 */ 477 private void fixTemporaryId(RegistryObjectType o, HashMap idMap) throws RegistryException { 478 //Fix the id of the object if there is an entry in the idMap 479 480 // Fix the composed Classification and ExternalIdentifier first 481 Classification[] classifications = o.getClassification(); 482 for (int i=0; i<classifications.length; i++) { 483 if (idMap.containsKey(classifications[i].getId())) { 484 classifications[i].setId((String)(idMap.get(classifications[i].getId()))); 485 } 486 } 487 ExternalIdentifier[] eids = o.getExternalIdentifier(); 488 for (int i=0; i<eids.length; i++) { 489 if (idMap.containsKey(eids[i].getId())) { 490 eids[i].setId((String)(idMap.get(eids[i].getId()))); 491 } 492 } 493 494 //Fix the id of the object if there is an entry in the idMap 495 if (idMap.containsKey(o.getId())) { 496 o.setId((String)(idMap.get(o.getId()))); 497 } 498 499 RegistryObjectType acp = (RegistryObjectType)o.getAccessControlPolicy(); 500 if ((acp != null) && (idMap.containsKey(acp.getId()))) { 501 acp.setId((String)(idMap.get(acp.getId()))); 502 } 503 504 //Now fix ID/IDREFs that are specific to the type of RegistryObject 505 if (o instanceof org.oasis.ebxml.registry.bindings.rim.Association) { 506 Association ass = (Association)o; 507 508 Object src = ass.getSourceObject(); 509 if (src !=null) { 510 String id = bu.getObjectId(src); 511 if (idMap.containsKey(id)) { 512 bu.setObjectId(src, (String)idMap.get(id)); 513 } 514 } 515 516 Object target = ass.getTargetObject(); 517 if (target !=null) { 518 String id = bu.getObjectId(target); 519 if (idMap.containsKey(id)) { 520 bu.setObjectId(target, (String)idMap.get(id)); 521 } 522 } 523 524 } else if (o instanceof org.oasis.ebxml.registry.bindings.rim.AuditableEvent) { 525 526 AuditableEvent ae = (AuditableEvent)o; 527 528 RegistryObjectType ro = (RegistryObjectType)ae.getRegistryObject(); 529 if (idMap.containsKey(ro.getId())) { 530 ro.setId((String)(idMap.get(ro.getId()))); 531 } 532 533 RegistryObjectType user = (RegistryObjectType)ae.getUser(); 534 if (idMap.containsKey(user.getId())) { 535 user.setId((String)(idMap.get(user.getId()))); 536 } 537 } else if (o instanceof org.oasis.ebxml.registry.bindings.rim.Classification) { 538 Classification cl = (Classification)o; 539 540 if (cl.getClassificationScheme() instanceof ClassificationSchemeType) { 541 ClassificationScheme sch = (ClassificationScheme)cl.getClassificationScheme(); 542 if ((sch != null) && (idMap.containsKey(sch.getId()))) { 543 sch.setId((String)(idMap.get(sch.getId()))); 544 } 545 } 546 547 if (cl.getClassifiedObject() instanceof RegistryObjectType) { 548 RegistryObjectType co = (RegistryObjectType)cl.getClassifiedObject(); 549 if (co !=null && idMap.containsKey(co.getId())) { 550 co.setId((String)(idMap.get(co.getId()))); 551 } 552 } 553 554 if (cl.getClassificationNode() instanceof RegistryObjectType) { 555 ClassificationNode node = (ClassificationNode)cl.getClassificationNode(); 556 if ((node != null) && (idMap.containsKey(node.getId()))) { 557 node.setId((String)(idMap.get(node.getId()))); 558 } 559 } 560 561 562 } else if (o instanceof org.oasis.ebxml.registry.bindings.rim.ClassificationNode) { 563 ClassificationNode node = (ClassificationNode)o; 564 565 ClassificationNode parent = null; 566 if (node.getParent() instanceof ClassificationNode) { 567 parent = (ClassificationNode) node.getParent(); 568 } 569 570 if ((parent != null) && (idMap.containsKey(parent.getId()))) { 571 parent.setId((String)(idMap.get(parent.getId()))); 572 } 573 } else if (o instanceof org.oasis.ebxml.registry.bindings.rim.ClassificationScheme) { 574 } else if (o instanceof org.oasis.ebxml.registry.bindings.rim.ExternalIdentifier) { 575 ExternalIdentifier ei = (ExternalIdentifier)o; 576 577 if (ei.getIdentificationScheme() instanceof ClassificationScheme) { 578 ClassificationScheme sch = (ClassificationScheme)ei.getIdentificationScheme(); 579 if (sch!=null && idMap.containsKey(sch.getId())) { 580 sch.setId((String)(idMap.get(sch.getId()))); 581 } 582 } 583 584 } else if (o instanceof org.oasis.ebxml.registry.bindings.rim.ExternalLink) { 585 } else if (o instanceof org.oasis.ebxml.registry.bindings.rim.ExtrinsicObject) { 586 } else if (o instanceof org.oasis.ebxml.registry.bindings.rim.Organization) { 587 Organization org = (Organization)o; 588 589 Object obj = org.getPrimaryContact(); 590 String id = bu.getObjectId(obj); 591 592 if (idMap.containsKey(id)) { 593 bu.setObjectId(obj, (String)(idMap.get(id))); 594 } 595 596 OrganizationType parent = null; 597 598 if (org.getParent() instanceof OrganizationType) { 599 parent = (OrganizationType)org.getParent(); 600 } 601 602 if ((parent != null) && (idMap.containsKey(parent.getId()))) { 603 parent.setId((String)(idMap.get(parent.getId()))); 604 } 605 } else if (o instanceof org.oasis.ebxml.registry.bindings.rim.RegistryPackage) { 606 607 // Recusively fix the RO under RegistryPackage 608 RegistryPackage pkg = (RegistryPackage) o; 609 RegistryObjectList roList = pkg.getRegistryObjectList(); 610 ArrayList rosInPkg = bu.getRegistryObjectList(roList); 611 Iterator iter = rosInPkg.iterator(); 612 while (iter.hasNext()) { 613 RegistryObjectType ro = (RegistryObjectType)iter.next(); 614 fixTemporaryId(ro, idMap); 615 } 616 617 } else if (o instanceof org.oasis.ebxml.registry.bindings.rim.Service) { 618 } else if (o instanceof org.oasis.ebxml.registry.bindings.rim.ServiceBinding) { 619 ServiceBinding bind = (ServiceBinding)o; 620 621 ServiceBinding target = (ServiceBinding)bind.getTargetBinding(); 622 if (target != null && idMap.containsKey(target.getId())) { 623 target.setId((String)(idMap.get(target.getId()))); 624 } 625 626 } else if (o instanceof org.oasis.ebxml.registry.bindings.rim.SpecificationLink) { 627 SpecificationLink sl = (SpecificationLink)o; 628 629 Object so = sl.getSpecificationObject(); 630 if (so !=null) { 631 String id = bu.getObjectId(so); 632 if (idMap.containsKey(id)) { 633 bu.setObjectId(so, (String)idMap.get(id)); 634 } 635 } 636 637 638 } else if (o instanceof org.oasis.ebxml.registry.bindings.rim.User) { 639 User u = (User)o; 640 641 if (u.getOrganization() instanceof org.oasis.ebxml.registry.bindings.rim.Organization) { 642 Organization org = (Organization)u.getOrganization(); 643 //Org may not yet be submitted if it is to be submitted after the user registration. 644 if ((org != null) && idMap.containsKey(org.getId())) { 645 org.setId((String)(idMap.get(org.getId()))); 646 } 647 } 648 649 } else { 650 throw new RegistryException("Unexpected object: " + o); 651 } 652 } 653 654 public void fixTemporaryIds(ArrayList objs, HashMap idMap) throws RegistryException { 655 656 Iterator iter = objs.iterator(); 657 // For checking UUID uniqueness within a SubmitObjectsRequest 658 ArrayList ids = new ArrayList(); 659 while (iter.hasNext()) { 660 Object o = iter.next(); 661 662 if (o instanceof org.oasis.ebxml.registry.bindings.rim.RegistryObjectType) { 663 RegistryObjectType ro = (RegistryObjectType)o; 664 checkId(ids, idMap, ro); 665 } 666 else { 667 throw new RegistryException("Unexpected object: " + o); 668 } 669 } 670 671 //Now iterate over each object and replace id defs/refs with new ids. 672 iter = objs.iterator(); 673 while (iter.hasNext()) { 674 RegistryObjectType ro = (RegistryObjectType)iter.next(); 675 fixTemporaryId(ro, idMap); 676 } 677 } 678 679 680 /*** 681 * check whether the referenced object for Association/Classification 682 * /ClassificationNode/Organization exist within the request document 683 */ 684 private void checkReferencedObject(Object object) throws ReferencedObjectNotFoundException 685 , RegistryException { 686 if (object instanceof RegistryObjectType) { 687 RegistryObjectType ro = (RegistryObjectType) object; 688 // Recursively check the nested Classification 689 Classification [] classifications = ro.getClassification(); 690 for(int i=0; i < classifications.length; i++) { 691 checkReferencedObject(classifications[i]); 692 } 693 // Recursively check the nested ExternalIdentifier 694 ExternalIdentifier [] extIds = ro.getExternalIdentifier(); 695 for(int i=0; i < extIds.length; i++) { 696 checkReferencedObject(extIds[i]); 697 } 698 } 699 else { 700 throw new RegistryException("Unknow Object type!"); 701 } 702 703 704 if (object instanceof org.oasis.ebxml.registry.bindings.rim.Association) { 705 Association ass = (Association)object; 706 if (ass.getSourceObject()==null) { 707 throw new ReferencedObjectNotFoundException("The Association " 708 + ass.getId() 709 + " is referencing a sourceObject that does not exist " 710 + "within the request"); 711 } 712 if (ass.getTargetObject()==null) { 713 throw new ReferencedObjectNotFoundException("The Association " 714 + ass.getId() 715 + " is referencing a targetObject that does not exist " 716 + "within the request"); 717 } 718 } 719 else if (object instanceof org.oasis.ebxml.registry.bindings.rim 720 .Classification) { 721 Classification cl = (Classification) object; 722 if (cl.getClassifiedObject()==null) { 723 throw new ReferencedObjectNotFoundException("The Classification " 724 + cl.getId() 725 + " is referencing a ClassifiedObject that does not exist " 726 + "within the request"); 727 } 728 } 729 else if (object instanceof org.oasis.ebxml.registry.bindings.rim 730 .ClassificationNode) { 731 } 732 else if(object instanceof org.oasis.ebxml.registry.bindings.rim.ExternalIdentifier) { 733 ExternalIdentifier extId = (ExternalIdentifier) object; 734 if (extId.getIdentificationScheme()==null) { 735 throw new ReferencedObjectNotFoundException("The ExternalIdentifier " 736 + extId.getId() 737 + " is referencing a identificationScheme that does not exist " 738 + "within the request"); 739 } 740 } 741 else if (object instanceof org.oasis.ebxml.registry.bindings.rim 742 .Organization) { 743 Organization org = (Organization) object; 744 if (org.getPrimaryContact()==null) { 745 throw new ReferencedObjectNotFoundException("The Organization " 746 + org.getId() 747 + " is referencing a primaryContact that does not exist " 748 + "within the request"); 749 } 750 } 751 } 752 753 /*** 754 * check whether the referenced object for Association/Classification 755 * /ClassificationNode/Organization exist within the request document 756 * <br> 757 * Add a RegistryError (warning) to the RegistryErrorList if a RegistryEntry 758 * has object status, majorVersion and minorVersion 759 */ 760 private void checkObjects(ArrayList objs, RegistryErrorList errorList) 761 throws RegistryException { 762 763 Iterator iter = objs.iterator(); 764 ArrayList ids = new ArrayList(); 765 766 while(iter.hasNext()) { 767 Object object = iter.next(); 768 checkReferencedObject(object); 769 770 if (object instanceof RegistryEntryType) { 771 RegistryEntryType re = (RegistryEntryType) object; 772 String warningMessage = null; 773 if (re.getStatus() != null) { 774 warningMessage = "status"; 775 } 776 if (re.hasMajorVersion()) { 777 warningMessage = "majorVersion"; 778 } 779 if (re.hasMinorVersion()) { 780 warningMessage = "minorVersion"; 781 } 782 if (warningMessage != null) { 783 warningMessage = "The " + warningMessage + " of RegistryEntry " 784 + re.getId() + " is ignored"; 785 RegistryError error = new RegistryError(); 786 error.setSeverity(ErrorType.WARNING); 787 error.setContent(warningMessage); 788 error.setErrorCode("unknown"); 789 error.setCodeContext("LifeCycleManagerImpl.submitObjects"); 790 errorList.addRegistryError(error); 791 } 792 } 793 } 794 } 795 796 private void indexContent(User user, ArrayList al, HashMap idToRepositoryItemMap, HashMap idMap) { 797 Iterator iter = al.iterator(); 798 while (iter.hasNext()) { 799 Object obj = iter.next(); 800 801 if (obj instanceof ExtrinsicObjectType) { 802 ExtrinsicObjectType eo = (ExtrinsicObjectType)obj; 803 try { 804 RepositoryItem indexableContent = (RepositoryItem)idToRepositoryItemMap.get(eo.getId()); 805 LeafRegistryObjectList objs = cim.catalogContent(eo, indexableContent); 806 807 ArrayList indexedMetadata = bu.getRegistryObjectList(objs); 808 809 //Replace temporary ids with proper UUID. 810 fixTemporaryIds(indexedMetadata, idMap); 811 812 /* 813 * For RegistryObjects, the DAO will take care which objects already 814 * exist and update them instead. 815 * 816 * Metadata for each ExtrisnicObject is stored independently in a separate transaction. 817 */ 818 pm.insert(user, indexedMetadata); 819 } 820 catch (RegistryException e) { 821 e.printStackTrace(); 822 } 823 } 824 } 825 } 826 827 /*** Approves one or more previously submitted objects */ 828 public RegistryResponse approveObjects(User user, ApproveObjectsRequest req) { 829 RegistryResponse resp = null; 830 RegistryErrorList el = new RegistryErrorList(); 831 try { 832 ArrayList idList = new ArrayList(); 833 ObjectRefListItem [] objRefListItems = req.getObjectRefList() 834 .getObjectRefListItem(); 835 for (int i=0; i < objRefListItems.length; i++) { 836 idList.add(objRefListItems[i].getObjectRef().getId()); 837 } 838 pm.updateStatus(user, idList 839 , org.oasis.ebxml.registry.bindings.rim.types.StatusType.APPROVED 840 , el); 841 resp = new RegistryResponse(); 842 resp.setStatus(org.oasis.ebxml.registry.bindings.rs.types.StatusType 843 .SUCCESS); 844 if (el.getRegistryErrorCount() > 0) { 845 // warning exists 846 resp.setRegistryErrorList(el); 847 } 848 } 849 catch (ObjectsNotFoundException e) { 850 Iterator notExistIt = e.getNotExistIds().iterator(); 851 while (notExistIt.hasNext()) { 852 String id = (String)notExistIt.next(); 853 RegistryError re = new RegistryError(); 854 re.setContent("The object with id " + id + " does not exist"); 855 re.setErrorCode("unknown"); 856 re.setCodeContext("LifeCycleManagerImpl.approveObjects"); 857 el.addRegistryError(re); 858 } 859 resp = new RegistryResponse(); 860 resp.setStatus(org.oasis.ebxml.registry.bindings.rs.types.StatusType 861 .FAILURE); 862 resp.setRegistryErrorList(el); 863 } 864 catch (NonRegistryEntryFoundException e) { 865 RegistryError re = new RegistryError(); 866 re.setContent(e.getMessage()); 867 re.setErrorCode("unknown"); 868 re.setCodeContext("LifeCycleManagerImpl.approveObjects"); 869 el.addRegistryError(re); 870 resp = new RegistryResponse(); 871 resp.setStatus(org.oasis.ebxml.registry.bindings.rs.types.StatusType 872 .FAILURE); 873 resp.setRegistryErrorList(el); 874 } 875 catch (RegistryException e) { 876 resp = util.createRegistryResponseFromThrowable(e, "LifeCycleManagerImpl.approveObjects", "Unknown"); 877 // Append any warnings 878 RegistryError [] errs = el.getRegistryError(); 879 RegistryErrorList newEl = resp.getRegistryErrorList(); 880 for (int i=0; i < errs.length ;i++) { 881 newEl.addRegistryError(errs[i]); 882 } 883 } 884 return resp; 885 } 886 887 /*** 888 * @throws RegistryException when the Repository items do not exist 889 */ 890 private void updateRepositoryItems(HashMap idToRepositoryItemMap) throws RegistryException { 891 if (idToRepositoryItemMap != null) { 892 893 Collection keySet = idToRepositoryItemMap.keySet(); 894 895 if (keySet != null) { 896 897 Iterator iter = keySet.iterator(); 898 899 while (iter.hasNext()) { 900 901 String id = (String)iter.next(); 902 RepositoryItem ri = (RepositoryItem)idToRepositoryItemMap.get(id); 903 if (!(ri.getId().equals(id))) { 904 ri.setId(id); 905 } 906 907 DataHandler dh = ri.getDataHandler(); 908 909 // Updating the repository item 910 rm.update(ri); 911 } 912 } 913 } 914 } 915 916 public RegistryResponse updateObjects(User user, UpdateObjectsRequest req 917 , HashMap idToRepositoryMap) { 918 RegistryResponse resp = null; 919 RegistryErrorList el = new RegistryErrorList(); 920 try { 921 LeafRegistryObjectList objs = req.getLeafRegistryObjectList(); 922 ArrayList al = bu.getRegistryObjectList(objs); 923 System.err.println("LifeCycleManager, size: " + al.size()); 924 checkObjects(al, el); 925 if (idToRepositoryMap != null) { 926 qs.checkQuota(user.getId()); 927 928 //fix ri ID to match first ExtrinsicObject 929 //(in case where ri is submitted without id OR 930 //id doesn't match EO) 931 //only works for submission of one ri and one ExtrinsicObject 932 correctRepositoryItemId(al, idToRepositoryMap); 933 934 updateRepositoryItems(idToRepositoryMap); 935 } 936 pm.update(user, al); 937 resp = new RegistryResponse(); 938 resp.setStatus(org.oasis.ebxml.registry.bindings.rs.types.StatusType 939 .SUCCESS); 940 if (el.getRegistryErrorCount() > 0) { 941 // warning exists 942 resp.setRegistryErrorList(el); 943 } 944 } 945 catch (ObjectsNotFoundException e) { 946 Iterator notExistIt = e.getNotExistIds().iterator(); 947 while (notExistIt.hasNext()) { 948 String id = (String)notExistIt.next(); 949 RegistryError re = new RegistryError(); 950 re.setContent("The object with id " + id + " does not exist"); 951 re.setErrorCode("unknown"); 952 re.setCodeContext("LifeCycleManagerImpl.updateObjects"); 953 el.addRegistryError(re); 954 } 955 resp = new RegistryResponse(); 956 resp.setStatus(org.oasis.ebxml.registry.bindings.rs.types.StatusType 957 .FAILURE); 958 resp.setRegistryErrorList(el); 959 } 960 catch (ReferencedObjectNotFoundException e) { 961 RegistryError re = new RegistryError(); 962 re.setContent(e.getMessage()); 963 re.setErrorCode("unknown"); 964 re.setCodeContext("LifeCycleManagerImpl.updateObjects"); 965 el.addRegistryError(re); 966 resp = new RegistryResponse(); 967 resp.setStatus(org.oasis.ebxml.registry.bindings.rs.types.StatusType 968 .FAILURE); 969 resp.setRegistryErrorList(el); 970 } 971 catch (AssociateToDeprecatedRegistryEntryException e) { 972 RegistryError re = new RegistryError(); 973 re.setContent(e.getMessage()); 974 re.setErrorCode("unknown"); 975 re.setCodeContext("LifeCycleManagerImpl.submitObjects"); 976 el.addRegistryError(re); 977 resp = new RegistryResponse(); 978 resp.setStatus(org.oasis.ebxml.registry.bindings.rs.types.StatusType 979 .FAILURE); 980 resp.setRegistryErrorList(el); 981 } 982 catch (InvalidURLsException e) { 983 // We should have unified mapping in util to generate 984 // RegistryErrorList Later 985 986 Iterator roIter = e.getSourceRegistryObjects().iterator(); 987 while (roIter.hasNext()) { 988 Object ro = roIter.next(); 989 RegistryError re = new RegistryError(); 990 if (ro instanceof ExternalLink) { 991 ExternalLink extLink = (ExternalLink) ro; 992 re.setContent("The ExternalLink with id " + extLink.getId() 993 + " is not resolvable, the Http URL is " 994 + extLink.getExternalURI()); 995 } 996 else if (ro instanceof ServiceBinding) { 997 ServiceBinding serviceBinding = (ServiceBinding) ro; 998 re.setContent("The ServiceBinding with id " + serviceBinding 999 .getId() + " is not resolvable, the Http URL is " 1000 + serviceBinding.getAccessURI()); 1001 } 1002 else { 1003 re.setContent("Internal Error happens, unknown " 1004 + "RegistryObjectType"); 1005 } 1006 re.setErrorCode("unknown"); 1007 re.setCodeContext("LifeCycleManagerImpl.submitObjects"); 1008 el.addRegistryError(re); 1009 } 1010 resp = new RegistryResponse(); 1011 resp.setStatus(org.oasis.ebxml.registry.bindings.rs.types.StatusType 1012 .FAILURE); 1013 resp.setRegistryErrorList(el); 1014 } 1015 catch (ReferencesExistException e) { 1016 RegistryError re = new RegistryError(); 1017 re.setContent("Deleting object denied. " + e.getMessage()); 1018 re.setErrorCode("unknown"); 1019 re.setCodeContext("LifeCycleManagerImpl.updateObjects"); 1020 el.addRegistryError(re); 1021 resp = new RegistryResponse(); 1022 resp.setStatus(org.oasis.ebxml.registry.bindings.rs.types.StatusType 1023 .FAILURE); 1024 resp.setRegistryErrorList(el); 1025 } 1026 catch (QuotaExceededException e) { 1027 RegistryError re = new RegistryError(); 1028 re.setContent(e.getMessage()); 1029 re.setErrorCode("unknown"); 1030 re.setCodeContext("LifeCycleManagerImpl.updateObjects"); 1031 el.addRegistryError(re); 1032 resp = new RegistryResponse(); 1033 resp.setStatus(org.oasis.ebxml.registry.bindings.rs.types.StatusType 1034 .FAILURE); 1035 resp.setRegistryErrorList(el); 1036 } 1037 catch (RegistryException e) { 1038 resp = util.createRegistryResponseFromThrowable(e, "LifeCycleManagerImpl.updateObjects", "Unknown"); 1039 // Append any warnings 1040 RegistryError [] errs = el.getRegistryError(); 1041 RegistryErrorList newEl = resp.getRegistryErrorList(); 1042 for (int i=0; i < errs.length ;i++) { 1043 newEl.addRegistryError(errs[i]); 1044 } 1045 } 1046 return resp; 1047 } 1048 1049 /*** Deprecates one or more previously submitted objects */ 1050 public RegistryResponse deprecateObjects(User user, DeprecateObjectsRequest req) { 1051 RegistryResponse resp = null; 1052 RegistryErrorList el = new RegistryErrorList(); 1053 try { 1054 ArrayList idList = new ArrayList(); 1055 ObjectRefListItem [] objRefListItems = req.getObjectRefList() 1056 .getObjectRefListItem(); 1057 for (int i=0; i < objRefListItems.length; i++) { 1058 idList.add(objRefListItems[i].getObjectRef().getId()); 1059 } 1060 pm.updateStatus(user, idList 1061 , org.oasis.ebxml.registry.bindings.rim.types.StatusType.DEPRECATED 1062 , el); 1063 resp = new RegistryResponse(); 1064 resp.setStatus(org.oasis.ebxml.registry.bindings.rs.types.StatusType 1065 .SUCCESS); 1066 if (el.getRegistryErrorCount() > 0) { 1067 // warning exists 1068 resp.setRegistryErrorList(el); 1069 } 1070 } 1071 catch (ObjectsNotFoundException e) { 1072 Iterator notExistIt = e.getNotExistIds().iterator(); 1073 while (notExistIt.hasNext()) { 1074 String id = (String)notExistIt.next(); 1075 RegistryError re = new RegistryError(); 1076 re.setContent("The object with id " + id + " does not exist"); 1077 re.setErrorCode("unknown"); 1078 re.setCodeContext("LifeCycleManagerImpl.deprecateObjects"); 1079 el.addRegistryError(re); 1080 } 1081 resp = new RegistryResponse(); 1082 resp.setStatus(org.oasis.ebxml.registry.bindings.rs.types.StatusType 1083 .FAILURE); 1084 resp.setRegistryErrorList(el); 1085 } 1086 catch (NonRegistryEntryFoundException e) { 1087 RegistryError re = new RegistryError(); 1088 re.setContent(e.getMessage()); 1089 re.setErrorCode("unknown"); 1090 re.setCodeContext("LifeCycleManagerImpl.deprecateObjects"); 1091 el.addRegistryError(re); 1092 resp = new RegistryResponse(); 1093 resp.setStatus(org.oasis.ebxml.registry.bindings.rs.types.StatusType 1094 .FAILURE); 1095 resp.setRegistryErrorList(el); 1096 } 1097 catch (RegistryException e) { 1098 resp = util.createRegistryResponseFromThrowable(e, "LifeCycleManagerImpl.deprecateObjects", "Unknown"); 1099 // Append any warnings 1100 RegistryError [] errs = el.getRegistryError(); 1101 RegistryErrorList newEl = resp.getRegistryErrorList(); 1102 for (int i=0; i < errs.length ;i++) { 1103 newEl.addRegistryError(errs[i]); 1104 } 1105 } 1106 return resp; 1107 } 1108 1109 /*** 1110 * Removes one or more previously submitted objects from the registry. If the 1111 * deletionScope is "DeleteRepositoryItemOnly", it will assume all the 1112 * ObjectRef under ObjectRefList is referencing repository items. If the 1113 * deletionScope is "DeleteAll", the reference may be either RegistryObject 1114 * or repository item. In both case, if the referenced object cannot be found, 1115 * RegistryResponse with errors list will be returned. 1116 */ 1117 public RegistryResponse removeObjects(User user, RemoveObjectsRequest req) { 1118 RegistryResponse resp = null; 1119 try { 1120 ArrayList idList = new ArrayList(); 1121 ObjectRefListItem [] objRefListItems = req.getObjectRefList() 1122 .getObjectRefListItem(); 1123 for (int i=0; i < objRefListItems.length; i++) { 1124 System.err.println("removeObjects: id = " + objRefListItems[i].getObjectRef().getId()); 1125 idList.add(objRefListItems[i].getObjectRef().getId()); 1126 } 1127 1128 int deletionScope = DeletionScopeType.DELETEALL_TYPE; 1129 if (req.getDeletionScope() != null) { 1130 deletionScope = req.getDeletionScope().getType(); 1131 } 1132 1133 //DeletionScope=DeleteRepositoryItemOnly. If any repository item 1134 //does not exist, it will stop 1135 if (deletionScope == DeletionScopeType 1136 .DELETEREPOSITORYITEMONLY.getType()) { 1137 ArrayList notExist = rm.itemsExist(idList); 1138 if (notExist.size() > 0) { 1139 throw new ObjectsNotFoundException(notExist); 1140 } 1141 rm.delete(idList); 1142 } 1143 else if (deletionScope == DeletionScopeType 1144 .DELETEALL.getType()) { 1145 //Check all referenced objects exist, all the objects should 1146 //be repository items or/and Registry Object 1147 ArrayList notExist = pm.registryObjectsExist(idList); 1148 if (notExist.size() > 0) { 1149 throw new ObjectsNotFoundException(notExist); 1150 } 1151 1152 //find out which id is not an id of a repository item (i.e. 1153 //referencing RO only 1154 ArrayList nonItemsIds = rm.itemsExist(idList); 1155 1156 //find out which id is an id of a repository item 1157 ArrayList itemsIds = new ArrayList(); 1158 Iterator idListIt = idList.iterator(); 1159 while(idListIt.hasNext()) { 1160 Object id = idListIt.next(); 1161 if (!nonItemsIds.contains(id)) { 1162 itemsIds.add(id); 1163 } 1164 } 1165 1166 // Delete the repository items 1167 rm.delete(itemsIds); 1168 1169 //Delete all ROs with the ids 1170 pm.delete(user, idList); 1171 } 1172 else { 1173 throw new RegistryException("Undefined deletionScope"); 1174 } 1175 resp = new RegistryResponse(); 1176 resp.setStatus(org.oasis.ebxml.registry.bindings.rs.types.StatusType 1177 .SUCCESS); 1178 } 1179 catch (ObjectsNotFoundException e) { 1180 RegistryErrorList el = new RegistryErrorList(); 1181 Iterator notExistIt = e.getNotExistIds().iterator(); 1182 while (notExistIt.hasNext()) { 1183 String id = (String)notExistIt.next(); 1184 RegistryError re = new RegistryError(); 1185 re.setContent("The object with id " + id + " does not exist"); 1186 re.setErrorCode("unknown"); 1187 re.setCodeContext("LifeCycleManagerImpl.removeObjects"); 1188 el.addRegistryError(re); 1189 } 1190 resp = new RegistryResponse(); 1191 resp.setStatus(org.oasis.ebxml.registry.bindings.rs.types.StatusType 1192 .FAILURE); 1193 resp.setRegistryErrorList(el); 1194 } 1195 catch (ReferencesExistException e) { 1196 RegistryErrorList el = new RegistryErrorList(); 1197 RegistryError re = new RegistryError(); 1198 re.setContent("Deleting object denied. " + e.getMessage()); 1199 re.setErrorCode("unknown"); 1200 re.setCodeContext("LifeCycleManagerImpl.removeObjects"); 1201 el.addRegistryError(re); 1202 resp = new RegistryResponse(); 1203 resp.setStatus(org.oasis.ebxml.registry.bindings.rs.types.StatusType 1204 .FAILURE); 1205 resp.setRegistryErrorList(el); 1206 } 1207 catch (RegistryException e) { 1208 resp = util.createRegistryResponseFromThrowable(e, 1209 "LifeCycleManagerImpl.removeObjects", "Unknown"); 1210 } 1211 return resp; 1212 } 1213 1214 /*** Add slots to one or more registry entries. */ 1215 1216 public RegistryResponse addSlots(AddSlotsRequest req) { 1217 1218 RegistryResponse resp = null; 1219 try { 1220 String objectRefId = req.getObjectRef().getId(); 1221 Slot[] slots = req.getSlot(); 1222 ArrayList slotsList = new ArrayList(); 1223 for (int i=0; i < slots.length; i++) { 1224 slotsList.add(slots[i]); 1225 } 1226 pm.addSlots(objectRefId, slotsList 1227 ); 1228 1229 resp = new RegistryResponse(); 1230 resp.setStatus(org.oasis.ebxml.registry.bindings.rs.types.StatusType 1231 .SUCCESS); 1232 } 1233 catch (SlotsParentNotExistException e) { 1234 RegistryErrorList el = new RegistryErrorList(); 1235 String parentId = e.getParentId(); 1236 RegistryError re = new RegistryError(); 1237 re.setContent("The parent '" + parentId + "' of these slots does " 1238 + "not exist"); 1239 re.setErrorCode("unknown"); 1240 re.setCodeContext("LifeCycleManagerImpl.addSlots"); 1241 el.addRegistryError(re); 1242 resp = new RegistryResponse(); 1243 resp.setStatus(org.oasis.ebxml.registry.bindings.rs.types.StatusType 1244 .FAILURE); 1245 resp.setRegistryErrorList(el); 1246 } 1247 catch (SlotsExistException e) { 1248 RegistryErrorList el = new RegistryErrorList(); 1249 Iterator iter = e.getSlotsNames().iterator(); 1250 String parentId = e.getParentId(); 1251 while(iter.hasNext()) { 1252 RegistryError re = new RegistryError(); 1253 String slotName = (String)iter.next(); 1254 re.setContent("The Slot '" + slotName + "' for the" 1255 + " RegistryObject" 1256 + " '" + parentId + "' already exists"); 1257 re.setErrorCode("unknown"); 1258 re.setCodeContext("LifeCycleManagerImpl.addSlots"); 1259 el.addRegistryError(re); 1260 } 1261 resp = new RegistryResponse(); 1262 resp.setStatus(org.oasis.ebxml.registry.bindings.rs.types.StatusType 1263 .FAILURE); 1264 resp.setRegistryErrorList(el); 1265 } 1266 catch (DuplicateSlotsException e) { 1267 RegistryErrorList el = new RegistryErrorList(); 1268 Iterator iter = e.getSlotsNames().iterator(); 1269 String parentId = e.getParentId(); 1270 while(iter.hasNext()) { 1271 RegistryError re = new RegistryError(); 1272 String slotName = (String)iter.next(); 1273 re.setContent("More than one Slot have the name '" + slotName 1274 + "' for the RegistryObject " 1275 + "'" + parentId + "'"); 1276 re.setErrorCode("unknown"); 1277 re.setCodeContext("LifeCycleManagerImpl.addSlots"); 1278 el.addRegistryError(re); 1279 } 1280 resp = new RegistryResponse(); 1281 resp.setStatus(org.oasis.ebxml.registry.bindings.rs.types.StatusType 1282 .FAILURE); 1283 resp.setRegistryErrorList(el); 1284 } 1285 catch (RegistryException e) { 1286 resp = util.createRegistryResponseFromThrowable(e, "LifeCycleManagerImpl.addSlots", "Unknown"); 1287 } 1288 return resp; 1289 1290 } 1291 1292 1293 /*** Remove specified slots from one or more registry entries. */ 1294 public RegistryResponse removeSlots(RemoveSlotsRequest req) { 1295 RegistryResponse resp = null; 1296 try { 1297 String objectRefId = req.getObjectRef().getId(); 1298 Slot[] slots = req.getSlot(); 1299 ArrayList slotsList = new ArrayList(); 1300 for (int i=0; i < slots.length; i++) { 1301 slotsList.add(slots[i]); 1302 } 1303 pm.removeSlots(objectRefId, slotsList); 1304 resp = new RegistryResponse(); 1305 resp.setStatus(org.oasis.ebxml.registry.bindings.rs.types.StatusType 1306 .SUCCESS); 1307 } 1308 catch (SlotNotExistException e) { 1309 RegistryError re = new RegistryError(); 1310 re.setContent(e.getMessage()); 1311 re.setErrorCode("unknown"); 1312 re.setCodeContext("LifeCycleManagerImpl.removeSlots"); 1313 1314 RegistryErrorList el = new RegistryErrorList(); 1315 el.addRegistryError(re); 1316 1317 resp = new RegistryResponse(); 1318 resp.setStatus(org.oasis.ebxml.registry.bindings.rs.types.StatusType 1319 .FAILURE); 1320 resp.setRegistryErrorList(el); 1321 } 1322 catch (RegistryException e) { 1323 resp = util.createRegistryResponseFromThrowable(e, "LifeCycleManagerImpl.removeSlots", "Unknown"); 1324 } 1325 return resp; 1326 } 1327 1328 public static void printUsage() { 1329 System.out.println("usage: -submitObjects | -approveObjects | -updateObjects " + 1330 "| -deprecateObjects | -removeObjects | -addSlots | - removeSlots " 1331 + "[SubmitObjectsRequest | " 1332 + "ApproveObjectsRequest | " 1333 + "UpdateObjectsRequest | " 1334 + "DeprecateObjectsRequest | " 1335 + "RemoveObjectsRequest | " 1336 + "AddSlotsRequest] " 1337 + "-repItem [repository item] -repItemId [id] -contentId [contentId] " 1338 + "-userId [user id]"); 1339 } 1340 1341 public static void main(String[] args) { 1342 if (args.length < 2) { 1343 printUsage(); 1344 return; 1345 } 1346 String command = args[0]; 1347 String requestFile = args[1]; 1348 String itemFile = null; 1349 String itemId = null; 1350 String contentId = null; 1351 String userId = null; 1352 1353 for (int i=2; i < args.length; i++) { 1354 if (args[i].equalsIgnoreCase("-repItem")) { 1355 itemFile = args[i+1]; 1356 } 1357 else if (args[i].equalsIgnoreCase("-repItemId")) { 1358 itemId = args[i+1]; 1359 } 1360 else if (args[i].equalsIgnoreCase("-contentId")) { 1361 contentId = args[i+1]; 1362 } 1363 else if (args[i].equalsIgnoreCase("-userId")) { 1364 userId = args[i+1]; 1365 } 1366 } 1367 if (userId==null) { 1368 System.err.println("missing userId"); 1369 } 1370 1371 try { 1372 LifeCycleManagerImpl lcm = LifeCycleManagerImpl.getInstance(); 1373 User user = new User(); 1374 user.setId(userId); 1375 if (command.equalsIgnoreCase("-submitObjects")) { 1376 1377 FileReader fr = new FileReader(requestFile); 1378 SubmitObjectsRequest req = SubmitObjectsRequest.unmarshal(fr); 1379 long t1 = System.currentTimeMillis(); 1380 RegistryResponse response = new RegistryResponse(); 1381 if (itemFile==null) { 1382 // without repository item 1383 response = lcm.submitObjects(user, req, null); 1384 } 1385 else { 1386 // with repository item 1387 if (itemId==null || contentId==null) { 1388 System.err.println("missing repItemId/contentId"); 1389 return; 1390 } 1391 File repositoryFile = new File(itemFile); 1392 //String id = args[3]; 1393 //String contentId = args[4]; 1394 System.out.println("id:" + itemId); 1395 System.out.println("contentId:" + contentId); 1396 HashMap repositoryMap = new HashMap(); 1397 //needed so that compiler won't argue about type ambiguity... 1398 String nullTemp = null; 1399 repositoryMap.put(itemId, new RepositoryItem(contentId, nullTemp, new 1400 DataHandler(new FileDataSource(repositoryFile)))); 1401 response = lcm.submitObjects(user, req, repositoryMap); 1402 } 1403 long t2 = System.currentTimeMillis(); 1404 response.marshal(new OutputStreamWriter(System.err)); 1405 } 1406 1407 else if (command.equalsIgnoreCase("-approveObjects")) { 1408 FileReader fr = new FileReader(requestFile); 1409 1410 ApproveObjectsRequest req = ApproveObjectsRequest.unmarshal(fr); 1411 1412 long t1 = System.currentTimeMillis(); 1413 RegistryResponse response = lcm.approveObjects(user, req); 1414 long t2 = System.currentTimeMillis(); 1415 1416 System.err.println("Elapsed time in seconds: " + (t2-t1)/1000); 1417 System.err.println("RegistryResponse:"); 1418 response.marshal(new OutputStreamWriter(System.err)); 1419 } 1420 1421 else if (command.equalsIgnoreCase("-updateObjects")) { 1422 FileReader fr = new FileReader(requestFile); 1423 UpdateObjectsRequest req = UpdateObjectsRequest.unmarshal(fr); 1424 long t1 = System.currentTimeMillis(); 1425 RegistryResponse response = new RegistryResponse(); 1426 if (itemFile==null) { 1427 // without repository item 1428 response = lcm.updateObjects(user, req, null); 1429 } 1430 else { 1431 // with repository item 1432 if (itemId==null || contentId==null) { 1433 System.err.println("missing repItemId/contentId"); 1434 return; 1435 } 1436 File repositoryFile = new File(itemFile); 1437 System.out.println("id:" + itemId); 1438 System.out.println("contentId:" + contentId); 1439 HashMap repositoryMap = new HashMap(); 1440 //needed so that compiler won't argue about type ambiguity... 1441 String nullTemp = null; 1442 repositoryMap.put(itemId, new RepositoryItem(contentId, nullTemp, new 1443 DataHandler(new FileDataSource(repositoryFile)))); 1444 response = lcm.updateObjects(user, req, repositoryMap); 1445 } 1446 long t2 = System.currentTimeMillis(); 1447 response.marshal(new OutputStreamWriter(System.err)); 1448 } 1449 1450 else if (command.equalsIgnoreCase("-deprecateObjects")) { 1451 FileReader fr = new FileReader(requestFile); 1452 1453 DeprecateObjectsRequest req = DeprecateObjectsRequest.unmarshal 1454 (fr); 1455 1456 long t1 = System.currentTimeMillis(); 1457 RegistryResponse response = lcm.deprecateObjects(user, req); 1458 long t2 = System.currentTimeMillis(); 1459 1460 System.err.println("Elapsed time in seconds: " + (t2-t1)/1000); 1461 response.marshal(new OutputStreamWriter(System.err)); 1462 } 1463 else if (command.equalsIgnoreCase("-removeObjects")) { 1464 FileReader fr = new FileReader(requestFile); 1465 1466 RemoveObjectsRequest req = RemoveObjectsRequest.unmarshal 1467 (fr); 1468 1469 long t1 = System.currentTimeMillis(); 1470 RegistryResponse response = lcm.removeObjects(user, req); 1471 long t2 = System.currentTimeMillis(); 1472 1473 System.err.println("Elapsed time in seconds: " + (t2-t1)/1000); 1474 response.marshal(new OutputStreamWriter(System.err)); 1475 1476 } 1477 else if (command.equalsIgnoreCase("-addSlots")) { 1478 FileReader fr = new FileReader(requestFile); 1479 1480 AddSlotsRequest req = AddSlotsRequest.unmarshal 1481 (fr); 1482 1483 long t1 = System.currentTimeMillis(); 1484 RegistryResponse response = lcm.addSlots(req); 1485 long t2 = System.currentTimeMillis(); 1486 1487 System.err.println("Elapsed time in seconds: " + (t2-t1)/1000); 1488 response.marshal(new OutputStreamWriter(System.err)); 1489 } 1490 else if (command.equalsIgnoreCase("-removeSlots")) { 1491 FileReader fr = new FileReader(requestFile); 1492 1493 RemoveSlotsRequest req = RemoveSlotsRequest.unmarshal 1494 (fr); 1495 1496 long t1 = System.currentTimeMillis(); 1497 RegistryResponse response = lcm.removeSlots(req); 1498 long t2 = System.currentTimeMillis(); 1499 1500 System.err.println("Elapsed time in seconds: " + (t2-t1)/1000); 1501 response.marshal(new OutputStreamWriter(System.err)); 1502 } 1503 else { 1504 printUsage(); 1505 } 1506 1507 } catch (Exception e) { 1508 e.printStackTrace(); 1509 } 1510 } 1511 1512 /* 1513 * Fix Repository item's ID to match ID in first 1514 * associated ExtrinsicObject. (in case where ri 1515 * is submitted without id or id doesn't match id 1516 * of ExtrinsicObject). 1517 * Currently Only works for submission of one 1518 * Repository item and its associated ExtrinsicObject. 1519 * Called in updateObjects() and submitObjects(). 1520 */ 1521 private void correctRepositoryItemId(ArrayList objs, 1522 HashMap idToRepositoryItemMap){ 1523 if(objs.size() == 1){ 1524 Object obj = objs.get(0); 1525 if (obj instanceof RegistryEntryType) { 1526 RegistryEntryType firstRe = (RegistryEntryType)objs.get(0); 1527 if(firstRe != null && 1528 firstRe instanceof ExtrinsicObject){ 1529 String correctId = firstRe.getId(); 1530 if(idToRepositoryItemMap.size() == 1){ 1531 Iterator attachIter = idToRepositoryItemMap.keySet().iterator(); 1532 String attachIdKey = (String)attachIter.next(); 1533 RepositoryItem attachRi = 1534 (RepositoryItem)idToRepositoryItemMap.get(attachIdKey); 1535 String attachId = attachRi.getId(); 1536 1537 if(correctId != null && 1538 !correctId.equals(attachId)){ 1539 System.err.println("[LifeCycleManager::correctRepositoryItemId()]" + 1540 " RepositoryItem id [" + 1541 attachId + 1542 "] does not match Registry Object id [" + 1543 correctId + 1544 "]"); 1545 System.err.println("[LifeCycleManager::correctRepositoryItemId()] " + 1546 " Updating RepositoryItem id to " + 1547 correctId); 1548 //remove old key 1549 idToRepositoryItemMap.remove(attachRi.getId()); 1550 attachRi.setId(correctId); 1551 //add new key and ri 1552 idToRepositoryItemMap.put(correctId, attachRi); 1553 } 1554 } 1555 } 1556 } 1557 } 1558 } 1559 1560 }

This page was automatically generated by Maven