private void assertConstraintValue(final SingleFieldConstraint sfc) { if (DataType.TYPE_STRING.equals(sfc.getFieldType())) { if (sfc.getValue() == null) { sfc.setValue(""); } } }
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 onChange(ChangeEvent event) { setModified(true); c.setValue(box.getText()); } });
public void onChange(ChangeEvent event) { setModified(true); c.setValue(box.getText()); } });
@Override SingleFieldConstraint constructSingleFieldConstraint( ConditionCol52 c, List<DTCellValue52> columnData ) { SingleFieldConstraint sfc = new SingleFieldConstraint( c.getFactField() ); sfc.setConstraintValueType( c.getConstraintValueType() ); sfc.setFieldType( c.getFieldType() ); sfc.setOperator( "in" ); List<String> consumedValues = new ArrayList<String>(); StringBuilder value = new StringBuilder(); value.append( "( " ); for ( DTCellValue52 cv : columnData ) { //Skip the "otherwise" cell itself if ( cv.isOtherwise() ) { continue; } //Ensure cell values start and end with quotes String scv = GuidedDTDRLUtilities.convertDTCellValueToString( cv ); if ( scv != null ) { if ( !consumedValues.contains( scv ) ) { value.append( scv ).append( ", " ); } consumedValues.add( scv ); } } value.delete( value.lastIndexOf( "," ), value.length() - 1 ); value.append( ")" ); sfc.setValue( value.toString() ); return sfc; }
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 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(); } } });
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; }
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; }
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; }
@Test public void testFromAccumulateCompositePattern() throws Exception { FactPattern pattern1 = new FactPattern("Person"); SingleFieldConstraint constraint1 = new SingleFieldConstraint("name"); constraint1.setOperator("=="); constraint1.setValue("Toni"); pattern1.addConstraint(constraint1); FactPattern pattern2 = new FactPattern("Address"); SingleFieldConstraint constraint2 = new SingleFieldConstraint("street"); constraint2.setOperator("!="); constraint2.setValue("some street"); pattern2.addConstraint(constraint2); FromAccumulateCompositeFactPattern fromAccumulateCompositeFactPattern = new FromAccumulateCompositeFactPattern(); fromAccumulateCompositeFactPattern.setSourcePattern(pattern1); fromAccumulateCompositeFactPattern.setFactPattern(pattern2); ExpressionFormLine expression = new ExpressionFormLine(); expression.setBinding("person.addresses"); fromAccumulateCompositeFactPattern.setExpression(expression); model.lhs = new IPattern[]{fromAccumulateCompositeFactPattern}; assertTrue(validator.isValid()); }
@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 testFromAccumulateCompositePattern() throws Exception { FactPattern pattern1 = new FactPattern("Person"); SingleFieldConstraint constraint1 = new SingleFieldConstraint("name"); constraint1.setOperator("=="); constraint1.setValue("Toni"); pattern1.addConstraint(constraint1); FactPattern pattern2 = new FactPattern("Address"); SingleFieldConstraint constraint2 = new SingleFieldConstraint("street"); constraint2.setOperator("!="); constraint2.setValue("some street"); pattern2.addConstraint(constraint2); FromAccumulateCompositeFactPattern fromAccumulateCompositeFactPattern = new FromAccumulateCompositeFactPattern(); fromAccumulateCompositeFactPattern.setSourcePattern(pattern1); fromAccumulateCompositeFactPattern.setFactPattern(pattern2); ExpressionFormLine expression = new ExpressionFormLine(); expression.setBinding("person.addresses"); fromAccumulateCompositeFactPattern.setExpression(expression); model.lhs = new IPattern[]{fromAccumulateCompositeFactPattern}; 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); }
@Test public void testConnectiveConstraintSecondValue() { TemplateModel m = new TemplateModel(); m.name = "t1"; FactPattern p1 = new FactPattern("Person"); m.addLhsItem(p1); final SingleFieldConstraint X = new SingleFieldConstraint(); X.setFieldName("field1"); X.setFieldType(DataType.TYPE_STRING); X.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE); X.setValue("$f1"); X.setOperator("=="); p1.addConstraint(X); ConnectiveConstraint connective = new ConnectiveConstraint(); connective.setConstraintValueType(BaseSingleFieldConstraint.TYPE_TEMPLATE); connective.setFieldType(DataType.TYPE_STRING); connective.setOperator("|| =="); connective.setValue("$f2"); X.setConnectives(new ConnectiveConstraint[1]); X.getConnectives()[0] = connective; String expected = "rule \"t1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "Person( field1 == \"bar\" )\n" + "then\n" + "end\n"; m.addRow(new String[]{null, "bar"}); checkMarshall(expected, m); }