コード例 #1
0
  /**
   * Creates a new version of the RepositoryItem associated with specified ExtrinsicObject. Note
   * that when the RepositoryItem is versioned its ExtrinsicObject must also be versioned.
   */
  public RepositoryItem createRepositoryItemVersion(ExtrinsicObjectType eo)
      throws RegistryException {
    RepositoryItem riNew = null;

    try {
      ExtrinsicObjectType eoNew = (ExtrinsicObjectType) createRegistryObjectVersion(eo);

      String latestContentVersionName = rm.getLatestVersionName(context, eo.getLid());
      String nextContentVersionName = nextVersion(latestContentVersionName);

      VersionInfoType nextContentVersionInfo = bu.rimFac.createVersionInfoType();
      nextContentVersionInfo.setVersionName(nextContentVersionName);

      // Set the contentComment from the submitted object's contentVersionInfo
      VersionInfoType submittedContentVersionInfo = eo.getContentVersionInfo();
      if (submittedContentVersionInfo != null) {
        nextContentVersionInfo.setComment(submittedContentVersionInfo.getComment());
      }

      // Update the eo contentVersionName to match newContentVersionName
      eoNew.setContentVersionInfo(nextContentVersionInfo);

      RepositoryItem riOld = (RepositoryItem) context.getRepositoryItemsMap().get(eo.getId());
      riNew = (RepositoryItem) riOld.clone();

      // A new version must have a unique id that matches its new ExtrinsicObject eoNew
      riNew.setId(eoNew.getId());

      // Now remeber in context.newRIVersionMap fro later replacement
      // Should we be using old or new eo.getId().
      // Maybe we dont need newRIVersionMap and newROVersionMap
      // Lets see how to just use existing idMap and other structures.
      context.getNewRIVersionMap().put(context.getRepositoryItemsMap().get(eo.getId()), riNew);
    } catch (CloneNotSupportedException e) {
      // This cannot happen
      throw new RegistryException(e);
    } catch (JAXBException e) {
      throw new RegistryException(e);
    }

    return riNew;
  }
コード例 #2
0
  public boolean needToVersionRepositoryItem(ExtrinsicObjectType eo, RepositoryItem riNew)
      throws RegistryException {
    boolean needToVersion = true;

    try {
      // dontVersion eo imples dontVersion ro
      needToVersion = needToVersionRegistryObject(eo);

      if (needToVersion) {
        // This is an existing object not a newly submitted object
        // See if repository item has changed or not.
        HashMap slotsMap;

        // Honour dontVersion flag if specified on request
        if (!context.getRegistryRequestStack().empty()) {
          slotsMap = bu.getSlotsFromRequest(context.getCurrentRegistryRequest());
          if (slotsMap.containsKey(bu.CANONICAL_SLOT_LCM_DONT_VERSION_CONTENT)) {
            String val = (String) slotsMap.get(bu.CANONICAL_SLOT_LCM_DONT_VERSION_CONTENT);
            if (val.trim().equalsIgnoreCase("true")) {
              needToVersion = false;
            }
          }
        }

        // Honour dontVersion flag if specified on ro
        slotsMap = bu.getSlotsFromRegistryObject(eo);
        if (slotsMap.containsKey(bu.CANONICAL_SLOT_LCM_DONT_VERSION_CONTENT)) {
          String val = (String) slotsMap.get(bu.CANONICAL_SLOT_LCM_DONT_VERSION_CONTENT);
          if (val.trim().equalsIgnoreCase("true")) {
            needToVersion = false;
          }
        }
      }

      if (needToVersion) {
        if (riNew == null) {
          needToVersion = false;
          return needToVersion;
        } else {
          RepositoryItem riOld = null;

          try {
            riOld = rm.getRepositoryItem(eo.getId());
          } catch (RepositoryItemNotFoundException e) {
            // It is possible that there is no RepositoryItem yet.
            // Ignore the exception.
          } catch (ObjectNotFoundException e) {
            // It is possible that there is no RepositoryItem yet.
            // Ignore the exception.
          }

          if (riOld == null) {
            needToVersion = false;
          } else {
            if (repositoryItemsAreIdentical(riOld, riNew)) {
              needToVersion = false;
            }
          }
        }
      }

      // Must set contentVersionName to match latest versionName if existing object
      // or set to version 1.1 if new object.
      if (!needToVersion) {
        ExtrinsicObjectType lastVersion =
            (ExtrinsicObjectType) getLatestVersionOfRegistryObject(eo);

        VersionInfoType contentVersionInfo = eo.getContentVersionInfo();
        if (contentVersionInfo == null) {
          contentVersionInfo = bu.rimFac.createVersionInfoType();
        }

        if (lastVersion == null) {
          // This is the first ExtrinsicObject version.
          if (riNew != null) {
            // This is the first RepositoryItem version. Make sure versionName is "1.1"
            contentVersionInfo.setVersionName("1.1");
          } else {
            // No repository item means that the contentVersionInfo MUST be set to null
            contentVersionInfo = null;
          }
        } else {
          // This is not the first ExtrinsicObject version.
          // Note that contentversionName is set even if no RI is submitted since
          // it is OK to update just the EO and have new version use last version of RO

          VersionInfoType lastContentVersionInfo = lastVersion.getContentVersionInfo();

          if (lastContentVersionInfo == null) {
            // Previous version had no repository item
            String lastContentVersionName = rm.getLatestVersionName(context, eo.getLid());
            if (lastContentVersionName != null) {
              contentVersionInfo.setVersionName(lastContentVersionName);
            } else {
              contentVersionInfo.setVersionName("1.1");
            }
          } else {
            // Previous version had a repository item
            // Use the last contentVersionName
            contentVersionInfo.setVersionName(lastContentVersionInfo.getVersionName());
          }
        }
        eo.setContentVersionInfo(contentVersionInfo);
      }

    } catch (JAXBException e) {
      throw new RegistryException(e);
    }

    return needToVersion;
  }