void handleArchivedForSavePackage(PackageConfigData data, PackageItem item) {
   for (Iterator<AssetItem> iter = item.getAssets(); iter.hasNext(); ) {
     AssetItem assetItem = iter.next();
     if (!assetItem.isArchived()) {
       assetItem.archiveItem(true);
       assetItem.checkin(data.getDescription());
     }
   }
 }
 void handleUnarchivedForSavePackage(
     PackageConfigData data, PackageItem item, Calendar packageLastModified) {
   for (Iterator<AssetItem> iter = item.getAssets(); iter.hasNext(); ) {
     AssetItem assetItem = iter.next();
     // Unarchive the assets archived after the package
     // ( == at the same time that the package was archived)
     if (assetItem.getLastModified().compareTo(packageLastModified) >= 0) {
       assetItem.archiveItem(false);
       assetItem.checkin(data.getDescription());
     }
   }
 }
 protected String[] listImagesInPackage(String packageName) throws SerializationException {
   // load package
   PackageItem item = rulesRepository.loadPackage(packageName);
   List<String> retList = new ArrayList<String>();
   Iterator<AssetItem> iter = item.getAssets();
   while (iter.hasNext()) {
     AssetItem pitem = iter.next();
     if (pitem.getFormat().equalsIgnoreCase("png")
         || pitem.getFormat().equalsIgnoreCase("gif")
         || pitem.getFormat().equalsIgnoreCase("jpg")) {
       retList.add(pitem.getName());
     }
   }
   return (String[]) retList.toArray(new String[] {});
 }
  /** This will build the package. */
  private void buildPackage() {
    AssetSelector selector = SelectorManager.getInstance().getSelector(selectorConfigName);
    if (selector == null) {
      this.errors.add(
          new ContentAssemblyError(
              this.pkg, "The selector named " + selectorConfigName + " is not available."));
      return;
    }
    Iterator it = pkg.getAssets();
    while (it.hasNext()) {

      AssetItem asset = (AssetItem) it.next();

      if (!asset.isArchived() && (selector.isAssetAllowed(asset))) {
        buildAsset(asset);
      }
    }
  }
  public String getDRL() {
    StringBuffer src = new StringBuffer();
    src.append("package " + this.pkg.getName() + "\n");
    src.append(ServiceImplementation.getDroolsHeader(this.pkg) + "\n\n");

    // now we load up the DSL files
    builder.setDSLFiles(
        BRMSPackageBuilder.getDSLMappingFiles(
            pkg,
            new BRMSPackageBuilder.DSLErrorEvent() {
              public void recordError(AssetItem asset, String message) {
                errors.add(new ContentAssemblyError(asset, message));
              }
            }));

    // do the functions and declared types.
    AssetItemIterator it =
        this.pkg.listAssetsByFormat(new String[] {AssetFormats.FUNCTION, AssetFormats.DRL_MODEL});
    while (it.hasNext()) {
      AssetItem func = (AssetItem) it.next();
      if (!func.isArchived()) {
        src.append(func.getContent() + "\n\n");
      }
    }

    // now the rules
    Iterator iter = pkg.getAssets();
    while (iter.hasNext()) {
      AssetItem asset = (AssetItem) iter.next();
      if (!asset.isArchived()) {

        ContentHandler h = ContentManager.getHandler(asset.getFormat());
        if (h instanceof IRuleAsset) {
          IRuleAsset ruleAsset = (IRuleAsset) h;
          ruleAsset.assembleDRL(builder, asset, src);
        }

        src.append("\n\n");
      }
    }

    return src.toString();
  }
  /** @deprecated in favour of {@link compareSnapshots(SnapshotComparisonPageRequest)} */
  protected SnapshotDiffs compareSnapshots(
      String packageName, String firstSnapshotName, String secondSnapshotName) {
    SnapshotDiffs diffs = new SnapshotDiffs();
    List<SnapshotDiff> list = new ArrayList<SnapshotDiff>();

    PackageItem leftPackage = rulesRepository.loadPackageSnapshot(packageName, firstSnapshotName);
    PackageItem rightPackage = rulesRepository.loadPackageSnapshot(packageName, secondSnapshotName);

    // Older one has to be on the left.
    if (isRightOlderThanLeft(leftPackage, rightPackage)) {
      PackageItem temp = leftPackage;
      leftPackage = rightPackage;
      rightPackage = temp;

      diffs.leftName = secondSnapshotName;
      diffs.rightName = firstSnapshotName;
    } else {
      diffs.leftName = firstSnapshotName;
      diffs.rightName = secondSnapshotName;
    }

    Iterator<AssetItem> leftExistingIter = leftPackage.getAssets();
    while (leftExistingIter.hasNext()) {
      AssetItem left = leftExistingIter.next();
      if (isPackageItemDeleted(rightPackage, left)) {
        SnapshotDiff diff = new SnapshotDiff();

        diff.name = left.getName();
        diff.diffType = SnapshotDiff.TYPE_DELETED;
        diff.leftUuid = left.getUUID();

        list.add(diff);
      }
    }

    Iterator<AssetItem> rightExistingIter = rightPackage.getAssets();
    while (rightExistingIter.hasNext()) {
      AssetItem right = rightExistingIter.next();
      AssetItem left = null;
      if (right != null && leftPackage.containsAsset(right.getName())) {
        left = leftPackage.loadAsset(right.getName());
      }

      // Asset is deleted or added
      if (right == null || left == null) {
        SnapshotDiff diff = new SnapshotDiff();

        if (left == null) {
          diff.name = right.getName();
          diff.diffType = SnapshotDiff.TYPE_ADDED;
          diff.rightUuid = right.getUUID();
        }

        list.add(diff);
      } else if (isAssetArchivedOrRestored(right, left)) { // Has the asset
        // been archived
        // or restored
        SnapshotDiff diff = new SnapshotDiff();

        diff.name = right.getName();
        diff.leftUuid = left.getUUID();
        diff.rightUuid = right.getUUID();

        if (left.isArchived()) {
          diff.diffType = SnapshotDiff.TYPE_RESTORED;
        } else {
          diff.diffType = SnapshotDiff.TYPE_ARCHIVED;
        }

        list.add(diff);
      } else if (isAssetItemUpdated(right, left)) { // Has the asset been
        // updated
        SnapshotDiff diff = new SnapshotDiff();

        diff.name = right.getName();
        diff.leftUuid = left.getUUID();
        diff.rightUuid = right.getUUID();
        diff.diffType = SnapshotDiff.TYPE_UPDATED;

        list.add(diff);
      }
    }

    diffs.diffs = list.toArray(new SnapshotDiff[list.size()]);
    return diffs;
  }