dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #40948
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20860: support bulk deletion of enrollment
------------------------------------------------------------
revno: 20860
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-10-23 12:32:46 +0700
message:
support bulk deletion of enrollment
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 2015-10-22 04:57:26 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java 2015-10-23 05:32:46 +0000
@@ -241,7 +241,7 @@
importSummary.setStatus( ImportStatus.ERROR );
importSummary.setDescription( "TrackedEntityInstance " + trackedEntityInstance.getTrackedEntityInstance()
+ " already have an active enrollment in program " + program.getUid() );
- importSummary.getImportCount().incrementIgnored();
+ importSummary.incrementIgnored();
return importSummary;
}
@@ -258,7 +258,7 @@
importSummary.setDescription( "TrackedEntityInstance " + trackedEntityInstance.getTrackedEntityInstance()
+ " already have a completed enrollment in program " + program.getUid() + ", and this program is" +
" configured to only allow enrolling one time." );
- importSummary.getImportCount().incrementIgnored();
+ importSummary.incrementIgnored();
return importSummary;
}
@@ -272,7 +272,7 @@
if ( !importConflicts.isEmpty() )
{
importSummary.setStatus( ImportStatus.ERROR );
- importSummary.getImportCount().incrementIgnored();
+ importSummary.incrementIgnored();
return importSummary;
}
@@ -287,6 +287,7 @@
importSummary.setStatus( ImportStatus.ERROR );
importSummary.setDescription( "Could not enroll TrackedEntityInstance "
+ enrollment.getTrackedEntityInstance() + " into program " + enrollment.getProgram() );
+ importSummary.incrementIgnored();
return importSummary;
}
@@ -335,20 +336,14 @@
if ( enrollment == null || enrollment.getEnrollment() == null )
{
- importSummary = new ImportSummary( ImportStatus.ERROR, "No enrollment or enrollment ID was supplied" );
- importSummary.getImportCount().incrementIgnored();
-
- return importSummary;
+ return new ImportSummary( ImportStatus.ERROR, "No enrollment or enrollment ID was supplied" ).incrementIgnored();
}
ProgramInstance programInstance = programInstanceService.getProgramInstance( enrollment.getEnrollment() );
if ( programInstance == null )
{
- importSummary = new ImportSummary( ImportStatus.ERROR, "Enrollment ID was not valid." );
- importSummary.getImportCount().incrementIgnored();
-
- return importSummary;
+ return new ImportSummary( ImportStatus.ERROR, "Enrollment ID was not valid." ).incrementIgnored();
}
Set<ImportConflict> importConflicts = new HashSet<>();
@@ -385,10 +380,7 @@
}
else
{
- importSummary = new ImportSummary( ImportStatus.ERROR, "Re-enrollment is not allowed, please create a new enrollment." );
- importSummary.getImportCount().incrementIgnored();
-
- return importSummary;
+ return new ImportSummary( ImportStatus.ERROR, "Re-enrollment is not allowed, please create a new enrollment." ).incrementIgnored();
}
}
@@ -415,10 +407,10 @@
if ( programInstance != null )
{
programInstanceService.deleteProgramInstance( programInstance );
- return new ImportSummary( ImportStatus.SUCCESS, "Deletion of enrollment " + uid + " was successful." );
+ return new ImportSummary( ImportStatus.SUCCESS, "Deletion of enrollment " + uid + " was successful." ).incrementDeleted();
}
- return new ImportSummary( ImportStatus.ERROR, "ID " + uid + " does not point to a valid enrollment" );
+ return new ImportSummary( ImportStatus.ERROR, "ID " + uid + " does not point to a valid enrollment" ).incrementIgnored();
}
@Override
=== 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-10-23 05:12:02 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/JacksonEnrollmentService.java 2015-10-23 05:32:46 +0000
@@ -43,6 +43,7 @@
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
+import java.util.stream.Collectors;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -142,6 +143,7 @@
List<Enrollment> create = new ArrayList<>();
List<Enrollment> update = new ArrayList<>();
+ List<String> delete = new ArrayList<>();
if ( importOptions.getImportStrategy().isCreate() )
{
@@ -168,9 +170,14 @@
}
}
}
+ else if ( importOptions.getImportStrategy().isDelete() )
+ {
+ delete.addAll( enrollments.stream().map( Enrollment::getEnrollment ).collect( Collectors.toList() ) );
+ }
importSummaries.addImportSummaries( addEnrollments( create ) );
importSummaries.addImportSummaries( updateEnrollments( update ) );
+ importSummaries.addImportSummaries( deleteEnrollments( delete ) );
return importSummaries;
}