=== modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java' --- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java 2012-12-06 21:41:42 +0000 +++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java 2012-12-07 13:04:36 +0000 @@ -29,6 +29,7 @@ import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator; import org.hisp.dhis.dataset.DataSet; +import org.hisp.dhis.hierarchy.HierarchyViolationException; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.organisationunit.OrganisationUnitService; import org.hisp.dhis.web.webapi.v1.domain.Facilities; @@ -124,40 +125,13 @@ //-------------------------------------------------------------------------- @RequestMapping( value = "/{id}", method = RequestMethod.DELETE ) - public ResponseEntity deleteFacility() - { - return new ResponseEntity( HttpStatus.OK ); - } - - //-------------------------------------------------------------------------- - // EXTRA WEB METHODS - //-------------------------------------------------------------------------- - - @RequestMapping( value = "/activate/{id}", method = RequestMethod.POST ) - public ResponseEntity activateFacility( @PathVariable String id ) - { - OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( id ); - - if ( organisationUnit != null ) - { - organisationUnit.setActive( true ); - organisationUnitService.updateOrganisationUnit( organisationUnit ); - - return new ResponseEntity( HttpStatus.OK ); - } - - return new ResponseEntity( HttpStatus.NOT_FOUND ); - } - - @RequestMapping( value = "/deactivate/{id}", method = RequestMethod.POST ) - public ResponseEntity deactivateFacility( @PathVariable String id ) - { - OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( id ); - - if ( organisationUnit != null ) - { - organisationUnit.setActive( false ); - organisationUnitService.updateOrganisationUnit( organisationUnit ); + public ResponseEntity deleteFacility( @PathVariable String id ) throws HierarchyViolationException + { + OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( id ); + + if ( organisationUnit != null ) + { + organisationUnitService.deleteOrganisationUnit( organisationUnit ); return new ResponseEntity( HttpStatus.OK ); } @@ -173,7 +147,7 @@ { Facility facility = new Facility(); facility.setId( organisationUnit.getUid() ); - facility.setName( organisationUnit.getName() ); + facility.setName( organisationUnit.getDisplayName() ); facility.setActive( organisationUnit.isActive() ); facility.setCreatedAt( organisationUnit.getLastUpdated() ); facility.setUpdatedAt( organisationUnit.getLastUpdated() ); @@ -215,4 +189,16 @@ return facility; } + + //-------------------------------------------------------------------------- + // EXCEPTION HANDLERS + //-------------------------------------------------------------------------- + +/* + @ExceptionHandler( Exception.class ) + public ResponseEntity exceptionHandler( Exception ex ) + { + return new ResponseEntity( ex.getMessage(), HttpStatus.FORBIDDEN ); + } +*/ } === added file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityServiceController.java' --- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityServiceController.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityServiceController.java 2012-12-07 13:04:36 +0000 @@ -0,0 +1,89 @@ +package org.hisp.dhis.web.webapi.v1.controller; + +/* + * Copyright (c) 2004-2012, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.organisationunit.OrganisationUnitService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +/** + * @author Morten Olav Hansen + */ +@Controller( value = "facility-service-controller-" + FredController.PREFIX ) +@RequestMapping( FacilityServiceController.RESOURCE_PATH ) +public class FacilityServiceController +{ + public static final String RESOURCE_PATH = "/" + FredController.PREFIX + "/facility-service"; + + @Autowired + @Qualifier( "org.hisp.dhis.organisationunit.OrganisationUnitService" ) + private OrganisationUnitService organisationUnitService; + + //-------------------------------------------------------------------------- + // EXTRA WEB METHODS + //-------------------------------------------------------------------------- + + @RequestMapping( value = "/{id}/activate", method = RequestMethod.POST ) + public ResponseEntity activateFacility( @PathVariable String id ) + { + OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( id ); + + if ( organisationUnit != null ) + { + organisationUnit.setActive( true ); + organisationUnitService.updateOrganisationUnit( organisationUnit ); + + return new ResponseEntity( HttpStatus.OK ); + } + + return new ResponseEntity( HttpStatus.NOT_FOUND ); + } + + @RequestMapping( value = "/{id}/deactivate", method = RequestMethod.POST ) + public ResponseEntity deactivateFacility( @PathVariable String id ) + { + OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( id ); + + if ( organisationUnit != null ) + { + organisationUnit.setActive( false ); + organisationUnitService.updateOrganisationUnit( organisationUnit ); + + return new ResponseEntity( HttpStatus.OK ); + } + + return new ResponseEntity( HttpStatus.NOT_FOUND ); + } +} === modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-web/dhis-web-api-fred/src/main/resources/META-INF/dhis/beans.xml 2012-12-06 20:06:23 +0000 +++ dhis-2/dhis-web/dhis-web-api-fred/src/main/resources/META-INF/dhis/beans.xml 2012-12-07 13:04:36 +0000 @@ -2,6 +2,6 @@ + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd"> === modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/resources/META-INF/dhis/webapi-fred.xml' --- dhis-2/dhis-web/dhis-web-api-fred/src/main/resources/META-INF/dhis/webapi-fred.xml 2012-12-06 20:06:23 +0000 +++ dhis-2/dhis-web/dhis-web-api-fred/src/main/resources/META-INF/dhis/webapi-fred.xml 2012-12-07 13:04:36 +0000 @@ -2,7 +2,8 @@ === modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/facilities.vm' --- dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/facilities.vm 2012-12-06 22:11:44 +0000 +++ dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/facilities.vm 2012-12-07 13:04:36 +0000 @@ -5,7 +5,7 @@ var id = $(this).parent().parent().find('.facility-id').text(); $.ajax({ - url: 'facilities/activate/' + id, + url: 'facility-service/' + id + '/activate', type: 'POST', async: false }).complete(function () { @@ -19,7 +19,7 @@ var id = $(this).parent().parent().find('.facility-id').text(); $.ajax({ - url: 'facilities/deactivate/' + id, + url: 'facility-service/' + id + '/deactivate', type: 'POST', async: false }).complete(function () { @@ -31,9 +31,11 @@
@@ -48,7 +50,7 @@ -->
- +
@@ -59,25 +61,33 @@ - #foreach( $facility in $entity.facilities ) - - - - + #foreach( $facility in $entity.facilities ) + + + + - - - #end + + + #end
ID
$facility.id$facility.name - #if( $facility.active ) - - #else - - #end -
$facility.id$facility.name + #if( $facility.active ) + + #else + + #end + -
- - -
-
+
+ + +
+
=== modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/layout.vm' --- dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/layout.vm 2012-12-06 21:55:24 +0000 +++ dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/layout.vm 2012-12-07 13:04:36 +0000 @@ -12,7 +12,7 @@ @@ -33,30 +33,21 @@ - FRED Facility API v1.0 + FRED Facility API v1.0 -
-
- -
- -
+
#parse( $page )
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueSetController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueSetController.java 2012-11-29 13:22:38 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueSetController.java 2012-12-07 13:04:36 +0000 @@ -54,7 +54,7 @@ import static org.hisp.dhis.api.utils.ContextUtils.CONTENT_TYPE_XML; @Controller -@RequestMapping( value = DataValueSetController.RESOURCE_PATH ) +@RequestMapping(value = DataValueSetController.RESOURCE_PATH) public class DataValueSetController { public static final String RESOURCE_PATH = "/dataValueSets"; @@ -67,7 +67,7 @@ @Autowired private IntegrationService integrationService; - @RequestMapping( method = RequestMethod.GET, produces = { "text/html", "text/plain" } ) + @RequestMapping(method = RequestMethod.GET, produces = { "text/html", "text/plain" }) public String getDataValueSets( Model model ) throws Exception { DataValueSets dataValueSets = new DataValueSets(); @@ -78,7 +78,7 @@ return "dataValueSets"; } - @RequestMapping( method = RequestMethod.GET, produces = "application/xml" ) + @RequestMapping(method = RequestMethod.GET, produces = "application/xml") public void getDataValueSet( @RequestParam String dataSet, @RequestParam String period, @RequestParam String orgUnit, HttpServletResponse response ) throws IOException { @@ -88,8 +88,8 @@ dataValueSetService.writeDataValueSet( dataSet, period, orgUnit, response.getOutputStream() ); } - @RequestMapping( method = RequestMethod.POST, consumes = "application/xml" ) - @PreAuthorize( "hasRole('ALL') or hasRole('F_DATAVALUE_ADD')" ) + @RequestMapping(method = RequestMethod.POST, consumes = "application/xml") + @PreAuthorize("hasRole('ALL') or hasRole('F_DATAVALUE_ADD')") public void postDxf2DataValueSet( ImportOptions importOptions, HttpServletResponse response, InputStream in, Model model ) throws IOException { @@ -101,8 +101,8 @@ JacksonUtils.toXml( response.getOutputStream(), summary ); } - @RequestMapping( method = RequestMethod.POST, consumes = "application/json" ) - @PreAuthorize( "hasRole('ALL') or hasRole('F_DATAVALUE_ADD')" ) + @RequestMapping(method = RequestMethod.POST, consumes = "application/json") + @PreAuthorize("hasRole('ALL') or hasRole('F_DATAVALUE_ADD')") public void postJsonDataValueSet( ImportOptions importOptions, HttpServletResponse response, InputStream in, Model model ) throws IOException { @@ -114,8 +114,8 @@ JacksonUtils.toJson( response.getOutputStream(), summary ); } - @RequestMapping( method = RequestMethod.POST, consumes = "application/sdmx+xml" ) - @PreAuthorize( "hasRole('ALL') or hasRole('F_DATAVALUE_ADD')" ) + @RequestMapping(method = RequestMethod.POST, consumes = "application/sdmx+xml") + @PreAuthorize("hasRole('ALL') or hasRole('F_DATAVALUE_ADD')") public void postSDMXDataValueSet( ImportOptions importOptions, HttpServletResponse response, InputStream in, Model model ) throws IOException { @@ -127,11 +127,10 @@ JacksonUtils.toXml( response.getOutputStream(), summary ); } - @ExceptionHandler( IllegalArgumentException.class ) + @ExceptionHandler(IllegalArgumentException.class) public void handleError( IllegalArgumentException ex, HttpServletResponse response ) throws IOException { ContextUtils.conflictResponse( response, ex.getMessage() ); } } - \ No newline at end of file