Search in sources :

Example 26 with ActionFieldValue

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

the class RuleModelDRLPersistenceTest method getComplexModel.

private RuleModel getComplexModel(boolean useDsl) {
    final RuleModel m = new RuleModel();
    m.name = "Complex Rule";
    m.setPackageName("org.test");
    m.addAttribute(new RuleAttribute("no-loop", "true"));
    m.addAttribute(new RuleAttribute("salience", "-10"));
    m.addAttribute(new RuleAttribute("agenda-group", "aGroup"));
    final FactPattern pat = new FactPattern("Person");
    pat.setBoundName("p1");
    final SingleFieldConstraint con = new SingleFieldConstraint();
    con.setFieldBinding("f1");
    con.setFieldName("age");
    con.setOperator("<");
    con.setValue("42");
    pat.addConstraint(con);
    m.addLhsItem(pat);
    final CompositeFactPattern comp = new CompositeFactPattern("not");
    comp.addFactPattern(new FactPattern("Cancel"));
    m.addLhsItem(comp);
    final ActionUpdateField upd1 = new ActionUpdateField();
    upd1.setVariable("p1");
    upd1.addFieldValue(new ActionFieldValue("status", "rejected", DataType.TYPE_STRING));
    upd1.addFieldValue(new ActionFieldValue("name", "Fred", DataType.TYPE_STRING));
    m.addRhsItem(upd1);
    final ActionRetractFact ret = new ActionRetractFact("p1");
    m.addRhsItem(ret);
    if (useDsl) {
        final DSLSentence sen = new DSLSentence();
        sen.setDefinition("Send an email to {administrator}");
        m.addRhsItem(sen);
    }
    addModelField("org.test.Person", "this", "org.test.Person", DataType.TYPE_THIS);
    addModelField("org.test.Person", "age", Integer.class.getName(), DataType.TYPE_NUMERIC_INTEGER);
    addModelField("org.test.Person", "status", String.class.getName(), DataType.TYPE_STRING);
    return m;
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) ActionRetractFact(org.drools.workbench.models.datamodel.rule.ActionRetractFact) ActionUpdateField(org.drools.workbench.models.datamodel.rule.ActionUpdateField) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) RuleAttribute(org.drools.workbench.models.datamodel.rule.RuleAttribute) 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) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) DSLSentence(org.drools.workbench.models.datamodel.rule.DSLSentence)

Example 27 with ActionFieldValue

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

the class RuleModelDRLPersistenceUnmarshallingI18NTest method testI18N_JP_InsertFact.

@Test
public void testI18N_JP_InsertFact() {
    final String drl = "package org.test;\n" + "rule \"r1\"\n" + "dialect \"mvel\"\n" + "when\n" + "then\n" + "帽子 fact0 = new 帽子();\n" + "fact0.setサイズ( 55 );\n" + "insert( fact0 );\n" + "end";
    addModelField("帽子", "サイズ", "java.lang.Integer", DataType.TYPE_NUMERIC_INTEGER);
    final RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, new ArrayList<String>(), dmo);
    assertNotNull(m);
    assertEquals(1, m.rhs.length);
    assertTrue(m.rhs[0] instanceof ActionInsertFact);
    final ActionInsertFact aif = (ActionInsertFact) m.rhs[0];
    assertEquals("帽子", aif.getFactType());
    assertEquals("fact0", aif.getBoundName());
    assertEquals(1, aif.getFieldValues().length);
    final ActionFieldValue afv = aif.getFieldValues()[0];
    assertEquals("サイズ", afv.getField());
    assertEquals("55", afv.getValue());
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, afv.getType());
    assertEquals(FieldNatureType.TYPE_LITERAL, afv.getNature());
}
Also used : ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 28 with ActionFieldValue

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

the class RuleModelDRLPersistenceUnmarshallingI18NTest method testI18N_US_InsertFact.

@Test
public void testI18N_US_InsertFact() {
    final String drl = "package org.test;\n" + "rule \"r1\"\n" + "dialect \"mvel\"\n" + "when\n" + "then\n" + "Applicant fact0 = new Applicant();\n" + "fact0.setAge( 55 );\n" + "insert( fact0 );\n" + "end";
    addModelField("Applicant", "age", "java.lang.Integer", DataType.TYPE_NUMERIC_INTEGER);
    final RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, new ArrayList<String>(), dmo);
    assertNotNull(m);
    assertEquals(1, m.rhs.length);
    assertTrue(m.rhs[0] instanceof ActionInsertFact);
    final ActionInsertFact aif = (ActionInsertFact) m.rhs[0];
    assertEquals("Applicant", aif.getFactType());
    assertEquals("fact0", aif.getBoundName());
    assertEquals(1, aif.getFieldValues().length);
    final ActionFieldValue afv = aif.getFieldValues()[0];
    assertEquals("age", afv.getField());
    assertEquals("55", afv.getValue());
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, afv.getType());
    assertEquals(FieldNatureType.TYPE_LITERAL, afv.getNature());
}
Also used : ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 29 with ActionFieldValue

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

the class GuidedDTDRLPersistence method doAction.

private void doAction(List<LabelledAction> actions, ActionSetFieldCol52 sf, String cell) {
    LabelledAction a = findByLabelledAction(actions, sf.getBoundName(), sf.isUpdate());
    if (a == null) {
        a = new LabelledAction();
        a.boundName = sf.getBoundName();
        a.isUpdate = sf.isUpdate();
        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;
    ActionFieldValue val = new ActionFieldValue(sf.getFactField(), cell, sf.getType());
    asf.addFieldValue(val);
}
Also used : ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) ActionUpdateField(org.drools.workbench.models.datamodel.rule.ActionUpdateField) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue)

Example 30 with ActionFieldValue

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

the class GuidedDTDRLPersistence method doAction.

private void doAction(List<LabelledAction> actions, ActionInsertFactCol52 ac, String 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;
    ActionFieldValue val = new ActionFieldValue(ac.getFactField(), cell, ac.getType());
    ins.addFieldValue(val);
}
Also used : ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) ActionInsertLogicalFact(org.drools.workbench.models.datamodel.rule.ActionInsertLogicalFact)

Aggregations

ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)136 Test (org.junit.Test)113 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)71 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)71 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)65 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)63 ActionUpdateField (org.drools.workbench.models.datamodel.rule.ActionUpdateField)53 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)48 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)41 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)41 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)33 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)30 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)28 TemplateModel (org.drools.workbench.models.guided.template.shared.TemplateModel)26 IAction (org.drools.workbench.models.datamodel.rule.IAction)25 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)24 ActionSetField (org.drools.workbench.models.datamodel.rule.ActionSetField)23 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)23 BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)21 ArrayList (java.util.ArrayList)19