=== 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-03-18 16:13:20 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java 2014-03-19 10:55:15 +0000 @@ -111,6 +111,7 @@ public Enrollments getEnrollments( TrackedEntityInstance trackedEntityInstance ) { org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstance = getTrackedEntityInstance( trackedEntityInstance.getTrackedEntityInstance() ); + return getEnrollments( entityInstance ); } @@ -225,6 +226,11 @@ @Override public Enrollment getEnrollment( ProgramInstance programInstance ) { + if ( programInstance.getEntityInstance() == null ) + { + return null; + } + Enrollment enrollment = new Enrollment(); enrollment.setEnrollment( programInstance.getUid() ); @@ -401,6 +407,7 @@ @Override public void completeEnrollment( Enrollment enrollment ) { + ProgramInstance programInstance = programInstanceService.getProgramInstance( enrollment.getEnrollment() ); Assert.notNull( programInstance ); === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EnrollmentController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EnrollmentController.java 2014-03-18 08:10:10 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EnrollmentController.java 2014-03-19 10:55:15 +0000 @@ -153,7 +153,7 @@ // ------------------------------------------------------------------------- @RequestMapping( value = "", method = RequestMethod.POST, consumes = MediaType.APPLICATION_XML_VALUE ) - @PreAuthorize("hasRole('ALL') or hasRole('F_PROGRAM_ENROLLMENT')") + @PreAuthorize( "hasRole('ALL') or hasRole('F_PROGRAM_ENROLLMENT')" ) public void postEnrollmentXml( HttpServletRequest request, HttpServletResponse response ) throws IOException { ImportSummaries importSummaries = enrollmentService.addEnrollmentsXml( request.getInputStream() ); @@ -178,7 +178,7 @@ } @RequestMapping( value = "", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE ) - @PreAuthorize("hasRole('ALL') or hasRole('F_PROGRAM_ENROLLMENT')") + @PreAuthorize( "hasRole('ALL') or hasRole('F_PROGRAM_ENROLLMENT')" ) public void postEnrollmentJson( HttpServletRequest request, HttpServletResponse response ) throws IOException { ImportSummaries importSummaries = enrollmentService.addEnrollmentsJson( request.getInputStream() ); @@ -208,7 +208,7 @@ @RequestMapping( value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_XML_VALUE ) @ResponseStatus( value = HttpStatus.NO_CONTENT ) - @PreAuthorize("hasRole('ALL') or hasRole('F_PROGRAM_UNENROLLMENT')") + @PreAuthorize( "hasRole('ALL') or hasRole('F_PROGRAM_UNENROLLMENT')" ) public void updateEnrollmentXml( @PathVariable String id, HttpServletRequest request, HttpServletResponse response ) throws IOException { ImportSummary importSummary = enrollmentService.updateEnrollmentXml( id, request.getInputStream() ); @@ -217,7 +217,7 @@ @RequestMapping( value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE ) @ResponseStatus( value = HttpStatus.NO_CONTENT ) - @PreAuthorize("hasRole('ALL') or hasRole('F_PROGRAM_UNENROLLMENT')") + @PreAuthorize( "hasRole('ALL') or hasRole('F_PROGRAM_UNENROLLMENT')" ) public void updateEnrollmentJson( @PathVariable String id, HttpServletRequest request, HttpServletResponse response ) throws IOException { ImportSummary importSummary = enrollmentService.updateEnrollmentJson( id, request.getInputStream() ); @@ -226,19 +226,21 @@ @RequestMapping( value = "/{id}/cancelled", method = RequestMethod.PUT ) @ResponseStatus( HttpStatus.NO_CONTENT ) - @PreAuthorize("hasRole('ALL') or hasRole('F_PROGRAM_UNENROLLMENT')") + @PreAuthorize( "hasRole('ALL') or hasRole('F_PROGRAM_UNENROLLMENT')" ) public void cancelEnrollment( @PathVariable String id ) throws NotFoundException { Enrollment enrollment = getEnrollment( id ); + enrollment.setStatus( EnrollmentStatus.CANCELLED ); enrollmentService.cancelEnrollment( enrollment ); } @RequestMapping( value = "/{id}/completed", method = RequestMethod.PUT ) @ResponseStatus( HttpStatus.NO_CONTENT ) - @PreAuthorize("hasRole('ALL') or hasRole('F_PROGRAM_UNENROLLMENT')") + @PreAuthorize( "hasRole('ALL') or hasRole('F_PROGRAM_UNENROLLMENT')" ) public void completedEnrollment( @PathVariable String id ) throws NotFoundException { Enrollment enrollment = getEnrollment( id ); + enrollment.setStatus( EnrollmentStatus.COMPLETED ); enrollmentService.completeEnrollment( enrollment ); } @@ -248,7 +250,7 @@ @RequestMapping( value = "/{id}", method = RequestMethod.DELETE ) @ResponseStatus( HttpStatus.NO_CONTENT ) - @PreAuthorize("hasRole('ALL') or hasRole('F_PROGRAM_UNENROLLMENT')") + @PreAuthorize( "hasRole('ALL') or hasRole('F_PROGRAM_UNENROLLMENT')" ) public void deleteEnrollment( @PathVariable String id ) throws NotFoundException { Enrollment enrollment = getEnrollment( id );