=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExchangeClasses.java' --- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExchangeClasses.java 2013-05-10 12:07:51 +0000 +++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExchangeClasses.java 2013-05-31 04:06:10 +0000 @@ -29,6 +29,7 @@ import org.hisp.dhis.attribute.Attribute; import org.hisp.dhis.chart.Chart; +import org.hisp.dhis.common.BaseDimensionalObject; import org.hisp.dhis.common.IdentifiableObject; import org.hisp.dhis.concept.Concept; import org.hisp.dhis.constant.Constant; @@ -90,6 +91,9 @@ // these are the ones that are available for dxf2 import private static Map, String> importClasses; + // these will be listed on the global resource page + private static Map, String> publicResourceClasses; + static { allExportClasses = new LinkedHashMap, String>(); @@ -118,7 +122,7 @@ allExportClasses.put( DataElement.class, "dataElements" ); allExportClasses.put( DataElementGroup.class, "dataElementGroups" ); allExportClasses.put( DataElementGroupSet.class, "dataElementGroupSets" ); - + allExportClasses.put( DataElementOperand.class, "dataElementOperands" ); allExportClasses.put( IndicatorType.class, "indicatorTypes" ); @@ -151,6 +155,8 @@ allExportClasses.put( Program.class, "programs" ); allExportClasses.put( ProgramStage.class, "programStages" ); + allExportClasses.put( BaseDimensionalObject.class, "dimensions" ); + exportClasses = new LinkedHashMap, String>( allExportClasses ); importClasses = new LinkedHashMap, String>( allExportClasses ); @@ -168,7 +174,7 @@ exportClasses.remove( ProgramStage.class ); importClasses.remove( Program.class ); importClasses.remove( ProgramStage.class ); - + // special class which is created on demand in association with other objects exportClasses.remove( DataElementOperand.class ); importClasses.remove( DataElementOperand.class ); === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DimensionController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DimensionController.java 2013-04-23 12:02:26 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DimensionController.java 2013-05-31 04:06:10 +0000 @@ -27,6 +27,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import org.hisp.dhis.api.utils.WebUtils; import org.hisp.dhis.common.DimensionService; import org.hisp.dhis.common.DimensionalObject; import org.springframework.beans.factory.annotation.Autowired; @@ -35,13 +36,14 @@ 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.RequestParam; @Controller -@RequestMapping( value = DimensionController.RESOURCE_PATH ) +@RequestMapping(value = DimensionController.RESOURCE_PATH) public class DimensionController { public static final String RESOURCE_PATH = "/dimensions"; - + // ------------------------------------------------------------------------- // Dependencies // ------------------------------------------------------------------------- @@ -53,26 +55,38 @@ // Controller // ------------------------------------------------------------------------- - @RequestMapping( value = "/{uid}", method = RequestMethod.GET ) - public String getDimension( @PathVariable( "uid" ) String uid, Model model ) + @RequestMapping(value = "/{uid}", method = RequestMethod.GET) + public String getDimension( @PathVariable("uid") String uid, + @RequestParam( value = "links", defaultValue = "true", required = false ) Boolean links, Model model ) { DimensionalObject dimension = dimensionService.getDimension( uid ); - + model.addAttribute( "model", dimension ); model.addAttribute( "viewClass", "dimensional" ); - + + if ( links ) + { + WebUtils.generateLinks( dimension ); + } + return "dimension"; } @RequestMapping( method = RequestMethod.GET ) - public String getDimensions( Model model ) + public String getDimensions( + @RequestParam( value = "links", defaultValue = "true", required = false ) Boolean links, Model model ) { WebMetaData metaData = new WebMetaData(); - - metaData.setDimensions( dimensionService.getAllDimensions() ); - + + metaData.setDimensions( dimensionService.getAllDimensions() ); + model.addAttribute( "model", metaData ); - + + if ( links ) + { + WebUtils.generateLinks( metaData ); + } + return "dimensions"; } } === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ContextUtils.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ContextUtils.java 2013-04-16 18:19:38 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ContextUtils.java 2013-05-31 04:06:10 +0000 @@ -28,8 +28,9 @@ */ import javassist.util.proxy.ProxyObject; - import org.apache.commons.io.IOUtils; +import org.hisp.dhis.common.BaseDimensionalObject; +import org.hisp.dhis.common.DimensionalObject; import org.hisp.dhis.common.IdentifiableObject; import org.hisp.dhis.dxf2.metadata.ExchangeClasses; import org.hisp.dhis.setting.SystemSettingManager; @@ -184,7 +185,7 @@ response.setContentType( CONTENT_TYPE_TEXT ); PrintWriter writer = null; - + try { writer = response.getWriter(); @@ -218,7 +219,17 @@ clazz = clazz.getSuperclass(); } - String resourcePath = ExchangeClasses.getAllExportMap().get( clazz ); + String resourcePath; + + // special case + if ( DimensionalObject.class.isAssignableFrom( clazz ) ) + { + resourcePath = ExchangeClasses.getAllExportMap().get( BaseDimensionalObject.class ); + } + else + { + resourcePath = ExchangeClasses.getAllExportMap().get( clazz ); + } return getRootPath( getRequest() ) + "/" + resourcePath; } @@ -272,15 +283,15 @@ /** * Adds basic authentication by adding an Authorization header to the * given HttpHeaders object. - * - * @param headers the HttpHeaders object. + * + * @param headers the HttpHeaders object. * @param username the user name. * @param password the password. */ public static void setBasicAuth( HttpHeaders headers, String username, String password ) { - String authorisation = username + ":" + password; - byte[] encodedAuthorisation = Base64.encode( authorisation.getBytes() ); + String authorisation = username + ":" + password; + byte[] encodedAuthorisation = Base64.encode( authorisation.getBytes() ); headers.add( "Authorization", "Basic " + new String( encodedAuthorisation ) ); } } === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebUtils.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebUtils.java 2012-10-26 17:22:12 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebUtils.java 2013-05-31 04:06:10 +0000 @@ -30,6 +30,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hisp.dhis.api.controller.WebMetaData; +import org.hisp.dhis.common.DimensionalObject; import org.hisp.dhis.common.IdentifiableObject; import org.hisp.dhis.common.Pager; import org.hisp.dhis.system.util.ReflectionUtils; @@ -48,7 +49,7 @@ { private static final Log log = LogFactory.getLog( WebUtils.class ); - @SuppressWarnings( "unchecked" ) + @SuppressWarnings("unchecked") public static void generateLinks( WebMetaData metaData ) { Class baseType = null; @@ -56,9 +57,10 @@ for ( Field field : fields ) { - if ( ReflectionUtils.isCollection( field.getName(), metaData, IdentifiableObject.class ) ) + if ( ReflectionUtils.isCollection( field.getName(), metaData, IdentifiableObject.class ) || + ReflectionUtils.isCollection( field.getName(), metaData, DimensionalObject.class ) ) { - List objects = new ArrayList( (Collection) ReflectionUtils.getFieldObject( field, metaData ) ); + List objects = new ArrayList( (Collection) ReflectionUtils.getFieldObject( field, metaData ) ); if ( !objects.isEmpty() ) { @@ -69,7 +71,7 @@ baseType = objects.get( 0 ).getClass(); - for ( IdentifiableObject object : objects ) + for ( Object object : objects ) { generateLinks( object ); } @@ -77,16 +79,22 @@ } } - if ( metaData.getPager() != null && baseType != null ) + if ( baseType == null ) + { + log.warn( "baseType was not found, returning." ); + return; + } + + if ( metaData.getPager() != null ) { String basePath = ContextUtils.getPath( baseType ); Pager pager = metaData.getPager(); if ( pager.getPage() < pager.getPageCount() ) { - String nextPath = basePath + "?page=" + ( pager.getPage() + 1 ); + String nextPath = basePath + "?page=" + (pager.getPage() + 1); nextPath += pager.pageSizeIsDefault() ? "" : "&pageSize=" + pager.getPageSize(); - + pager.setNextPage( nextPath ); } @@ -99,9 +107,9 @@ } else { - String prevPath = basePath + "?page=" + ( pager.getPage() - 1 ); + String prevPath = basePath + "?page=" + (pager.getPage() - 1); prevPath += pager.pageSizeIsDefault() ? "" : "&pageSize=" + pager.getPageSize(); - + pager.setPrevPage( prevPath ); } } === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/list.xsl' --- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/list.xsl 2013-05-17 03:29:07 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/list.xsl 2013-05-31 04:06:10 +0000 @@ -19,7 +19,7 @@ d:organisationUnitGroupSets|d:indicatorTypes|d:attributeTypes|d:reports|d:constants| d:sqlViews|d:validationRules|d:validationRuleGroups|d:users|d:userGroups|d:userAuthorityGroups| d:reportTables|d:mapLegends|d:mapLegendSets|d:mapLayers|d:optionSets|d:interpretations| - d:sections|d:userRoles|d:organisationUnitLevels|d:programs|d:programStages"> + d:sections|d:userRoles|d:organisationUnitLevels|d:programs|d:programStages|d:dimensions">