use of org.drools.workbench.models.datamodel.rule.ActionWorkItemFieldValue in project drools by kiegroup.
the class RuleModelDRLPersistenceImpl method buildFieldValue.
private ActionFieldValue buildFieldValue(final boolean isJavaDialect, String field, String value, final String dataType, final Map<String, String> boundParams) {
if (value.contains("wiWorkItem.getResult")) {
field = field.substring(0, 1).toUpperCase() + field.substring(1);
String wiParam = field.substring("Results".length());
if (wiParam.equals("BooleanResult")) {
return new ActionWorkItemFieldValue(field, DataType.TYPE_BOOLEAN, "WorkItem", wiParam, Boolean.class.getName());
} else if (wiParam.equals("StringResult")) {
return new ActionWorkItemFieldValue(field, DataType.TYPE_STRING, "WorkItem", wiParam, String.class.getName());
} else if (wiParam.equals("IntegerResult")) {
return new ActionWorkItemFieldValue(field, DataType.TYPE_NUMERIC_INTEGER, "WorkItem", wiParam, Integer.class.getName());
} else if (wiParam.equals("FloatResult")) {
return new ActionWorkItemFieldValue(field, DataType.TYPE_NUMERIC_FLOAT, "WorkItem", wiParam, Float.class.getName());
}
}
value = removeNumericSuffix(value, dataType);
final int fieldNature = inferFieldNature(dataType, value, boundParams, isJavaDialect);
// If the field is a formula don't adjust the param value
String paramValue = value;
switch(fieldNature) {
case FieldNatureType.TYPE_FORMULA:
break;
case FieldNatureType.TYPE_VARIABLE:
paramValue = "=" + paramValue;
break;
case FieldNatureType.TYPE_TEMPLATE:
paramValue = unwrapTemplateKey(value);
break;
default:
paramValue = adjustParam(dataType, value, boundParams, isJavaDialect);
}
ActionFieldValue fieldValue = new ActionFieldValue(field, paramValue, dataType);
fieldValue.setNature(fieldNature);
return fieldValue;
}
use of org.drools.workbench.models.datamodel.rule.ActionWorkItemFieldValue in project drools by kiegroup.
the class RuleModelDRLPersistenceTest method testRHSActionWorkItemSetFields.
@Test
public // Test that WorkItem Parameters can be used to set fields on existing Facts
void testRHSActionWorkItemSetFields() {
RuleModel m = new RuleModel();
m.name = "WorkItem";
FactPattern fp1 = new FactPattern("Results");
fp1.setBoundName("$r");
m.addLhsItem(fp1);
ActionExecuteWorkItem awi = new ActionExecuteWorkItem();
PortableWorkDefinition pwd = new PortableWorkDefinition();
pwd.setName("WorkItem");
awi.setWorkDefinition(pwd);
PortableBooleanParameterDefinition p1 = new PortableBooleanParameterDefinition();
p1.setName("BooleanResult");
pwd.addResult(p1);
PortableFloatParameterDefinition p2 = new PortableFloatParameterDefinition();
p2.setName("FloatResult");
pwd.addResult(p2);
PortableIntegerParameterDefinition p3 = new PortableIntegerParameterDefinition();
p3.setName("IntegerResult");
pwd.addResult(p3);
PortableStringParameterDefinition p4 = new PortableStringParameterDefinition();
p4.setName("StringResult");
pwd.addResult(p4);
m.addRhsItem(awi);
ActionSetField asf = new ActionSetField();
asf.setVariable("$r");
ActionWorkItemFieldValue fv1 = new ActionWorkItemFieldValue("ResultsBooleanResult", DataType.TYPE_BOOLEAN, "WorkItem", "BooleanResult", Boolean.class.getName());
asf.addFieldValue(fv1);
ActionWorkItemFieldValue fv2 = new ActionWorkItemFieldValue("ResultsFloatResult", DataType.TYPE_NUMERIC_FLOAT, "WorkItem", "FloatResult", Float.class.getName());
asf.addFieldValue(fv2);
ActionWorkItemFieldValue fv3 = new ActionWorkItemFieldValue("ResultsIntegerResult", DataType.TYPE_NUMERIC_INTEGER, "WorkItem", "IntegerResult", Integer.class.getName());
asf.addFieldValue(fv3);
ActionWorkItemFieldValue fv4 = new ActionWorkItemFieldValue("ResultsStringResult", DataType.TYPE_STRING, "WorkItem", "StringResult", String.class.getName());
asf.addFieldValue(fv4);
m.addRhsItem(asf);
String result = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
assertTrue(result.indexOf("org.drools.core.process.instance.WorkItemManager wim = (org.drools.core.process.instance.WorkItemManager) drools.getWorkingMemory().getWorkItemManager();") != -1);
assertTrue(result.indexOf("org.drools.core.process.instance.impl.WorkItemImpl wiWorkItem = new org.drools.core.process.instance.impl.WorkItemImpl();") != -1);
assertTrue(result.indexOf("$r.setResultsBooleanResult( (java.lang.Boolean) wiWorkItem.getResult( \"BooleanResult\" ) );") != -1);
assertTrue(result.indexOf("$r.setResultsFloatResult( (java.lang.Float) wiWorkItem.getResult( \"FloatResult\" ) );") != -1);
assertTrue(result.indexOf("$r.setResultsIntegerResult( (java.lang.Integer) wiWorkItem.getResult( \"IntegerResult\" ) );") != -1);
assertTrue(result.indexOf("$r.setResultsStringResult( (java.lang.String) wiWorkItem.getResult( \"StringResult\" ) );") != -1);
assertTrue(result.indexOf("wim.internalExecuteWorkItem( wiWorkItem );") != -1);
checkMarshalling(null, m);
}
use of org.drools.workbench.models.datamodel.rule.ActionWorkItemFieldValue in project drools by kiegroup.
the class GuidedDTDRLPersistence method doAction.
private void doAction(List<LabelledAction> actions, ActionWorkItemSetFieldCol52 sf, String cell) {
if (Boolean.TRUE.equals(Boolean.parseBoolean(cell))) {
LabelledAction a = findByLabelledAction(actions, sf.getBoundName());
if (a == null) {
a = new LabelledAction();
a.boundName = sf.getBoundName();
if (!sf.isUpdate()) {
a.action = new ActionSetField(sf.getBoundName());
} else {
a.action = new ActionUpdateField(sf.getBoundName());
}
actions.add(a);
} else if (sf.isUpdate() && !(a.action instanceof ActionUpdateField)) {
// lets swap it out for an update as the user has asked for it.
ActionSetField old = (ActionSetField) a.action;
ActionUpdateField update = new ActionUpdateField(sf.getBoundName());
update.setFieldValues(old.getFieldValues());
a.action = update;
}
ActionSetField asf = (ActionSetField) a.action;
ActionWorkItemFieldValue val = new ActionWorkItemFieldValue(sf.getFactField(), sf.getType(), sf.getWorkItemName(), sf.getWorkItemResultParameterName(), sf.getParameterClassName());
asf.addFieldValue(val);
}
}
use of org.drools.workbench.models.datamodel.rule.ActionWorkItemFieldValue in project drools by kiegroup.
the class GuidedDTDRLPersistence method doAction.
private void doAction(List<LabelledAction> actions, ActionWorkItemInsertFactCol52 ac, String cell) {
if (Boolean.TRUE.equals(Boolean.parseBoolean(cell))) {
LabelledAction a = findByLabelledAction(actions, ac.getBoundName());
if (a == null) {
a = new LabelledAction();
a.boundName = ac.getBoundName();
if (!ac.isInsertLogical()) {
ActionInsertFact ins = new ActionInsertFact(ac.getFactType());
ins.setBoundName(ac.getBoundName());
a.action = ins;
} else {
ActionInsertLogicalFact ins = new ActionInsertLogicalFact(ac.getFactType());
ins.setBoundName(ac.getBoundName());
a.action = ins;
}
actions.add(a);
}
ActionInsertFact ins = (ActionInsertFact) a.action;
ActionWorkItemFieldValue val = new ActionWorkItemFieldValue(ac.getFactField(), ac.getType(), ac.getWorkItemName(), ac.getWorkItemResultParameterName(), ac.getParameterClassName());
ins.addFieldValue(val);
}
}
use of org.drools.workbench.models.datamodel.rule.ActionWorkItemFieldValue in project drools by kiegroup.
the class RuleModelDRLPersistenceTest method testRHSActionWorkItemInsertFacts.
@Test
public // Test that WorkItem Parameters can be used to set fields on new Fact
void testRHSActionWorkItemInsertFacts() {
RuleModel m = new RuleModel();
m.name = "WorkItem";
ActionExecuteWorkItem awi = new ActionExecuteWorkItem();
PortableWorkDefinition pwd = new PortableWorkDefinition();
pwd.setName("WorkItem");
awi.setWorkDefinition(pwd);
PortableBooleanParameterDefinition p1 = new PortableBooleanParameterDefinition();
p1.setName("BooleanResult");
pwd.addResult(p1);
PortableFloatParameterDefinition p2 = new PortableFloatParameterDefinition();
p2.setName("FloatResult");
pwd.addResult(p2);
PortableIntegerParameterDefinition p3 = new PortableIntegerParameterDefinition();
p3.setName("IntegerResult");
pwd.addResult(p3);
PortableStringParameterDefinition p4 = new PortableStringParameterDefinition();
p4.setName("StringResult");
pwd.addResult(p4);
m.addRhsItem(awi);
ActionInsertFact aif = new ActionInsertFact();
aif.setBoundName("$r");
aif.setFactType("Results");
ActionWorkItemFieldValue fv1 = new ActionWorkItemFieldValue("ResultsBooleanResult", DataType.TYPE_BOOLEAN, "WorkItem", "BooleanResult", Boolean.class.getName());
aif.addFieldValue(fv1);
ActionWorkItemFieldValue fv2 = new ActionWorkItemFieldValue("ResultsFloatResult", DataType.TYPE_NUMERIC_FLOAT, "WorkItem", "FloatResult", Float.class.getName());
aif.addFieldValue(fv2);
ActionWorkItemFieldValue fv3 = new ActionWorkItemFieldValue("ResultsIntegerResult", DataType.TYPE_NUMERIC_INTEGER, "WorkItem", "IntegerResult", Integer.class.getName());
aif.addFieldValue(fv3);
ActionWorkItemFieldValue fv4 = new ActionWorkItemFieldValue("ResultsStringResult", DataType.TYPE_STRING, "WorkItem", "StringResult", String.class.getName());
aif.addFieldValue(fv4);
m.addRhsItem(aif);
String result = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
assertTrue(result.indexOf("org.drools.core.process.instance.WorkItemManager wim = (org.drools.core.process.instance.WorkItemManager) drools.getWorkingMemory().getWorkItemManager();") != -1);
assertTrue(result.indexOf("org.drools.core.process.instance.impl.WorkItemImpl wiWorkItem = new org.drools.core.process.instance.impl.WorkItemImpl();") != -1);
assertTrue(result.indexOf("Results $r = new Results();") != -1);
assertTrue(result.indexOf("$r.setResultsBooleanResult( (java.lang.Boolean) wiWorkItem.getResult( \"BooleanResult\" ) );") != -1);
assertTrue(result.indexOf("$r.setResultsFloatResult( (java.lang.Float) wiWorkItem.getResult( \"FloatResult\" ) );") != -1);
assertTrue(result.indexOf("$r.setResultsIntegerResult( (java.lang.Integer) wiWorkItem.getResult( \"IntegerResult\" ) );") != -1);
assertTrue(result.indexOf("$r.setResultsStringResult( (java.lang.String) wiWorkItem.getResult( \"StringResult\" ) );") != -1);
assertTrue(result.indexOf("insert( $r );") != -1);
checkMarshalling(null, m);
}
Aggregations