protected String createPackage(String name, String description, String format, String[] workspace)
      throws RulesRepositoryException {

    log.info("USER: "******" CREATING package [" + name + "]");
    PackageItem item = rulesRepository.createPackage(name, description, format, workspace);

    return item.getUUID();
  }
 /** @deprecated in favour of {@link findAssetPage(AssetPageRequest)} */
 @WebRemote
 @Restrict("#{identity.loggedIn}")
 public TableDataResult listAssetsWithPackageName(
     String packageName, String formats[], int skip, int numRows, String tableConfig)
     throws SerializationException {
   PackageItem pkg = getRulesRepository().loadPackage(packageName);
   return listAssets(pkg.getUUID(), formats, skip, numRows, tableConfig);
 }
 protected String createSubPackage(String name, String description, String parentNode)
     throws SerializationException {
   log.info(
       "USER: "******" CREATING subPackage ["
           + name
           + "], parent ["
           + parentNode
           + "]");
   PackageItem item = rulesRepository.createSubPackage(name, description, parentNode);
   return item.getUUID();
 }
  private void archiveOrUnarchiveAsset(String uuid, boolean archive) {
    try {
      AssetItem item = getRulesRepository().loadAssetByUUID(uuid);

      serviceSecurity.checkSecurityIsPackageDeveloper(item);

      if (item.getPackage().isArchived()) {
        throw new RulesRepositoryException(
            "The package ["
                + item.getPackageName()
                + "] that asset ["
                + item.getName()
                + "] belongs to is archived. You need to unarchive it first.");
      }

      log.info(
          "USER:"******" ARCHIVING asset: ["
              + item.getName()
              + "] UUID: ["
              + item.getUUID()
              + "] ");

      try {
        ContentHandler handler = getContentHandler(item);
        if (handler instanceof ICanHasAttachment) {
          ((ICanHasAttachment) handler).onAttachmentRemoved(item);
        }
      } catch (IOException e) {
        log.error("Unable to remove asset attachment", e);
      }

      item.archiveItem(archive);
      PackageItem pkg = item.getPackage();
      pkg.updateBinaryUpToDate(false);
      RuleBaseCache.getInstance().remove(pkg.getUUID());
      if (archive) {
        item.checkin("archived");
      } else {
        item.checkin("unarchived");
      }

      push("packageChange", pkg.getName());

    } catch (RulesRepositoryException e) {
      log.error("Unable to get item format.", e);
      throw e;
    }
  }
  private void handleIteratePackages(
      boolean archive,
      String workspace,
      RepositoryFilter filter,
      List<PackageConfigData> result,
      PackageIterator pkgs) {
    pkgs.setArchivedIterator(archive);
    while (pkgs.hasNext()) {
      PackageItem packageItem = pkgs.next();

      PackageConfigData data = new PackageConfigData();
      data.setUuid(packageItem.getUUID());
      data.setName(packageItem.getName());
      data.setArchived(packageItem.isArchived());
      data.setWorkspaces(packageItem.getWorkspaces());
      handleIsPackagesListed(archive, workspace, filter, result, data);

      data.subPackages = listSubPackages(packageItem, archive, null, filter);
    }
  }
  @WebRemote
  @Restrict("#{identity.loggedIn}")
  public void changePackageState(String uuid, String newState) {

    serviceSecurity.checkSecurityIsPackageDeveloper(uuid);

    PackageItem pkg = getRulesRepository().loadPackageByUUID(uuid);
    log.info(
        "USER:"******" CHANGING Package STATUS. Asset name, uuid: "
            + "["
            + pkg.getName()
            + ", "
            + pkg.getUUID()
            + "]"
            + " to ["
            + newState
            + "]");
    pkg.changeStatus(newState);

    getRulesRepository().save();
  }