Ejemplo n.º 1
0
  public void checkRegistryObjectLidOnNewObject(RegistryObjectType ro) throws RegistryException {
    String id = ro.getId();
    String lid = ro.getLid();

    // Object does not exists already
    if (lid == null) {
      ro.setLid(ro.getId());
    }
  }
Ejemplo n.º 2
0
  // TODO: Consider replacing versions with idToVersionsMap as a performance optimization in future.
  private boolean isIdInVersions(String id) {
    RegistryObjectType ro = null;
    boolean foundId = false;

    if (versions != null) {
      Iterator iter = versions.iterator();

      while (iter.hasNext()) {
        ro = (RegistryObjectType) iter.next();

        if (id.equals(ro.getId())) {
          foundId = true;
          break;
        }
      }
    }

    return (foundId);
  }
Ejemplo n.º 3
0
  public void checkRegistryObjectLid(RegistryObjectType ro) throws RegistryException {
    String id = ro.getId();
    String lid = ro.getLid();

    String existingObjectLid = (String) context.getIdToLidMap().get(id);

    // Assign lid if not specified, validate lid if specified
    if (existingObjectLid != null) {
      if (lid == null) {
        ro.setLid(existingObjectLid);
      } else {
        // Validate that lid matches existing objects lid
        if (!lid.equals(existingObjectLid)) {
          throw new RegistryException(
              ServerResourceBundle.getInstance()
                  .getString("message.idDoesNotMatch", new Object[] {lid, existingObjectLid, id}));
        }
      }
    } else {
      checkRegistryObjectLidOnNewObject(ro);
    }
  }
Ejemplo n.º 4
0
  public RegistryObjectType createRegistryObjectVersion(RegistryObjectType ro)
      throws RegistryException {
    RegistryObjectType roNew = null;

    try {
      Utility util = Utility.getInstance();

      RegistryObjectType lastVersion = getLatestVersionOfRegistryObject(ro);
      String nextVersion = null;
      if (lastVersion == null) {
        nextVersion = "1.1";
      } else {
        nextVersion = nextVersion(lastVersion.getVersionInfo().getVersionName());
      }

      roNew = bu.cloneRegistryObject(ro);
      VersionInfoType nextVersionInfo = bu.rimFac.createVersionInfoType();
      nextVersionInfo.setVersionName(nextVersion);

      // Set the comment from the request comment (per the spec)
      if (!context.getRegistryRequestStack().empty()) {
        nextVersionInfo.setComment(context.getCurrentRegistryRequest().getComment());
      }

      roNew.setVersionInfo(nextVersionInfo);

      // A new version must have a unique id
      String id = ro.getId();
      String lid = ro.getLid();
      String idNew = id;

      // Only change id if it already exists in versions
      // Need to preserve client supplied id in the case where lid is an
      // existing lid but id is new
      if (isIdInVersions(id)) {
        // Make id of next version be lid with ":nextVersion" as suffix, if this id is already in
        // use in a version
        idNew = lid + ":" + nextVersion; // Utility.getInstance().createId();
        roNew.setId(idNew);

        // Add entry to idMap so old id and refs to it are mapped to idNew
        context.getIdMap().put(id, idNew);
      }

      // Add entry to context.newROVersionMap for later replacement
      context.getNewROVersionMap().put(ro, roNew);

      // Assign new ids to all composed RegistryObjects within roNew
      Set composedObjects = bu.getComposedRegistryObjects(roNew, -1);

      Iterator iter = composedObjects.iterator();
      while (iter.hasNext()) {
        RegistryObjectType composedObject = (RegistryObjectType) iter.next();

        // check for composed object if exist change the id and lid and
        // also update the idMap.
        if (objectExists(composedObject.getId())) {
          String oldId = composedObject.getId();
          String newId = oldId + ":" + nextVersion;
          composedObject.setId(newId);
          composedObject.setLid(newId);
          context.getIdMap().put(oldId, newId);
        }

        String composedId = composedObject.getId();
        String composedLid = composedObject.getLid();
        String composedIdNew = composedId;

        if (!util.isValidRegistryId(composedId)) { // Replace the id if it's not a valid ID already
          composedIdNew = util.createId();

          composedObject.setId(composedIdNew);

          // Add entry to idMap so old composedId and refs to it are mapped to composedIdNew
          context.getIdMap().put(composedId, composedIdNew);
        }

        if (composedLid == null || composedLid.trim().length() == 0) {
          composedObject.setLid(composedIdNew);
        }
        // Set the parent id of this composed object to point to the new parent
        bu.setParentIdForComposedObject(composedObject, idNew);
      }
    } catch (JAXRException e) {
      throw new RegistryException(e);
    } catch (JAXBException e) {
      throw new RegistryException(e);
    }
    return roNew;
  }