dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #30404
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15435: Simplified resource view in web-api, removed /api/resources, resource view is served directly on ...
------------------------------------------------------------
revno: 15435
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-05-27 15:46:18 +0200
message:
Simplified resource view in web-api, removed /api/resources, resource view is served directly on /api/ now. Uses SchemaDescriptors to generate resources based on apiEndpoint property.
removed:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/ResourceController.java
modified:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/IndexController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/Resource.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/Resources.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/webapi/controller/IndexController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/IndexController.java 2014-05-27 08:46:50 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/IndexController.java 2014-05-27 13:46:18 +0000
@@ -28,8 +28,14 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import org.hisp.dhis.schema.Schema;
+import org.hisp.dhis.schema.SchemaService;
import org.hisp.dhis.webapi.utils.ContextUtils;
+import org.hisp.dhis.webapi.webdomain.Resource;
+import org.hisp.dhis.webapi.webdomain.Resources;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@@ -43,6 +49,9 @@
@Controller
public class IndexController
{
+ @Autowired
+ private SchemaService schemaService;
+
//--------------------------------------------------------------------------
// GET
//--------------------------------------------------------------------------
@@ -50,14 +59,30 @@
@RequestMapping( value = "/api", method = RequestMethod.GET )
public void getIndex( HttpServletRequest request, HttpServletResponse response ) throws IOException
{
- String location = response.encodeRedirectURL( "/resources" );
+ String location = response.encodeRedirectURL( "/" );
response.sendRedirect( ContextUtils.getRootPath( request ) + location );
}
@RequestMapping( value = "/", method = RequestMethod.GET )
- public void getIndexWithSlash( HttpServletRequest request, HttpServletResponse response ) throws IOException
+ public String getResources( Model model, HttpServletRequest request )
{
- String location = response.encodeRedirectURL( "/resources" );
- response.sendRedirect( ContextUtils.getRootPath( request ) + location );
+ Resources resources = new Resources();
+
+ for ( Schema schema : schemaService.getSchemas() )
+ {
+ if ( schema.haveEndpoint() )
+ {
+ Resource resource = new Resource();
+ resource.setSingular( schema.getSingular() );
+ resource.setPlural( schema.getPlural() );
+ resource.setHref( ContextUtils.getRootPath( request ) + schema.getApiEndpoint() );
+
+ resources.getResources().add( resource );
+ }
+ }
+
+ model.addAttribute( "model", resources );
+
+ return "resources";
}
}
=== removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/ResourceController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/ResourceController.java 2014-05-22 12:40:24 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/ResourceController.java 1970-01-01 00:00:00 +0000
@@ -1,74 +0,0 @@
-package org.hisp.dhis.webapi.controller;
-
-/*
- * Copyright (c) 2004-2014, 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.webapi.utils.ContextUtils;
-import org.hisp.dhis.webapi.webdomain.Resource;
-import org.hisp.dhis.webapi.webdomain.Resources;
-import org.springframework.stereotype.Controller;
-import org.springframework.ui.Model;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-
-import java.util.Map;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-@Controller
-@RequestMapping( value = ResourceController.RESOURCE_PATH )
-public class ResourceController
-{
- public static final String RESOURCE_PATH = "/resources";
-
- //-------------------------------------------------------------------------------------------------------
- // GET
- //-------------------------------------------------------------------------------------------------------
-
- @RequestMapping( method = RequestMethod.GET )
- public String getResources( @RequestParam Map<String, String> parameters, Model model )
- {
- WebOptions options = new WebOptions( parameters );
- Resources resources = new Resources();
-
- if ( options.hasLinks() )
- {
- for ( Resource resource : resources.getResources() )
- {
- resource.setHref( ContextUtils.getPath( resource.getClazz() ) );
- }
- }
-
- model.addAttribute( "model", resources );
- model.addAttribute( "viewClass", "detailed" );
-
- return "resources";
- }
-}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/Resource.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/Resource.java 2014-05-22 12:40:24 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/Resource.java 2014-05-27 13:46:18 +0000
@@ -29,16 +29,9 @@
*/
import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.annotation.JsonView;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
-import org.hisp.dhis.common.BaseLinkableObject;
import org.hisp.dhis.common.DxfNamespaces;
-import org.hisp.dhis.common.view.DetailedView;
-
-import java.util.ArrayList;
-import java.util.List;
/**
* At some point this class will be extended to show all available options
@@ -46,77 +39,59 @@
*
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
-@JacksonXmlRootElement( localName = "resource", namespace = DxfNamespaces.DXF_2_0 )
+@JacksonXmlRootElement(localName = "resource", namespace = DxfNamespaces.DXF_2_0)
public class Resource
- extends BaseLinkableObject
{
- private String name;
-
- private Class<?> clazz;
-
- private List<String> methods = new ArrayList<String>();
-
- private List<String> mediaTypes = new ArrayList<String>();
+ private String singular;
+
+ private String plural;
+
+ private String href;
public Resource()
{
}
- public Resource( String name, Class<?> clazz, List<String> methods, List<String> mediaTypes )
- {
- this.name = name;
- this.clazz = clazz;
- this.methods = methods;
- this.mediaTypes = mediaTypes;
- }
-
- @JsonProperty
- @JsonView( {DetailedView.class} )
- @JacksonXmlProperty( isAttribute = true )
- public String getName()
- {
- return name;
- }
-
- public void setName( String name )
- {
- this.name = name;
- }
-
- @JsonProperty
- @JacksonXmlElementWrapper( localName = "methods", namespace = DxfNamespaces.DXF_2_0 )
- @JacksonXmlProperty( localName = "method", namespace = DxfNamespaces.DXF_2_0 )
- public List<String> getMethods()
- {
- return methods;
- }
-
- public void setMethods( List<String> methods )
- {
- this.methods = methods;
- }
-
- @JsonProperty
- @JacksonXmlElementWrapper( localName = "mediaTypes", namespace = DxfNamespaces.DXF_2_0 )
- @JacksonXmlProperty( localName = "mediaType", namespace = DxfNamespaces.DXF_2_0 )
- public List<String> getMediaTypes()
- {
- return mediaTypes;
- }
-
- public void setMediaTypes( List<String> mediaTypes )
- {
- this.mediaTypes = mediaTypes;
- }
-
- public Class<?> getClazz()
- {
- return clazz;
- }
-
- public void setClazz( Class<?> clazz )
- {
- this.clazz = clazz;
+ public Resource( String singular, String plural )
+ {
+ this.singular = singular;
+ this.plural = plural;
+ }
+
+ @JsonProperty
+ @JacksonXmlProperty( isAttribute = true )
+ public String getSingular()
+ {
+ return singular;
+ }
+
+ public void setSingular( String singular )
+ {
+ this.singular = singular;
+ }
+
+ @JsonProperty
+ @JacksonXmlProperty( isAttribute = true )
+ public String getPlural()
+ {
+ return plural;
+ }
+
+ public void setPlural( String plural )
+ {
+ this.plural = plural;
+ }
+
+ @JsonProperty
+ @JacksonXmlProperty( isAttribute = true )
+ public String getHref()
+ {
+ return href;
+ }
+
+ public void setHref( String href )
+ {
+ this.href = href;
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/Resources.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/Resources.java 2014-05-22 12:40:24 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/Resources.java 2014-05-27 13:46:18 +0000
@@ -34,21 +34,14 @@
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import org.hisp.dhis.common.BaseCollection;
import org.hisp.dhis.common.DxfNamespaces;
-import org.hisp.dhis.common.IdentifiableObject;
-import org.hisp.dhis.dxf2.metadata.ExchangeClasses;
-import org.springframework.http.MediaType;
-import org.springframework.util.StringUtils;
-import org.springframework.web.bind.annotation.RequestMethod;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
/**
- * At some point this class will be extended to show all available options
- * for a current user for this resource. For now it is only used for index page.
- *
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
-@JacksonXmlRootElement( localName = "dxf2", namespace = DxfNamespaces.DXF_2_0 )
+@JacksonXmlRootElement(localName = "dxf2", namespace = DxfNamespaces.DXF_2_0)
public class Resources
extends BaseCollection
{
@@ -56,12 +49,12 @@
public Resources()
{
- generateResources();
+
}
@JsonProperty
- @JacksonXmlElementWrapper( localName = "resources", namespace = DxfNamespaces.DXF_2_0 )
- @JacksonXmlProperty( localName = "resource", namespace = DxfNamespaces.DXF_2_0 )
+ @JacksonXmlElementWrapper(localName = "resources", namespace = DxfNamespaces.DXF_2_0)
+ @JacksonXmlProperty(localName = "resource", namespace = DxfNamespaces.DXF_2_0)
public List<Resource> getResources()
{
return resources;
@@ -71,34 +64,4 @@
{
this.resources = resources;
}
-
- //----------------------------------------------------------------------------------------------
- // Helpers
- //----------------------------------------------------------------------------------------------
-
- private void generateResources()
- {
- List<String> requestMethods = new ArrayList<String>();
- requestMethods.add( RequestMethod.GET.toString() );
-
- List<String> mediaTypes = new ArrayList<String>();
- mediaTypes.add( MediaType.TEXT_HTML.toString() );
- mediaTypes.add( MediaType.APPLICATION_JSON.toString() );
- mediaTypes.add( MediaType.APPLICATION_XML.toString() );
- mediaTypes.add( new MediaType( "application", "javascript" ).toString() );
-
- for ( Map.Entry<Class<? extends IdentifiableObject>, String> entry : ExchangeClasses.getAllExportMap().entrySet() )
- {
- resources.add( new Resource( StringUtils.capitalize( entry.getValue() ), entry.getKey(), requestMethods, mediaTypes ) );
- }
-
- Collections.sort(resources, new Comparator<Resource>()
- {
- @Override
- public int compare( Resource o1, Resource o2 )
- {
- return o1.getName().compareTo( o2.getName() );
- }
- });
- }
}