dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #33442
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17064: minor fix in SchemaController, throw 404 if type/property is not found
------------------------------------------------------------
revno: 17064
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2014-10-12 15:32:32 +0700
message:
minor fix in SchemaController, throw 404 if type/property is not found
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Property.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SchemaController.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-api/src/main/java/org/hisp/dhis/schema/Property.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Property.java 2014-10-01 11:50:02 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Property.java 2014-10-12 08:32:32 +0000
@@ -35,8 +35,6 @@
import org.hisp.dhis.common.DxfNamespaces;
import org.hisp.dhis.common.IdentifiableObject;
import org.hisp.dhis.common.NameableObject;
-import org.hisp.dhis.node.annotation.NodeRoot;
-import org.hisp.dhis.node.annotation.NodeSimple;
import org.springframework.core.Ordered;
import java.lang.reflect.Method;
@@ -45,19 +43,16 @@
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
@JacksonXmlRootElement( localName = "property", namespace = DxfNamespaces.DXF_2_0 )
-@NodeRoot( isWritable = false, isPersisted = false )
public class Property implements Ordered
{
/**
* Class for property.
*/
- @NodeSimple
private Class<?> klass;
/**
* If this property is a collection, this is the class of the items inside the collection.
*/
- @NodeSimple
private Class<?> itemKlass;
/**
@@ -74,32 +69,27 @@
* Name for this property, if this class is a collection, it is the name of the items -inside- the collection
* and not the collection wrapper itself.
*/
- @NodeSimple
private String name;
/**
* Name for actual field, used to persistence operations and getting setter/getter.
*/
- @NodeSimple
private String fieldName;
/**
* Is this property persisted somewhere. This property will be used to create criteria queries
* on demand (default: false)
*/
- @NodeSimple
private boolean persisted;
/**
* Name of collection wrapper.
*/
- @NodeSimple
private String collectionName;
/**
* If this Property is a collection, should it be wrapped with collectionName?
*/
- @NodeSimple
private boolean collectionWrapping;
/**
@@ -107,19 +97,16 @@
*
* @see org.hisp.dhis.common.annotation.Description
*/
- @NodeSimple
private String description;
/**
* Namespace used for this property.
*/
- @NodeSimple
private String namespace;
/**
* Usually only used for XML. Is this property considered an attribute.
*/
- @NodeSimple
private boolean attribute;
/**
@@ -128,7 +115,6 @@
* of the collection, e.g. List<String> would set simple to be true, but List<DataElement> would set it
* to false.
*/
- @NodeSimple
private boolean simple;
/**
@@ -136,14 +122,12 @@
*
* @see java.util.Collection
*/
- @NodeSimple
private boolean collection;
/**
* If this property is a complex object or a collection, is this property considered
* the owner of that relationship (important for imports etc).
*/
- @NodeSimple
private boolean owner;
/**
@@ -151,7 +135,6 @@
*
* @see org.hisp.dhis.common.IdentifiableObject
*/
- @NodeSimple
private boolean identifiableObject;
/**
@@ -159,13 +142,16 @@
*
* @see org.hisp.dhis.common.NameableObject
*/
- @NodeSimple
private boolean nameableObject;
- @NodeSimple
+ /**
+ * Can this property be read.
+ */
private boolean readable;
- @NodeSimple
+ /**
+ * Can this property be written to.
+ */
private boolean writable;
public Property()
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SchemaController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SchemaController.java 2014-08-13 13:25:19 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SchemaController.java 2014-10-12 08:32:32 +0000
@@ -33,17 +33,19 @@
import org.hisp.dhis.schema.SchemaService;
import org.hisp.dhis.schema.Schemas;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
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;
import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.client.HttpClientErrorException;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
@Controller
-@RequestMapping( value = "/schemas", method = RequestMethod.GET )
+@RequestMapping(value = "/schemas", method = RequestMethod.GET)
public class SchemaController
{
@Autowired
@@ -55,10 +57,17 @@
return new Schemas( schemaService.getSortedSchemas() );
}
- @RequestMapping( value = "/{type}" )
+ @RequestMapping(value = "/{type}")
public @ResponseBody Schema getSchema( @PathVariable String type )
{
- return schemaService.getSchemaBySingularName( type );
+ Schema schema = schemaService.getSchemaBySingularName( type );
+
+ if ( schema != null )
+ {
+ return schema;
+ }
+
+ throw new HttpClientErrorException( HttpStatus.NOT_FOUND, "Type " + type + " does not exist." );
}
@RequestMapping( value = "/{type}/{property}" )
@@ -71,6 +80,6 @@
return schema.getPropertyMap().get( property );
}
- return null;
+ throw new HttpClientErrorException( HttpStatus.NOT_FOUND, "Property " + property + " does not exist on type " + type + "." );
}
}