private DSLSentence toDSLSentence(final List<SimpleDSLSentence> simpleDslSentences, final String dslLine) { DSLSentence dslSentence = new DSLSentence(); for (SimpleDSLSentence simpleDslSentence : simpleDslSentences) { String dslPattern = simpleDslSentence.getDsl(); // Dollar breaks the matcher, need to escape them. dslPattern = dslPattern.replace("$", "\\$"); //A DSL Pattern can contain Regex itself, for example "When the ages is less than {num:1?[0-9]?[0-9]}" String regex = dslPattern.replaceAll("\\{.*?\\}", "(.*)"); Matcher matcher = Pattern.compile(regex).matcher(dslLine); if (matcher.matches()) { dslPattern = dslPattern.replace("\\$", "$"); dslSentence.setDrl(simpleDslSentence.getDrl()); dslSentence.setDefinition(dslPattern); for (int i = 0; i < matcher.groupCount(); i++) { dslSentence.getValues().get(i).setValue(matcher.group(i + 1)); } return dslSentence; } } dslSentence.setDefinition(dslLine); return dslSentence; }
/** * This is used by the GUI when adding a sentence to LHS or RHS. * @return */ public DSLSentence copy() { final DSLSentence copy = new DSLSentence(); copy.drl = getDrl(); copy.definition = getDefinition(); copy.values = mapCopy(getValues()); return copy; }
private DSLSentence buildDslSentence() { DSLSentence dsl = new DSLSentence(); dsl.setDrl( "Person( sex == {$sex} )" ); dsl.setDefinition( "Person is {$sex:ENUM:Person.sex}" ); return dsl; }
if (entry.getSection() == DSLMappingEntry.CONDITION) { final DSLMappingEntry definition = entry; final DSLSentence sentence = new DSLSentence(); sentence.setDrl(definition.getMappingValue()); sentence.setDefinition(definition.getMappingKey()); } else if (entry.getSection() == DSLMappingEntry.CONSEQUENCE) { final DSLMappingEntry definition = entry; final DSLSentence sentence = new DSLSentence(); sentence.setDrl(definition.getMappingValue()); sentence.setDefinition(definition.getMappingKey());
private TemplateModel getComplexModel() { final TemplateModel m = new TemplateModel(); m.addAttribute(new RuleAttribute("no-loop", "true")); final FactPattern pat = new FactPattern("Person"); pat.setBoundName("p1"); final SingleFieldConstraint con = new SingleFieldConstraint(); con.setFactType("Person"); 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 set = new ActionUpdateField(); set.setVariable("p1"); set.addFieldValue(new ActionFieldValue("status", "rejected", DataType.TYPE_STRING)); m.addRhsItem(set); final ActionRetractFact ret = new ActionRetractFact("p1"); m.addRhsItem(ret); final DSLSentence sen = new DSLSentence(); sen.setDefinition("Send an email to {administrator}"); m.addRhsItem(sen); return m; }