← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15896: use rootNode for index controller

 

------------------------------------------------------------
revno: 15896
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2014-06-28 12:34:29 +0700
message:
  use rootNode for index controller
removed:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseCollection.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
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/IndexController.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
=== removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseCollection.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseCollection.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseCollection.java	1970-01-01 00:00:00 +0000
@@ -1,105 +0,0 @@
-package org.hisp.dhis.common;
-
-/*
- * 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 com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-@JacksonXmlRootElement( localName = "collection", namespace = DxfNamespaces.DXF_2_0)
-public class BaseCollection
-    implements LinkableObject
-{
-    private Pager pager;
-
-    private LinkableObject linkableObject;
-
-    public BaseCollection()
-    {
-        linkableObject = new BaseLinkableObject();
-    }
-
-    //-------------------------------------------------------------------------------------
-    // Dependencies
-    //-------------------------------------------------------------------------------------
-
-    @JsonProperty
-    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
-    public Pager getPager()
-    {
-        return pager;
-    }
-
-    public void setPager( Pager pager )
-    {
-        this.pager = pager;
-    }
-
-    public LinkableObject getLinkableObject()
-    {
-        return linkableObject;
-    }
-
-    public void setLinkableObject( LinkableObject linkableObject )
-    {
-        this.linkableObject = linkableObject;
-    }
-
-    //-------------------------------------------------------------------------------------
-    // Serializable fields
-    //-------------------------------------------------------------------------------------
-
-    @JsonProperty
-    @JacksonXmlProperty( isAttribute = true, namespace = DxfNamespaces.DXF_2_0)
-    public String getHref()
-    {
-        if ( linkableObject == null )
-        {
-            return null;
-        }
-
-        return linkableObject.getHref();
-    }
-
-    /**
-     * Set link for collection. This will be replaced for 2.7 with a real linkableObject.
-     *
-     * @param link
-     */
-    public void setHref( String link )
-    {
-        if ( linkableObject != null )
-        {
-            linkableObject.setHref( link );
-        }
-    }
-}

=== 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-06-28 04:21:56 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/IndexController.java	2014-06-28 05:34:29 +0000
@@ -28,20 +28,19 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hisp.dhis.common.DxfNamespaces;
+import org.hisp.dhis.node.types.CollectionNode;
+import org.hisp.dhis.node.types.ComplexNode;
+import org.hisp.dhis.node.types.RootNode;
+import org.hisp.dhis.node.types.SimpleNode;
 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.hisp.dhis.webapi.service.ContextService;
 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;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
+import org.springframework.web.bind.annotation.ResponseBody;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -52,37 +51,45 @@
     @Autowired
     private SchemaService schemaService;
 
+    @Autowired
+    private ContextService contextService;
+
     //--------------------------------------------------------------------------
     // GET
     //--------------------------------------------------------------------------
 
     @RequestMapping( value = "/api", method = RequestMethod.GET )
-    public void getIndex( HttpServletRequest request, HttpServletResponse response ) throws IOException
+    public @ResponseBody RootNode getIndex()
     {
-        String location = response.encodeRedirectURL( "/" );
-        response.sendRedirect( ContextUtils.getRootPath( request ) + location );
+        return createRootNode();
     }
 
     @RequestMapping( value = "/", method = RequestMethod.GET )
-    public String getResources( Model model, HttpServletRequest request )
-    {
-        Resources resources = new Resources();
+    public @ResponseBody RootNode getIndexSlash()
+    {
+        return createRootNode();
+    }
+
+    private RootNode createRootNode()
+    {
+        RootNode rootNode = new RootNode( "metadata" );
+        rootNode.setNamespace( DxfNamespaces.DXF_2_0 );
+        rootNode.setDefaultNamespace( DxfNamespaces.DXF_2_0 );
+
+        CollectionNode collectionNode = rootNode.addChild( new CollectionNode( "resources" ) );
 
         for ( Schema schema : schemaService.getSchemas() )
         {
             if ( schema.haveApiEndpoint() )
             {
-                Resource resource = new Resource();
-                resource.setSingular( schema.getSingular() );
-                resource.setPlural( schema.getPlural() );
-                resource.setHref( ContextUtils.getRootPath( request ) + schema.getApiEndpoint() );
+                ComplexNode complexNode = collectionNode.addChild( new ComplexNode( "resource" ) );
 
-                resources.getResources().add( resource );
+                complexNode.addChild( new SimpleNode( "singular", schema.getSingular() ) );
+                complexNode.addChild( new SimpleNode( "plural", schema.getPlural() ) );
+                complexNode.addChild( new SimpleNode( "href", contextService.getContextPath() + "/api" + schema.getApiEndpoint() ) );
             }
         }
 
-        model.addAttribute( "model", resources );
-
-        return "resources";
+        return rootNode;
     }
 }

=== removed 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-27 13:46:18 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/Resource.java	1970-01-01 00:00:00 +0000
@@ -1,97 +0,0 @@
-package org.hisp.dhis.webapi.webdomain;
-
-/*
- * 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 com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
-import org.hisp.dhis.common.DxfNamespaces;
-
-/**
- * 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 = "resource", namespace = DxfNamespaces.DXF_2_0)
-public class Resource
-{
-    private String singular;
-
-    private String plural;
-
-    private String href;
-
-    public Resource()
-    {
-
-    }
-
-    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;
-    }
-}

=== removed 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-27 13:46:18 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/Resources.java	1970-01-01 00:00:00 +0000
@@ -1,67 +0,0 @@
-package org.hisp.dhis.webapi.webdomain;
-
-/*
- * 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 com.fasterxml.jackson.annotation.JsonProperty;
-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.BaseCollection;
-import org.hisp.dhis.common.DxfNamespaces;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-@JacksonXmlRootElement(localName = "dxf2", namespace = DxfNamespaces.DXF_2_0)
-public class Resources
-    extends BaseCollection
-{
-    private List<Resource> resources = new ArrayList<Resource>();
-
-    public Resources()
-    {
-
-    }
-
-    @JsonProperty
-    @JacksonXmlElementWrapper(localName = "resources", namespace = DxfNamespaces.DXF_2_0)
-    @JacksonXmlProperty(localName = "resource", namespace = DxfNamespaces.DXF_2_0)
-    public List<Resource> getResources()
-    {
-        return resources;
-    }
-
-    public void setResources( List<Resource> resources )
-    {
-        this.resources = resources;
-    }
-}