Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

Commit

Permalink
Merge pull request #22 from lanceleverich/0.6.x
Browse files Browse the repository at this point in the history
0.6.x
  • Loading branch information
sotty committed Jun 29, 2015
2 parents d64d8ca + 6583786 commit 3b6e2e5
Show file tree
Hide file tree
Showing 16 changed files with 292 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,7 @@
import org.drools.compiler.lang.api.PackageDescrBuilder;
import org.drools.compiler.lang.api.PatternDescrBuilder;
import org.drools.compiler.lang.api.RuleDescrBuilder;
import org.drools.compiler.lang.descr.AndDescr;
import org.drools.compiler.lang.descr.BaseDescr;
import org.drools.compiler.lang.descr.ConditionalElementDescr;
import org.drools.compiler.lang.descr.ExpectationDescr;
import org.drools.compiler.lang.descr.ExpectationRuleDescr;
import org.drools.compiler.lang.descr.ExprConstraintDescr;
import org.drools.compiler.lang.descr.NamedConsequenceDescr;
import org.drools.compiler.lang.descr.NotDescr;
import org.drools.compiler.lang.descr.OrDescr;
import org.drools.compiler.lang.descr.PatternDescr;
import org.drools.compiler.lang.descr.RuleDescr;
import org.drools.compiler.lang.descr.*;
import org.drools.core.util.StringUtils;

import java.util.*;
Expand Down Expand Up @@ -337,7 +327,9 @@ public void injectMainExpectationRuleWithContext( ExpectationRuleDescr xp, Expec
public void buildFulfillRule( PackageDescrBuilder builder, ExpectationRuleDescr rule, ExpectationDescr expectations ) {

RuleDescr fulfillRule = expectations.getFulfill();
AttributeDescr noloop = new AttributeDescr("no-loop","");
fulfillRule.addAnnotation( "Propagation", "EAGER" );
fulfillRule.addAttribute(noloop);
boolean addMatchConsequence = ! StringUtils.isEmpty( fulfillRule.getConsequence().toString().trim() );

AndDescr fulfillLhs = fulfillRule.getLhs();
Expand Down Expand Up @@ -378,6 +370,8 @@ public void buildFulfillRule( PackageDescrBuilder builder, ExpectationRuleDescr
public void buildViolationRule( PackageDescrBuilder builder, ExpectationRuleDescr rule, ExpectationDescr expectations ) {

RuleDescr violRule = expectations.getViolation();
AttributeDescr noloop = new AttributeDescr("no-loop","");
violRule.addAttribute(noloop);
violRule.addAnnotation( "Propagation", "EAGER" );

AndDescr violLhs = violRule.getLhs();
Expand All @@ -387,6 +381,15 @@ public void buildViolationRule( PackageDescrBuilder builder, ExpectationRuleDesc

NotDescr not = new NotDescr( expectations.getExpectLhs() );
violLhs.addDescr( not );
if (expectations.getExpired() != null) {
RuleDescr expireRule = expectations.getExpired();
AndDescr additional = expireRule.getLhs();
for (BaseDescr descr: additional.getDescrs()) {
if (descr instanceof PatternDescr) {
violLhs.addDescr(descr);
}
}
}

if ( ! rule.isExpectationDisabled() ) {
violLhs.addDescr( expectPattern( expectations.getLabel(), extractVars( rule.getLhs(), expectations.getLabel() ), true ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,7 @@
import org.drools.compiler.compiler.DescrBuildError;
import org.drools.compiler.compiler.DrlExprParser;
import org.drools.compiler.compiler.DroolsParserException;
import org.drools.compiler.lang.descr.AndDescr;
import org.drools.compiler.lang.descr.BaseDescr;
import org.drools.compiler.lang.descr.ConditionalElementDescr;
import org.drools.compiler.lang.descr.ConstraintConnectiveDescr;
import org.drools.compiler.lang.descr.ExprConstraintDescr;
import org.drools.compiler.lang.descr.NotDescr;
import org.drools.compiler.lang.descr.OperatorDescr;
import org.drools.compiler.lang.descr.OrDescr;
import org.drools.compiler.lang.descr.PatternDescr;
import org.drools.compiler.lang.descr.RelationalExprDescr;
import org.drools.compiler.lang.descr.*;
import org.drools.core.base.evaluators.Operator;
import org.drools.core.base.evaluators.TimeIntervalParser;
import org.kie.internal.builder.conf.LanguageLevelOption;
Expand All @@ -33,8 +24,14 @@ public static long calcExpirationOffset( AndDescr trigger, BaseDescr ce ) {
return offset;
} else if ( ce instanceof OrDescr ) {
long offset = 0;
for ( BaseDescr child : ( (AndDescr) ce ).getDescrs() ) {
offset = Math.max( offset, calcExpirationOffset( trigger, child ) );
for (BaseDescr child : ((AndDescr) ce).getDescrs()) {
offset = Math.max(offset, calcExpirationOffset(trigger, child));
}
return offset;
} else if ( ce instanceof ForallDescr) {
long offset = 0;
for (BaseDescr child: ((ForallDescr)ce).getDescrs()) {
offset = Math.max(offset, calcExpirationOffset(trigger, child));
}
return offset;
} else if ( ce instanceof PatternDescr ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
import org.kie.api.definition.type.Position;
import org.kie.api.definition.type.Role;

import java.io.Serializable;

@Role( Role.Type.EVENT )
public class Closure {
public class Closure implements Serializable {

private static final long serialVersionUID = -8527852726387485481L;

@Position( 0 )
private String label;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import org.kie.api.definition.type.Position;
import org.kie.api.definition.type.Role;

import java.io.Serializable;
import java.util.List;

@Role( Role.Type.EVENT )
public class Compensation {
public class Compensation implements Serializable {

private static final long serialVersionUID = 3083918175399259003L;
@Position( 0 )
private String label;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
import org.kie.api.runtime.rule.FactHandle;
import org.kie.api.runtime.rule.Match;

import java.io.Serializable;
import java.util.List;

@PropertyReactive
public class Expectation {
public class Expectation implements Serializable {

private static final long serialVersionUID = 4773544980103621154L;
// id of the initial activation
@Key @Position( 0 )
private long originId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
import org.kie.api.definition.type.PropertyReactive;
import org.kie.api.runtime.rule.Match;

import java.io.Serializable;

@PropertyReactive
public class ExpectationContext {
public class ExpectationContext implements Serializable {

private static final long serialVersionUID = -3564358457726574602L;
@Key
@Position( 0 )
private long ctxId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import org.kie.api.definition.type.Role;

import java.io.Serializable;
import java.util.List;

@Role( Role.Type.EVENT )
public class Failure implements ExpectationResult {
public class Failure implements ExpectationResult, Serializable {

private static final long serialVersionUID = 3613740920596589903L;
private long originId;

private String ruleName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import org.kie.api.definition.type.PropertyReactive;
import org.kie.api.definition.type.Role;

import java.io.Serializable;
import java.util.List;

@Role( Role.Type.EVENT )
@PropertyReactive
public class Fulfill implements ExpectationResult {
public class Fulfill implements ExpectationResult, Serializable {

private static final long serialVersionUID = 6649565452855024414L;
// id of the initial activation
@Key
@Position( 0 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
import org.kie.api.definition.type.PropertyReactive;
import org.kie.api.runtime.rule.Match;

import java.io.Serializable;
import java.util.List;

@PropertyReactive
public class OneShotExpectation extends Expectation {
public class OneShotExpectation extends Expectation implements Serializable {

private static final long serialVersionUID = 4741942003493008807L;

public OneShotExpectation( long originId, String label, Match act, long actId, List tuple, long start, long duration, boolean active, String ruleName ) {
super( originId, label, act, actId, tuple, start, duration, active, ruleName );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
import org.kie.api.runtime.rule.FactHandle;
import org.kie.api.runtime.rule.Match;

import java.io.Serializable;
import java.util.List;

@Role( Role.Type.EVENT )
@PropertyReactive
public class Pending {
public class Pending implements Serializable {

private static final long serialVersionUID = -669101176444937215L;
@Key
@Position( 0 )
private String label;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import org.kie.api.definition.type.Role;

import java.io.Serializable;
import java.util.List;

@Role( Role.Type.EVENT )
public class Success implements ExpectationResult {
public class Success implements ExpectationResult, Serializable {

private static final long serialVersionUID = -330971009668327807L;
private long originId;

private String ruleName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
import org.kie.api.definition.type.PropertyReactive;
import org.kie.api.definition.type.Role;

import java.io.Serializable;
import java.util.List;

@Role( Role.Type.EVENT )
@PropertyReactive
public class Viol implements ExpectationResult {
public class Viol implements ExpectationResult, Serializable {

private static final long serialVersionUID = -6363181832369683908L;
// id of the initial activation
@Key
private long originId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@
import org.antlr.runtime.Token;
import org.antlr.runtime.TokenStream;
import org.drools.compiler.lang.api.*;
import org.drools.compiler.lang.api.impl.CEDescrBuilderImpl;
import org.drools.compiler.lang.api.impl.ExpectationDescrBuilderImpl;
import org.drools.compiler.lang.descr.AndDescr;
import org.drools.compiler.lang.descr.BaseDescr;
import org.drools.compiler.lang.descr.ExpectationRuleDescr;
import org.drools.compiler.lang.descr.*;
import it.unibo.deis.lia.org.drools.expectations.DRLExpectationHelper;
import org.drools.compiler.lang.descr.PatternDescr;

import java.util.List;

Expand Down Expand Up @@ -202,37 +200,55 @@ private String expectation( ECEPackageDescrBuilder packageDescr, ECERuleDescrBui
null,
DroolsEditorType.KEYWORD);

boolean negated = false;
if (helper.validateIdentifierKey(ExpectationSoftKeywords.ONE)) {
parser.match(input,
DRL6Lexer.ID,
ExpectationSoftKeywords.ONE,
null,
DroolsEditorType.KEYWORD);
expectDescr.one();
} else {
if (helper.validateIdentifierKey( DroolsSoftKeywords.NOT )) {
CEDescrBuilder lhs = new CEDescrBuilderImpl(expectDescr, new AndDescr());
do {

boolean negated = false;
if (helper.validateIdentifierKey(ExpectationSoftKeywords.ONE)) {
parser.match(input,
DRL6Lexer.ID,
DroolsSoftKeywords.NOT,
ExpectationSoftKeywords.ONE,
null,
DroolsEditorType.KEYWORD);
negated = true;
expectDescr.one();
} else {
if (helper.validateIdentifierKey(DroolsSoftKeywords.NOT)) {
parser.match(input,
DRL6Lexer.ID,
DroolsSoftKeywords.NOT,
null,
DroolsEditorType.KEYWORD);
negated = true;
}
}
}

String label = null;
if ( input.LA( 1 ) == DRL6Lexer.ID && input.LA( 2 ) == DRL6Lexer.COLON && !helper.validateCEKeyword( 1 ) ) {
label = parser.label(DroolsEditorType.IDENTIFIER_PATTERN);
if ( state.failed ) return null;
}
String label = null;
boolean contained = false;
if (input.LA(1) == DRL6Lexer.ID && input.LA(2) == DRL6Lexer.COLON && !helper.validateCEKeyword(1)) {
label = parser.label(DroolsEditorType.IDENTIFIER_PATTERN);
if (state.failed) return null;
} else if (helper.validateCEKeyword(1)) {
if (helper.validateIdentifierKey(DroolsSoftKeywords.FORALL)) {
contained = true;
}
}

if ( state.backtracking == 0 ) {
parser.lhsPattern( negated ? expectDescr.expectLhs().not().pattern() : expectDescr.expectLhs().pattern(), label, false );
} else {
parser.lhsPattern( null, label, false );
}
if (state.backtracking == 0) {
if (contained) {
parser.lhsForall(negated ? lhs.not():lhs);
} else {
parser.lhsPattern(negated ? lhs.not().pattern():lhs.pattern(), label, false);
}

} else {
parser.lhsPattern(null, label, false);
}
} while (!helper.validateIdentifierKey(ExpectationSoftKeywords.FAILSON)
&& !helper.validateIdentifierKey(ExpectationSoftKeywords.ONFULFILL)
&& !helper.validateIdentifierKey(ExpectationSoftKeywords.ONVIOLATION)
&& !helper.validateIdentifierKey(DroolsSoftKeywords.END));

((ExpectationDescr)expectDescr.getDescr()).setExpectLhs((AndDescr)lhs.getDescr());
failsOn(packageDescr, expectDescr, (ExpectationRuleDescr) rule.getDescr() );

onFulfill( packageDescr, expectDescr, (ExpectationRuleDescr) rule.getDescr() );
Expand Down Expand Up @@ -427,7 +443,13 @@ private void compensation( ECERuleDescrBuilder ruleDescrBuilder ) {


boolean isExpectationNext() {
return helper.validateIdentifierKey( ExpectationSoftKeywords.EXPECT ) || (input.LA( 1 ) == DRL6Lexer.ID && input.LA( 2 ) == DRL6Lexer.COLON);
if (helper.validateIdentifierKey( ExpectationSoftKeywords.EXPECT )) {
return true;
}
if (input.LA( 1 ) == DRL6Lexer.ID && input.LA( 2 ) == DRL6Lexer.COLON) {
return true;
}
return false;
}

boolean isRepairNext() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,24 @@ protected void sleep( int time ) {
((SessionPseudoClock) clock ).advanceTime( time, TimeUnit.MILLISECONDS );
}

protected Object newTextMessage( KieSession kSession, String sendingPhone, String receivingPhone, String message, String emoticon ) {
try {
FactType msgType = kSession.getKieBase().getFactType( "org.drools", "TextMsg" );
Object o = null;

o = msgType.newInstance();
msgType.set( o, "sendingPhone", sendingPhone );
msgType.set( o, "receivingPhone", receivingPhone );
msgType.set( o, "message", message);
msgType.set( o, "emoticon", emoticon);
return o;
} catch ( InstantiationException e ) {
fail( e.getMessage() );
} catch ( IllegalAccessException e ) {
fail( e.getMessage() );
}
return null;
}

protected Object newMessage( KieSession kSession, String sender, String receiver, String body, String more ) {
try {
Expand Down
Loading

0 comments on commit 3b6e2e5

Please sign in to comment.