private FactPattern visitFactPattern(FactPattern pattern) { FactPattern clone = new FactPattern(); clone.setBoundName(pattern.getBoundName()); clone.setFactType(pattern.getFactType()); clone.setNegated(pattern.isNegated()); CEPWindow cloneCEPWindow = new CEPWindow(); cloneCEPWindow.setOperator(pattern.getWindow().getOperator()); cloneCEPWindow.setParameters(cloneCEPWindowParameters(pattern.getWindow())); clone.setWindow(cloneCEPWindow); for (FieldConstraint fc : pattern.getFieldConstraints()) { clone.addConstraint((FieldConstraint) visit(fc)); } return clone; }
if (fp.isNegated()) { messages.add(new UnsupportedIPatternParserMessage()); return nodes; if (fp.getWindow().getOperator() != null) { messages.add(new UnsupportedIPatternParserMessage()); return nodes; final TypeNode node = new TypeNodeImpl(fp.getFactType()); if (fp.isBound()) { node.setBinding(fp.getBoundName()); for (FieldConstraint fc : fp.getFieldConstraints()) { nodes.addAll(visit(fc, model,
private Optional<IPattern> checkNegatedFactPattern(final FactPattern fp, final String factType) { if (fp.isNegated()) { if (fp.getFactType().equals(factType)) { return Optional.of(fp); } } return Optional.empty(); }
public FactPattern makeFactPattern() { final FactPattern factPattern = new FactPattern(); factPattern.setBoundName(getBoundName()); factPattern.setFactType(getFactType()); return factPattern; }
@Test public void testComparingFieldToExpression() throws Exception { FactPattern f1 = new FactPattern(); f1.setBoundName("f1"); FactPattern f2 = new FactPattern(); SingleFieldConstraint constraint = new SingleFieldConstraint(); constraint.setOperator("=="); constraint.getExpressionValue().appendPart(new ExpressionVariable("field", "java.lang.Number", "Number")); f2.addConstraint(constraint); model.lhs = new IPattern[]{f1, f2}; assertTrue(validator.isValid()); }
private void generateFactPattern(final FactPattern pattern, final LHSGeneratorContext gctx) { if (pattern.isNegated()) { buf.append("not "); } else if (pattern.isBound()) { bindingsPatterns.put(pattern.getBoundName(), pattern); buf.append(pattern.getBoundName()); buf.append(" : "); } if (pattern.getFactType() != null) { buf.append(pattern.getFactType()); } buf.append("( "); // top level constraints if (pattern.getConstraintList() != null) { generateConstraints(pattern, gctx); } buf.append(")"); //Add CEP window definition CEPWindow window = pattern.getWindow(); if (window.isDefined()) { buf.append(" "); buf.append(window.getOperator()); buf.append(buildOperatorParameterDRL(window.getParameters())); } }
public String getFactType() { if ( this.factPattern == null ) { return null; } return this.factPattern.getFactType(); }
@Test public void testMissingValueWhenOperatorExists() throws Exception { FactPattern pattern = new FactPattern("Person"); SingleFieldConstraint constraint = new SingleFieldConstraint("age"); constraint.setOperator("=="); pattern.addConstraint(constraint); model.lhs = new IPattern[]{pattern}; assertFalse(validator.isValid()); assertEquals(1, validator.getErrors().size()); assertEquals(MISSING_VALUE_WHEN_OPERATOR_IS_SET, validator.getErrors().get(0)); verify(constants).FactType0HasAField1ThatHasAnOperatorSetButNoValuePleaseAddAValueOrRemoveTheOperator("Person", "age"); }
private Set<String> visitFactPattern(FactPattern pattern) { final Set<String> factTypes = new HashSet<String>(); factTypes.add(pattern.getFactType()); for (FieldConstraint fc : pattern.getFieldConstraints()) { factTypes.addAll(visit(fc)); } return factTypes; }
private String getLHSBindingType(IPattern pat, String var) { if (pat instanceof FromCompositeFactPattern) { pat = ((FromCompositeFactPattern) pat).getFactPattern(); } if (pat instanceof CompositeFactPattern) { for (IPattern iPattern : ((CompositeFactPattern) pat).getPatterns()) { String type = getLHSBindingType(iPattern, var); if (type != null) { return type; } } } if (pat instanceof FactPattern) { final FactPattern p = (FactPattern) pat; if (p.isBound() && var.equals(p.getBoundName())) { return p.getFactType(); } for (FieldConstraint fc : p.getFieldConstraints()) { String type = getFieldBinding(fc, var); if (type != null) { return type; } } } return null; }
private static FactPattern buildFactPattern() { FactPattern fp = new FactPattern(); fp.setBoundName( "$f" ); fp.setFactType( "FactType" ); fp.setNegated( true ); CEPWindow win = new CEPWindow(); win.setOperator( "winOp" ); win.setParameter( "winKey", "winPar" ); fp.setWindow( win ); fp.addConstraint( buildSingleFieldConstraint() ); return fp; }
protected BRLConditionColumn whenThereIsABRLFactPattern(final String factType, final String binding) { final FactPattern fp = new FactPattern(factType); fp.setBoundName(binding); final BRLConditionColumn brl = new BRLConditionColumn(); brl.getDefinition().add(fp); dtable.getConditions().add(brl); return brl; }
/** * This returns the pattern label. */ private Widget getPatternLabel(final FactPattern fp) { ClickHandler click = new ClickHandler() { public void onClick(ClickEvent event) { popupCreator.showPatternPopup(fp, null, false); } }; String patternName = (pattern.isBound()) ? pattern.getFactType() + " <b>[" + pattern.getBoundName() + "]</b>" : pattern.getFactType(); String desc; if (isAll0WithLabel) { desc = GuidedRuleEditorResources.CONSTANTS.All0with(patternName); } else { if (pattern.getNumberOfConstraints() > 0) { desc = GuidedRuleEditorResources.CONSTANTS.ThereIsAAn0With(patternName); } else { desc = GuidedRuleEditorResources.CONSTANTS.ThereIsAAn0(patternName); } desc = anA(desc, patternName); } return new ClickableLabel(desc, click, !this.readOnly); }
public String getBoundFactType(String boundName) { for (CompositeColumn<?> cc : this.model.getConditions()) { if (cc instanceof Pattern52) { final Pattern52 p = (Pattern52) cc; if (p.isBound() && p.getBoundName() .equals(boundName)) { return p.getFactType(); } } else if (cc instanceof BRLConditionColumn) { final BRLConditionColumn brl = (BRLConditionColumn) cc; for (IPattern p : brl.getDefinition()) { if (p instanceof FactPattern) { FactPattern fp = (FactPattern) p; if (fp.isBound() && fp.getBoundName() .equals(boundName)) { return fp.getFactType(); } } } } } return ""; }
((FactPattern) rm.lhs[0]).getFactType()); assertEquals("p1", ((FactPattern) rm.lhs[0]).getBoundName()); ((FactPattern) rm.lhs[1]).getFactType()); assertEquals("c", ((FactPattern) rm.lhs[1]).getBoundName()); person.getConstraintList().getConstraints().length); SingleFieldConstraint cons = (SingleFieldConstraint) person.getConstraint(0); assertEquals(BaseSingleFieldConstraint.TYPE_LITERAL, cons.getConstraintValueType()); cons = (SingleFieldConstraint) person.getConstraint(1); assertEquals(BaseSingleFieldConstraint.TYPE_RET_VALUE, cons.getConstraintValueType()); cons = (SingleFieldConstraint) person.getConstraint(2); assertEquals(BaseSingleFieldConstraint.TYPE_PREDICATE, cons.getConstraintValueType()); assertEquals(person.isNegated(), true); cheese.getConstraintList().getConstraints().length); cons = (SingleFieldConstraint) cheese.getConstraint(0); assertEquals("type", cons.getFieldName());
private void addNewFact(String itemText, int position) { this.model.addLhsItem(new FactPattern(itemText), position); }
ExpressionPart variable; if (fact != null) { variable = new ExpressionVariable(fact.getBoundName(), fact.getFactType()); } else {
private void visitFactPattern(final FactPattern pattern) { this.factPattern = pattern; for (FieldConstraint fc : pattern.getFieldConstraints()) { visit(fc); } }
if (fact.isBound()) { if (includePatterns) { result.add(fact.getBoundName()); for (int j = 0; j < fact.getFieldConstraints().length; j++) { FieldConstraint fc = fact.getFieldConstraints()[j]; if (fc instanceof SingleFieldConstraintEBLeftSide) { SingleFieldConstraintEBLeftSide exp = (SingleFieldConstraintEBLeftSide) fc;
@Override public String getBoundName() { if (fp instanceof FactPattern) { return ((FactPattern) fp).getBoundName(); } throw new UnsupportedOperationException(); }