public FieldConstraint asFieldConstraint(final RuleModel m, final FactPattern factPattern) { SingleFieldConstraint con = new SingleFieldConstraint(); con.setConstraintValueType(SingleFieldConstraint.TYPE_PREDICATE); con.setValue(expr); return con; } }
public void onClick(ClickEvent event) { SingleFieldConstraint con = new SingleFieldConstraint(); con.setConstraintValueType(SingleFieldConstraint.TYPE_PREDICATE); hasConstraints.addConstraint(con); modeller.refreshWidget(); popup.hide(); } });
public void onClick(ClickEvent event) { SingleFieldConstraint con = new SingleFieldConstraint(); con.setConstraintValueType(SingleFieldConstraint.TYPE_PREDICATE); fp.addConstraint(con); modeller.refreshWidget(); popup.hide(); } });
public void onClick(ClickEvent event) { SingleFieldConstraint con = new SingleFieldConstraint(); con.setConstraintValueType(SingleFieldConstraint.TYPE_PREDICATE); hasConstraints.addConstraint(con); modeller.refreshWidget(); popup.hide(); } });
public void onClick(ClickEvent event) { sfc.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL); sfc.setId(customFormPopUp.getFormId()); sfc.setValue(customFormPopUp.getFormValue()); doTypeChosen(customFormPopUp); } });
public void onClick(ClickEvent event) { sfc.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL); sfc.setId(customFormPopUp.getFormId()); sfc.setValue(customFormPopUp.getFormValue()); doTypeChosen(customFormPopUp); } });
public void onClick(ClickEvent event) { SingleFieldConstraint con = new SingleFieldConstraint(); con.setConstraintValueType(SingleFieldConstraint.TYPE_PREDICATE); fp.addConstraint(con); modeller.refreshWidget(); popup.hide(); } });
public void onExpressionTypeChanged(ExpressionTypeChangeEvent event) { try { //Change "operator" drop-down as the content depends on data-type constraint.setFieldType(event.getNewType()); inner.setWidget(row, 1 + col, operatorDropDown(constraint, inner, row, 2 + col)); //Change "value" editor to the pen icon as the applicable Widget depends on data-type constraint.setConstraintValueType(SingleFieldConstraint.TYPE_UNDEFINED); constraint.setValue(""); inner.setWidget(row, 2 + col, createValueEditor(constraint)); } catch (Exception e) { e.printStackTrace(); } } });
public void onExpressionTypeChanged(ExpressionTypeChangeEvent event) { try { //Change "operator" drop-down as the content depends on data-type constraint.setFieldType(event.getNewType()); inner.setWidget(row, 1 + col, operatorDropDown(constraint, inner, row, 2 + col)); //Change "value" editor to the pen icon as the applicable Widget depends on data-type constraint.setConstraintValueType(SingleFieldConstraint.TYPE_UNDEFINED); constraint.setValue(""); inner.setWidget(row, 2 + col, createValueEditor(constraint)); } catch (Exception e) { e.printStackTrace(); } } });
@Test public void testOnChangeCallbackRegisteredForConstraintValueEditor() throws Exception { final SingleFieldConstraint constraint = new SingleFieldConstraint(); constraint.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL); constraint.setFieldName("a"); final ConstraintValueEditor editor = mock(ConstraintValueEditor.class); doReturn(editor).when(factPatternWidget).constraintValueEditor(constraint); final SingleFieldConstraint constraintTwo = new SingleFieldConstraint(); constraintTwo.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL); constraintTwo.setFieldName("b"); final ConstraintValueEditor editorTwo = mock(ConstraintValueEditor.class); doReturn(editorTwo).when(factPatternWidget).constraintValueEditor(constraintTwo); factPatternWidget.createValueEditor(constraint); factPatternWidget.createValueEditor(constraintTwo); verify(editor).init(); verify(editorTwo).init(); verify(editor).setOnValueChangeCommand(commandCaptor.capture()); commandCaptor.getValue().execute(); verify(editorTwo).hideError(); verify(factPatternWidget).setModified(true); verify(editorTwo).refresh(); } }
private SingleFieldConstraint visitSingleFieldConstraint(SingleFieldConstraint sfc) { SingleFieldConstraint clone = new SingleFieldConstraint(); clone.setConstraintValueType(sfc.getConstraintValueType()); clone.setExpressionValue((ExpressionFormLine) visit(sfc.getExpressionValue())); clone.setFieldBinding(sfc.getFieldBinding()); clone.setFactType(sfc.getFactType()); clone.setFieldName(sfc.getFieldName()); clone.setFieldType(sfc.getFieldType()); clone.setId(sfc.getId()); clone.setOperator(sfc.getOperator()); clone.setParent((FieldConstraint) visit(sfc.getParent())); for (Map.Entry<String, String> entry : sfc.getParameters().entrySet()) { clone.setParameter(entry.getKey(), entry.getValue()); } clone.setValue(sfc.getValue()); if (sfc.getConnectives() != null) { clone.setConnectives(new ConnectiveConstraint[sfc.getConnectives().length]); for (int i = 0; i < sfc.getConnectives().length; i++) { clone.getConnectives()[i] = (ConnectiveConstraint) visit(sfc.getConnectives()[i]); } } return clone; }
public static GuidedDecisionTable52 makeTableWithBRLFragmentConditionColWithPredicate(final String packageName, final Collection<Import> imports, final String tableName) { final GuidedDecisionTable52 dt = new GuidedDecisionTable52(); dt.setPackageName(packageName); dt.getImports().getImports().addAll(imports); dt.setTableName(tableName); final BRLConditionColumn brl = new BRLConditionColumn(); final FactPattern fp1 = new FactPattern(); fp1.setFactType("Applicant"); final SingleFieldConstraint sfc1 = new SingleFieldConstraint(); sfc1.setConstraintValueType(BaseSingleFieldConstraint.TYPE_PREDICATE); sfc1.setValue("age = 45"); fp1.addConstraint(sfc1); brl.getDefinition().add(fp1); brl.getChildColumns().add(new BRLConditionVariableColumn("f1", DataType.TYPE_BOOLEAN)); dt.getConditions().add(brl); dt.setData(DataUtilities.makeDataLists(new Object[][]{ new Object[]{"1", "desc", true} })); return dt; }
@Override public RuleModel getRuleModel() { final RuleModel ruleModel = new RuleModel(); ruleModel.lhs = new IPattern[1]; final FactPattern factPattern = new FactPattern(); final SingleFieldConstraint constraint = new SingleFieldConstraint(); constraint.setValue("value"); constraint.setFieldType("fieldType"); constraint.setFactType("factType"); constraint.setFieldName("fieldName"); constraint.setOperator("in"); constraint.setConstraintValueType(BaseSingleFieldConstraint.TYPE_TEMPLATE); factPattern.addConstraint(constraint); ruleModel.lhs[0] = factPattern; return ruleModel; } });
@Test public void testEmptyLiteralNonStringFieldConstraints() throws Exception { FactPattern f1 = new FactPattern("Applicant"); f1.setBoundName("$a"); SingleFieldConstraint constraint = new SingleFieldConstraint(); constraint.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL); constraint.setFieldType(DataType.TYPE_NUMERIC_INTEGER); constraint.setFactType("Applicant"); constraint.setOperator("=="); constraint.setFieldName("age"); f1.addConstraint(constraint); model.lhs = new IPattern[]{f1}; assertFalse(validator.isValid()); }
@Test public void testEmptyLiteralNonStringFieldConstraints() throws Exception { FactPattern f1 = new FactPattern("Applicant"); f1.setBoundName("$a"); SingleFieldConstraint constraint = new SingleFieldConstraint(); constraint.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL); constraint.setFieldType(DataType.TYPE_NUMERIC_INTEGER); constraint.setFactType("Applicant"); constraint.setOperator("=="); constraint.setFieldName("age"); f1.addConstraint(constraint); model.lhs = new IPattern[]{f1}; assertFalse(validator.isValid()); }
@Test public void testEmptyLiteralStringFieldConstraints() throws Exception { FactPattern f1 = new FactPattern("Applicant"); f1.setBoundName("$a"); SingleFieldConstraint constraint = new SingleFieldConstraint(); constraint.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL); constraint.setFieldType(DataType.TYPE_STRING); constraint.setFactType("Applicant"); constraint.setOperator("=="); constraint.setFieldName("name"); f1.addConstraint(constraint); model.lhs = new IPattern[]{f1}; assertTrue(validator.isValid()); }
@Test public void testEmptyLiteralStringFieldConstraints() throws Exception { FactPattern f1 = new FactPattern("Applicant"); f1.setBoundName("$a"); SingleFieldConstraint constraint = new SingleFieldConstraint(); constraint.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL); constraint.setFieldType(DataType.TYPE_STRING); constraint.setFactType("Applicant"); constraint.setOperator("=="); constraint.setFieldName("name"); f1.addConstraint(constraint); model.lhs = new IPattern[]{f1}; assertTrue(validator.isValid()); }
@Test public void testAddRowInvalidColumnCount() throws Exception { TemplateModel m = new TemplateModel(); m.name = "t1"; FactPattern p = new FactPattern("Person"); SingleFieldConstraint con = new SingleFieldConstraint(); con.setFieldType(DataType.TYPE_STRING); con.setFieldName("field1"); con.setOperator("=="); con.setValue("$f1"); con.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE); p.addConstraint(con); m.addLhsItem(p); try { m.addRow(new String[]{}); Assert.fail("Expected IlegalArgumentException"); } catch (IllegalArgumentException iae) { assertEquals("Invalid numbers of columns: 0 expected: 1", iae.getMessage()); } } }
@Test public void testSimpleSingleValue() { TemplateModel m = new TemplateModel(); m.name = "t1"; FactPattern p = new FactPattern("Person"); SingleFieldConstraint con = new SingleFieldConstraint(); con.setFieldType(DataType.TYPE_STRING); con.setFieldName("field1"); con.setOperator("=="); con.setValue("$f1"); con.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE); p.addConstraint(con); m.addLhsItem(p); m.addRow(new String[]{"foo"}); String expected = "rule \"t1_0\"" + "dialect \"mvel\"\n" + "when \n" + "Person( field1 == \"foo\" )" + "then \n" + "end"; checkMarshall(expected, m); }
@Test public void testSimpleFromCollect() { TemplateModel m = new TemplateModel(); m.name = "r1"; FactPattern fp = new FactPattern("Person"); SingleFieldConstraint sfc = new SingleFieldConstraint("field1"); sfc.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE); sfc.setFieldType(DataType.TYPE_STRING); sfc.setOperator("=="); sfc.setValue("$f1"); fp.addConstraint(sfc); FromCollectCompositeFactPattern fac = new FromCollectCompositeFactPattern(); fac.setRightPattern(fp); fac.setFactPattern(new FactPattern("java.util.List")); m.addLhsItem(fac); String expected = "rule \"r1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "java.util.List( ) from collect ( Person( field1 == \"foo\" ) ) \n" + "then\n" + "end"; m.addRow(new String[]{"foo"}); checkMarshall(expected, m); }