← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20783: add service method for checking existence of PSI (by uid)

 

------------------------------------------------------------
revno: 20783
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-10-20 13:26:49 +0700
message:
  add service method for checking existence of PSI (by uid)
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/program/ProgramStageInstanceStoreTest.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/ProgramStageInstanceService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java	2015-09-28 19:06:45 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java	2015-10-20 06:26:49 +0000
@@ -69,6 +69,8 @@
      */
     void updateProgramStageInstance( ProgramStageInstance programStageInstance );
 
+    boolean programStageInstanceExists(String uid);
+
     /**
      * Returns a {@link TrackedEntityAttribute}.
      *

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceStore.java	2015-09-24 08:32:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceStore.java	2015-10-20 06:26:49 +0000
@@ -139,4 +139,6 @@
      * @return the number of ProgramStageInstances.
      */
     long getProgramStageInstanceCountLastUpdatedAfter( Date time );
+
+    boolean exists( String uid );
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java	2015-09-24 08:32:10 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java	2015-10-20 06:26:49 +0000
@@ -148,6 +148,12 @@
     }
 
     @Override
+    public boolean programStageInstanceExists( String uid )
+    {
+        return programStageInstanceStore.exists( uid );
+    }
+
+    @Override
     public List<ProgramStageInstance> getProgramStageInstances( Collection<ProgramInstance> programInstances,
         EventStatus status )
     {

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java	2015-09-29 16:08:34 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java	2015-10-20 06:26:49 +0000
@@ -291,6 +291,13 @@
         return rs != null ? rs.intValue() : 0;
     }
 
+    @Override
+    public boolean exists( String uid )
+    {
+        Integer result = jdbcTemplate.queryForObject( "select count(*) from programstageinstance where uid=?", Integer.class, uid );
+        return result != null && result > 0;
+    }
+
     // -------------------------------------------------------------------------
     // Supportive methods
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/program/ProgramStageInstanceStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/program/ProgramStageInstanceStoreTest.java	2015-09-03 03:11:47 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/program/ProgramStageInstanceStoreTest.java	2015-10-20 06:26:49 +0000
@@ -28,16 +28,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
 import org.hisp.dhis.DhisSpringTest;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementService;
@@ -52,6 +42,15 @@
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import static org.junit.Assert.*;
+
 /**
  * @author Chau Thu Tran
  */
@@ -230,9 +229,9 @@
 
         DateTime testDate1 = DateTime.now();
         testDate1.withTimeAtStartOfDay();
-        testDate1 = testDate1.minusDays( 70  );
+        testDate1 = testDate1.minusDays( 70 );
         incidenDate = testDate1.toDate();
-        
+
         DateTime testDate2 = DateTime.now();
         testDate2.withTimeAtStartOfDay();
         enrollmentDate = testDate2.toDate();
@@ -266,6 +265,17 @@
     }
 
     @Test
+    public void testProgramStageInstanceExists()
+    {
+        programStageInstanceStore.save( programStageInstanceA );
+        programStageInstanceStore.save( programStageInstanceB );
+
+        assertTrue( programStageInstanceStore.exists( programStageInstanceA.getUid() ) );
+        assertTrue( programStageInstanceStore.exists( programStageInstanceB.getUid() ) );
+        assertFalse( programStageInstanceStore.exists( "aaaabbbbccc" ) );
+    }
+
+    @Test
     public void testGetProgramStageInstanceByProgramInstanceStage()
     {
         programStageInstanceStore.save( programStageInstanceA );
@@ -305,7 +315,7 @@
         assertTrue( stageInstances.contains( programStageInstanceB ) );
         assertTrue( stageInstances.contains( programStageInstanceD1 ) );
     }
-    
+
     @Test
     public void testGetOverDueEventCount()
     {