=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java 2014-07-03 13:13:37 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java 2014-07-30 09:46:29 +0000 @@ -28,18 +28,9 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import java.io.InputStream; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - +import com.google.common.base.Enums; +import com.google.common.base.Optional; +import com.google.common.collect.Lists; import org.hisp.dhis.acl.Access; import org.hisp.dhis.acl.AclService; import org.hisp.dhis.common.BaseIdentifiableObject; @@ -83,9 +74,16 @@ import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseStatus; -import com.google.common.base.Enums; -import com.google.common.base.Optional; -import com.google.common.collect.Lists; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.InputStream; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; /** * @author Morten Olav Hansen @@ -130,7 +128,7 @@ // GET //-------------------------------------------------------------------------- - @RequestMapping( method = RequestMethod.GET ) + @RequestMapping(method = RequestMethod.GET) public @ResponseBody RootNode getObjectList( @RequestParam Map parameters, HttpServletResponse response, HttpServletRequest request ) { @@ -219,7 +217,7 @@ options.getOptions().put( "viewClass", "sharing" ); } - handleLinksAndAccess( options, entityList ); + handleLinksAndAccess( options, entityList, false ); linkService.generatePagerLinks( pager, getEntityClass() ); @@ -244,15 +242,15 @@ return rootNode; } - @RequestMapping( value = "/{uid}/{property}", method = RequestMethod.GET ) - public @ResponseBody RootNode getObjectProperty( @PathVariable( "uid" ) String uid, @PathVariable( "property" ) String property, + @RequestMapping(value = "/{uid}/{property}", method = RequestMethod.GET) + public @ResponseBody RootNode getObjectProperty( @PathVariable("uid") String uid, @PathVariable("property") String property, @RequestParam Map parameters, HttpServletRequest request, HttpServletResponse response ) throws Exception { return getObjectInternal( uid, parameters, Lists.newArrayList(), Lists.newArrayList( property ) ); } - @RequestMapping( value = "/{uid}", method = RequestMethod.GET ) - public @ResponseBody RootNode getObject( @PathVariable( "uid" ) String uid, @RequestParam Map parameters, + @RequestMapping(value = "/{uid}", method = RequestMethod.GET) + public @ResponseBody RootNode getObject( @PathVariable("uid") String uid, @RequestParam Map parameters, HttpServletRequest request, HttpServletResponse response ) throws Exception { List fields = Lists.newArrayList( contextService.getParameterValues( "fields" ) ); @@ -281,7 +279,7 @@ if ( options.hasLinks() ) { - linkService.generateLinks( entities ); + linkService.generateLinks( entities, true ); } if ( aclService.isSupported( getEntityClass() ) ) @@ -324,7 +322,7 @@ // POST //-------------------------------------------------------------------------- - @RequestMapping( method = RequestMethod.POST, consumes = { "application/xml", "text/xml" } ) + @RequestMapping(method = RequestMethod.POST, consumes = { "application/xml", "text/xml" }) public void postXmlObject( HttpServletResponse response, HttpServletRequest request, InputStream input ) throws Exception { if ( !aclService.canCreate( currentUserService.getCurrentUser(), getEntityClass() ) ) @@ -343,7 +341,7 @@ renderService.toXml( response.getOutputStream(), summary ); } - @RequestMapping( method = RequestMethod.POST, consumes = "application/json" ) + @RequestMapping(method = RequestMethod.POST, consumes = "application/json") public void postJsonObject( HttpServletResponse response, HttpServletRequest request, InputStream input ) throws Exception { if ( !aclService.canCreate( currentUserService.getCurrentUser(), getEntityClass() ) ) @@ -366,9 +364,9 @@ // PUT //-------------------------------------------------------------------------- - @RequestMapping( value = "/{uid}", method = RequestMethod.PUT, consumes = { MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE } ) - @ResponseStatus( value = HttpStatus.NO_CONTENT ) - public void putXmlObject( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid, InputStream + @RequestMapping(value = "/{uid}", method = RequestMethod.PUT, consumes = { MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE }) + @ResponseStatus(value = HttpStatus.NO_CONTENT) + public void putXmlObject( HttpServletResponse response, HttpServletRequest request, @PathVariable("uid") String uid, InputStream input ) throws Exception { List objects = getEntity( uid ); @@ -397,9 +395,9 @@ renderService.toXml( response.getOutputStream(), summary ); } - @RequestMapping( value = "/{uid}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE ) - @ResponseStatus( value = HttpStatus.NO_CONTENT ) - public void putJsonObject( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid, InputStream + @RequestMapping(value = "/{uid}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE) + @ResponseStatus(value = HttpStatus.NO_CONTENT) + public void putJsonObject( HttpServletResponse response, HttpServletRequest request, @PathVariable("uid") String uid, InputStream input ) throws Exception { List objects = getEntity( uid ); @@ -432,9 +430,9 @@ // DELETE //-------------------------------------------------------------------------- - @RequestMapping( value = "/{uid}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE ) - @ResponseStatus( value = HttpStatus.NO_CONTENT ) - public void deleteObject( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid ) throws + @RequestMapping(value = "/{uid}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE) + @ResponseStatus(value = HttpStatus.NO_CONTENT) + public void deleteObject( HttpServletResponse response, HttpServletRequest request, @PathVariable("uid") String uid ) throws Exception { List objects = getEntity( uid ); @@ -558,7 +556,7 @@ protected void addAccessProperties( List objects ) { User user = currentUserService.getCurrentUser(); - + for ( T object : objects ) { Access access = new Access(); @@ -568,16 +566,16 @@ access.setRead( aclService.canRead( user, object ) ); access.setUpdate( aclService.canUpdate( user, object ) ); access.setDelete( aclService.canDelete( user, object ) ); - + ((BaseIdentifiableObject) object).setAccess( access ); } } - protected void handleLinksAndAccess( WebOptions options, List entityList ) + protected void handleLinksAndAccess( WebOptions options, List entityList, boolean deepScan ) { if ( options != null && options.hasLinks() ) { - linkService.generateLinks( entityList ); + linkService.generateLinks( entityList, deepScan ); } if ( entityList != null && aclService.isSupported( getEntityClass() ) ) @@ -596,7 +594,7 @@ private String entitySimpleName; - @SuppressWarnings( "unchecked" ) + @SuppressWarnings("unchecked") protected Class getEntityClass() { if ( entityClass == null ) @@ -628,7 +626,7 @@ return entitySimpleName; } - @SuppressWarnings( "unchecked" ) + @SuppressWarnings("unchecked") protected T getEntityInstance() { try === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DashboardController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DashboardController.java 2014-06-11 20:27:54 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DashboardController.java 2014-07-30 09:46:29 +0000 @@ -236,13 +236,13 @@ if ( item.getEmbeddedItem() != null ) { - linkService.generateLinks( item.getEmbeddedItem() ); + linkService.generateLinks( item.getEmbeddedItem(), true ); } else if ( item.getLinkItems() != null ) { for ( IdentifiableObject link : item.getLinkItems() ) { - linkService.generateLinks( link ); + linkService.generateLinks( link, true ); } } } === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DimensionController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DimensionController.java 2014-06-25 15:56:22 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DimensionController.java 2014-07-30 09:46:29 +0000 @@ -91,7 +91,7 @@ if ( links ) { - linkService.generateLinks( dimension ); + linkService.generateLinks( dimension, true ); } return "dimension"; @@ -134,7 +134,7 @@ if ( links ) { - linkService.generateLinks( metaData ); + linkService.generateLinks( metaData, false ); } return "dimensions"; @@ -152,7 +152,7 @@ if ( links ) { - linkService.generateLinks( metaData ); + linkService.generateLinks( metaData, false ); } return "dimensions"; @@ -194,7 +194,7 @@ if ( links ) { - linkService.generateLinks( metaData ); + linkService.generateLinks( metaData, false ); } return "dimensions"; === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/dataelement/DataElementGroupController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/dataelement/DataElementGroupController.java 2014-06-12 15:36:36 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/dataelement/DataElementGroupController.java 2014-07-30 09:46:29 +0000 @@ -99,7 +99,7 @@ if ( options.hasLinks() ) { - linkService.generateLinks( metaData ); + linkService.generateLinks( metaData, false ); } model.addAttribute( "model", metaData ); @@ -146,7 +146,7 @@ if ( options.hasLinks() ) { - linkService.generateLinks( metaData ); + linkService.generateLinks( metaData, false ); } model.addAttribute( "model", metaData ); === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/service/DefaultLinkService.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/service/DefaultLinkService.java 2014-07-30 09:09:41 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/service/DefaultLinkService.java 2014-07-30 09:46:29 +0000 @@ -100,13 +100,13 @@ } @Override - public void generateLinks( T object ) + public void generateLinks( T object, boolean deepScan ) { - generateLinks( object, contextService.getServletPath() ); + generateLinks( object, contextService.getServletPath(), deepScan ); } @Override - public void generateLinks( T object, String hrefBase ) + public void generateLinks( T object, String hrefBase, boolean deepScan ) { if ( Collection.class.isInstance( object ) ) { @@ -114,12 +114,12 @@ for ( Object collectionObject : collection ) { - generateLink( collectionObject, hrefBase, false ); + generateLink( collectionObject, hrefBase, deepScan ); } } else { - generateLink( object, hrefBase, true ); + generateLink( object, hrefBase, deepScan ); } } === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/service/LinkService.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/service/LinkService.java 2014-06-18 07:15:48 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/service/LinkService.java 2014-07-30 09:46:29 +0000 @@ -51,17 +51,19 @@ * Uses hrefBase from ContextService.getServletPath(). * * @param object Object (can be collection) to set HREFs on + * @param deepScan Generate links also on deeper levels (only one level down) * @see javax.servlet.http.HttpServletRequest * @see ContextService */ - void generateLinks( T object ); + void generateLinks( T object, boolean deepScan ); /** * Generate HREF and set it using reflection, required a setHref(String) method in your class. * * @param object Object (can be collection) to set HREFs on * @param hrefBase Used as starting point of HREF + * @param deepScan Generate links also on deeper levels (only one level down) * @see javax.servlet.http.HttpServletRequest */ - void generateLinks( T object, String hrefBase ); + void generateLinks( T object, String hrefBase, boolean deepScan ); }