/** * 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()); } }
// The Asset is being effectively added to the target package so treat as though the Content is // being added private void attachmentAdded(AssetItem item) { ICanHasAttachment attachmentHandler = null; ContentHandler contentHandler = ContentManager.getHandler(item.getFormat()); if (contentHandler instanceof ICanHasAttachment) { attachmentHandler = (ICanHasAttachment) contentHandler; try { attachmentHandler.onAttachmentAdded(item); } catch (IOException ioe) { log.error("Unable to remove asset attachment", ioe); } } }
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; }
/** Builds assets that are "rule" assets (ie things that are not functions etc). */ protected void buildAsset(AssetItem asset) { ContentHandler contentHandler = ContentManager.getHandler(asset.getFormat()); if (contentHandler instanceof ICompilable && !asset.getDisabled()) { try { compile(asset, (ICompilable) contentHandler); } catch (DroolsParserException e) { errorLogger.addError(asset, e.getMessage()); throw new RulesRepositoryException(e); } catch (IOException e) { errorLogger.addError(asset, e.getMessage()); } } }
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; }
private void addRuleAssetToVerifier() { ContentHandler handler = ContentManager.getHandler(ruleAsset.getFormat()); if (!(handler instanceof IRuleAsset)) { throw new IllegalStateException("IRuleAsset Expected"); } RuleModel model = (RuleModel) ruleAsset.getContent(); String brl = BRXMLPersistence.getInstance().marshal(model); verifier.addResourcesToVerify( ResourceFactory.newByteArrayResource(brl.getBytes()), ResourceType.BRL); }
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); } } }
/** Builds assets that are "rule" assets (ie things that are not functions etc). */ private void buildAsset(AssetItem asset) { ContentHandler h = ContentManager.getHandler(asset.getFormat()); if (h instanceof IRuleAsset) { try { ((IRuleAsset) h).compile(builder, asset, new ErrorLogger()); if (builder.hasErrors()) { this.recordBuilderErrors(asset); // clear the errors, so we don't double report. builder.clearErrors(); } } catch (DroolsParserException e) { throw new RulesRepositoryException(e); } catch (IOException e) { throw new RulesRepositoryException(e); } } }
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(); }
private ContentHandler getContentHandler(AssetItem repoAsset) { return ContentManager.getHandler(repoAsset.getFormat()); }