public void storeAssetContent(RuleAsset asset, AssetItem repoAsset) throws SerializationException { RuleModel data = (RuleModel) asset.getContent(); if (data.name == null) { data.name = repoAsset.getName(); } repoAsset.updateContent(getBrlXmlPersistence().marshal(data)); }
@Test public void testStore() throws Exception { FactModelContentHandler ch = new FactModelContentHandler(); RulesRepository repo = rulesRepository; PackageItem pkg = repo.loadDefaultPackage(); AssetItem asset = pkg.addAsset("testDeclaredTypeStore", ""); asset.updateFormat("model.drl"); asset.updateContent("declare Foo\n name: String\n end"); asset.checkin(""); RuleAsset ass = new RuleAsset(); ch.retrieveAssetContent(ass, asset); assertTrue(ass.getContent() instanceof FactModels); FactModels fm = (FactModels) ass.getContent(); assertEquals(1, fm.models.size()); FactMetaModel mm = (FactMetaModel) fm.models.get(0); assertEquals(1, mm.getFields().size()); assertEquals("Foo", mm.getName()); FieldMetaModel fmm = (FieldMetaModel) mm.getFields().get(0); assertEquals("name", fmm.name); mm.getFields().add(new FieldMetaModel("age", "int")); ch.storeAssetContent(ass, asset); assertTrue(asset.getContent().indexOf("age: int") > -1); asset.updateContent("rubbish here"); asset.checkin(""); ch.retrieveAssetContent(ass, asset); assertTrue(ass.getContent() instanceof RuleContentText); ch.storeAssetContent(ass, asset); assertEquals("rubbish here", asset.getContent()); }
public void onSave() { try { String s = callSave( ((IFrameElement) ((com.google.gwt.dom.client.Element) frame.getElement())) .getContentDocument()); String p = callPreprocessingData( ((IFrameElement) ((com.google.gwt.dom.client.Element) frame.getElement())) .getContentDocument()); if (asset.getContent() == null) { asset.setContent(new RuleFlowContentModel()); } ((RuleFlowContentModel) asset.getContent()).setXml(null); ((RuleFlowContentModel) asset.getContent()).setJson(s); ((RuleFlowContentModel) asset.getContent()).setPreprocessingdata(p); } catch (Exception e) { GWT.log("JSNI method callSave() threw an exception:", e); Window.alert("JSNI method callSave() threw an exception: " + e); } }
public DefaultRuleContentWidget(RuleAsset a, int visibleLines) { asset = a; data = (RuleContentText) asset.getContent(); if (data.content == null) { data.content = ""; } text = new TextArea(); text.setWidth("100%"); text.setVisibleLines((visibleLines == -1) ? 16 : visibleLines); text.setText(data.content); text.getElement().setAttribute("spellcheck", "false"); // NON-NLS text.setStyleName("default-text-Area"); // NON-NLS text.addChangeHandler( new ChangeHandler() { public void onChange(ChangeEvent event) { data.content = text.getText(); makeDirty(); } }); text.addKeyDownHandler( new KeyDownHandler() { public void onKeyDown(KeyDownEvent event) { if (event.getNativeKeyCode() == KeyCodes.KEY_TAB) { int pos = text.getCursorPos(); insertText("\t"); text.setCursorPos(pos + 1); text.cancelKey(); text.setFocus(true); } } }); initWidget(text); }
private List<String> applyWorkingSets(Set<String> activeWorkingSets) throws SerializationException { if (activeWorkingSets == null) { return new LinkedList<String>(); } RuleAsset[] workingSets = getAssetService() .loadRuleAssets(activeWorkingSets.toArray(new String[activeWorkingSets.size()])); List<String> constraintRules = new LinkedList<String>(); if (workingSets != null) { for (RuleAsset workingSet : workingSets) { WorkingSetConfigData wsConfig = (WorkingSetConfigData) workingSet.getContent(); if (wsConfig.constraints != null) { for (ConstraintConfiguration config : wsConfig.constraints) { constraintRules.add(ConstraintsFactory.getInstance().getVerifierRule(config)); } } } } return constraintRules; }
public XmlFileWidget(final RuleAsset asset, final RuleViewer viewer) { super(asset, viewer); data = (RuleContentText) asset.getContent(); if (data.content == null) { data.content = ""; } text = new TextArea(); text.setWidth("100%"); text.setVisibleLines(16); text.setText(data.content); text.setStyleName("default-text-Area"); text.addChangeHandler( new ChangeHandler() { public void onChange(ChangeEvent event) { data.content = text.getText(); } }); layout.addRow(text); }
public WorkitemDefinitionEditor(RuleAsset a, int visibleLines) { asset = a; data = (RuleContentText) asset.getContent(); if (data.content == null) { data.content = "Empty!"; } Grid layout = new Grid(1, 2); WorkitemDefinitionElementsBrowser browser = new WorkitemDefinitionElementsBrowser( new WorkitemDefinitionElementSelectedListener() { public void onElementSelected(String elementName, String pasteValue) { insertText(pasteValue, true); } }); layout.setWidget(0, 0, browser); text = new TextArea(); text.setWidth("100%"); text.setVisibleLines((visibleLines == -1) ? 25 : visibleLines); text.setText(data.content); text.getElement().setAttribute("spellcheck", "false"); // NON-NLS text.setStyleName("default-text-Area"); // NON-NLS text.addChangeHandler( new ChangeHandler() { public void onChange(ChangeEvent event) { data.content = text.getText(); makeDirty(); } }); text.addKeyDownHandler( new KeyDownHandler() { public void onKeyDown(KeyDownEvent event) { if (event.getNativeKeyCode() == KeyCodes.KEY_TAB) { event.preventDefault(); event.stopPropagation(); int pos = text.getCursorPos(); insertText("\t", false); text.setCursorPos(pos + 1); text.cancelKey(); text.setFocus(true); } } }); layout.setWidget(0, 1, text); layout.getColumnFormatter().setWidth(0, "10%"); layout.getColumnFormatter().setWidth(1, "90%"); layout .getCellFormatter() .setAlignment(0, 0, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP); layout .getCellFormatter() .setAlignment(0, 1, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP); layout.setWidth("95%"); initWidget(layout); }
public void assembleDRL( BRMSPackageBuilder builder, RuleAsset asset, StringBuilder stringBuilder) { String drl = getSourceDRL((RuleModel) asset.getContent(), builder); stringBuilder.append(drl); }
public void compile(BRMSPackageBuilder builder, RuleAsset asset, AssemblyErrorLogger logger) throws DroolsParserException, IOException { builder.addPackageFromDrl( new StringReader(getSourceDRL((RuleModel) asset.getContent(), builder))); }