Search in sources :

Example 1 with ActionWorkItemFieldValue

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;
}
Also used : ActionWorkItemFieldValue(org.drools.workbench.models.datamodel.rule.ActionWorkItemFieldValue) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)

Example 2 with ActionWorkItemFieldValue

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);
}
Also used : PortableIntegerParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableIntegerParameterDefinition) ActionWorkItemFieldValue(org.drools.workbench.models.datamodel.rule.ActionWorkItemFieldValue) PortableFloatParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableFloatParameterDefinition) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) PortableStringParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableStringParameterDefinition) ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) PortableWorkDefinition(org.drools.workbench.models.datamodel.workitems.PortableWorkDefinition) PortableBooleanParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableBooleanParameterDefinition) ActionExecuteWorkItem(org.drools.workbench.models.datamodel.rule.ActionExecuteWorkItem) Test(org.junit.Test)

Example 3 with ActionWorkItemFieldValue

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);
    }
}
Also used : ActionWorkItemFieldValue(org.drools.workbench.models.datamodel.rule.ActionWorkItemFieldValue) ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) ActionUpdateField(org.drools.workbench.models.datamodel.rule.ActionUpdateField)

Example 4 with ActionWorkItemFieldValue

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);
    }
}
Also used : ActionWorkItemFieldValue(org.drools.workbench.models.datamodel.rule.ActionWorkItemFieldValue) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) ActionInsertLogicalFact(org.drools.workbench.models.datamodel.rule.ActionInsertLogicalFact)

Example 5 with ActionWorkItemFieldValue

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);
}
Also used : PortableIntegerParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableIntegerParameterDefinition) ActionWorkItemFieldValue(org.drools.workbench.models.datamodel.rule.ActionWorkItemFieldValue) PortableFloatParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableFloatParameterDefinition) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) PortableStringParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableStringParameterDefinition) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) PortableWorkDefinition(org.drools.workbench.models.datamodel.workitems.PortableWorkDefinition) PortableBooleanParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableBooleanParameterDefinition) ActionExecuteWorkItem(org.drools.workbench.models.datamodel.rule.ActionExecuteWorkItem) Test(org.junit.Test)

Aggregations

ActionWorkItemFieldValue (org.drools.workbench.models.datamodel.rule.ActionWorkItemFieldValue)9 ActionExecuteWorkItem (org.drools.workbench.models.datamodel.rule.ActionExecuteWorkItem)6 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)6 PortableBooleanParameterDefinition (org.drools.workbench.models.datamodel.workitems.PortableBooleanParameterDefinition)6 PortableFloatParameterDefinition (org.drools.workbench.models.datamodel.workitems.PortableFloatParameterDefinition)6 PortableWorkDefinition (org.drools.workbench.models.datamodel.workitems.PortableWorkDefinition)6 Test (org.junit.Test)6 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)5 ArrayList (java.util.ArrayList)4 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)4 ActionSetField (org.drools.workbench.models.datamodel.rule.ActionSetField)4 PortableIntegerParameterDefinition (org.drools.workbench.models.datamodel.workitems.PortableIntegerParameterDefinition)4 PortableStringParameterDefinition (org.drools.workbench.models.datamodel.workitems.PortableStringParameterDefinition)4 GuidedDTTemplateDataProvider (org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider)4 TemplateDataProvider (org.drools.workbench.models.guided.dtable.backend.util.TemplateDataProvider)4 ActionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionCol52)4 ActionWorkItemCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemCol52)4 BaseColumn (org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)4 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)4 DescriptionCol52 (org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52)4