← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20846: updated TEI service/controller, now uses import summary

 

------------------------------------------------------------
revno: 20846
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-10-22 12:16:58 +0700
message:
  updated TEI service/controller, now uses import summary
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/AbstractTrackedEntityInstanceService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/TrackedEntityInstanceService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/TrackedEntityInstanceServiceTest.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/TrackedEntityInstanceController.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-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/AbstractTrackedEntityInstanceService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/AbstractTrackedEntityInstanceService.java	2015-10-08 13:12:38 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/AbstractTrackedEntityInstanceService.java	2015-10-22 05:16:58 +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.HashSet;
-import java.util.List;
-import java.util.Set;
-
+import com.google.common.collect.Lists;
 import org.hisp.dhis.common.CodeGenerator;
 import org.hisp.dhis.common.IdentifiableObjectManager;
 import org.hisp.dhis.commons.collection.CachingMap;
@@ -57,7 +52,11 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.util.Assert;
 
-import com.google.common.collect.Lists;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -107,7 +106,7 @@
     public List<TrackedEntityInstance> getTrackedEntityInstances( TrackedEntityInstanceQueryParams params )
     {
         List<org.hisp.dhis.trackedentity.TrackedEntityInstance> teis = entityInstanceService.getTrackedEntityInstances( params );
-        
+
         List<TrackedEntityInstance> teiItems = new ArrayList<>();
 
         for ( org.hisp.dhis.trackedentity.TrackedEntityInstance trackedEntityInstance : teis )
@@ -147,20 +146,20 @@
         trackedEntityInstance.setInactive( entityInstance.isInactive() );
 
         if ( includeRelationships )
-        {            
+        {
             //TODO include relationships in data model and void transactional query in for-loop
-            
+
             Collection<Relationship> relationships = relationshipService.getRelationshipsForTrackedEntityInstance( entityInstance );
-    
+
             for ( Relationship entityRelationship : relationships )
             {
                 org.hisp.dhis.dxf2.events.trackedentity.Relationship relationship = new org.hisp.dhis.dxf2.events.trackedentity.Relationship();
                 relationship.setDisplayName( entityRelationship.getRelationshipType().getDisplayName() );
                 relationship.setTrackedEntityInstanceA( entityRelationship.getEntityInstanceA().getUid() );
                 relationship.setTrackedEntityInstanceB( entityRelationship.getEntityInstanceB().getUid() );
-    
+
                 relationship.setRelationship( entityRelationship.getRelationshipType().getUid() );
-    
+
                 // we might have cases where A <=> A, so we only include the relative if the UIDs do not match
                 if ( !entityRelationship.getEntityInstanceA().getUid().equals( entityInstance.getUid() ) )
                 {
@@ -170,7 +169,7 @@
                 {
                     relationship.setRelative( getTrackedEntityInstance( entityRelationship.getEntityInstanceB(), false ) );
                 }
-    
+
                 trackedEntityInstance.getRelationships().add( relationship );
             }
         }
@@ -352,14 +351,38 @@
     // -------------------------------------------------------------------------
 
     @Override
-    public void deleteTrackedEntityInstance( TrackedEntityInstance trackedEntityInstance )
+    public ImportSummary deleteTrackedEntityInstance( String uid )
     {
-        org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstance = teiService.getTrackedEntityInstance( trackedEntityInstance.getTrackedEntityInstance() );
+        org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstance = teiService.getTrackedEntityInstance( uid );
 
         if ( entityInstance != null )
         {
             teiService.deleteTrackedEntityInstance( entityInstance );
-        }
+            return new ImportSummary( ImportStatus.SUCCESS, "Deletion of tracked entity instance " + uid + " was successful." );
+        }
+
+        return new ImportSummary( ImportStatus.ERROR, "ID " + uid + " does not point to a valid tracked entity instance" );
+    }
+
+    @Override
+    public ImportSummaries deleteTrackedEntityInstances( List<String> uids )
+    {
+        ImportSummaries importSummaries = new ImportSummaries();
+        int counter = 0;
+
+        for ( String uid : uids )
+        {
+            importSummaries.addImportSummary( deleteTrackedEntityInstance( uid ) );
+
+            if ( counter % FLUSH_FREQUENCY == 0 )
+            {
+                dbmsManager.clearSession();
+            }
+
+            counter++;
+        }
+
+        return importSummaries;
     }
 
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/TrackedEntityInstanceService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/TrackedEntityInstanceService.java	2015-10-08 13:12:38 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/TrackedEntityInstanceService.java	2015-10-22 05:16:58 +0000
@@ -84,5 +84,7 @@
     // DELETE
     // -------------------------------------------------------------------------
 
-    void deleteTrackedEntityInstance( TrackedEntityInstance trackedEntityInstance );
+    ImportSummary deleteTrackedEntityInstance( String uid );
+
+    ImportSummaries deleteTrackedEntityInstances( List<String> uids );
 }

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/TrackedEntityInstanceServiceTest.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/TrackedEntityInstanceServiceTest.java	2015-09-03 10:14:18 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/TrackedEntityInstanceServiceTest.java	2015-10-22 05:16:58 +0000
@@ -161,7 +161,7 @@
     public void testDeletePerson()
     {
         TrackedEntityInstance trackedEntityInstance = trackedEntityInstanceService.getTrackedEntityInstance( maleA.getUid() );
-        trackedEntityInstanceService.deleteTrackedEntityInstance( trackedEntityInstance );
+        trackedEntityInstanceService.deleteTrackedEntityInstance( trackedEntityInstance.getTrackedEntityInstance() );
 
         assertNull( trackedEntityInstanceService.getTrackedEntityInstance( maleA.getUid() ) );
         assertNotNull( trackedEntityInstanceService.getTrackedEntityInstance( maleB.getUid() ) );

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/TrackedEntityInstanceController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/TrackedEntityInstanceController.java	2015-10-20 04:15:40 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/TrackedEntityInstanceController.java	2015-10-22 05:16:58 +0000
@@ -40,6 +40,7 @@
 import org.hisp.dhis.dxf2.importsummary.ImportSummaries;
 import org.hisp.dhis.dxf2.importsummary.ImportSummary;
 import org.hisp.dhis.dxf2.render.RenderService;
+import org.hisp.dhis.dxf2.webmessage.WebMessageException;
 import org.hisp.dhis.event.EventStatus;
 import org.hisp.dhis.fieldfilter.FieldFilterService;
 import org.hisp.dhis.importexport.ImportStrategy;
@@ -128,8 +129,7 @@
         @RequestParam( required = false ) Integer page,
         @RequestParam( required = false ) Integer pageSize,
         @RequestParam( required = false ) boolean totalPages,
-        @RequestParam( required = false ) boolean skipPaging,
-        HttpServletResponse response ) throws Exception
+        @RequestParam( required = false ) boolean skipPaging ) throws Exception
     {
         List<String> fields = Lists.newArrayList( contextService.getParameterValues( "fields" ) );
 
@@ -210,7 +210,6 @@
         @RequestParam( required = false ) Integer pageSize,
         @RequestParam( required = false ) boolean totalPages,
         @RequestParam( required = false ) boolean skipPaging,
-        Model model,
         HttpServletResponse response ) throws Exception
     {
         Set<String> orgUnits = TextUtils.splitToArray( ou, TextUtils.SEMICOLON );
@@ -244,7 +243,6 @@
         @RequestParam( required = false ) Integer pageSize,
         @RequestParam( required = false ) boolean totalPages,
         @RequestParam( required = false ) boolean skipPaging,
-        Model model,
         HttpServletResponse response ) throws Exception
     {
         Set<String> orgUnits = TextUtils.splitToArray( ou, TextUtils.SEMICOLON );
@@ -278,7 +276,6 @@
         @RequestParam( required = false ) Integer pageSize,
         @RequestParam( required = false ) boolean totalPages,
         @RequestParam( required = false ) boolean skipPaging,
-        Model model,
         HttpServletResponse response ) throws Exception
     {
         Set<String> orgUnits = TextUtils.splitToArray( ou, TextUtils.SEMICOLON );
@@ -419,11 +416,14 @@
     @RequestMapping( value = "/{id}", method = RequestMethod.DELETE )
     @PreAuthorize( "hasRole('ALL') or hasRole('F_TRACKED_ENTITY_INSTANCE_ADD')" )
     @ResponseStatus( HttpStatus.NO_CONTENT )
-    public void deleteTrackedEntityInstance( @PathVariable String id )
-        throws NotFoundException
+    public void deleteTrackedEntityInstance( @PathVariable String id ) throws WebMessageException
     {
-        TrackedEntityInstance trackedEntityInstance = getTrackedEntityInstance( id );
-        trackedEntityInstanceService.deleteTrackedEntityInstance( trackedEntityInstance );
+        if ( !instanceService.trackedEntityInstanceExists( id ) )
+        {
+            throw new WebMessageException( WebMessageUtils.notFound( "Tracked entity instance not found for ID " + id ) );
+        }
+
+        trackedEntityInstanceService.deleteTrackedEntityInstance( id );
     }
 
     // -------------------------------------------------------------------------