コード例 #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());
    }
  }
コード例 #2
0
  private ModuleItem handlePackageItem(AssetItem item, Asset asset) throws SerializationException {
    ModuleItem packageItem = item.getModule();

    ContentHandler handler = ContentManager.getHandler(asset.getFormat());
    handler.retrieveAssetContent(asset, item);

    asset.setReadonly(asset.getMetaData().isHasSucceedingVersion() || asset.isArchived());

    if (packageItem.isSnapshot()) {
      asset.setReadonly(true);
    }
    return packageItem;
  }
コード例 #3
0
  private PackageItem handlePackageItem(AssetItem item, RuleAsset asset)
      throws SerializationException {
    PackageItem pkgItem = item.getPackage();

    ContentHandler handler = ContentManager.getHandler(asset.metaData.format);
    handler.retrieveAssetContent(asset, pkgItem, item);

    asset.isreadonly = asset.metaData.hasSucceedingVersion;

    if (pkgItem.isSnapshot()) {
      asset.isreadonly = true;
    }
    return pkgItem;
  }
コード例 #4
0
  private void addDRLRulesToVerifier() {

    AssetItemIterator rules = packageItem.listAssetsByFormat(AssetFormats.DRL);

    while (rules.hasNext()) {
      AssetItem rule = rules.next();

      ContentHandler contentHandler = ContentManager.getHandler(rule.getFormat());
      if (contentHandler.isRuleAsset()) {
        IRuleAsset ruleAsset = (IRuleAsset) contentHandler;
        String drl = ruleAsset.getRawDRL(rule);
        verifier.addResourcesToVerify(
            ResourceFactory.newReaderResource(new StringReader(drl)), ResourceType.DRL);
      }
    }
  }