← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17932: strategy support for enrollments

 

------------------------------------------------------------
revno: 17932
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2015-01-10 18:48:14 +0700
message:
  strategy support for enrollments
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/JacksonEnrollmentService.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/enrollment/AbstractEnrollmentService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java	2014-11-06 09:21:02 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java	2015-01-10 11:48:14 +0000
@@ -78,37 +78,37 @@
     implements EnrollmentService
 {
     @Autowired
-    private ProgramInstanceService programInstanceService;
-
-    @Autowired
-    private ProgramService programService;
-
-    @Autowired
-    private TrackedEntityInstanceService trackedEntityInstanceService;
-
-    @Autowired
-    private org.hisp.dhis.trackedentity.TrackedEntityInstanceService teiService;
-
-    @Autowired
-    private TrackedEntityAttributeService trackedEntityAttributeService;
-
-    @Autowired
-    private TrackedEntityAttributeValueService trackedEntityAttributeValueService;
+    protected ProgramInstanceService programInstanceService;
+
+    @Autowired
+    protected ProgramService programService;
+
+    @Autowired
+    protected TrackedEntityInstanceService trackedEntityInstanceService;
+
+    @Autowired
+    protected org.hisp.dhis.trackedentity.TrackedEntityInstanceService teiService;
+
+    @Autowired
+    protected TrackedEntityAttributeService trackedEntityAttributeService;
+
+    @Autowired
+    protected TrackedEntityAttributeValueService trackedEntityAttributeValueService;
 
     @Autowired
     protected CurrentUserService currentUserService;
 
     @Autowired
-    private TrackedEntityCommentService commentService;
-
-    @Autowired
-    private IdentifiableObjectManager manager;
-
-    @Autowired
-    private I18nManager i18nManager;
-
-    @Autowired
-    private UserService userService;
+    protected TrackedEntityCommentService commentService;
+
+    @Autowired
+    protected IdentifiableObjectManager manager;
+
+    @Autowired
+    protected I18nManager i18nManager;
+
+    @Autowired
+    protected UserService userService;
 
     // -------------------------------------------------------------------------
     // READ
@@ -431,8 +431,7 @@
             return importSummary;
         }
 
-        org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstance = getTrackedEntityInstance( enrollment
-            .getTrackedEntityInstance() );
+        org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstance = getTrackedEntityInstance( enrollment.getTrackedEntityInstance() );
         Program program = getProgram( enrollment.getProgram() );
 
         programInstance.setProgram( program );
@@ -467,7 +466,7 @@
         saveTrackedEntityComment( programInstance, enrollment );
 
         importSummary.setReference( enrollment.getEnrollment() );
-        importSummary.getImportCount().incrementImported();
+        importSummary.getImportCount().incrementUpdated();
 
         return importSummary;
     }

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/JacksonEnrollmentService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/JacksonEnrollmentService.java	2015-01-10 11:26:52 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/JacksonEnrollmentService.java	2015-01-10 11:48:14 +0000
@@ -36,6 +36,7 @@
 import org.hisp.dhis.importexport.ImportStrategy;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.StreamUtils;
+import org.springframework.util.StringUtils;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -142,9 +143,30 @@
         Enrollments create = new Enrollments();
         Enrollments update = new Enrollments();
 
-        for ( Enrollment enrollment : enrollments )
-        {
-            importSummaries.addImportSummary( addEnrollment( enrollment ) );
+        if ( strategy.isCreate() )
+        {
+            create.getEnrollments().addAll( enrollments );
+        }
+        else if ( strategy.isCreateAndUpdate() )
+        {
+            for ( Enrollment enrollment : enrollments )
+            {
+                if ( StringUtils.isEmpty( enrollment.getEnrollment() ) )
+                {
+                    create.getEnrollments().add( enrollment );
+                }
+                else
+                {
+                    if ( programInstanceService.getProgramInstance( enrollment.getEnrollment() ) == null )
+                    {
+                        create.getEnrollments().add( enrollment );
+                    }
+                    else
+                    {
+                        update.getEnrollments().add( enrollment );
+                    }
+                }
+            }
         }
 
         for ( Enrollment enrollment : create.getEnrollments() )
@@ -154,7 +176,7 @@
 
         for ( Enrollment enrollment : update.getEnrollments() )
         {
-            importSummaries.addImportSummary( addEnrollment( enrollment ) );
+            importSummaries.addImportSummary( updateEnrollment( enrollment ) );
         }
 
         return importSummaries;