private ConnectiveConstraint visitConnectiveConstraint(ConnectiveConstraint cc) { ConnectiveConstraint clone = new ConnectiveConstraint(); clone.setConstraintValueType(cc.getConstraintValueType()); clone.setExpressionValue((ExpressionFormLine) visit(cc.getExpressionValue())); clone.setFactType(cc.getFactType()); clone.setFieldName(cc.getFieldName()); clone.setFieldType(cc.getFieldType()); clone.setOperator(cc.getOperator()); for (Map.Entry<String, String> entry : cc.getParameters().entrySet()) { clone.setParameter(entry.getKey(), entry.getValue()); } clone.setValue(cc.getValue()); return clone; }
private void setUpConnectiveConstraint(ConnectiveConstraint cc) { this.factType = cc.getFactType(); this.fieldName = cc.getFieldName(); this.fieldType = cc.getFieldType(); }
private void fixConnectiveConstraints(SingleFieldConstraint sfc) { if (sfc.getConnectives() == null) { return; } for (ConnectiveConstraint cc : sfc.getConnectives()) { if (cc.getFieldName() == null) { cc.setFieldName(sfc.getFieldName()); cc.setFieldType(sfc.getFieldType()); } } }
@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); }
private void visitSingleFieldConstraint(SingleFieldConstraint sfc) { InterpolationVariable var = new InterpolationVariable(sfc.getValue(), sfc.getFieldType(), (factPattern == null ? "" : factPattern.getFactType()), sfc.getFieldName(), sfc.getOperator()); if (BaseSingleFieldConstraint.TYPE_TEMPLATE == sfc.getConstraintValueType() && !vars.containsKey(var)) { vars.put(var, vars.size()); } //Visit Connection constraints if (sfc.getConnectives() != null) { for (int i = 0; i < sfc.getConnectives().length; i++) { final ConnectiveConstraint cc = sfc.getConnectives()[i]; InterpolationVariable ccVar = new InterpolationVariable(cc.getValue(), cc.getFieldType(), (factPattern == null ? "" : factPattern.getFactType()), cc.getFieldName()); if (BaseSingleFieldConstraint.TYPE_TEMPLATE == cc.getConstraintValueType() && !vars.containsKey(ccVar)) { vars.put(ccVar, vars.size()); } } } }
@Test public void testConnectiveOperatorsInteger() throws Exception { doReturn("org.Address").when(connectiveConstraint).getFactType(); doReturn("number").when(connectiveConstraint).getFieldName(); connectives.connectives(singleFieldConstraint); verify(connectives).getDropdown(OperatorsOracle.COMPARABLE_CONNECTIVES, connectiveConstraint); }
final Map<String, String> connectiveParameters = conn.getParameters(); conn.getConstraintValueType(), conn.getFieldType(), conn.getOperator(), connectiveParameters, conn.getValue(), conn.getExpressionValue(), cctx, true);
@Test public void testAbbreviatedCondition() throws Exception { final String resourcePath = RULES_ROOT + "matchPeopleAbbreviatedCondition.rdrl"; final GuidedEditorContent content = guidedRuleService.loadContent(getPath(resourcePath)); final RuleModel model = content.getModel(); Assertions.assertThat(model.lhs.length).isEqualTo(1); final FactPattern pattern = (FactPattern) model.lhs[0]; final SingleFieldConstraint fieldConstraintOne = (SingleFieldConstraint) pattern.getConstraint(0); Assertions.assertThat(fieldConstraintOne.getConnectives()).hasSize(2); final ConnectiveConstraint fieldConstraintTwo = fieldConstraintOne.getConnectives()[0]; final ConnectiveConstraint fieldConstraintThree = fieldConstraintOne.getConnectives()[1]; Assertions.assertThat(fieldConstraintOne.getFieldName()).isEqualTo("age"); Assertions.assertThat(fieldConstraintOne.getOperator()).isEqualTo(Operator.NOT_EQUAL.getOperatorString()); Assertions.assertThat(fieldConstraintOne.getValue()).isEqualTo("18"); Assertions.assertThat(fieldConstraintTwo.getFieldName()).isEqualTo("age"); Assertions.assertThat(fieldConstraintTwo.getOperator()).isEqualTo("&& " + Operator.LESS.getOperatorString()); Assertions.assertThat(fieldConstraintTwo.getValue()).isEqualTo("25"); Assertions.assertThat(fieldConstraintThree.getFieldName()).isEqualTo("age"); Assertions.assertThat(fieldConstraintThree.getOperator()).isEqualTo("&& " + Operator.GREATER.getOperatorString()); Assertions.assertThat(fieldConstraintThree.getValue()).isEqualTo("15"); final List<ValidationMessage> messages = validateResource(resourcePath); Assertions.assertThat(messages).isEmpty(); }
void connectiveOperatorDropDown(final ConnectiveConstraint cc, final Callback<Widget> callback) { if (!isReadOnly) { final String factType = cc.getFactType(); final String fieldName = cc.getFieldName(); this.getDataModelOracle().getConnectiveOperatorCompletions(factType, fieldName, new Callback<String[]>() { @Override public void callback(final String[] operators) { final CEPOperatorsDropdown dropdown = getDropdown(operators, cc); dropdown.addPlaceholder(GuidedRuleEditorResources.CONSTANTS.pleaseChoose(), ""); dropdown.addValueChangeHandler(new ValueChangeHandler<OperatorSelection>() { public void onValueChange(ValueChangeEvent<OperatorSelection> event) { OperatorSelection selection = event.getValue(); String selected = selection.getValue(); cc.setOperator(selected); } }); callback.callback(dropdown); } }); } else { final SmallLabel w = new SmallLabel("<b>" + (cc.getOperator() == null ? GuidedRuleEditorResources.CONSTANTS.pleaseChoose() : HumanReadable.getOperatorDisplayName(cc.getOperator())) + "</b>"); callback.callback(w); } }
private void visitSingleFieldConstraint(SingleFieldConstraintEBLeftSide sfexp) { String genericType = sfexp.getExpressionLeftSide().getGenericType(); String factType = sfexp.getExpressionLeftSide().getPreviousClassType(); if (factType == null) { factType = sfexp.getExpressionLeftSide().getClassType(); } InterpolationVariable var = new InterpolationVariable(sfexp.getValue(), genericType, factType, sfexp.getFieldName()); if (BaseSingleFieldConstraint.TYPE_TEMPLATE == sfexp.getConstraintValueType() && !vars.containsKey(var)) { vars.put(var, vars.size()); } //Visit Connection constraints if (sfexp.getConnectives() != null) { for (int i = 0; i < sfexp.getConnectives().length; i++) { final ConnectiveConstraint cc = sfexp.getConnectives()[i]; InterpolationVariable ccVar = new InterpolationVariable(cc.getValue(), genericType, factType, cc.getFieldName()); if (BaseSingleFieldConstraint.TYPE_TEMPLATE == cc.getConstraintValueType() && !vars.containsKey(ccVar)) { vars.put(ccVar, vars.size()); } } } }
String connectiveValue = constraint.substring(connectiveOperator.length()).trim(); connectiveConstraints[i] = new ConnectiveConstraint(); connectiveConstraints[i].setOperator((isAnd ? "&& " : "|| ") + (connectiveOperator == null ? null : connectiveOperator.trim())); connectiveConstraints[i].setFactType(factPattern.getFactType()); connectiveConstraints[i].setFieldName(con.getFieldName()); connectiveConstraints[i].setFieldType(con.getFieldType()); setValueOnConstraint(m, operator,
String fieldName = cc.getFieldName(); if (fieldName.equals(DataType.TYPE_THIS)) { showLiteralSelector = CEPOracle.isCEPOperator(cc.getOperator()); showFormulaSelector = showFormulaSelector && showLiteralSelector;
private void fixConstraints(FactPattern fp, SingleFieldConstraint sfc) { final FieldConstraint parent = sfc.getParent(); if (parent == null) { sfc.setFactType(fp.getFactType()); } else if (parent instanceof SingleFieldConstraint) { sfc.setFactType(((SingleFieldConstraint) parent).getFieldType()); } sfc.setFieldName(fixFieldName(sfc.getFieldName())); if (sfc.getConnectives() == null) { return; } for (ConnectiveConstraint cc : sfc.getConnectives()) { cc.setFactType(fp.getFactType()); cc.setFieldName(fixFieldName(cc.getFieldName())); } }
@Override protected void generateConstraint(final FieldConstraint constr, final LHSGeneratorContext gctx) { boolean generateTemplateCheck = isTemplateKey(constr); if (generateTemplateCheck) { if (constr instanceof SingleFieldConstraint && ((SingleFieldConstraint) constr).getConnectives() != null) { // if there are connectives, and the first is a template key, then all templates keys must be checked up front // individual connectives, that have template keys, will still need to be checked too. SingleFieldConstraint sconstr = (SingleFieldConstraint) constr; buf.append("@if{" + ((SingleFieldConstraint) constr).getValue() + " != empty"); for (int j = 0; j < sconstr.getConnectives().length; j++) { final ConnectiveConstraint conn = sconstr.getConnectives()[j]; if (conn.getConstraintValueType() == BaseSingleFieldConstraint.TYPE_TEMPLATE) { buf.append(" || " + conn.getValue() + " != empty"); } } buf.append("}"); } else { buf.append("@if{" + ((SingleFieldConstraint) constr).getValue() + " != empty}"); } } buf.append("@code{hasLHSOutput" + gctx.getDepth() + "_" + gctx.getOffset() + " = true}"); super.generateConstraint(constr, gctx); if (generateTemplateCheck) { buf.append("@end{}"); } }
static String extractFieldName(final BaseSingleFieldConstraint con) { if (con instanceof SingleFieldConstraintEBLeftSide) { return ((SingleFieldConstraintEBLeftSide) con).getExpressionLeftSide().getFieldName(); } else if (con instanceof SingleFieldConstraint) { return ((SingleFieldConstraint) con).getFieldName(); } else if (con instanceof ConnectiveConstraint) { return ((ConnectiveConstraint) con).getFieldName(); } return null; }
private Set<String> visitConnectiveConstraint(ConnectiveConstraint cc) { final Set<String> factTypes = new HashSet<String>(); if (cc.getFactType() != null) { factTypes.add(cc.getFactType()); } return factTypes; }
/** * This adds a new connective. */ public void addNewConnective() { String fieldName = this.fieldName; String fieldType = this.fieldType; String factType = this.factType; if ( this.connectives == null ) { this.connectives = new ConnectiveConstraint[]{ new ConnectiveConstraint( factType, fieldName, fieldType ) }; } else { final ConnectiveConstraint[] newList = new ConnectiveConstraint[ this.connectives.length + 1 ]; for ( int i = 0; i < this.connectives.length; i++ ) { newList[ i ] = this.connectives[ i ]; } newList[ this.connectives.length ] = new ConnectiveConstraint( factType, fieldName, fieldType ); this.connectives = newList; } }
((SingleFieldConstraint) con).setFieldType(type); } else if (con instanceof ConnectiveConstraint) { ((ConnectiveConstraint) con).setFieldType(type);
@Test public void testConnectiveConstraintFirstValue() { 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 == \"foo\" )\n" + "then\n" + "end\n"; m.addRow(new String[]{"foo", null}); checkMarshall(expected, m); }
private void setUpConnectiveConstraint(ConnectiveConstraint cc) { this.factType = cc.getFactType(); this.fieldName = cc.getFieldName(); this.fieldType = cc.getFieldType(); }