← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19863: Added trackedEntityAttribute to programRuleAction

 

------------------------------------------------------------
revno: 19863
committer: Markus Bekken <markus.bekken@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-08-26 20:14:12 +0200
message:
  Added trackedEntityAttribute to programRuleAction
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleAction.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/programrule/hibernate/ProgramRuleAction.hbm.xml
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/programrule/ProgramRuleActionServiceTest.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/programrule/ProgramRuleActionStoreTest.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleAction.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleAction.java	2015-07-13 12:34:39 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleAction.java	2015-08-26 18:14:12 +0000
@@ -33,6 +33,7 @@
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+
 import org.hisp.dhis.common.BaseIdentifiableObject;
 import org.hisp.dhis.common.DxfNamespaces;
 import org.hisp.dhis.common.IdentifiableObject;
@@ -42,6 +43,7 @@
 import org.hisp.dhis.common.view.ExportView;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.program.ProgramStageSection;
+import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
 
 /**
  * @author markusbekken
@@ -98,6 +100,18 @@
      * </ul>
      */
     private DataElement dataElement;
+    
+    /**
+     * The data element that is affected by the rule action.
+     * Used for:
+     * <p/>
+     * <ul>
+     * <li>hidefield</li>
+     * <li>showwarning</li>
+     * <li>showerror</li>
+     * </ul>
+     */
+    private TrackedEntityAttribute attribute;
 
     /**
      * The program stage section that is affected by the rule action.
@@ -133,12 +147,13 @@
 
     }
 
-    public ProgramRuleAction( String name, ProgramRule programRule, ProgramRuleActionType programRuleActionType, DataElement dataElement, String location, String content, String data )
+    public ProgramRuleAction( String name, ProgramRule programRule, ProgramRuleActionType programRuleActionType, DataElement dataElement, TrackedEntityAttribute attribute, String location, String content, String data )
     {
         this.name = name;
         this.programRule = programRule;
         this.programRuleActionType = programRuleActionType;
         this.dataElement = dataElement;
+        this.attribute = attribute;
         this.location = location;
         this.content = content;
         this.data = data;
@@ -186,6 +201,20 @@
     {
         this.dataElement = dataElement;
     }
+    
+    @JsonProperty( "trackedEntityAttribute" )
+    @JsonView( { DetailedView.class, ExportView.class } )
+    @JacksonXmlProperty( localName = "trackedEntityAttribute", namespace = DxfNamespaces.DXF_2_0 )
+    public TrackedEntityAttribute getAttribute()
+    {
+        return attribute;
+    }
+
+    public void setAttribute( TrackedEntityAttribute attribute )
+    {
+        this.attribute = attribute;
+    }
+
 
     @JsonProperty
     @JsonSerialize( as = BaseIdentifiableObject.class )
@@ -254,6 +283,7 @@
                 location = programRuleAction.getLocation();
                 content = programRuleAction.getContent();
                 data = programRuleAction.getData();
+                attribute = programRuleAction.getAttribute();
             }
             else if ( strategy.isMerge() )
             {
@@ -264,6 +294,7 @@
                 location = programRuleAction.getLocation() == null ? location : programRuleAction.getLocation();
                 content = programRuleAction.getContent() == null ? content : programRuleAction.getContent();
                 data = programRuleAction.getData() == null ? data : programRuleAction.getData();
+                attribute = programRuleAction.getAttribute() == null ? attribute : programRuleAction.getAttribute();
             }
         }
     }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/programrule/hibernate/ProgramRuleAction.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/programrule/hibernate/ProgramRuleAction.hbm.xml	2015-06-23 15:59:19 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/programrule/hibernate/ProgramRuleAction.hbm.xml	2015-08-26 18:14:12 +0000
@@ -28,6 +28,9 @@
     <many-to-one name="dataElement" class="org.hisp.dhis.dataelement.DataElement"
       column="dataelementid" foreign-key="fk_programruleaction_dataelement" />
 
+    <many-to-one name="attribute" class="org.hisp.dhis.trackedentity.TrackedEntityAttribute"
+      column="trackedentityattributeid" foreign-key="fk_programrulevariable_trackedentityattribute" />
+
     <many-to-one name="programStageSection" class="org.hisp.dhis.program.ProgramStageSection"
       column="programstagesectionid" foreign-key="fk_programruleaction_programstagesection" />
 

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/programrule/ProgramRuleActionServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/programrule/ProgramRuleActionServiceTest.java	2015-06-23 15:59:19 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/programrule/ProgramRuleActionServiceTest.java	2015-08-26 18:14:12 +0000
@@ -39,8 +39,11 @@
 import org.hisp.dhis.DhisSpringTest;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.hibernate.exception.CreateAccessDeniedException;
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramService;
+import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
+import org.hisp.dhis.trackedentity.TrackedEntityAttributeService;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
@@ -50,6 +53,7 @@
     private ProgramRule programRuleA;
     private ProgramRule programRuleB;
     private ProgramRule programRuleC;
+    private TrackedEntityAttribute attributeA;
     private DataElement dataElementA;
     private Program programA;
     
@@ -60,6 +64,9 @@
     private DataElementService dataElementService;
     
     @Autowired
+    private TrackedEntityAttributeService attributeService;
+    
+    @Autowired
     private ProgramRuleActionService actionService;
 
     @Autowired
@@ -73,38 +80,43 @@
         programRuleB = createProgramRule( 'B', programA );
         programRuleC = createProgramRule( 'C', programA );
         dataElementA = createDataElement( 'A' );
+        attributeA = createTrackedEntityAttribute('a');
         
         programService.addProgram( programA );
         programRuleService.addProgramRule( programRuleA );
         programRuleService.addProgramRule( programRuleB );
         programRuleService.addProgramRule( programRuleC );
         dataElementService.addDataElement( dataElementA );
+        attributeService.addTrackedEntityAttribute(attributeA);
     }
     
     @Test
     public void testAddGet()
     {
-        ProgramRuleAction actionA = new ProgramRuleAction( "ActionA", programRuleA, ProgramRuleActionType.ASSIGNVARIABLE, null, null, "$myvar", "true");
-        ProgramRuleAction actionB = new ProgramRuleAction( "ActionB", programRuleA, ProgramRuleActionType.DISPLAYTEXT, null, "con","Hello", "$placeofliving");
-        ProgramRuleAction actionC = new ProgramRuleAction( "ActionC", programRuleA, ProgramRuleActionType.HIDEFIELD, dataElementA, null, null, null);
+        ProgramRuleAction actionA = new ProgramRuleAction( "ActionA", programRuleA, ProgramRuleActionType.ASSIGNVARIABLE, null, null, null, "$myvar", "true");
+        ProgramRuleAction actionB = new ProgramRuleAction( "ActionB", programRuleA, ProgramRuleActionType.DISPLAYTEXT, null, null, "con","Hello", "$placeofliving");
+        ProgramRuleAction actionC = new ProgramRuleAction( "ActionC", programRuleA, ProgramRuleActionType.HIDEFIELD, dataElementA, null, null, null, null);
+        ProgramRuleAction actionD = new ProgramRuleAction( "ActionC", programRuleA, ProgramRuleActionType.HIDEFIELD, null, attributeA, null, null, null);
         
         int idA = actionService.addProgramRuleAction( actionA );
         int idB = actionService.addProgramRuleAction( actionB );
         int idC = actionService.addProgramRuleAction( actionC );
+        int idD = actionService.addProgramRuleAction( actionD );
         
         assertEquals( actionA, actionService.getProgramRuleAction( idA ) );
         assertEquals( actionB, actionService.getProgramRuleAction( idB ) );
         assertEquals( actionC, actionService.getProgramRuleAction( idC ) );
+        assertEquals( actionD, actionService.getProgramRuleAction( idD ) );
     }
     
     @Test
     public void testGetByProgram()
     {
-        ProgramRuleAction actionD = new ProgramRuleAction( "ActionD", programRuleB, ProgramRuleActionType.ASSIGNVARIABLE, null, null, "$myvar", "true");
-        ProgramRuleAction actionE = new ProgramRuleAction( "ActionE", programRuleB, ProgramRuleActionType.DISPLAYTEXT, null, "con","Hello", "$placeofliving");
-        ProgramRuleAction actionF = new ProgramRuleAction( "ActionF", programRuleB, ProgramRuleActionType.HIDEFIELD, dataElementA, null, null, null);
+        ProgramRuleAction actionD = new ProgramRuleAction( "ActionD", programRuleB, ProgramRuleActionType.ASSIGNVARIABLE, null, null, null, "$myvar", "true");
+        ProgramRuleAction actionE = new ProgramRuleAction( "ActionE", programRuleB, ProgramRuleActionType.DISPLAYTEXT, null, null, "con","Hello", "$placeofliving");
+        ProgramRuleAction actionF = new ProgramRuleAction( "ActionF", programRuleB, ProgramRuleActionType.HIDEFIELD, dataElementA, null, null, null, null);
         //Add an action that is not part of programRuleB....
-        ProgramRuleAction actionG = new ProgramRuleAction( "ActionG", programRuleC, ProgramRuleActionType.HIDEFIELD, dataElementA, null, null, null);
+        ProgramRuleAction actionG = new ProgramRuleAction( "ActionG", programRuleC, ProgramRuleActionType.HIDEFIELD, dataElementA, null, null, null, null);
         
         actionService.addProgramRuleAction( actionD );
         actionService.addProgramRuleAction( actionE );
@@ -125,7 +137,7 @@
     @Test
     public void testUpdate()
     {
-        ProgramRuleAction actionH = new ProgramRuleAction( "ActionH", programRuleB, ProgramRuleActionType.ASSIGNVARIABLE, null, null, "$myvar", "true");
+        ProgramRuleAction actionH = new ProgramRuleAction( "ActionH", programRuleB, ProgramRuleActionType.ASSIGNVARIABLE, null, null, null, "$myvar", "true");
         
         int idH = actionService.addProgramRuleAction( actionH );
         
@@ -144,8 +156,8 @@
     @Test
     public void testDeleteProgramRuleVariable()
     {
-        ProgramRuleAction actionI = new ProgramRuleAction( "ActionI", programRuleA, ProgramRuleActionType.ASSIGNVARIABLE, null, null, "$myvar", "true");
-        ProgramRuleAction actionJ = new ProgramRuleAction( "ActionJ", programRuleA, ProgramRuleActionType.DISPLAYTEXT, null, "con","Hello", "$placeofliving");
+        ProgramRuleAction actionI = new ProgramRuleAction( "ActionI", programRuleA, ProgramRuleActionType.ASSIGNVARIABLE, null, null, null, "$myvar", "true");
+        ProgramRuleAction actionJ = new ProgramRuleAction( "ActionJ", programRuleA, ProgramRuleActionType.DISPLAYTEXT, null, null, "con","Hello", "$placeofliving");
         
         int idI = actionService.addProgramRuleAction( actionI );
         int idJ = actionService.addProgramRuleAction( actionJ );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/programrule/ProgramRuleActionStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/programrule/ProgramRuleActionStoreTest.java	2015-06-23 15:59:19 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/programrule/ProgramRuleActionStoreTest.java	2015-08-26 18:14:12 +0000
@@ -75,9 +75,9 @@
     @Test
     public void testGetByProgram()
     {
-        ProgramRuleAction actionA = new ProgramRuleAction( "ActionA", programRuleA, ProgramRuleActionType.ASSIGNVARIABLE, null, null, "$myvar", "true");        
-        ProgramRuleAction actionB = new ProgramRuleAction( "ActionB", programRuleA, ProgramRuleActionType.DISPLAYTEXT, null, "con","Hello", "$placeofliving");
-        ProgramRuleAction actionC = new ProgramRuleAction( "ActionC", programRuleA, ProgramRuleActionType.HIDEFIELD, dataElementA, null, null, null);
+        ProgramRuleAction actionA = new ProgramRuleAction( "ActionA", programRuleA, ProgramRuleActionType.ASSIGNVARIABLE, null, null, null, "$myvar", "true");        
+        ProgramRuleAction actionB = new ProgramRuleAction( "ActionB", programRuleA, ProgramRuleActionType.DISPLAYTEXT, null, null, "con","Hello", "$placeofliving");
+        ProgramRuleAction actionC = new ProgramRuleAction( "ActionC", programRuleA, ProgramRuleActionType.HIDEFIELD, dataElementA, null, null, null, null);
        
         actionStore.save( actionA );
         actionStore.save( actionB );