Exemplo n.º 1
0
  /**
   * This will create a new asset. It will be saved, but not checked in. The initial state will be
   * the draft state. Returns the UUID of the asset.
   */
  public String createNewRule(
      NewAssetWithContentConfiguration<? extends PortableObject> configuration)
      throws SerializationException {

    final String assetName = configuration.getAssetName();
    final String description = configuration.getDescription();
    final String initialCategory = configuration.getInitialCategory();
    final String packageName = configuration.getPackageName();
    final String format = configuration.getFormat();
    final PortableObject content = configuration.getContent();

    log.info(
        "USER:"******" CREATING new asset name ["
            + assetName
            + "] in package ["
            + packageName
            + "]");

    try {

      // Create new Asset
      ModuleItem pkg = rulesRepository.loadModule(packageName);
      AssetItem assetItem = pkg.addAsset(assetName, description, initialCategory, format);

      // Set the Assets content - no need to use AssetTemplateCreator().applyPreBuiltTemplates() as
      // we are provided a model
      // Use a transient Asset object so we can use ContentHandler to convert between model and
      // persisted format correctly.
      Asset asset = new AssetPopulator().populateFrom(assetItem);
      ContentHandler handler = ContentManager.getHandler(assetItem.getFormat());
      asset.setContent(content);
      handler.storeAssetContent(asset, assetItem);

      rulesRepository.save();

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

      return assetItem.getUUID();

    } catch (RulesRepositoryException e) {
      // If we want to display an explicit error message of "duplicate asset", we can achieve this
      // in client error handler.
      /*            if ( e.getCause() instanceof ItemExistsException ) {
          return "DUPLICATE";
      }*/
      log.error(
          "An error occurred creating new asset ["
              + assetName
              + "] in package ["
              + packageName
              + "]: ",
          e);
      throw new SerializationException(e.getMessage());
    }
  }
Exemplo n.º 2
0
  /**
   * This will create a new asset. It will be saved, but not checked in. The initial state will be
   * the draft state. Returns the UUID of the asset.
   */
  public String createNewRule(
      String ruleName,
      String description,
      String initialCategory,
      String initialPackage,
      String format)
      throws SerializationException {
    log.info(
        "USER:"******" CREATING new asset name ["
            + ruleName
            + "] in package ["
            + initialPackage
            + "]");

    try {

      ModuleItem pkg = rulesRepository.loadModule(initialPackage);
      AssetItem asset = pkg.addAsset(ruleName, description, initialCategory, format);

      new AssetTemplateCreator().applyPreBuiltTemplates(ruleName, format, asset);
      rulesRepository.save();

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

      return asset.getUUID();
    } catch (RulesRepositoryException e) {
      // If we want to display an explicit error message of "duplicate asset", we can achieve this
      // in client error handler.
      /*            if ( e.getCause() instanceof ItemExistsException ) {
          return "DUPLICATE";
      }*/
      log.error(
          "An error occurred creating new asset"
              + ruleName
              + "] in package ["
              + initialPackage
              + "]: ",
          e);
      throw new SerializationException(e.getMessage());
    }
  }
Exemplo n.º 3
0
  public void deleteUncheckedRule(String uuid) {
    AssetItem asset = rulesRepository.loadAssetByUUID(uuid);

    ModuleItem packageItem = asset.getModule();
    packageItem.updateBinaryUpToDate(false);

    asset.remove();

    rulesRepository.save();
    push("packageChange", packageItem.getName());
  }