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());
}
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;
}
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()]);
}
}
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;
}
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;
}
Aggregations