← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14893: npe assertions, changed from string to integer for programId saveProgramEnrollmentAction, was cau...

 

------------------------------------------------------------
revno: 14893
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-04-18 13:34:14 +0700
message:
  npe assertions, changed from string to integer for programId saveProgramEnrollmentAction, was caused it to be looked up as uid and not id, there might be other similar cases around
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstance.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/SaveProgramEnrollmentAction.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/program/ProgramInstance.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstance.java	2014-04-04 22:14:22 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstance.java	2014-04-18 06:34:14 +0000
@@ -41,6 +41,7 @@
 import org.hisp.dhis.sms.outbound.OutboundSms;
 import org.hisp.dhis.trackedentity.TrackedEntityInstance;
 import org.hisp.dhis.trackedentitycomment.TrackedEntityComment;
+import org.springframework.util.Assert;
 
 import java.util.ArrayList;
 import java.util.Date;
@@ -118,6 +119,9 @@
      */
     public void enrollTrackedEntityInstance( TrackedEntityInstance entityInstance, Program program )
     {
+        Assert.notNull( entityInstance );
+        Assert.notNull( program );
+
         setEntityInstance( entityInstance );
         entityInstance.getProgramInstances().add( this );
 

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/SaveProgramEnrollmentAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/SaveProgramEnrollmentAction.java	2014-04-06 15:48:31 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/SaveProgramEnrollmentAction.java	2014-04-18 06:34:14 +0000
@@ -28,12 +28,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
-
+import com.opensymphony.xwork2.Action;
 import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager;
@@ -46,7 +41,11 @@
 import org.hisp.dhis.trackedentity.TrackedEntityInstance;
 import org.hisp.dhis.trackedentity.TrackedEntityInstanceService;
 
-import com.opensymphony.xwork2.Action;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
 
 /**
  * @author Abyot Asalefew Gizaw
@@ -110,9 +109,9 @@
         this.entityInstanceId = entityInstanceId;
     }
 
-    private String programId;
+    private Integer programId;
 
-    public void setProgramId( String programId )
+    public void setProgramId( Integer programId )
     {
         this.programId = programId;
     }
@@ -156,8 +155,18 @@
 
         Program program = programService.getProgram( programId );
 
+        if ( program == null )
+        {
+            return INPUT;
+        }
+
         OrganisationUnit orgunit = selectionManager.getSelectedOrganisationUnit();
 
+        if ( orgunit == null )
+        {
+            return INPUT;
+        }
+
         Date enrollment = (enrollmentDate == null || enrollmentDate.isEmpty()) ? null : format
             .parseDate( enrollmentDate );
 
@@ -183,7 +192,7 @@
         // ---------------------------------------------------------------------
         // Update enrollment-date and incident-date
         // ---------------------------------------------------------------------
-        
+
         else
         {
             programInstance.setEnrollmentDate( enrollment );