Search in sources :

Example 1 with RuleMetadata

use of org.drools.workbench.models.datamodel.rule.RuleMetadata in project drools by kiegroup.

the class RuleModelTest method testMetaData.

@Test
public void testMetaData() {
    final RuleModel m = new RuleModel();
    final RuleMetadata rm = new RuleMetadata("foo", "bar");
    // test add
    m.addMetadata(rm);
    assertEquals(1, m.metadataList.length);
    assertEquals(rm, m.metadataList[0]);
    // should be able to find it
    RuleMetadata gm = m.getMetaData("foo");
    assertNotNull(gm);
    // test add and remove
    final RuleMetadata rm2 = new RuleMetadata("foo2", "bar2");
    m.addMetadata(rm2);
    assertEquals(2, m.metadataList.length);
    assertEquals(rm2, m.metadataList[1]);
    assertEquals("@foo(bar)", rm.toString());
    m.removeMetadata(0);
    assertEquals(1, m.metadataList.length);
    assertEquals(rm2, m.metadataList[0]);
    assertEquals("@foo2(bar2)", (m.metadataList[0]).toString());
    // should be able to find it now that it was removed
    gm = m.getMetaData("foo");
    assertNull(gm);
    // test add via update method
    m.updateMetadata(rm);
    gm = m.getMetaData("foo");
    assertNotNull(gm);
    // test update of existing element
    rm.setValue("bar2");
    m.updateMetadata(rm);
    gm = m.getMetaData("foo");
    assertNotNull(gm);
    assertEquals("bar2", gm.getValue());
}
Also used : RuleMetadata(org.drools.workbench.models.datamodel.rule.RuleMetadata) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 2 with RuleMetadata

use of org.drools.workbench.models.datamodel.rule.RuleMetadata in project drools by kiegroup.

the class RuleModelDRLPersistenceImpl method getRuleModel.

private RuleModel getRuleModel(final ExpandedDRLInfo expandedDRLInfo, final PackageDataModelOracle dmo, final Collection<RuleModelIActionPersistenceExtension> extensions) throws RuleModelDRLPersistenceException {
    // De-serialize model
    RuleDescr ruleDescr = parseDrl(expandedDRLInfo);
    RuleModel model = new RuleModel();
    model.name = ruleDescr.getName();
    model.parentName = ruleDescr.getParentName();
    for (AnnotationDescr annotation : ruleDescr.getAnnotations()) {
        model.addMetadata(new RuleMetadata(annotation.getName(), annotation.getValuesAsString()));
    }
    // De-serialize Package name
    final String packageName = PackageNameParser.parsePackageName(expandedDRLInfo.plainDrl);
    model.setPackageName(packageName);
    // De-serialize imports
    final Imports imports = ImportsParser.parseImports(expandedDRLInfo.plainDrl);
    for (Import item : imports.getImports()) {
        model.getImports().addImport(item);
    }
    boolean isJavaDialect = parseAttributes(model, ruleDescr.getAttributes());
    Map<String, String> boundParams = parseLhs(model, ruleDescr.getLhs(), isJavaDialect, expandedDRLInfo, dmo);
    parseRhs(model, expandedDRLInfo.consequence != null ? expandedDRLInfo.consequence : (String) ruleDescr.getConsequence(), isJavaDialect, boundParams, expandedDRLInfo, dmo, extensions);
    return model;
}
Also used : Import(org.kie.soup.project.datamodel.imports.Import) RuleDescr(org.drools.compiler.lang.descr.RuleDescr) RuleMetadata(org.drools.workbench.models.datamodel.rule.RuleMetadata) Imports(org.kie.soup.project.datamodel.imports.Imports) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) AnnotationDescr(org.drools.compiler.lang.descr.AnnotationDescr)

Example 3 with RuleMetadata

use of org.drools.workbench.models.datamodel.rule.RuleMetadata in project drools by kiegroup.

the class GuidedDTDRLPersistence method doMetadata.

void doMetadata(List<BaseColumn> allColumns, List<MetadataCol52> metadataCols, List<DTCellValue52> row, RuleModel rm) {
    // setup temp list
    List<RuleMetadata> metadataList = new ArrayList<RuleMetadata>();
    for (int j = 0; j < metadataCols.size(); j++) {
        MetadataCol52 meta = metadataCols.get(j);
        int index = allColumns.indexOf(meta);
        final DTCellValue52 dcv = row.get(index);
        String cell = GuidedDTDRLUtilities.convertDTCellValueToString(dcv);
        if (validateMetadataCell(cell)) {
            metadataList.add(new RuleMetadata(meta.getMetadata(), cell));
        }
    }
    if (metadataList.size() > 0) {
        rm.metadataList = metadataList.toArray(new RuleMetadata[metadataList.size()]);
    }
}
Also used : MetadataCol52(org.drools.workbench.models.guided.dtable.shared.model.MetadataCol52) ArrayList(java.util.ArrayList) RuleMetadata(org.drools.workbench.models.datamodel.rule.RuleMetadata) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)

Example 4 with RuleMetadata

use of org.drools.workbench.models.datamodel.rule.RuleMetadata in project drools-wb by kiegroup.

the class RuleModelCloneVisitor method visitRuleMetadata.

private RuleMetadata visitRuleMetadata(RuleMetadata md) {
    RuleMetadata clone = new RuleMetadata();
    clone.setAttributeName(md.getAttributeName());
    clone.setValue(md.getValue());
    return clone;
}
Also used : RuleMetadata(org.drools.workbench.models.datamodel.rule.RuleMetadata)

Example 5 with RuleMetadata

use of org.drools.workbench.models.datamodel.rule.RuleMetadata in project drools-wb by kiegroup.

the class RuleModelCloneVisitor method visitRuleModel.

public RuleModel visitRuleModel(RuleModel model) {
    RuleModel clone = new RuleModel();
    clone.modelVersion = model.modelVersion;
    clone.name = model.name;
    clone.parentName = model.parentName;
    clone.setNegated(model.isNegated());
    if (model.attributes != null) {
        clone.attributes = new RuleAttribute[model.attributes.length];
        for (int i = 0; i < model.attributes.length; i++) {
            RuleAttribute attr = model.attributes[i];
            clone.attributes[i] = (RuleAttribute) visit(attr);
        }
    }
    if (model.metadataList != null) {
        clone.metadataList = new RuleMetadata[model.metadataList.length];
        for (int i = 0; i < model.metadataList.length; i++) {
            RuleMetadata md = model.metadataList[i];
            clone.metadataList[i] = (RuleMetadata) visit(md);
        }
    }
    if (model.lhs != null) {
        clone.lhs = new IPattern[model.lhs.length];
        for (int i = 0; i < model.lhs.length; i++) {
            IPattern pattern = model.lhs[i];
            clone.lhs[i] = (IPattern) visit(pattern);
        }
    }
    if (model.rhs != null) {
        clone.rhs = new IAction[model.rhs.length];
        for (int i = 0; i < model.rhs.length; i++) {
            IAction action = model.rhs[i];
            clone.rhs[i] = (IAction) visit(action);
        }
    }
    return clone;
}
Also used : IPattern(org.drools.workbench.models.datamodel.rule.IPattern) IAction(org.drools.workbench.models.datamodel.rule.IAction) RuleAttribute(org.drools.workbench.models.datamodel.rule.RuleAttribute) RuleMetadata(org.drools.workbench.models.datamodel.rule.RuleMetadata) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint)

Aggregations

RuleMetadata (org.drools.workbench.models.datamodel.rule.RuleMetadata)9 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)5 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)2 CompositeFieldConstraint (org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint)2 FieldConstraint (org.drools.workbench.models.datamodel.rule.FieldConstraint)2 IAction (org.drools.workbench.models.datamodel.rule.IAction)2 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)2 RuleAttribute (org.drools.workbench.models.datamodel.rule.RuleAttribute)2 MetadataCol52 (org.drools.workbench.models.guided.dtable.shared.model.MetadataCol52)2 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 AnnotationDescr (org.drools.compiler.lang.descr.AnnotationDescr)1 RuleDescr (org.drools.compiler.lang.descr.RuleDescr)1 ActionCallMethod (org.drools.workbench.models.datamodel.rule.ActionCallMethod)1 ActionFieldFunction (org.drools.workbench.models.datamodel.rule.ActionFieldFunction)1 ActionGlobalCollectionAdd (org.drools.workbench.models.datamodel.rule.ActionGlobalCollectionAdd)1 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)1 ActionRetractFact (org.drools.workbench.models.datamodel.rule.ActionRetractFact)1