/** * 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()); } }
private static List<MultiViewRow> createRows(Asset[] assets) { List<MultiViewRow> rows = new ArrayList<MultiViewRow>(); for (Asset ruleAsset : assets) { MultiViewRow row = new MultiViewRow(ruleAsset.getUuid(), ruleAsset.getName(), AssetFormats.BUSINESS_RULE); rows.add(row); } return rows; }
public void migrate(Module jcrModule, Asset jcrAsset) { if (!AssetFormats.DSL.equals(jcrAsset.getFormat()) && !AssetFormats.DSL_TEMPLATE_RULE.equals(jcrAsset.getFormat())) { throw new IllegalArgumentException( "The jcrAsset (" + jcrAsset + ") has the wrong format (" + jcrAsset.getFormat() + ")."); } Path path = migrationPathManager.generatePathForAsset(jcrModule, jcrAsset); enumService.save(path, ((RuleContentText) jcrAsset.getContent()).content, null, ""); }
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; }
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); }
public TemporalBRLAssetVerifier(Verifier verifier, Asset ruleAsset, ModuleItem packageItem) { super(verifier, packageItem); if (!ruleAsset.getFormat().equals(AssetFormats.BUSINESS_RULE)) { throw new IllegalStateException( "Unexpected format " + ruleAsset.getFormat() + "! Only " + AssetFormats.BUSINESS_RULE + " expected!"); } this.verifier = verifier; this.ruleAsset = ruleAsset; }
@WebRemote @LoggedIn public String checkinVersion(Asset asset) throws SerializationException { serviceSecurity.checkIsPackageDeveloperOrAnalyst(asset); log.info( "USER:"******" CHECKING IN asset: [" + asset.getName() + "] UUID: [" + asset.getUuid() + "] "); return repositoryAssetOperations.checkinVersion(asset); }
private void addRuleViewInToSimplePanel( final MultiViewRow row, final SimplePanel content, final Asset asset) { eventBus.fireEvent( new RefreshModuleDataModelEvent( asset.getMetaData().getModuleName(), new Command() { public void execute() { RuleViewerSettings ruleViewerSettings = new RuleViewerSettings(); ruleViewerSettings.setDocoVisible(false); ruleViewerSettings.setMetaVisible(false); ruleViewerSettings.setStandalone(true); Command closeCommand = new Command() { public void execute() { // TODO: No handle for this -Rikkola- ruleViews.remove(row.getUuid()); rows.remove(row); doViews(); } }; final RuleViewer ruleViewer = new RuleViewer(asset, clientFactory, eventBus, ruleViewerSettings); // ruleViewer.setDocoVisible( showDescription ); // ruleViewer.setMetaVisible( showMetadata ); content.add(ruleViewer); ruleViewer.setWidth("100%"); ruleViewer.setHeight("100%"); ruleViews.put(row.getUuid(), ruleViewer); } })); }
public void doCheckin(Widget editor, Asset asset, String comment, boolean closeAfter) { if (editor instanceof SaveEventListener) { ((SaveEventListener) editor).onSave(); } performCheckIn(comment, closeAfter, asset); if (editor instanceof SaveEventListener) { ((SaveEventListener) editor).onAfterSave(); } eventBus.fireEvent(new RefreshModuleEditorEvent(asset.getMetaData().getModuleUUID())); // lastSaved = System.currentTimeMillis(); // resetDirty(); }
/** * This actually does the hard work of loading up an asset based on its format. * * <p>Role-based Authorization check: This method can be accessed if user has following * permissions: 1. The user has a ANALYST_READ role or higher (i.e., ANALYST) and this role has * permission to access the category which the asset belongs to. Or. 2. The user has a * package.readonly role or higher (i.e., package.admin, package.developer) and this role has * permission to access the package which the asset belongs to. */ @WebRemote @LoggedIn public Asset loadRuleAsset(String uuid) throws SerializationException { long time = System.currentTimeMillis(); AssetItem item = rulesRepository.loadAssetByUUID(uuid); Asset asset = new AssetPopulator().populateFrom(item); asset.setMetaData(repositoryAssetOperations.populateMetaData(item)); serviceSecurity.checkIsPackageReadOnlyOrAnalystReadOnly(asset); ModuleItem pkgItem = handlePackageItem(item, asset); log.debug( "Package: " + pkgItem.getName() + ", asset: " + item.getName() + ". Load time taken for asset: " + (System.currentTimeMillis() - time)); UserInbox.recordOpeningEvent(item); return asset; }
/** * In some cases we will want to flush the package dependency stuff for suggestion completions. * The user will still need to reload the asset editor though. */ public void flushSuggestionCompletionCache(final String packageName, Asset asset) { if (AssetFormats.isPackageDependency(asset.getFormat())) { LoadingPopup.showMessage(constants.RefreshingContentAssistance()); eventBus.fireEvent( new RefreshModuleDataModelEvent( packageName, new Command() { public void execute() { // Some assets depend on the SuggestionCompletionEngine. This event is to notify // them that the // SuggestionCompletionEngine has been changed, they need to refresh their UI to // represent the changes. eventBus.fireEvent(new RefreshSuggestionCompletionEngineEvent(packageName)); LoadingPopup.close(); } })); } }
private void performCheckIn(String comment, final boolean closeAfter, final Asset asset) { asset.setCheckinComment(comment); final boolean[] saved = {false}; if (!saved[0]) LoadingPopup.showMessage(constants.SavingPleaseWait()); RepositoryServiceFactory.getAssetService() .checkinVersion( asset, new GenericCallback<String>() { public void onSuccess(String uuid) { if (uuid == null) { ErrorPopup.showMessage( constants.FailedToCheckInTheItemPleaseContactYourSystemAdministrator()); return; } if (uuid.startsWith("ERR")) { // NON-NLS ErrorPopup.showMessage(uuid.substring(5)); return; } flushSuggestionCompletionCache(asset.getMetaData().getModuleName(), asset); /* if ( editor instanceof DirtyableComposite ) { ((DirtyableComposite) editor).resetDirty(); }*/ LoadingPopup.close(); saved[0] = true; // showInfoMessage( constants.SavedOK() ); if (!closeAfter) { eventBus.fireEvent( new RefreshAssetEditorEvent(asset.getMetaData().getModuleName(), uuid)); } // fire after check-in event eventBus.fireEvent(new AfterAssetEditorCheckInEvent(uuid, MultiViewEditor.this)); } }); }
public EnumEditor(Asset a, int visibleLines) { data = (RuleContentText) a.getContent(); if (data.content == null) { data.content = ""; } cellTable = new CellTable<EnumRow>(); cellTable.setWidth("100%"); panel = new VerticalPanel(); String[] array = data.content.split("\n"); for (String line : array) { EnumRow enumRow = new EnumRow(line); dataProvider.getList().add(enumRow); } DeleteButtonCell deleteButton = new DeleteButtonCell(); Column<EnumRow, String> delete = new Column<EnumRow, String>(deleteButton) { @Override public String getValue(EnumRow enumRow1) { return ""; } }; Column<EnumRow, String> columnFirst = new Column<EnumRow, String>(new EditTextCell()) { @Override public String getValue(EnumRow enumRow) { return enumRow.getFactName(); } }; Column<EnumRow, String> columnSecond = new Column<EnumRow, String>(new EditTextCell()) { @Override public String getValue(EnumRow enumRow) { return enumRow.getFieldName(); } }; Column<EnumRow, String> columnThird = new Column<EnumRow, String>(new EditTextCell()) { @Override public String getValue(EnumRow enumRow) { return enumRow.getContext(); } }; columnFirst.setFieldUpdater( new FieldUpdater<EnumRow, String>() { public void update(int index, EnumRow object, String value) { object.setFactName(value); } }); columnSecond.setFieldUpdater( new FieldUpdater<EnumRow, String>() { public void update(int index, EnumRow object, String value) { object.setFieldName(value); } }); columnThird.setFieldUpdater( new FieldUpdater<EnumRow, String>() { public void update(int index, EnumRow object, String value) { object.setContext(value); } }); cellTable.addColumn(delete); cellTable.addColumn(columnFirst, "Fact"); cellTable.addColumn(columnSecond, "Field"); cellTable.addColumn(columnThird, "Context"); // Connect the table to the data provider. dataProvider.addDataDisplay(cellTable); delete.setFieldUpdater( new FieldUpdater<EnumRow, String>() { public void update(int index, EnumRow object, String value) { dataProvider.getList().remove(object); } }); Button addButton = new Button( "+", new ClickHandler() { public void onClick(ClickEvent clickEvent) { EnumRow enumRow = new EnumRow(""); dataProvider.getList().add(enumRow); } }); panel.add(cellTable); panel.add(addButton); initWidget(panel); }
private boolean isValidatorTypeAsset() { return isMemberOfFormats(asset.getFormat(), VALIDATING_FORMATS); }
public boolean showViewSourceButton() { return isMemberOfFormats(asset.getFormat(), SOURCE_FORMATS); }
private void addAssets(Asset[] assets) { for (Asset ruleAsset : assets) { this.assets.put(ruleAsset.getUuid(), ruleAsset); } }
private boolean isVerificationTypeAsset() { return isMemberOfFormats(asset.getFormat(), VERIFY_FORMATS); }
public boolean showArchiveButton() { return asset.getVersionNumber() != 0; }
public boolean showDeleteButton() { return asset.getVersionNumber() == 0; }
private boolean isAssetDecisionTable(Asset ruleAsset) { return AssetFormats.DECISION_TABLE_GUIDED.equals(ruleAsset.getFormat()) || AssetFormats.DECISION_SPREADSHEET_XLS.equals(ruleAsset.getFormat()); }
public ModelAttachmentFileWidget( Asset asset, RuleViewer viewer, ClientFactory clientFactory, EventBus eventBus) { super(asset, viewer, clientFactory, eventBus); this.packageName = asset.getMetaData().getPackageName(); }
public boolean showSelectWorkingSetsButton() { return BUSINESS_RULE.equals(asset.getFormat()) || RULE_TEMPLATE.equals(asset.getFormat()); }