dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #24645
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12118: minor fixes to enrollment api
------------------------------------------------------------
revno: 12118
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-09-17 17:53:05 +0200
message:
minor fixes to enrollment api
modified:
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/PersonController.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-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 2013-09-17 15:26:14 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EnrollmentController.java 2013-09-17 15:53:05 +0000
@@ -29,11 +29,16 @@
*/
import org.hisp.dhis.api.controller.WebOptions;
+import org.hisp.dhis.api.controller.exception.NotFoundException;
+import org.hisp.dhis.api.utils.ContextUtils;
+import org.hisp.dhis.dxf2.events.enrollment.Enrollment;
import org.hisp.dhis.dxf2.events.enrollment.EnrollmentService;
import org.hisp.dhis.dxf2.events.enrollment.Enrollments;
+import org.hisp.dhis.dxf2.importsummary.ImportSummary;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
@@ -45,7 +50,7 @@
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
@Controller
-@RequestMapping( value = EnrollmentController.RESOURCE_PATH )
+@RequestMapping(value = EnrollmentController.RESOURCE_PATH)
public class EnrollmentController
{
public static final String RESOURCE_PATH = "/enrollments";
@@ -57,11 +62,11 @@
// READ
// -------------------------------------------------------------------------
- @RequestMapping( value = "", method = RequestMethod.GET )
+ @RequestMapping(value = "", method = RequestMethod.GET)
public String getEnrollments(
- @RequestParam( value = "orgUnit", required = false ) String orgUnitUid,
- @RequestParam( value = "program", required = false ) String programUid,
- @RequestParam( value = "person", required = false ) String personUid,
+ @RequestParam(value = "orgUnit", required = false) String orgUnitUid,
+ @RequestParam(value = "program", required = false) String programUid,
+ @RequestParam(value = "person", required = false) String personUid,
@RequestParam Map<String, String> parameters, Model model, HttpServletRequest request )
{
WebOptions options = new WebOptions( parameters );
@@ -74,4 +79,37 @@
return "enrollments";
}
+
+ @RequestMapping( value = "/{id}", method = RequestMethod.GET )
+ public String getEnrollment( @PathVariable String id, @RequestParam Map<String, String> parameters, Model model ) throws NotFoundException
+ {
+ WebOptions options = new WebOptions( parameters );
+ Enrollment enrollment = getEnrollment( id );
+
+ model.addAttribute( "model", enrollment );
+ model.addAttribute( "viewClass", options.getViewClass( "detailed" ) );
+
+ return "person";
+ }
+
+ // -------------------------------------------------------------------------
+ // HELPERS
+ // -------------------------------------------------------------------------
+
+ private Enrollment getEnrollment( String id ) throws NotFoundException
+ {
+ Enrollment enrollment = enrollmentService.getEnrollment( id );
+
+ if ( enrollment == null )
+ {
+ throw new NotFoundException( "Enrollment", id );
+ }
+
+ return enrollment;
+ }
+
+ private String getResourcePath( HttpServletRequest request, ImportSummary importSummary )
+ {
+ return ContextUtils.getContextPath( request ) + "/api/" + "enrollments" + "/" + importSummary.getReference();
+ }
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/PersonController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/PersonController.java 2013-09-17 12:15:39 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/PersonController.java 2013-09-17 15:53:05 +0000
@@ -137,23 +137,11 @@
return "persons";
}
- private OrganisationUnit getOrganisationUnit( String orgUnitUid )
- {
- OrganisationUnit organisationUnit = manager.get( OrganisationUnit.class, orgUnitUid );
-
- if ( organisationUnit == null )
- {
- throw new HttpClientErrorException( HttpStatus.BAD_REQUEST, "orgUnit is not a valid uid." );
- }
-
- return organisationUnit;
- }
-
@RequestMapping( value = "/{id}", method = RequestMethod.GET )
- public String getPerson( @PathVariable String id, @RequestParam Map<String, String> parameters, Model model )
+ public String getPerson( @PathVariable String id, @RequestParam Map<String, String> parameters, Model model ) throws NotFoundException
{
WebOptions options = new WebOptions( parameters );
- Person person = personService.getPerson( id );
+ Person person = getPerson( id );
model.addAttribute( "model", person );
model.addAttribute( "viewClass", options.getViewClass( "detailed" ) );
@@ -276,4 +264,16 @@
{
return ContextUtils.getContextPath( request ) + "/api/" + "persons" + "/" + importSummary.getReference();
}
+
+ private OrganisationUnit getOrganisationUnit( String orgUnitUid )
+ {
+ OrganisationUnit organisationUnit = manager.get( OrganisationUnit.class, orgUnitUid );
+
+ if ( organisationUnit == null )
+ {
+ throw new HttpClientErrorException( HttpStatus.BAD_REQUEST, "orgUnit is not a valid uid." );
+ }
+
+ return organisationUnit;
+ }
}