← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20894: KeyJsonValueController, added resource for getting meta-data

 

------------------------------------------------------------
revno: 20894
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-10-29 12:35:01 -0400
message:
  KeyJsonValueController, added resource for getting meta-data
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/KeyJsonValueController.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/KeyJsonValueController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/KeyJsonValueController.java	2015-10-29 16:28:44 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/KeyJsonValueController.java	2015-10-29 16:35:01 +0000
@@ -34,6 +34,7 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.commons.beanutils.BeanUtils;
 import org.hisp.dhis.appmanager.App;
 import org.hisp.dhis.appmanager.AppManager;
 import org.hisp.dhis.dxf2.render.RenderService;
@@ -117,7 +118,8 @@
     }
 
     /**
-     * Retrieves the KeyJsonValue represented by the given key from the given namespace.
+     * Retrieves the value of the KeyJsonValue represented by the given key from 
+     * the given namespace.
      */
     @RequestMapping( value = "/{namespace}/{key}", method = RequestMethod.GET, produces = "application/json" )
     public @ResponseBody String getKeyJsonValue(
@@ -142,6 +144,35 @@
     }
 
     /**
+     * Retrieves the KeyJsonValue represented by the given key from the given namespace.
+     */
+    @RequestMapping( value = "/{namespace}/{key}/metaData", method = RequestMethod.GET, produces = "application/json" )
+    public @ResponseBody KeyJsonValue getKeyJsonValueMetaData(
+        @PathVariable String namespace, @PathVariable String key, HttpServletResponse response )
+        throws Exception
+    {
+        if ( !hasAccess( namespace ) )
+        {
+            throw new WebMessageException( WebMessageUtils.forbidden( "The namespace '" + namespace +
+                "' is protected, and you don't have the right authority to access it." ) );
+        }
+
+        KeyJsonValue keyJsonValue = keyJsonValueService.getKeyJsonValue( namespace, key );
+
+        if ( keyJsonValue == null )
+        {
+            throw new WebMessageException( WebMessageUtils
+                .notFound( "The key '" + key + "' was not found in the namespace '" + namespace + "'." ) );
+        }
+
+        KeyJsonValue metaDataValue = new KeyJsonValue();
+        BeanUtils.copyProperties( metaDataValue, keyJsonValue );
+        metaDataValue.setValue( null );
+        
+        return metaDataValue;
+    }
+
+    /**
      * Creates a new KeyJsonValue Object on the given namespace with the key and value supplied.
      */
     @RequestMapping( value = "/{namespace}/{key}", method = RequestMethod.POST, produces = "application/json", consumes = "application/json" )