=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultExportService.java' --- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultExportService.java 2012-05-25 21:10:19 +0000 +++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultExportService.java 2012-05-26 14:32:28 +0000 @@ -65,11 +65,11 @@ @Override public MetaData getMetaData() { - return getMetaData( ExportOptions.getDefaultExportOptions() ); + return getMetaData( Options.getDefaultOptions() ); } @Override - public MetaData getMetaData( ExportOptions exportOptions ) + public MetaData getMetaData( Options options ) { MetaData metaData = new MetaData(); @@ -77,6 +77,11 @@ for ( Map.Entry> entry : ExchangeClasses.getExportMap().entrySet() ) { + if ( !options.isEnabled( entry.getKey() ) ) + { + continue; + } + @SuppressWarnings( "unchecked" ) Class idObjectClass = (Class) entry.getValue(); === removed file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExportOptions.java' --- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExportOptions.java 2012-05-16 18:08:43 +0000 +++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExportOptions.java 1970-01-01 00:00:00 +0000 @@ -1,499 +0,0 @@ -package org.hisp.dhis.dxf2.metadata; - -/* - * Copyright (c) 2012, 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. - */ - -/** - * @author Morten Olav Hansen - */ -public class ExportOptions -{ - //-------------------------------------------------------------------------- - // Static helpers - //-------------------------------------------------------------------------- - - static private final ExportOptions defaultExportOptions = new ExportOptions(); - - static public ExportOptions getDefaultExportOptions() - { - return defaultExportOptions; - } - - //-------------------------------------------------------------------------- - // Fields for enabling/disabling options. This is very static ATM, but it is - // meant to be used by systems that auto-set beans, like Spring-MVC, which - // means it can be used as a simple argument in controller methods. - //-------------------------------------------------------------------------- - - private boolean users = false; - - private boolean userAuthorityGroups = false; - - private boolean userGroups = false; - - private boolean attributeTypes = true; - - private boolean messageConversations = false; - - private boolean dataElements = true; - - private boolean optionSets = true; - - private boolean dataElementGroups = true; - - private boolean dataElementGroupSets = true; - - private boolean concepts = true; - - private boolean categories = true; - - private boolean categoryOptions = true; - - private boolean categoryCombos = true; - - private boolean categoryOptionCombos = true; - - private boolean indicators = true; - - private boolean indicatorGroups = true; - - private boolean indicatorGroupSets = true; - - private boolean indicatorTypes = true; - - private boolean organisationUnits = true; - - private boolean organisationUnitGroups = true; - - private boolean organisationUnitGroupSets = true; - - private boolean organisationUnitLevels = true; - - private boolean dataSets = true; - - private boolean sections = true; - - private boolean validationRules = true; - - private boolean validationRuleGroups = true; - - private boolean sqlViews = true; - - private boolean charts = true; - - private boolean reports = true; - - private boolean reportTables = true; - - private boolean documents = true; - - private boolean constants = true; - - private boolean maps = true; - - private boolean mapLegends = true; - - private boolean mapLegendSets = true; - - private boolean mapLayers = true; - - private boolean dataDictionaries = false; - - //--------------------------------------------------------------------------------------------------- - // Getters and setters for option - //--------------------------------------------------------------------------------------------------- - - public boolean isAttributeTypes() - { - return attributeTypes; - } - - public void setAttributeTypes( boolean attributeTypes ) - { - this.attributeTypes = attributeTypes; - } - - public boolean isUsers() - { - return users; - } - - public void setUsers( boolean users ) - { - this.users = users; - } - - public boolean isUserAuthorityGroups() - { - return userAuthorityGroups; - } - - public void setUserAuthorityGroups( boolean userAuthorityGroups ) - { - this.userAuthorityGroups = userAuthorityGroups; - } - - public boolean isUserGroups() - { - return userGroups; - } - - public void setUserGroups( boolean userGroups ) - { - this.userGroups = userGroups; - } - - public boolean isMessageConversations() - { - return messageConversations; - } - - public void setMessageConversations( boolean messageConversations ) - { - this.messageConversations = messageConversations; - } - - public boolean isDataElements() - { - return dataElements; - } - - public void setDataElements( boolean dataElements ) - { - this.dataElements = dataElements; - } - - public boolean isOptionSets() - { - return optionSets; - } - - public void setOptionSets( boolean optionSets ) - { - this.optionSets = optionSets; - } - - public boolean isDataElementGroups() - { - return dataElementGroups; - } - - public void setDataElementGroups( boolean dataElementGroups ) - { - this.dataElementGroups = dataElementGroups; - } - - public boolean isDataElementGroupSets() - { - return dataElementGroupSets; - } - - public void setDataElementGroupSets( boolean dataElementGroupSets ) - { - this.dataElementGroupSets = dataElementGroupSets; - } - - public boolean isConcepts() - { - return concepts; - } - - public void setConcepts( boolean concepts ) - { - this.concepts = concepts; - } - - public boolean isCategories() - { - return categories; - } - - public void setCategories( boolean categories ) - { - this.categories = categories; - } - - public boolean isCategoryOptions() - { - return categoryOptions; - } - - public void setCategoryOptions( boolean categoryOptions ) - { - this.categoryOptions = categoryOptions; - } - - public boolean isCategoryCombos() - { - return categoryCombos; - } - - public void setCategoryCombos( boolean categoryCombos ) - { - this.categoryCombos = categoryCombos; - } - - public boolean isCategoryOptionCombos() - { - return categoryOptionCombos; - } - - public void setCategoryOptionCombos( boolean categoryOptionCombos ) - { - this.categoryOptionCombos = categoryOptionCombos; - } - - public boolean isIndicators() - { - return indicators; - } - - public void setIndicators( boolean indicators ) - { - this.indicators = indicators; - } - - public boolean isIndicatorGroups() - { - return indicatorGroups; - } - - public void setIndicatorGroups( boolean indicatorGroups ) - { - this.indicatorGroups = indicatorGroups; - } - - public boolean isIndicatorGroupSets() - { - return indicatorGroupSets; - } - - public void setIndicatorGroupSets( boolean indicatorGroupSets ) - { - this.indicatorGroupSets = indicatorGroupSets; - } - - public boolean isIndicatorTypes() - { - return indicatorTypes; - } - - public void setIndicatorTypes( boolean indicatorTypes ) - { - this.indicatorTypes = indicatorTypes; - } - - public boolean isOrganisationUnits() - { - return organisationUnits; - } - - public void setOrganisationUnits( boolean organisationUnits ) - { - this.organisationUnits = organisationUnits; - } - - public boolean isOrganisationUnitGroups() - { - return organisationUnitGroups; - } - - public void setOrganisationUnitGroups( boolean organisationUnitGroups ) - { - this.organisationUnitGroups = organisationUnitGroups; - } - - public boolean isOrganisationUnitGroupSets() - { - return organisationUnitGroupSets; - } - - public void setOrganisationUnitGroupSets( boolean organisationUnitGroupSets ) - { - this.organisationUnitGroupSets = organisationUnitGroupSets; - } - - public boolean isOrganisationUnitLevels() - { - return organisationUnitLevels; - } - - public void setOrganisationUnitLevels( boolean organisationUnitLevels ) - { - this.organisationUnitLevels = organisationUnitLevels; - } - - public boolean isDataSets() - { - return dataSets; - } - - public void setDataSets( boolean dataSets ) - { - this.dataSets = dataSets; - } - - public boolean isSections() - { - return sections; - } - - public void setSections( boolean sections ) - { - this.sections = sections; - } - - public boolean isValidationRules() - { - return validationRules; - } - - public void setValidationRules( boolean validationRules ) - { - this.validationRules = validationRules; - } - - public boolean isValidationRuleGroups() - { - return validationRuleGroups; - } - - public void setValidationRuleGroups( boolean validationRuleGroups ) - { - this.validationRuleGroups = validationRuleGroups; - } - - public boolean isSqlViews() - { - return sqlViews; - } - - public void setSqlViews( boolean sqlViews ) - { - this.sqlViews = sqlViews; - } - - public boolean isCharts() - { - return charts; - } - - public void setCharts( boolean charts ) - { - this.charts = charts; - } - - public boolean isReports() - { - return reports; - } - - public void setReports( boolean reports ) - { - this.reports = reports; - } - - public boolean isReportTables() - { - return reportTables; - } - - public void setReportTables( boolean reportTables ) - { - this.reportTables = reportTables; - } - - public boolean isDocuments() - { - return documents; - } - - public void setDocuments( boolean documents ) - { - this.documents = documents; - } - - public boolean isConstants() - { - return constants; - } - - public void setConstants( boolean constants ) - { - this.constants = constants; - } - - public boolean isMaps() - { - return maps; - } - - public void setMaps( boolean maps ) - { - this.maps = maps; - } - - public boolean isMapLegends() - { - return mapLegends; - } - - public void setMapLegends( boolean mapLegends ) - { - this.mapLegends = mapLegends; - } - - public boolean isMapLegendSets() - { - return mapLegendSets; - } - - public void setMapLegendSets( boolean mapLegendSets ) - { - this.mapLegendSets = mapLegendSets; - } - - public boolean isMapLayers() - { - return mapLayers; - } - - public void setMapLayers( boolean mapLayers ) - { - this.mapLayers = mapLayers; - } - - public boolean isDataDictionaries() - { - return dataDictionaries; - } - - public void setDataDictionaries( boolean dataDictionaries ) - { - this.dataDictionaries = dataDictionaries; - } -} === modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExportService.java' --- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExportService.java 2012-04-11 15:11:09 +0000 +++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExportService.java 2012-05-26 14:32:28 +0000 @@ -34,5 +34,5 @@ { MetaData getMetaData(); - MetaData getMetaData( ExportOptions options ); + MetaData getMetaData( Options options ); } === added file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Options.java' --- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Options.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Options.java 2012-05-26 14:32:28 +0000 @@ -0,0 +1,135 @@ +package org.hisp.dhis.dxf2.metadata; + +/* + * Copyright (c) 2012, 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 java.util.HashMap; +import java.util.Map; + +/** + * @author Morten Olav Hansen + */ +public class Options +{ + //-------------------------------------------------------------------------- + // Static helpers + //-------------------------------------------------------------------------- + + static private final Options DEFAULT_OPTIONS = new Options( true ); + + static public Options getDefaultOptions() + { + return DEFAULT_OPTIONS; + } + + private static boolean isTrue( String bool ) + { + return bool != null && bool.equalsIgnoreCase( "true" ); + } + + private static boolean isFalse( String bool ) + { + return !isTrue( bool ); + } + + //-------------------------------------------------------------------------- + // Internal State + //-------------------------------------------------------------------------- + + private Map options = new HashMap(); + + private boolean assumeTrue; + + //-------------------------------------------------------------------------- + // Constructors + //-------------------------------------------------------------------------- + + public Options() + { + } + + public Options( boolean assumeTrue ) + { + this.assumeTrue = assumeTrue; + } + + public Options( Map options ) + { + System.err.println("Options: " + options); + + this.options = options; + this.assumeTrue = options.get( "assumeTrue" ) == null || options.get( "assumeTrue" ).equalsIgnoreCase( "true" ); + } + + public Options( Map options, boolean assumeTrue ) + { + System.err.println("Options: " + options); + + this.options = options; + this.assumeTrue = assumeTrue; + } + + //-------------------------------------------------------------------------- + // Get options for classes/strings etc + //-------------------------------------------------------------------------- + + public boolean isEnabled( String type ) + { + String enabled = options.get( type ); + + return isTrue( enabled ) || enabled == null && assumeTrue; + } + + public boolean isDisabled( String type ) + { + return !isEnabled( type ); + } + + //-------------------------------------------------------------------------- + // Getters and Setters + //-------------------------------------------------------------------------- + + public Map getOptions() + { + return options; + } + + public void setOptions( Map options ) + { + this.options = options; + } + + public boolean isAssumeTrue() + { + return assumeTrue; + } + + public void setAssumeTrue( boolean assumeTrue ) + { + this.assumeTrue = assumeTrue; + } +} === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MetaDataController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MetaDataController.java 2012-05-16 20:48:16 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MetaDataController.java 2012-05-26 14:32:28 +0000 @@ -40,11 +40,13 @@ import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.xml.bind.JAXBException; import java.io.IOException; +import java.util.Map; import java.util.zip.*; import static org.hisp.dhis.api.utils.ContextUtils.*; @@ -72,9 +74,9 @@ @RequestMapping( value = MetaDataController.RESOURCE_PATH, method = RequestMethod.GET ) @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" ) - public String export( ExportOptions exportOptions, Model model ) + public String export( @RequestParam Map parameters, Model model ) { - MetaData metaData = exportService.getMetaData( exportOptions ); + MetaData metaData = exportService.getMetaData( new Options( parameters ) ); model.addAttribute( "model", metaData ); model.addAttribute( "view", "export" ); @@ -84,9 +86,9 @@ @RequestMapping( value = MetaDataController.RESOURCE_PATH + ".zip", method = RequestMethod.GET, headers = {"Accept=application/xml, text/*"} ) @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" ) - public void exportZippedXML( ExportOptions exportOptions, HttpServletResponse response ) throws IOException, JAXBException + public void exportZippedXML( @RequestParam Map parameters, HttpServletResponse response ) throws IOException { - MetaData metaData = exportService.getMetaData( exportOptions ); + MetaData metaData = exportService.getMetaData( new Options( parameters ) ); contextUtils.configureResponse( response, CONTENT_TYPE_ZIP, CacheStrategy.NO_CACHE, "export.xml.zip", true ); response.addHeader( HEADER_CONTENT_TRANSFER_ENCODING, "binary" ); @@ -99,9 +101,9 @@ @RequestMapping( value = MetaDataController.RESOURCE_PATH + ".zip", method = RequestMethod.GET, headers = {"Accept=application/json"} ) @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" ) - public void exportZippedJSON( ExportOptions exportOptions, HttpServletResponse response ) throws IOException, JAXBException + public void exportZippedJSON( @RequestParam Map parameters, HttpServletResponse response ) throws IOException { - MetaData metaData = exportService.getMetaData( exportOptions ); + MetaData metaData = exportService.getMetaData( new Options( parameters ) ); contextUtils.configureResponse( response, CONTENT_TYPE_ZIP, CacheStrategy.NO_CACHE, "export.json.zip", true ); response.addHeader( HEADER_CONTENT_TRANSFER_ENCODING, "binary" ); @@ -114,9 +116,9 @@ @RequestMapping( value = MetaDataController.RESOURCE_PATH + ".gz", method = RequestMethod.GET, headers = {"Accept=application/xml, text/*"} ) @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" ) - public void exportGZippedXML( ExportOptions exportOptions, HttpServletResponse response ) throws IOException, JAXBException + public void exportGZippedXML( @RequestParam Map parameters, HttpServletResponse response ) throws IOException { - MetaData metaData = exportService.getMetaData( exportOptions ); + MetaData metaData = exportService.getMetaData( new Options( parameters ) ); response.setContentType( CONTENT_TYPE_GZIP ); GZIPOutputStream gzip = new GZIPOutputStream( response.getOutputStream() ); @@ -126,9 +128,9 @@ @RequestMapping( value = MetaDataController.RESOURCE_PATH + ".gz", method = RequestMethod.GET, headers = {"Accept=application/json"} ) @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" ) - public void exportGZippedJSON( ExportOptions exportOptions, HttpServletResponse response ) throws IOException, JAXBException + public void exportGZippedJSON( @RequestParam Map parameters, HttpServletResponse response ) throws IOException { - MetaData metaData = exportService.getMetaData( exportOptions ); + MetaData metaData = exportService.getMetaData( new Options( parameters ) ); response.setContentType( CONTENT_TYPE_GZIP ); GZIPOutputStream gzip = new GZIPOutputStream( response.getOutputStream() );