Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Informer : make Item and Group PropertyReactive

  • Loading branch information...
commit 67e5fddb8037b5b7cfc41f7b9e5f7cdf96173e6d 1 parent f5dab30
Davide Sottara sotty authored
Showing with 157 additions and 147 deletions.
  1. +22 −0 drools-informer/drools-informer-core/src/main/java/org/drools/informer/Group.java
  2. +16 −7 drools-informer/drools-informer-core/src/main/java/org/drools/informer/Item.java
  3. +11 −6 drools-informer/drools-informer-core/src/main/java/org/drools/informer/Questionnaire.java
  4. +8 −8 drools-informer/drools-informer-core/src/main/resources/org/drools/informer/Active.drl
  5. +18 −14 drools-informer/drools-informer-core/src/main/resources/org/drools/informer/Annotations.drl
  6. +1 −1  drools-informer/drools-informer-core/src/main/resources/org/drools/informer/Notes.drl
  7. +6 −2 drools-informer/drools-informer-core/src/main/resources/org/drools/informer/Queries.drl
  8. +17 −17 drools-informer/drools-informer-core/src/main/resources/org/drools/informer/ReadOnly.drl
  9. +12 −11 drools-informer/drools-informer-core/src/main/resources/org/drools/informer/Status.drl
  10. +15 −10 ...-informer/drools-informer-core/src/main/resources/org/drools/informer/presentation/presentation_adapter.drl
  11. +8 −4 drools-informer/drools-informer-core/src/test/java/org/drools/informer/AnnotationsTest.java
  12. +5 −3 drools-informer/drools-informer-core/src/test/java/org/drools/informer/QuestionStatusTest.java
  13. +5 −0 drools-informer/drools-informer-core/src/test/java/org/drools/informer/rules/ActiveTest.java
  14. +5 −0 drools-informer/drools-informer-core/src/test/java/org/drools/informer/rules/ReadOnlyTest.java
  15. +0 −60 drools-informer/drools-informer-core/src/test/resources/org/drools/informer/annotation_tests.drl
  16. +3 −3 drools-informer/drools-informer-interaction/src/main/resources/org/drools/informer/interaction/humanTask.drl
  17. +5 −1 drools-informer/drools-informer-interaction/src/test/java/TaskInteractionTest.java
22 drools-informer/drools-informer-core/src/main/java/org/drools/informer/Group.java
View
@@ -15,6 +15,9 @@
*/
package org.drools.informer;
+import org.drools.definition.type.Modifies;
+import org.drools.definition.type.PropertyReactive;
+
import java.util.*;
/**
@@ -34,6 +37,7 @@
*
* @author Damon Horrell
*/
+@PropertyReactive
public class Group extends Item {
public static final String COMMA_SEPARATOR = ",";
@@ -107,6 +111,7 @@ protected boolean validItemId(String itemId) {
*
* @param items
*/
+ @Modifies( "items" )
public void setItems(String[] items) {
this.items.clear();
if (items != null) {
@@ -122,6 +127,7 @@ public void setItems(String[] items) {
* @param itemId
* - cannot contain a comma
*/
+ @Modifies( "items" )
public void addItem(String itemId) {
if (validItemId(itemId)) {
this.items.add(itemId);
@@ -137,6 +143,7 @@ public void addItem(String itemId) {
* @param beforeItemId
* The entry before which the new item is to be inserted
*/
+ @Modifies( "items" )
public void insertItem(String itemId, String beforeItemId) {
if ((beforeItemId == null) || (beforeItemId.length() == 0)) {
addItem(itemId);
@@ -159,6 +166,7 @@ public void insertItem(String itemId, String beforeItemId) {
* @param afterItemId
* The entry after which the new item is to be inserted
*/
+ @Modifies( "items" )
public void appendItem(String itemId, String afterItemId) {
if ((afterItemId == null) || (afterItemId.length() == 0)) {
addItem(itemId);
@@ -179,6 +187,7 @@ public void appendItem(String itemId, String afterItemId) {
* The value to remove. Ignore if null or doesn't exist
* @return The index of the removed item, or -1 if not found
*/
+ @Modifies( "items" )
public int removeItem(String itemId) {
if (validItemId(itemId)) {
int pos = items.indexOf(itemId);
@@ -200,6 +209,7 @@ public int removeItem(String itemId) {
*
* @param items
*/
+ @Modifies( "items" )
public void setItems(Object[] items) {
if (items == null) {
this.items = null;
@@ -254,6 +264,7 @@ String getInternalItemsAsString() {
* @param items
* @deprecated
*/
+ @Modifies( "items" )
public void setItemsAsString(String items) {
this.items.clear();
if (items != null) {
@@ -271,4 +282,15 @@ public String toString() {
", items=" + items +
"} " + super.toString();
}
+
+
+ @Modifies( { "presentationStyles", "stylesList" } )
+ public void addPresentationStyle(String presentationStyle) {
+ super.addPresentationStyle(presentationStyle);
+ }
+
+ @Modifies( { "presentationStyles", "stylesList" } )
+ public void removePresentationStyle(String presentationStyle) {
+ super.removePresentationStyle(presentationStyle);
+ }
}
23 drools-informer/drools-informer-core/src/main/java/org/drools/informer/Item.java
View
@@ -16,6 +16,9 @@
package org.drools.informer;
+import org.drools.definition.type.Modifies;
+import org.drools.definition.type.PropertyReactive;
+
import java.util.*;
/**
@@ -23,6 +26,7 @@
*
* @author Damon Horrell
*/
+@PropertyReactive
public abstract class Item extends InformerObject {
private static final long serialVersionUID = 1L;
@@ -111,6 +115,7 @@ public void forceId(String newId) {
*
* @param presentationStyles
*/
+ @Modifies( { "presentationStyles", "stylesList" } )
public void setPresentationStyles(String[] presentationStyles) {
if (presentationStyles == null) {
this.presentationStyles.clear();
@@ -144,6 +149,7 @@ public void setPresentationStyles(String[] presentationStyles) {
*
* @param presentationStyles
*/
+ @Modifies( { "presentationStyles", "stylesList" } )
public void setPresentationStyles(Object[] presentationStyles) {
if (presentationStyles == null || presentationStyles.length == 0) {
this.presentationStyles = null;
@@ -157,6 +163,7 @@ public void setPresentationStyles(Object[] presentationStyles) {
*
* @param presentationStyle
*/
+ @Modifies( { "presentationStyles", "stylesList" } )
public void addPresentationStyle(String presentationStyle) {
if (presentationStyle != null) {
// if (this.presentationStyles == null) {
@@ -176,6 +183,7 @@ public void addPresentationStyle(String presentationStyle) {
*
* @param presentationStyle
*/
+ @Modifies( { "presentationStyles", "stylesList" } )
public void removePresentationStyle(String presentationStyle) {
// if (presentationStyle != null) {
// List<String> presentationStyles = new ArrayList<String>(Arrays.asList(getPresentationStyles()));
@@ -223,6 +231,7 @@ public String getPresentationStylesAsString() {
* @param presentationStyles
* @deprecated
*/
+ @Modifies( { "presentationStyles", "stylesList" } )
public void setPresentationStylesAsString(String presentationStyles) {
this.presentationStyles.clear();
if (presentationStyles != null && presentationStyles.length() != 0) {
@@ -276,12 +285,12 @@ public String toString() {
public List<String> getStylesList() {
- List list = new ArrayList();
- String[] styles = getPresentationStyles();
- if (styles != null) {
- list.addAll(Arrays.asList(styles));
- }
- return list;
-}
+ List list = new ArrayList();
+ String[] styles = getPresentationStyles();
+ if (styles != null) {
+ list.addAll(Arrays.asList(styles));
+ }
+ return list;
+ }
}
17 drools-informer/drools-informer-core/src/main/java/org/drools/informer/Questionnaire.java
View
@@ -280,15 +280,20 @@ public void setAvailableItems(Collection<String> availableItems) {
logger.debug("Available Items are: " + availableItems);
}
this.availableItems.clear();
- this.availableItems.addAll(availableItems);
+ this.availableItems.addAll( availableItems );
}
@Modifies( "availableItems" )
public void addAvailableItems(List<String> availableItems) {
- this.availableItems.addAll(availableItems);
+ this.availableItems.addAll( availableItems );
}
+ @Modifies( "availableItems" )
+ public void addAvailableItem( String availableItem ) {
+ this.availableItems.add( availableItem );
+ }
+
@@ -355,22 +360,22 @@ public int removeItem(String itemId) {
return super.removeItem(itemId);
}
- @Modifies( "presentationStyles" )
+ @Modifies( { "presentationStyles", "stylesList" } )
public void setPresentationStyles(String[] presentationStyles) {
super.setPresentationStyles(presentationStyles);
}
- @Modifies( "presentationStyles" )
+ @Modifies( { "presentationStyles", "stylesList" } )
public void setPresentationStyles(Object[] presentationStyles) {
super.setPresentationStyles(presentationStyles);
}
- @Modifies( "presentationStyles" )
+ @Modifies( { "presentationStyles", "stylesList" } )
public void addPresentationStyle(String presentationStyle) {
super.addPresentationStyle(presentationStyle);
}
- @Modifies( "presentationStyles" )
+ @Modifies( { "presentationStyles", "stylesList" } )
public void removePresentationStyle(String presentationStyle) {
super.removePresentationStyle(presentationStyle);
}
16 drools-informer/drools-informer-core/src/main/resources/org/drools/informer/Active.drl
View
@@ -31,7 +31,7 @@ import java.util.Set;
rule "build list of available items"
when
- $questionnaire : Questionnaire( $oldAvailableItems : availableItemSet, $items : itemList ) @watch( items )
+ $questionnaire : Questionnaire( $oldAvailableItems : availableItemSet, $items : itemList ) @watch( items, availableItems )
$newItems : Set( this != $oldAvailableItems ) from accumulate (
Item( $id : id != $questionnaire.id,
id memberOf $items,
@@ -61,7 +61,7 @@ end
rule "activate top-level item (if Questionnaire.activeItem is used)"
salience 4 // before: "activate/deactivate lower-level items (if Questionnaire.activeItem is used)"
when
- $questionnaire : Questionnaire( activeItem != null )
+ $questionnaire : Questionnaire( activeItem != null ) @watch( items )
$item : Item( id memberOf $questionnaire.itemList,
id == $questionnaire.activeItem,
active == false )
@@ -74,7 +74,7 @@ end
rule "deactivate top-level items (if Questionnaire.activeItem is used)"
salience 4 // before: "activate/deactivate lower-level items (if Questionnaire.activeItem is used)"
when
- $questionnaire : Questionnaire( activeItem != null )
+ $questionnaire : Questionnaire( activeItem != null ) @watch( items )
$item : Item( id memberOf $questionnaire.itemList,
id != $questionnaire.activeItem,
active == true )
@@ -89,12 +89,12 @@ end
rule "activate lower-level items (if Questionnaire.activeItem is used)"
salience 3 // before: "activate/deactivate InvalidAnswers"
when
- $questionnaire : Questionnaire( activeItem != null )
+ $questionnaire : Questionnaire( activeItem != null ) @watch( items )
$item : Item( id != $questionnaire.id,
id not memberOf $questionnaire.itemList,
active == false )
exists Group( id != $questionnaire.id, itemList contains $item.id,
- active == true )
+ active == true ) @watch( * )
then
modify ( $item ) {
setActive( true );
@@ -104,12 +104,12 @@ end
rule "deactivate lower-level items (if Questionnaire.activeItem is used)"
salience 3 // before: "activate/deactivate InvalidAnswers"
when
- $questionnaire : Questionnaire( activeItem != null )
+ $questionnaire : Questionnaire( activeItem != null ) @watch( items )
$item : Item( id != $questionnaire.id,
id not memberOf $questionnaire.itemList,
active == true )
not Group( id != $questionnaire.id, itemList contains $item.id,
- active == true )
+ active == true ) @watch( * )
then
modify ( $item ) {
setActive( false );
@@ -124,7 +124,7 @@ end
rule "activate everything (if Questionnaire.activeItem is not used)"
salience 3 // before: "activate/deactivate InvalidAnswers"
when
- $questionnaire : Questionnaire( activeItem == null )
+ $questionnaire : Questionnaire( activeItem == null ) @watch( items )
$item : Item( id != $questionnaire.id, active == false )
then
modify ( $item ) {
32 drools-informer/drools-informer-core/src/main/resources/org/drools/informer/Annotations.drl
View
@@ -103,22 +103,20 @@ end
rule "Question_Auto"
-dialect "mvel"
-no-loop
salience 1
when
$o : ISurveyable( $id : questionnaireId, surveyEnabled == true )
$k1 : Class() from $o.getClass()
Questionable( ) from $k1.getAnnotations()
$qst : Questionnaire( $ctx : context == $id )
- $fld : Field( $fldName : name, $fldKlass : class ) from AnnotationHelper.getFields($k1)
+ $fld : Field( $fldName : name, $fldKlass : class ) from AnnotationHelper.getFields( $k1 )
$qm : QuestionMark( $lab : label, $qType : type,
$req : required,
$dateFormat : dateFormat,
$oneShot : finalAnswer
) from $fld.getAnnotations()
not AllowedAnswers() from $fld.getAnnotations()
- not Question( context == $id, type == $fldName )
+ not Question( context == $id, type == $fldName ) @watch( * )
then
Question q = new Question( $fldName, $lab );
q.setContext( $id );
@@ -126,15 +124,19 @@ then
q.setRequired( $req );
q.setFinalAnswer( $oneShot );
q.setDateFormat( $dateFormat );
- $qst.addItem( q.id );
+
+
+ modify ( $qst ) {
+ addItem( q.getId() );
+ }
insert( q );
DomainModelAssociation dma = new DomainModelAssociation( );
- dma.setObject((Object) $o);
- dma.setQuestionId(q.id);
- dma.setContext($id);
- dma.setProperty($fldName);
- insert(dma);
+ dma.setObject( (Object) $o );
+ dma.setQuestionId( q.getId() );
+ dma.setContext( $id );
+ dma.setProperty( $fldName );
+ insert( dma );
end
@@ -147,11 +149,11 @@ when
$k1 : Class() from $o.getClass()
Questionable( ) from $k1.getAnnotations()
$qst : Questionnaire( $ctx : context == $id, $items : itemList )
- $fld : Field( $fldName : name, $fldKlass : class ) from AnnotationHelper.getFields($k1)
+ $fld : Field( $fldName : name, $fldKlass : class ) from AnnotationHelper.getFields( $k1 )
$q : QuestionMark( $lab : label, $qType : type,
$req : required ) from $fld.getAnnotations()
AllowedAnswers( $ansValues : values ) from $fld.getAnnotations()
- not MultipleChoiceQuestion( context == $id, type == $fldName ) @watch(*)
+ not MultipleChoiceQuestion( context == $id, type == $fldName ) @watch( * )
then
MultipleChoiceQuestion mcq = new MultipleChoiceQuestion( $fldName, $lab );
mcq.setContext( $id );
@@ -160,16 +162,18 @@ then
mcq.setPreLabel( $lab );
mcq.setPossibleAnswersByValue( $ansValues );
+
modify ( $qst ) {
addItem( mcq.getId() );
}
+ insert( mcq );
DomainModelAssociation dma = new DomainModelAssociation( );
- dma.setObject((Object) $o);
+ dma.setObject( (Object) $o );
dma.setQuestionId( mcq.getId() );
dma.setContext( $id );
dma.setProperty( $fldName );
- insert(dma);
+ insert( dma );
end
2  drools-informer/drools-informer-core/src/main/resources/org/drools/informer/Notes.drl
View
@@ -35,7 +35,7 @@ no-loop
when
$quest : Questionnaire( $itemz : itemList ) @watch( items )
$itemId : String() from $itemz;
- not Item( id == $itemId )
+ not Item( id == $itemId ) @watch( * )
then
modify ( $quest ) {
removeItem( $itemId );
8 drools-informer/drools-informer-core/src/main/resources/org/drools/informer/Queries.drl
View
@@ -18,6 +18,10 @@ package org.drools.informer
+query "getQuestionnaireByType" ( String $type, Questionnaire $quest )
+ $quest := Questionnaire( type == $type )
+end
+
query "getQuestionnaire" ( String $context, Questionnaire $quest )
$quest := Questionnaire( context == $context )
end
@@ -40,10 +44,10 @@ query "activeObjectsInContext" (String context)
end
query "getItemId"( String $type, String $context, String $id )
- Item( $type := type, $context := context, $id := id )
+ Item( $type := type, $context := context, $id := id ) @watch(*)
end
-query "getItem"( String $type, String $context, Item $item )
+query "getItem"( String $type, String $context, Item $item ) @watch(*)
$item := Item( $type := type, $context := context )
end
34 drools-informer/drools-informer-core/src/main/resources/org/drools/informer/ReadOnly.drl
View
@@ -30,12 +30,12 @@ rule "propagate readonly from group to subgroups"
no-loop
salience 5
when
- $item : Group( itemStyles : stylesList,
- stylesList not contains "readonly-inherited"
- && stylesList not contains "readonly" )
+ $item : Group( itemStyles : presentationStyles,
+ presentationStyles not contains "readonly-inherited"
+ && presentationStyles not contains "readonly" ) @watch( * )
exists (
Group( itemList contains $item.id, active == true,
- stylesList contains "readonly" || stylesList contains "readonly-inherited" )
+ presentationStyles contains "readonly" || presentationStyles contains "readonly-inherited" )
)
then
modify ( $item ) {
@@ -46,12 +46,12 @@ end
rule "propagate readonly from group to question"
salience 4
when
- $item : Question( itemStyles : stylesList,
- stylesList not contains "readonly-inherited"
- && stylesList not contains "readonly" ) @watch( presentationStyles )
+ $item : Question( itemStyles : presentationStyles,
+ presentationStyles not contains "readonly-inherited"
+ && presentationStyles not contains "readonly" )
exists (
Group( itemList contains $item.id, active == true,
- stylesList contains "readonly" || stylesList contains "readonly-inherited" )
+ presentationStyles contains "readonly" || presentationStyles contains "readonly-inherited" )
)
then
modify ( $item ) {
@@ -65,12 +65,12 @@ rule "remove readonly from group to subgroups"
no-loop
salience 2
when
- $item : Group( itemStyles : stylesList,
- stylesList contains "readonly-inherited"
- || stylesList contains "readonly" )
+ $item : Group( itemStyles : presentationStyles,
+ presentationStyles contains "readonly-inherited"
+ || presentationStyles contains "readonly" ) @watch( * )
not (
Group( itemList contains $item.id, active == true,
- stylesList contains "readonly" || stylesList contains "readonly-inherited" )
+ presentationStyles contains "readonly" || presentationStyles contains "readonly-inherited" )
)
then
modify ( $item ) {
@@ -81,13 +81,13 @@ end
rule "remove readonly from group to question"
salience 1
when
- $item : Question( itemStyles : stylesList,
- stylesList contains "readonly-inherited"
- || stylesList contains "readonly"
- ) @watch( presentationStyles )
+ $item : Question( itemStyles : presentationStyles,
+ presentationStyles contains "readonly-inherited"
+ || presentationStyles contains "readonly"
+ )
not (
Group( itemList contains $item.id, active == true,
- stylesList contains "readonly" || stylesList contains "readonly-inherited" )
+ presentationStyles contains "readonly" || presentationStyles contains "readonly-inherited" )
)
then
modify ( $item ) {
23 drools-informer/drools-informer-core/src/main/resources/org/drools/informer/Status.drl
View
@@ -47,14 +47,14 @@ declare Size
end
query includes( Group $master, String $qid )
- ( $master := Group( itemList contains $qid ) )
+ ( $master := Group( itemList contains $qid ) @watch( * ) )
or
(
- $master := Group( $list : itemList )
+ $master := Group( $list : itemList ) @watch( * )
and
- $inner := Group( id memberOf $list )
+ $inner := Group( id memberOf $list ) @watch( * )
and
- includes( $inner, $qid ; )
+ ?includes( $inner, $qid ; )
)
end
@@ -62,7 +62,7 @@ end
query size( String $formId, long $num )
$quest : Group( id == $formId )
Set( $num := size ) from accumulate (
- $q : Question( $qid : id )
+ $q : Question( $qid : id ) @watch( * )
and
?includes( $quest, $qid ; )
,
@@ -110,17 +110,18 @@ end
rule "Questionnaire Progress"
salience -1000 // when questionnaire is stable
when
- $quest : Questionnaire( $formId : id )
- Number( $num : longValue ) from accumulate (
- $q : Question( $qid : id, lastAnswer != null )
+ $quest : Questionnaire( $formId : id ) @watch( * )
+ accumulate (
+ $q : Question( $qid : id, lastAnswer != null ) @watch( * )
and
- ?includes( $quest, $qid ; )
+ ?includes( $quest, $qid; )
,
- count ( $q )
+ $num : count ( $q )
)
Size( formId == $formId, $max : num > 0 )
then
- Progress p = new Progress( $formId, (int) Math.round( 100.0*$num/$max ) );
+ Progress p = new Progress( $formId, (int) Math.round( 100.0 * $num.doubleValue() / $max ) );
+ System.out.println( "Making progress.... " + p );
insertLogical( p );
end
25 ...former/drools-informer-core/src/main/resources/org/drools/informer/presentation/presentation_adapter.drl
View
@@ -26,8 +26,9 @@ when
$ticket : SurveyTicket( $id : sid, questionnaire == null )
$quest : Questionnaire( id == $id )
then
- $ticket.setQuestionnaire( $quest );
- update($ticket);
+ modify ( $ticket ) {
+ setQuestionnaire( $quest );
+ }
end
@@ -55,7 +56,7 @@ end
rule "Clean adapters"
when
$gui : GUIAdapter( $id : itemId )
- not Item( id == $id )
+ not Item( id == $id ) @watch( * )
then
retract( $gui );
end
@@ -118,9 +119,12 @@ then
qga.setCurrentAnswer( $q.getLastAnswer() );
qga.setAnswerType($type.getValue());
qga.setValidationMessage( $q.getPostLabel() );
- $sga.getSurveyQuestions().add(qga);
- insert(qga);
- update($sga);
+
+ insert( qga );
+
+ modify( $sga ) {
+ getSurveyQuestions().add(qga);
+ }
end
@@ -178,10 +182,11 @@ when
$q : Question( $qid : id, $qLab : preLabel, $post : postLabel, $req : required, $type : answerType == Question.QuestionType.TYPE_BOOLEAN )
$qga : QuestionGUIAdapter( itemId == $qid, possibleAnswers == null)
then
- $qga.setPossibleAnswers( new java.util.ArrayList() );
- $qga.getPossibleAnswers().add( new PossibleAnswer("true", "Yes") );
- $qga.getPossibleAnswers().add( new PossibleAnswer("false", "No") );
- update($qga);
+ modify ( $qga ) {
+ setPossibleAnswers( new java.util.ArrayList() ),
+ getPossibleAnswers().add( new PossibleAnswer("true", "Yes") ),
+ getPossibleAnswers().add( new PossibleAnswer("false", "No") );
+ }
end
12 drools-informer/drools-informer-core/src/test/java/org/drools/informer/AnnotationsTest.java
View
@@ -22,11 +22,13 @@
import org.drools.agent.KnowledgeAgent;
import org.drools.agent.KnowledgeAgentConfiguration;
import org.drools.agent.KnowledgeAgentFactory;
+import org.drools.agent.impl.PrintStreamSystemEventListener;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.common.InternalFactHandle;
import org.drools.informer.generator.annotations.QuestionMark;
+import org.drools.informer.listener.DebugAgendaEventListener;
import org.drools.io.Resource;
import org.drools.io.impl.ChangeSetImpl;
import org.drools.io.impl.ClassPathResource;
@@ -54,19 +56,16 @@ public void testGenerateQuestionnaireWithAnnotations() throws NoSuchFieldExcepti
KnowledgeAgentConfiguration kaConfig = KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
kaConfig.setProperty("drools.agent.newInstance","false");
KnowledgeAgent kAgent = KnowledgeAgentFactory.newKnowledgeAgent("testAnnotationKA",kaConfig);
+// kAgent.setSystemEventListener( new PrintStreamSystemEventListener() );
ChangeSetImpl changeSet = new ChangeSetImpl();
ClassPathResource res1 = new ClassPathResource("org/drools/informer/informer-changeset.xml");
res1.setResourceType(ResourceType.CHANGE_SET);
-// ClassPathResource res3 = new ClassPathResource("org/drools/informer/annotation_tests.drl");
-// res3.setResourceType(ResourceType.DRL);
changeSet.setResourcesAdded(Arrays.asList((Resource) res1));
kAgent.applyChangeSet(changeSet);
-
-
StatefulKnowledgeSession kSession = kAgent.getKnowledgeBase().newStatefulKnowledgeSession();
kSession.setGlobal("kAgent",kAgent);
@@ -80,6 +79,11 @@ public void testGenerateQuestionnaireWithAnnotations() throws NoSuchFieldExcepti
kSession.insert(p2);
kSession.fireAllRules();
+
+ for ( Object o : kSession.getObjects() ) {
+ System.err.println(o);
+ }
+
assertEquals(1, kSession.getQueryResults("getQuestionnaire", p1.getQuestionnaireId(), Variable.v).size());
assertEquals(1, kSession.getQueryResults("getQuestionnaire",p2.getQuestionnaireId(), Variable.v).size());
8 drools-informer/drools-informer-core/src/test/java/org/drools/informer/QuestionStatusTest.java
View
@@ -20,6 +20,7 @@
import org.drools.agent.KnowledgeAgent;
import org.drools.agent.KnowledgeAgentConfiguration;
import org.drools.agent.KnowledgeAgentFactory;
+import org.drools.agent.impl.PrintStreamSystemEventListener;
import org.drools.builder.ResourceType;
import org.drools.core.util.Iterator;
import org.drools.informer.generator.annotations.QuestionMark;
@@ -50,12 +51,13 @@ public void testValidityStatus() throws NoSuchFieldException {
kaConfig.setProperty("drools.agent.newInstance","false");
KnowledgeAgent kAgent = KnowledgeAgentFactory.newKnowledgeAgent("testAnnotationKA",kaConfig);
+ kAgent.setSystemEventListener( new PrintStreamSystemEventListener());
+
ChangeSetImpl changeSet = new ChangeSetImpl();
ClassPathResource res1 = new ClassPathResource("org/drools/informer/informer-changeset.xml");
res1.setResourceType(ResourceType.CHANGE_SET);
- ClassPathResource res3 = new ClassPathResource("org/drools/informer/annotation_tests.drl");
- res3.setResourceType(ResourceType.DRL);
- changeSet.setResourcesAdded(Arrays.asList((Resource) res1, res3));
+
+ changeSet.setResourcesAdded(Arrays.asList((Resource) res1));
kAgent.applyChangeSet(changeSet);
5 drools-informer/drools-informer-core/src/test/java/org/drools/informer/rules/ActiveTest.java
View
@@ -20,6 +20,7 @@
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
+import org.drools.event.rule.DebugAgendaEventListener;
import org.drools.informer.*;
import org.drools.io.ResourceFactory;
import org.drools.runtime.StatefulKnowledgeSession;
@@ -64,6 +65,8 @@ public void setUp() throws Exception {
@Test
public void testActiveObjects() {
StatefulKnowledgeSession knowledgeSession = knowledgeBase.newStatefulKnowledgeSession();
+// knowledgeSession.addEventListener( new DebugAgendaEventListener( ) );
+
try {
Questionnaire questionnaire = new Questionnaire("questionnaire");
Group group1 = new Group("group1");
@@ -96,6 +99,8 @@ public void testActiveObjects() {
assertEquals(new HashSet<String>(Arrays.asList(new String[] { questionnaire.getId(), group1.getId(), group2.getId(), note1.getId(), note2.getId(),
note3.getId(), note4.getId(), note5.getId(), note6.getId() })), itemIds);
+ System.out.println( "------------------------------------------");
+
questionnaire.setActiveItem(group1.getId());
knowledgeSession.update(handleQuestionnaire, questionnaire);
knowledgeSession.fireAllRules();
5 drools-informer/drools-informer-core/src/test/java/org/drools/informer/rules/ReadOnlyTest.java
View
@@ -51,6 +51,7 @@ public void setUp() throws Exception {
knowledgeBuilder.add(ResourceFactory.newClassPathResource("org/drools/informer/Active.drl"), ResourceType.DRL);
knowledgeBuilder.add(ResourceFactory.newClassPathResource("org/drools/informer/Queries.drl"), ResourceType.DRL);
knowledgeBuilder.add(ResourceFactory.newClassPathResource("org/drools/informer/ReadOnly.drl"), ResourceType.DRL);
+ System.err.println( knowledgeBuilder.getErrors() );
assertFalse(knowledgeBuilder.hasErrors());
knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
knowledgeBase.addKnowledgePackages(knowledgeBuilder.getKnowledgePackages());
@@ -96,6 +97,10 @@ public void testReadOnly() {
knowledgeSession.insert(question1);
knowledgeSession.fireAllRules();
+ for ( Object o : knowledgeSession.getObjects() ) {
+ System.out.println( o );
+ }
+
assertEquals(true, isReadOnlyInherited(question1));
System.out.println( "-------------------------------------------" );
60 drools-informer/drools-informer-core/src/test/resources/org/drools/informer/annotation_tests.drl
View
@@ -1,60 +0,0 @@
-/*
- * Copyright 2011 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.drools.informer;
-
-import java.lang.annotation.Annotation;
-import org.drools.informer.generator.annotations.Questionable;
-import org.drools.informer.generator.annotations.QuestionMark;
-import org.drools.informer.generator.annotations.AllowedAnswers;
-import org.drools.informer.generator.ISurveyable;
-
-import org.drools.informer.Group;
-import org.drools.informer.InvalidAnswer;
-import org.drools.informer.Question;
-import org.drools.informer.Questionnaire;
-import org.drools.informer.MultipleChoiceQuestion;
-import org.drools.informer.MultipleChoiceQuestion.PossibleAnswer;
-import org.drools.informer.Note;
-import org.drools.informer.Item;
-import org.drools.informer.DomainModelAssociation;
-import org.drools.informer.Answer;
-import org.drools.informer.domain.DomainModelSupport;
-
-
-
-
-query questionnaire( String $context )
- $quest : Questionnaire( context == $context )
-end
-
-
-query question( String $context, String $type )
- $quest : Question( context == $context, type == $type )
-end
-
-query association( Object $obj, String $prop )
- $quest : DomainModelAssociation( object == $obj, property == $prop )
-end
-
-query associations( Object $obj )
- $quest : DomainModelAssociation( object == $obj )
-end
-
-
-
-
-
6 ...ls-informer/drools-informer-interaction/src/main/resources/org/drools/informer/interaction/humanTask.drl
View
@@ -426,9 +426,9 @@ when
$task : HumanTask( $tid : taskId, $curr : state != null )
TaskTransitionHolder( $xid : questionnaireId, taskId == $tid )
$tst : List() from accumulate ( AllowedTransition( $tid, $s, $tx, $new ; ) collectList( $tx.name() ) )
- $tranx: MultipleChoiceQuestion( type == "transition", context == $xid, $prev : possibleAnswersValuesAsList != $tst ) @watch( possibleAnswers, lastAnswer )
+ $tranx: MultipleChoiceQuestion( type == "transition", context == $xid, $prev : possibleAnswersValuesAsList != $tst ) @watch( * )
then
- System.out.println( "STTING TRANSITIONS " + $tst );
+ System.out.println( "SETTING TRANSITIONS " + $tst );
modify ( $tranx ) { setPossibleAnswersByValue( $tst ); }
end
@@ -440,7 +440,7 @@ when
transitionHolder( $xid, $tid, $owner ; )
$owners : MultipleChoiceQuestion( type == "owner", context == $xid,
$prev : possibleAnswersValuesAsList != $potential
- ) @watch( possibleAnswers, lastAnswer )
+ ) @watch( * )
then
System.out.println( "SETTING OWNERS " + $potential + " when prev was " + $prev ) ;
modify ( $owners ) { setPossibleAnswersByValue( $potential ); }
6 drools-informer/drools-informer-interaction/src/test/java/TaskInteractionTest.java
View
@@ -102,6 +102,7 @@ public void testSurveyTaskWithInteractionWithoutAlerting() {
kSession.insert( "surveytaskinter" );
kSession.fireAllRules();
+ report( kSession, System.err );
String mainTaskId = getMainTaskQuestId( kSession );
String questionId = getTransitionQuestion( kSession, mainTaskId );
@@ -275,18 +276,21 @@ public void testSurveyTask() {
kSession.insert( "surveytask" );
kSession.fireAllRules();
+ System.out.println( "_----------------------------------------_");
+
kSession.insert( new Answer( "question2", "testId", "someValue" ) );
kSession.fireAllRules();
+ System.out.println( "_----------------------------------------_");
report( kSession, System.err );
System.err.println( kSession.getGlobal( "list" ) );
System.err.println( kSession.getGlobal( "taskLog" ) );
- assertEquals( 15, kSession.getObjects().size() );
assertEquals( 4, ((List) kSession.getGlobal( "taskLog" )).size() );
+ assertEquals( 15, kSession.getObjects().size() );
kSession.dispose();
}
Please sign in to comment.
Something went wrong with that request. Please try again.