dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #20302
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9205: FRED-API: added dependency on hibernate-validator (and javax.validation), spring-hateoas. Uses Co...
------------------------------------------------------------
revno: 9205
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2012-12-07 17:16:37 +0300
message:
FRED-API: added dependency on hibernate-validator (and javax.validation), spring-hateoas. Uses ControllerLinkBuilder (from spring-hateoas) to properly generate links from a Spring Controller.
modified:
dhis-2/dhis-web/dhis-web-api-fred/pom.xml
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/FredController.java
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/layout.vm
dhis-2/pom.xml
--
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-fred/pom.xml'
--- dhis-2/dhis-web/dhis-web-api-fred/pom.xml 2012-12-06 20:06:23 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/pom.xml 2012-12-07 14:16:37 +0000
@@ -30,12 +30,12 @@
<groupId>org.hisp.dhis</groupId>
<artifactId>dhis-api</artifactId>
</dependency>
-<!--
- <dependency>
- <groupId>org.hisp.dhis</groupId>
- <artifactId>dhis-web-api</artifactId>
- </dependency>
--->
+ <!--
+ <dependency>
+ <groupId>org.hisp.dhis</groupId>
+ <artifactId>dhis-web-api</artifactId>
+ </dependency>
+ -->
<dependency>
<groupId>org.hisp.dhis</groupId>
<artifactId>dhis-dxf2</artifactId>
@@ -77,6 +77,18 @@
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
+ <groupId>org.springframework.hateoas</groupId>
+ <artifactId>spring-hateoas</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-validator</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.validation</groupId>
+ <artifactId>validation-api</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
</dependency>
=== 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-07 13:04:36 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java 2012-12-07 14:16:37 +0000
@@ -37,6 +37,7 @@
import org.hisp.dhis.web.webapi.v1.utils.GeoUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.hateoas.mvc.ControllerLinkBuilder;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
@@ -47,24 +48,26 @@
import java.util.*;
+import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
+
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
-@Controller( value = "facility-controller-" + FredController.PREFIX )
-@RequestMapping( FacilityController.RESOURCE_PATH )
+@Controller(value = "facility-controller-" + FredController.PREFIX)
+@RequestMapping(FacilityController.RESOURCE_PATH)
public class FacilityController
{
public static final String RESOURCE_PATH = "/" + FredController.PREFIX + "/facilities";
@Autowired
- @Qualifier( "org.hisp.dhis.organisationunit.OrganisationUnitService" )
+ @Qualifier("org.hisp.dhis.organisationunit.OrganisationUnitService")
private OrganisationUnitService organisationUnitService;
//--------------------------------------------------------------------------
// GET HTML
//--------------------------------------------------------------------------
- @RequestMapping( value = "", method = RequestMethod.GET )
+ @RequestMapping(value = "", method = RequestMethod.GET)
public String readFacilities( Model model )
{
Facilities facilities = new Facilities();
@@ -79,21 +82,21 @@
}
model.addAttribute( "entity", facilities );
- model.addAttribute( "baseUrl", "../.." );
+ model.addAttribute( "baseUrl", linkTo( FredController.class ).toString() );
model.addAttribute( "pageName", "facilities" );
model.addAttribute( "page", FredController.PREFIX + "/facilities.vm" );
return FredController.PREFIX + "/layout";
}
- @RequestMapping( value = "/{id}", method = RequestMethod.GET )
+ @RequestMapping(value = "/{id}", method = RequestMethod.GET)
public String readFacility( Model model, @PathVariable String id )
{
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( id );
Facility facility = convertToFacility( organisationUnit );
model.addAttribute( "entity", facility );
- model.addAttribute( "baseUrl", "../../.." );
+ model.addAttribute( "baseUrl", linkTo( FredController.class ).toString() );
model.addAttribute( "pageName", "facility" );
model.addAttribute( "page", FredController.PREFIX + "/facility.vm" );
@@ -104,7 +107,7 @@
// POST JSON
//--------------------------------------------------------------------------
- @RequestMapping( value = "/{id}", method = RequestMethod.POST )
+ @RequestMapping(value = "/{id}", method = RequestMethod.POST)
public ResponseEntity<Void> createFacility()
{
return new ResponseEntity<Void>( HttpStatus.OK );
@@ -114,7 +117,7 @@
// PUT JSON
//--------------------------------------------------------------------------
- @RequestMapping( value = "/{id}", method = RequestMethod.PUT )
+ @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
public ResponseEntity<Void> updateFacility()
{
return new ResponseEntity<Void>( HttpStatus.OK );
@@ -124,7 +127,7 @@
// DELETE JSON
//--------------------------------------------------------------------------
- @RequestMapping( value = "/{id}", method = RequestMethod.DELETE )
+ @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
public ResponseEntity<Void> deleteFacility( @PathVariable String id ) throws HierarchyViolationException
{
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( id );
@@ -151,6 +154,7 @@
facility.setActive( organisationUnit.isActive() );
facility.setCreatedAt( organisationUnit.getLastUpdated() );
facility.setUpdatedAt( organisationUnit.getLastUpdated() );
+ facility.setUrl( linkTo( FacilityController.class ).slash( facility.getId() ).toString() );
if ( organisationUnit.getFeatureType() != null && organisationUnit.getFeatureType().equalsIgnoreCase( "POINT" )
&& organisationUnit.getCoordinates() != null )
=== modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FredController.java'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FredController.java 2012-12-06 20:36:41 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FredController.java 2012-12-07 14:16:37 +0000
@@ -33,6 +33,8 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
+import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
+
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
@@ -42,10 +44,10 @@
{
public static final String PREFIX = "v1";
- @RequestMapping( value = { "", "/" }, method = RequestMethod.GET, produces = { MediaType.TEXT_HTML_VALUE, MediaType.TEXT_XML_VALUE } )
+ @RequestMapping( value = "", method = RequestMethod.GET, produces = { MediaType.TEXT_HTML_VALUE, MediaType.TEXT_XML_VALUE } )
public String home( Model model )
{
- model.addAttribute( "baseUrl", ".." );
+ model.addAttribute( "baseUrl", linkTo( FredController.class ).toString() );
model.addAttribute( "pageName", "home" );
model.addAttribute( "page", FredController.PREFIX + "/index.vm" );
=== 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-07 13:04:36 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/facilities.vm 2012-12-07 14:16:37 +0000
@@ -64,7 +64,7 @@
#foreach( $facility in $entity.facilities )
<tr>
<td class="facility-id" style="width: 1px;">$facility.id</td>
- <td class="facility-name"><a href="facilities/$facility.id">$facility.name</a></td>
+ <td class="facility-name"><a href="$facility.url">$facility.name</a></td>
<td class="facility-active" style="width: 1px;">
#if( $facility.active )
<button style="width: 44px;" class="deactivateButton btn btn-mini btn-success">
=== 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-07 13:04:36 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/layout.vm 2012-12-07 14:16:37 +0000
@@ -6,16 +6,16 @@
<title>FRED Facility API v1.0 (DHIS2)</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
- <script src="$baseUrl/dhis-web-commons/javascripts/jQuery/jquery.min.js?v=1.8.2"></script>
- <script src="$baseUrl/api-fred-resources/js/bootstrap.min.js?v=2.2.1"></script>
+ <script src="$baseUrl/../../dhis-web-commons/javascripts/jQuery/jquery.min.js?v=1.8.2"></script>
+ <script src="$baseUrl/../../api-fred-resources/js/bootstrap.min.js?v=2.2.1"></script>
- <link href="$baseUrl/api-fred-resources/css//bootstrap.min.css?v2.2.1" rel="stylesheet">
+ <link href="$baseUrl/../../api-fred-resources/css//bootstrap.min.css?v2.2.1" rel="stylesheet">
<style>
body {
padding-top : 60px;
}
</style>
- <link href="$baseUrl/api-fred-resources/css/bootstrap-responsive.min.css?v2.2.1" rel="stylesheet">
+ <link href="$baseUrl/../../api-fred-resources/css/bootstrap-responsive.min.css?v2.2.1" rel="stylesheet">
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js" type="text/javascript"></script>
@@ -33,12 +33,12 @@
<span class="icon-bar"></span>
</a>
- <a class="brand" href="../v1">FRED Facility API v1.0</a>
+ <a class="brand" href="$baseUrl">FRED Facility API v1.0</a>
<div class="nav-collapse collapse">
<ul class="nav">
- <li #if( $pageName == "home" )class="active"#end><a href="../"><span class="icon-home"> </span> Home</a></li>
- <li #if( $pageName == "facilities" )class="active"#end><a href="v1/facilities"><span class="icon-search"> </span> Facilities</a></li>
+ <li #if( $pageName == "home" )class="active"#end><a href="$baseUrl"><span class="icon-home"> </span> Home</a></li>
+ <li #if( $pageName == "facilities" )class="active"#end><a href="$baseUrl/facilities/"><span class="icon-search"> </span> Facilities</a></li>
</ul>
</div>
</div>
=== modified file 'dhis-2/pom.xml'
--- dhis-2/pom.xml 2012-12-06 09:06:40 +0000
+++ dhis-2/pom.xml 2012-12-07 14:16:37 +0000
@@ -392,6 +392,11 @@
<version>${spring.version}</version>
</dependency>
<dependency>
+ <groupId>org.springframework.hateoas</groupId>
+ <artifactId>spring-hateoas</artifactId>
+ <version>0.3.0.RELEASE</version>
+ </dependency>
+ <dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2.2</version>
@@ -634,6 +639,16 @@
<version>${hibernate.version}</version>
</dependency>
<dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-validator</artifactId>
+ <version>${hibernate-validator.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.validation</groupId>
+ <artifactId>validation-api</artifactId>
+ <version>1.0.0.GA</version>
+ </dependency>
+ <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
@@ -891,6 +906,7 @@
<spring.version>3.1.3.RELEASE</spring.version>
<spring.security.version>3.1.3.RELEASE</spring.security.version>
<hibernate.version>4.1.8.Final</hibernate.version>
+ <hibernate-validator.version>4.3.1.Final</hibernate-validator.version>
<jackson.version>2.1.1</jackson.version>
<camel.version>2.10.2</camel.version>
<slf4j.version>1.6.6</slf4j.version>