=== added directory 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/filter' === added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/filter/Filter.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/filter/Filter.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/filter/Filter.java 2013-10-30 12:51:03 +0000 @@ -0,0 +1,101 @@ +package org.hisp.dhis.filter; + +/* + * Copyright (c) 2004-2013, 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 com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonView; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; +import org.hisp.dhis.common.BaseNameableObject; +import org.hisp.dhis.common.DxfNamespaces; +import org.hisp.dhis.common.view.DetailedView; +import org.hisp.dhis.common.view.ExportView; + +/** + * @author Ovidiu Rosu + */ +@JacksonXmlRootElement(localName = "filter", namespace = DxfNamespaces.DXF_2_0) +public class Filter + extends BaseNameableObject +{ + /** + * Determines if a de-serialized file is compatible with this class. + */ + private static final long serialVersionUID = 8736213901318412954L; + + private String jsonFilter; + + private Integer sortOrder; + + //-------------------------------------------------------------------------- + // Constructors + //-------------------------------------------------------------------------- + + public Filter() + { + } + + public Filter( String name ) + { + this.name = name; + } + + public Filter( String uid, String description, String name, String jsonFilter ) + { + super( uid, description, name ); + this.jsonFilter = jsonFilter; + } + + // ------------------------------------------------------------------------- + // Getters and setters properties + // ------------------------------------------------------------------------- + + @JsonProperty + @JsonView({ DetailedView.class, ExportView.class }) + @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) + public String getJsonFilter() + { + return jsonFilter; + } + + public void setJsonFilter( String jsonFilter ) + { + this.jsonFilter = jsonFilter; + } + + public Integer getSortOrder() + { + return sortOrder; + } + + public void setSortOrder( Integer sortOrder ) + { + this.sortOrder = sortOrder; + } +} === added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/filter/FilterService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/filter/FilterService.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/filter/FilterService.java 2013-10-30 12:51:03 +0000 @@ -0,0 +1,57 @@ +package org.hisp.dhis.filter; + +/* + * Copyright (c) 2004-2013, 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.Collection; + +/** + * @author Ovidiu Rosu + */ +public interface FilterService +{ + Filter getFilter( Integer id ); + + Filter getFilterByUid( String uid ); + + Collection getAllFilters(); + + Collection getFiltersBetweenByName( String name, int first, int max ); + + Collection getFiltersBetween( int first, int max ); + + void saveFilter( Filter filter ); + + void updateFilter( Filter filter ); + + void deleteFilter( Filter filter ); + + int getFilterCountByName( String name ); + + int getFilterCount(); +} === added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/filter/FilterStore.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/filter/FilterStore.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/filter/FilterStore.java 2013-10-30 12:51:03 +0000 @@ -0,0 +1,39 @@ +package org.hisp.dhis.filter; + +/* + * Copyright (c) 2004-2013, 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 org.hisp.dhis.common.GenericIdentifiableObjectStore; + +/** + * @author Ovidiu Rosu + */ +public interface FilterStore + extends GenericIdentifiableObjectStore +{ +} === added directory 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/filter' === added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/filter/DefaultFilterService.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/filter/DefaultFilterService.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/filter/DefaultFilterService.java 2013-10-30 12:51:03 +0000 @@ -0,0 +1,136 @@ +package org.hisp.dhis.filter; + +/* + * Copyright (c) 2004-2013, 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 org.hisp.dhis.i18n.I18nService; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Collection; + +import static org.hisp.dhis.i18n.I18nUtils.*; + +/** + * @author Ovidiu Rosu + */ +@Transactional +public class DefaultFilterService + implements FilterService +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private FilterStore filterStore; + + public FilterStore getFilterStore() + { + return filterStore; + } + + public void setFilterStore( FilterStore filterStore ) + { + this.filterStore = filterStore; + } + + private I18nService i18nService; + + public I18nService getI18nService() + { + return i18nService; + } + + public void setI18nService( I18nService i18nService ) + { + this.i18nService = i18nService; + } + + // ------------------------------------------------------------------------- + // Logic + // ------------------------------------------------------------------------- + + @Override + public Filter getFilter( Integer id ) + { + return filterStore.get( id ); + } + + @Override + public Filter getFilterByUid( String uid ) + { + return filterStore.getByUid( uid ); + } + + @Override + public Collection getAllFilters() + { + return filterStore.getAll(); + } + + @Override + public Collection getFiltersBetweenByName( String name, int first, int max ) + { + return getObjectsBetweenByName( i18nService, filterStore, name, first, max ); + } + + @Override + public Collection getFiltersBetween( int first, int max ) + { + return getObjectsBetween( i18nService, filterStore, first, max ); + } + + @Override + public void saveFilter( Filter filter ) + { + filterStore.save( filter ); + } + + @Override + public void updateFilter( Filter filter ) + { + filterStore.update( filter ); + } + + @Override + public void deleteFilter( Filter filter ) + { + filterStore.delete( filter ); + } + + @Override + public int getFilterCountByName( String name ) + { + return getCountByName( i18nService, filterStore, name ); + } + + @Override + public int getFilterCount() + { + return filterStore.getCount(); + } +} === added directory 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/filter/hibernate' === added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/filter/hibernate/HibernateFilterStore.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/filter/hibernate/HibernateFilterStore.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/filter/hibernate/HibernateFilterStore.java 2013-10-30 12:51:03 +0000 @@ -0,0 +1,42 @@ +package org.hisp.dhis.filter.hibernate; + +/* + * Copyright (c) 2004-2013, 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 org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore; +import org.hisp.dhis.filter.Filter; +import org.hisp.dhis.filter.FilterStore; + +/** + * @author Ovidiu Rosu + */ +public class HibernateFilterStore + extends HibernateIdentifiableObjectStore + implements FilterStore +{ +} === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2013-10-23 22:03:17 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2013-10-25 19:53:21 +0000 @@ -55,6 +55,13 @@ + + + + + + + @@ -583,6 +590,12 @@ + + + + + + === added directory 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/filter' === added directory 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/filter/hibernate' === added file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/filter/hibernate/Filter.hbm.xml' --- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/filter/hibernate/Filter.hbm.xml 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/filter/hibernate/Filter.hbm.xml 2013-10-30 12:51:03 +0000 @@ -0,0 +1,25 @@ + +] + > + + + + + + + + + + &identifiableProperties; + + + + + + + + + === modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultExportService.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultExportService.java 2013-08-23 16:05:01 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultExportService.java 2013-10-30 12:51:03 +0000 @@ -28,15 +28,15 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.Map; - +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import net.sf.json.JSONObject; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hisp.dhis.common.IdentifiableObject; import org.hisp.dhis.common.IdentifiableObjectManager; +import org.hisp.dhis.filter.Filter; +import org.hisp.dhis.filter.FilterService; import org.hisp.dhis.scheduling.TaskId; import org.hisp.dhis.system.notification.NotificationLevel; import org.hisp.dhis.system.notification.Notifier; @@ -46,6 +46,14 @@ import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + /** * @author Morten Olav Hansen */ @@ -54,11 +62,9 @@ implements ExportService { private static final Log log = LogFactory.getLog( DefaultExportService.class ); - //------------------------------------------------------------------------------------------------------- // Dependencies //------------------------------------------------------------------------------------------------------- - @Autowired protected IdentifiableObjectManager manager; @@ -68,8 +74,14 @@ @Autowired private Notifier notifier; + @Autowired + private MetaDataDependencyService metaDataDependencyService; + + @Autowired + private FilterService filterService; + //------------------------------------------------------------------------------------------------------- - // ExportService Implementation + // ExportService Implementation - MetaData //------------------------------------------------------------------------------------------------------- @Override @@ -139,4 +151,120 @@ return metaData; } + + //------------------------------------------------------------------------------------------------------- + // ExportService Implementation - Detailed MetaData Export + //------------------------------------------------------------------------------------------------------- + + //@author Ovidiu Rosu + @Override + public MetaData getFilteredMetaData( FilterOptions filterOptions ) throws IOException + { + return getFilteredMetaData( filterOptions, null ); + } + + @Override + public MetaData getFilteredMetaData( FilterOptions filterOptions, TaskId taskId ) throws IOException + { + MetaData metaData = new MetaData(); + metaData.setCreated( new Date() ); + + log.info( "User '" + currentUserService.getCurrentUsername() + "' started export at " + new Date() ); + + if ( taskId != null ) + { + notifier.notify( taskId, "Exporting meta-data" ); + } + + Object jsonFilter = filterOptions.getRestrictionsJson().get( "jsonFilter" ); + String json; + + if ( jsonFilter == null ) + { + json = "{}"; + } + else + { + json = jsonFilter.toString(); + } + + + Map> identifiableObjectUidMap = new ObjectMapper().readValue( json, new TypeReference>>() + { + } ); + + Map> identifiableObjectMap; + + if ( filterOptions.getRestrictionsJson().get( "exportDependencies" ).equals( "true" ) ) + { + identifiableObjectMap = metaDataDependencyService.getIdentifiableObjectWithDependencyMap( identifiableObjectUidMap ); + } + else + { + identifiableObjectMap = metaDataDependencyService.getIdentifiableObjectMap( identifiableObjectUidMap ); + } + + for ( Map.Entry> identifiableObjectEntry : identifiableObjectMap.entrySet() ) + { + String message = "Exporting " + identifiableObjectEntry.getValue().size() + " " + StringUtils.capitalize( identifiableObjectEntry.getKey() ); + log.info( message ); + + if ( taskId != null ) + { + notifier.notify( taskId, message ); + } + + ReflectionUtils.invokeSetterMethod( identifiableObjectEntry.getKey(), metaData, identifiableObjectEntry.getValue() ); + } + + log.info( "Export done at " + new Date() ); + + if ( taskId != null ) + { + notifier.notify( taskId, NotificationLevel.INFO, "Export done", true ); + } + + return metaData; + } + + //------------------------------------------------------------------------------------------------------- + // ExportService Implementation - Filter functionality + //------------------------------------------------------------------------------------------------------- + + @Override + public List getFilters() + { + return (List) filterService.getAllFilters(); + } + + @Override + public void saveFilter( JSONObject json ) throws IOException + { + Filter filter = new Filter( json.getString( "name" ) ); + filter.setDescription( json.getString( "description" ) ); + filter.setJsonFilter( json.getString( "jsonFilter" ) ); + filter.setAutoFields(); + + filterService.saveFilter( filter ); + } + + @Override + public void updateFilter( JSONObject json ) throws IOException + { + Filter filter = filterService.getFilterByUid( json.getString( "uid" ) ); + filter.setName( json.getString( "name" ) ); + filter.setDescription( json.getString( "description" ) ); + filter.setJsonFilter( json.getString( "jsonFilter" ) ); + filter.setLastUpdated( new Date() ); + + filterService.updateFilter( filter ); + } + + @Override + public void deleteFilter( JSONObject json ) throws IOException + { + Filter filter = filterService.getFilterByUid( json.getString( "uid" ) ); + + filterService.deleteFilter( filter ); + } } === added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultMetaDataDependencyService.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultMetaDataDependencyService.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultMetaDataDependencyService.java 2013-10-30 12:51:03 +0000 @@ -0,0 +1,398 @@ +package org.hisp.dhis.dxf2.metadata; + +/* + * Copyright (c) 2004-2013, 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 com.fasterxml.jackson.annotation.JsonView; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.proxy.HibernateProxy; +import org.hisp.dhis.common.IdentifiableObject; +import org.hisp.dhis.common.IdentifiableObjectManager; +import org.hisp.dhis.common.view.ExportView; +import org.hisp.dhis.constant.Constant; +import org.hisp.dhis.constant.ConstantService; +import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; +import org.hisp.dhis.expression.Expression; +import org.hisp.dhis.expression.ExpressionService; +import org.hisp.dhis.indicator.Indicator; +import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.organisationunit.OrganisationUnitLevel; +import org.hisp.dhis.organisationunit.OrganisationUnitService; +import org.hisp.dhis.system.util.ReflectionUtils; +import org.hisp.dhis.validation.ValidationRule; +import org.springframework.beans.factory.annotation.Autowired; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.regex.Matcher; + +/** + * @author Ovidiu Rosu + */ +public class DefaultMetaDataDependencyService + implements MetaDataDependencyService +{ + private static final Log log = LogFactory.getLog( DefaultMetaDataDependencyService.class ); + + private final Class[] specialCases = new Class[]{ DataElement.class, Indicator.class, OrganisationUnit.class, ValidationRule.class }; + + //------------------------------------------------------------------------------------------------------- + // Dependencies + //------------------------------------------------------------------------------------------------------- + + @Autowired + private IdentifiableObjectManager manager; + + @Autowired + private ExpressionService expressionService; + + @Autowired + private ConstantService constantService; + + @Autowired + private OrganisationUnitService organisationUnitService; + + //-------------------------------------------------------------------------- + // Get MetaData dependency Map + //-------------------------------------------------------------------------- + + public Map> getIdentifiableObjectMap( Map> identifiableObjectUidMap ) + { + Map> identifiableObjectMap = new HashMap>(); + + for ( Map.Entry> identifiableObjectUidEntry : identifiableObjectUidMap.entrySet() ) + { + String className = identifiableObjectUidEntry.getKey(); + for ( Map.Entry, String> entry : ExchangeClasses.getExportMap().entrySet() ) + { + if ( entry.getValue().equals( className ) ) + { + Class identifiableObjectClass = entry.getKey(); + Collection identifiableObjects = manager.getByUid( identifiableObjectClass, identifiableObjectUidEntry.getValue() ); + + identifiableObjectMap.put( entry.getValue(), new ArrayList( identifiableObjects ) ); + } + } + } + + return identifiableObjectMap; + } + + public Map> getIdentifiableObjectWithDependencyMap( Map> identifiableObjectUidMap ) + { + Map> identifiableObjectMap = getIdentifiableObjectMap( identifiableObjectUidMap ); + Collection identifiableObjects = new HashSet(); + + for ( Map.Entry> identifiableObjectEntry : identifiableObjectMap.entrySet() ) + { + identifiableObjects.addAll( identifiableObjectEntry.getValue() ); + } + + Set dependencySet = getDependencySet( identifiableObjects ); + + for ( IdentifiableObject dependency : dependencySet ) + { + for ( Map.Entry, String> entry : ExchangeClasses.getExportMap().entrySet() ) + { + if ( entry.getKey().equals( dependency.getClass() ) ) + { + if ( identifiableObjectMap.get( entry.getValue() ) != null ) + { + identifiableObjectMap.get( entry.getValue() ).add( dependency ); + } + else + { + List idObjects = new ArrayList(); + idObjects.add( dependency ); + + identifiableObjectMap.put( entry.getValue(), idObjects ); + } + } + } + } + + return identifiableObjectMap; + } + + //-------------------------------------------------------------------------- + // Get MetaData dependency Set + //-------------------------------------------------------------------------- + + @Override + public Set getDependencySet( IdentifiableObject identifiableObject ) + { + Set dependencySet = new HashSet(); + dependencySet.addAll( computeAllDependencies( identifiableObject ) ); + + if ( isSpecialCase( identifiableObject ) ) + { + dependencySet.addAll( computeSpecialDependencyCase( identifiableObject ) ); + } + + return dependencySet; + } + + @Override + public Set getDependencySet( Collection identifiableObjects ) + { + Set dependencySet = new HashSet(); + + for ( IdentifiableObject identifiableObject : identifiableObjects ) + { + dependencySet.addAll( getDependencySet( identifiableObject ) ); + } + + return dependencySet; + } + + //-------------------------------------------------------------------------- + // Compute dependencies + //-------------------------------------------------------------------------- + + private List computeAllDependencies( IdentifiableObject identifiableObject ) + { + List finalDependencies = new ArrayList(); + List dependencies = getDependencies( identifiableObject ); + + if ( dependencies.isEmpty() ) + { + return finalDependencies; + } + else + { + for ( IdentifiableObject dependency : dependencies ) + { + log.debug( "[ COMPUTING DEPENDENCY ] : " + dependency.getName() ); + + finalDependencies.add( dependency ); + + List computedDependencies = computeAllDependencies( dependency ); + finalDependencies.addAll( computedDependencies ); + } + + return finalDependencies; + } + } + + private List getDependencies( IdentifiableObject identifiableObject ) + { + List dependencies = new ArrayList(); + List fields = ReflectionUtils.getAllFields( identifiableObject.getClass() ); + + for ( Field field : fields ) + { + for ( Map.Entry, String> entry : ExchangeClasses.getExportMap().entrySet() ) + { + if ( ReflectionUtils.isType( field, entry.getKey() ) ) + { + Method getterMethod = ReflectionUtils.findGetterMethod( field.getName(), identifiableObject ); + IdentifiableObject dependencyObject = ReflectionUtils.invokeGetterMethod( field.getName(), identifiableObject ); + + if ( dependencyObject != null && isExportView( getterMethod ) ) + { + log.debug( "[ DEPENDENCY OBJECT ] : " + dependencyObject.getName() ); + + if ( dependencyObject instanceof HibernateProxy ) + { + Object hibernateProxyObject = ((HibernateProxy) dependencyObject).getHibernateLazyInitializer().getImplementation(); + IdentifiableObject deProxyDependencyObject = (IdentifiableObject) hibernateProxyObject; + + dependencies.add( deProxyDependencyObject ); + } + else + { + dependencies.add( dependencyObject ); + } + } + } + else if ( ReflectionUtils.isCollection( field.getName(), identifiableObject, entry.getKey() ) ) + { + Method getterMethod = ReflectionUtils.findGetterMethod( field.getName(), identifiableObject ); + Collection dependencyCollection = ReflectionUtils.invokeGetterMethod( field.getName(), identifiableObject ); + + if ( dependencyCollection != null && isExportView( getterMethod ) ) + { + for ( IdentifiableObject dependencyElement : dependencyCollection ) + { + log.debug( "[ DEPENDENCY COLLECTION ELEMENT ] : " + dependencyElement.getName() ); + + if ( dependencyElement instanceof HibernateProxy ) + { + Object hibernateProxyObject = ((HibernateProxy) dependencyElement).getHibernateLazyInitializer().getImplementation(); + IdentifiableObject deProxyDependencyObject = (IdentifiableObject) hibernateProxyObject; + + dependencies.add( deProxyDependencyObject ); + } + else + { + dependencies.add( dependencyElement ); + } + } + } + } + } + } + + return dependencies; + } + + //-------------------------------------------------------------------------- + // Compute special case dependencies + //-------------------------------------------------------------------------- + + private boolean isSpecialCase( IdentifiableObject identifiableObject ) + { + for ( Class specialCase : specialCases ) + { + if ( identifiableObject.getClass().equals( specialCase ) ) + { + return true; + } + } + + return false; + } + + private Set computeSpecialDependencyCase( IdentifiableObject identifiableObject ) + { + Set resultSet = new HashSet(); + + if ( identifiableObject instanceof Indicator ) + { + List indicators = new ArrayList(); + indicators.add( (Indicator) identifiableObject ); + + Set dataElementSet = expressionService.getDataElementsInIndicators( indicators ); + + resultSet.addAll( dataElementSet ); + resultSet.addAll( getDependencySet( dataElementSet ) ); + + Set constantSet = new HashSet(); + + List expressions = new ArrayList(); + Collections.addAll( expressions, ((Indicator) identifiableObject).getNumerator(), ((Indicator) identifiableObject).getDenominator() ); + + for ( String expression : expressions ) + { + Matcher matcher = ExpressionService.CONSTANT_PATTERN.matcher( expression ); + while ( matcher.find() ) + { + String co = matcher.group( 1 ); + constantSet.add( constantService.getConstant( co ) ); + } + } + + resultSet.addAll( constantSet ); + resultSet.addAll( getDependencySet( constantSet ) ); + + return resultSet; + } + else if ( identifiableObject instanceof ValidationRule ) + { + Set dataElementSet = new HashSet(); + + Expression leftSide = ReflectionUtils.invokeGetterMethod( "leftSide", identifiableObject ); + Expression rightSide = ReflectionUtils.invokeGetterMethod( "rightSide", identifiableObject ); + + dataElementSet.addAll( expressionService.getDataElementsInExpression( leftSide.getExpression() ) ); + dataElementSet.addAll( expressionService.getDataElementsInExpression( rightSide.getExpression() ) ); + + resultSet.addAll( dataElementSet ); + resultSet.addAll( getDependencySet( dataElementSet ) ); + + Set constantSet = new HashSet(); + constantSet.addAll( constantService.getAllConstants() ); + + resultSet.addAll( constantSet ); + resultSet.addAll( getDependencySet( constantSet ) ); + + return resultSet; + } + else if ( identifiableObject instanceof DataElement ) + { + Set dataElementCategoryOptionComboSet = new HashSet(); + dataElementCategoryOptionComboSet.addAll( ((DataElement) identifiableObject).getCategoryCombo().getOptionCombos() ); + + resultSet.addAll( dataElementCategoryOptionComboSet ); + resultSet.addAll( getDependencySet( dataElementCategoryOptionComboSet ) ); + + return resultSet; + } + else if ( identifiableObject instanceof OrganisationUnit ) + { + Set organisationUnitLevelSet = new HashSet(); + int level = ((OrganisationUnit) identifiableObject).getOrganisationUnitLevel(); + + while ( level > 0 ) + { + organisationUnitLevelSet.add( organisationUnitService.getOrganisationUnitLevelByLevel( level ) ); + level--; + } + + resultSet.addAll( organisationUnitLevelSet ); + resultSet.addAll( getDependencySet( organisationUnitLevelSet ) ); + + return resultSet; + } + else + { + return resultSet; + } + } + + //-------------------------------------------------------------------------- + // Utils + //-------------------------------------------------------------------------- + + public boolean isExportView( Method method ) + { + if ( method.isAnnotationPresent( JsonView.class ) ) + { + Class[] viewClasses = method.getAnnotation( JsonView.class ).value(); + + for ( Class viewClass : viewClasses ) + { + if ( viewClass.equals( ExportView.class ) ) + { + return true; + } + } + } + + return false; + } +} === modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExchangeClasses.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExchangeClasses.java 2013-10-15 07:40:07 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExchangeClasses.java 2013-10-25 19:53:21 +0000 @@ -47,6 +47,7 @@ import org.hisp.dhis.dataset.DataSet; import org.hisp.dhis.dataset.Section; import org.hisp.dhis.document.Document; +import org.hisp.dhis.filter.Filter; import org.hisp.dhis.indicator.Indicator; import org.hisp.dhis.indicator.IndicatorGroup; import org.hisp.dhis.indicator.IndicatorGroupSet; @@ -197,6 +198,12 @@ // special class which is created on demand in association with other objects exportClasses.remove( DataElementOperand.class ); importClasses.remove( DataElementOperand.class ); + + //@author Ovidiu Rosu + allExportClasses.put( Filter.class, "filters" ); + // Filters are not available for export/import for now + exportClasses.remove( Filter.class ); + importClasses.remove( Filter.class ); } public static Map, String> getAllExportMap() === modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExportService.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExportService.java 2013-08-23 16:05:01 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExportService.java 2013-09-15 17:29:23 +0000 @@ -28,8 +28,13 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import net.sf.json.JSONObject; +import org.hisp.dhis.filter.Filter; import org.hisp.dhis.scheduling.TaskId; +import java.io.IOException; +import java.util.List; + /** * @author Morten Olav Hansen */ @@ -38,4 +43,17 @@ MetaData getMetaData( Options options ); MetaData getMetaData( Options options, TaskId taskId ); + +// @author Ovidiu Rosu + MetaData getFilteredMetaData( FilterOptions filterOptions ) throws IOException; + + MetaData getFilteredMetaData( FilterOptions filterOptions, TaskId taskId ) throws IOException; + + List getFilters(); + + void saveFilter( JSONObject json ) throws IOException; + + void updateFilter( JSONObject json ) throws IOException; + + void deleteFilter( JSONObject json ) throws IOException; } === added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/FilterOptions.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/FilterOptions.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/FilterOptions.java 2013-10-30 12:51:03 +0000 @@ -0,0 +1,62 @@ +package org.hisp.dhis.dxf2.metadata; + +/* + * Copyright (c) 2004-2013, 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 net.sf.json.JSONObject; + +/** + * @author Ovidiu Rosu + */ +public class FilterOptions + extends Options +{ + private JSONObject restrictionsJson; + + //-------------------------------------------------------------------------- + // Constructors + //-------------------------------------------------------------------------- + + public FilterOptions( JSONObject restrictionsJson ) + { + this.restrictionsJson = restrictionsJson; + } + + //-------------------------------------------------------------------------- + // Getters & Setters + //-------------------------------------------------------------------------- + + public JSONObject getRestrictionsJson() + { + return restrictionsJson; + } + + public void setRestrictionsJson( JSONObject restrictionsJson ) + { + this.restrictionsJson = restrictionsJson; + } +} === modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/MetaData.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/MetaData.java 2013-09-27 10:43:38 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/MetaData.java 2013-10-25 18:39:01 +0000 @@ -50,6 +50,7 @@ import org.hisp.dhis.dataset.DataSet; import org.hisp.dhis.dataset.Section; import org.hisp.dhis.document.Document; +import org.hisp.dhis.filter.Filter; import org.hisp.dhis.indicator.Indicator; import org.hisp.dhis.indicator.IndicatorGroup; import org.hisp.dhis.indicator.IndicatorGroupSet; @@ -181,6 +182,9 @@ private List relationshipTypes = new ArrayList(); + //@author Ovidiu Rosu + private List filters = new ArrayList(); + private List personIdentifierTypes = new ArrayList(); private List personAttributeTypes = new ArrayList(); @@ -814,6 +818,20 @@ this.dimensions = dimensions; } + //@author Ovidiu Rosu + @JsonProperty + @JacksonXmlElementWrapper(localName = "filters", namespace = DxfNamespaces.DXF_2_0) + @JacksonXmlProperty(localName = "filter", namespace = DxfNamespaces.DXF_2_0) + public List getFilters() + { + return filters; + } + + public void setFilters( List filters ) + { + this.filters = filters; + } + @Override public String toString() { === added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/MetaDataDependencyService.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/MetaDataDependencyService.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/MetaDataDependencyService.java 2013-08-27 06:44:31 +0000 @@ -0,0 +1,49 @@ +package org.hisp.dhis.dxf2.metadata; + +/* + * Copyright (c) 2004-2013, 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 org.hisp.dhis.common.IdentifiableObject; + +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * @author Ovidiu Rosu + */ +public interface MetaDataDependencyService +{ + Map> getIdentifiableObjectMap( Map> identifiableObjectUidMap ); + + Map> getIdentifiableObjectWithDependencyMap( Map> identifiableObjectUidMap ); + + Set getDependencySet( IdentifiableObject identifiableObject ); + + Set getDependencySet( Collection identifiableObjects ); +} === modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Options.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Options.java 2013-09-02 10:37:36 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Options.java 2013-09-08 17:26:58 +0000 @@ -163,6 +163,10 @@ this.assumeTrue = options.get( "assumeTrue" ) == null || options.get( "assumeTrue" ).equalsIgnoreCase( "true" ); } + public Options() + { + } + //-------------------------------------------------------------------------- // Get options for classes/strings etc //-------------------------------------------------------------------------- === modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/resources/META-INF/dhis/beans.xml 2013-10-08 17:16:47 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/resources/META-INF/dhis/beans.xml 2013-10-25 18:39:01 +0000 @@ -203,4 +203,7 @@ + + + === modified file 'dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/ehcache.xml' --- dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/ehcache.xml 2013-10-16 07:16:05 +0000 +++ dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/ehcache.xml 2013-10-25 19:53:21 +0000 @@ -116,6 +116,9 @@ + + + === modified file 'dhis-2/dhis-support/dhis-support-test/src/main/resources/log4j.properties' --- dhis-2/dhis-support/dhis-support-test/src/main/resources/log4j.properties 2009-10-31 01:31:57 +0000 +++ dhis-2/dhis-support/dhis-support-test/src/main/resources/log4j.properties 2013-08-11 09:19:11 +0000 @@ -7,5 +7,5 @@ log4j.appender.console.layout.ConversionPattern = * %-5p %d{ABSOLUTE} %m (%F [%t])%n # Categories (order: DEBUG, INFO, WARN, ERROR, FATAL) -log4j.rootCategory = FATAL, console +log4j.rootCategory = ERROR, console log4j.category.org.hisp.dhis = WARN === added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/FilterController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/FilterController.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/FilterController.java 2013-09-08 14:37:41 +0000 @@ -0,0 +1,43 @@ +package org.hisp.dhis.api.controller; + +/* + * Copyright (c) 2004-2013, 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 org.hisp.dhis.filter.Filter; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * @author Ovidiu Rosu + */ +@Controller +@RequestMapping( value = FilterController.RESOURCE_PATH ) +public class FilterController + extends AbstractCrudController +{ + public static final String RESOURCE_PATH = "/filters"; +} === added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/FilteredMetaDataController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/FilteredMetaDataController.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/FilteredMetaDataController.java 2013-09-16 13:33:28 +0000 @@ -0,0 +1,261 @@ +package org.hisp.dhis.api.controller; + +/* + * Copyright (c) 2004-2013, 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 com.fasterxml.jackson.databind.ObjectMapper; +import net.sf.json.JSONObject; +import org.hisp.dhis.api.utils.ContextUtils; +import org.hisp.dhis.common.view.ExportView; +import org.hisp.dhis.dxf2.metadata.*; +import org.hisp.dhis.dxf2.metadata.tasks.ImportMetaDataTask; +import org.hisp.dhis.dxf2.utils.JacksonUtils; +import org.hisp.dhis.filter.Filter; +import org.hisp.dhis.importexport.ImportStrategy; +import org.hisp.dhis.scheduling.TaskCategory; +import org.hisp.dhis.scheduling.TaskId; +import org.hisp.dhis.system.notification.Notifier; +import org.hisp.dhis.system.scheduling.Scheduler; +import org.hisp.dhis.user.CurrentUserService; +import org.hisp.dhis.user.User; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.*; +import java.util.List; +import java.util.Map; +import java.util.zip.GZIPOutputStream; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + +/** + * @author Ovidiu Rosu + */ +@Controller +public class FilteredMetaDataController +{ + public static final String RESOURCE_PATH = "/filteredMetaData"; + + @Autowired + private ExportService exportService; + + @Qualifier( "contextUtils" ) + @Autowired + private ContextUtils contextUtils; + + @Autowired + private Scheduler scheduler; + + @Autowired + private ImportService importService; + + @Autowired + private CurrentUserService currentUserService; + + @Autowired + private Notifier notifier; + + private boolean dryRun; + + private ImportStrategy strategy; + + //-------------------------------------------------------------------------- + // Getters & Setters + //-------------------------------------------------------------------------- + + public void setDryRun( boolean dryRun ) + { + this.dryRun = dryRun; + } + + public void setStrategy( String strategy ) + { + this.strategy = ImportStrategy.valueOf( strategy ); + } + + //-------------------------------------------------------------------------- + // Detailed MetaData Export - POST Requests + //-------------------------------------------------------------------------- + + @RequestMapping( value = FilteredMetaDataController.RESOURCE_PATH, headers = "Accept=application/json" ) + @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" ) + public String detailedExport( @RequestParam Map parameters, Model model ) throws IOException + { + WebOptions options = new WebOptions( parameters ); + MetaData metaData = exportService.getMetaData( options ); + + model.addAttribute( "model", metaData ); + model.addAttribute( "viewClass", "export" ); + + return "export"; + } + + @RequestMapping( method = RequestMethod.POST, value = FilteredMetaDataController.RESOURCE_PATH + ".xml", produces = "*/*" ) + @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" ) + public void exportXml( @RequestParam String exportJsonValue, HttpServletResponse response ) throws IOException + { + FilterOptions filterOptions = new FilterOptions( JSONObject.fromObject( exportJsonValue ) ); + MetaData metaData = exportService.getFilteredMetaData( filterOptions ); + + contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_XML, ContextUtils.CacheStrategy.NO_CACHE, "metaData.xml", true ); + JacksonUtils.toXmlWithView( response.getOutputStream(), metaData, ExportView.class ); + } + + @RequestMapping( method = RequestMethod.POST, value = FilteredMetaDataController.RESOURCE_PATH + ".json", produces = "*/*" ) + @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" ) + public void exportJson( @RequestParam String exportJsonValue, HttpServletResponse response ) throws IOException + { + FilterOptions filterOptions = new FilterOptions( JSONObject.fromObject( exportJsonValue ) ); + MetaData metaData = exportService.getFilteredMetaData( filterOptions ); + + contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_JSON, ContextUtils.CacheStrategy.NO_CACHE, "metaData.json", true ); + JacksonUtils.toJsonWithView( response.getOutputStream(), metaData, ExportView.class ); + } + + @RequestMapping( method = RequestMethod.POST, value = { FilteredMetaDataController.RESOURCE_PATH + ".xml.zip" }, produces = "*/*" ) + @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" ) + public void exportZippedXML( @RequestParam String exportJsonValue, HttpServletResponse response ) throws IOException + { + FilterOptions filterOptions = new FilterOptions( JSONObject.fromObject( exportJsonValue ) ); + MetaData metaData = exportService.getFilteredMetaData( filterOptions ); + + contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_ZIP, ContextUtils.CacheStrategy.NO_CACHE, "metaData.xml.zip", true ); + response.addHeader( ContextUtils.HEADER_CONTENT_TRANSFER_ENCODING, "binary" ); + + ZipOutputStream zip = new ZipOutputStream( response.getOutputStream() ); + zip.putNextEntry( new ZipEntry( "metaData.xml" ) ); + + JacksonUtils.toXmlWithView( zip, metaData, ExportView.class ); + } + + @RequestMapping( method = RequestMethod.POST, value = { FilteredMetaDataController.RESOURCE_PATH + ".json.zip" }, produces = "*/*" ) + @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" ) + public void exportZippedJSON( @RequestParam String exportJsonValue, HttpServletResponse response ) throws IOException + { + FilterOptions filterOptions = new FilterOptions( JSONObject.fromObject( exportJsonValue ) ); + MetaData metaData = exportService.getFilteredMetaData( filterOptions ); + + contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_ZIP, ContextUtils.CacheStrategy.NO_CACHE, "metaData.json.zip", true ); + response.addHeader( ContextUtils.HEADER_CONTENT_TRANSFER_ENCODING, "binary" ); + + ZipOutputStream zip = new ZipOutputStream( response.getOutputStream() ); + zip.putNextEntry( new ZipEntry( "metaData.json" ) ); + + JacksonUtils.toJsonWithView( zip, metaData, ExportView.class ); + } + + @RequestMapping( method = RequestMethod.POST, value = { FilteredMetaDataController.RESOURCE_PATH + ".xml.gz" }, produces = "*/*" ) + @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" ) + public void exportGZippedXML( @RequestParam String exportJsonValue, HttpServletResponse response ) throws IOException + { + FilterOptions filterOptions = new FilterOptions( JSONObject.fromObject( exportJsonValue ) ); + MetaData metaData = exportService.getFilteredMetaData( filterOptions ); + + contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_GZIP, ContextUtils.CacheStrategy.NO_CACHE, "metaData.xml.gz", true ); + response.addHeader( ContextUtils.HEADER_CONTENT_TRANSFER_ENCODING, "binary" ); + + GZIPOutputStream gzip = new GZIPOutputStream( response.getOutputStream() ); + JacksonUtils.toXmlWithView( gzip, metaData, ExportView.class ); + } + + @RequestMapping( method = RequestMethod.POST, value = { FilteredMetaDataController.RESOURCE_PATH + ".json.gz" }, produces = "*/*" ) + @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" ) + public void exportGZippedJSON( @RequestParam String exportJsonValue, HttpServletResponse response ) throws IOException + { + FilterOptions filterOptions = new FilterOptions( JSONObject.fromObject( exportJsonValue ) ); + MetaData metaData = exportService.getFilteredMetaData( filterOptions ); + + contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_GZIP, ContextUtils.CacheStrategy.NO_CACHE, "metaData.json.gz", true ); + response.addHeader( ContextUtils.HEADER_CONTENT_TRANSFER_ENCODING, "binary" ); + + GZIPOutputStream gzip = new GZIPOutputStream( response.getOutputStream() ); + JacksonUtils.toJsonWithView( gzip, metaData, ExportView.class ); + } + + //-------------------------------------------------------------------------- + // Detailed MetaData Export - Filter functionality + //-------------------------------------------------------------------------- + + @RequestMapping( method = RequestMethod.GET, value = FilteredMetaDataController.RESOURCE_PATH + "/getFilters" ) + @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" ) + public @ResponseBody String getFilters( HttpServletRequest request, HttpServletResponse response ) throws IOException + { + List filters = exportService.getFilters(); + contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_JSON, ContextUtils.CacheStrategy.NO_CACHE ); + return JacksonUtils.toJsonAsString( filters ); + } + + @RequestMapping( method = RequestMethod.POST, value = FilteredMetaDataController.RESOURCE_PATH + "/saveFilter" ) + @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" ) + public void saveFilter( @RequestBody JSONObject json, HttpServletResponse response ) throws IOException + { + exportService.saveFilter( json ); + } + + @RequestMapping( method = RequestMethod.POST, value = FilteredMetaDataController.RESOURCE_PATH + "/updateFilter" ) + @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" ) + public void updateFilter( @RequestBody JSONObject json, HttpServletResponse response ) throws IOException + { + exportService.updateFilter( json ); + } + + @RequestMapping( method = RequestMethod.POST, value = FilteredMetaDataController.RESOURCE_PATH + "/deleteFilter" ) + @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" ) + public void deleteFilter( @RequestBody JSONObject json, HttpServletResponse response ) throws IOException + { + exportService.deleteFilter( json ); + } + + //-------------------------------------------------------------------------- + // Detailed MetaData Import - POST Requests + //-------------------------------------------------------------------------- + + @RequestMapping( method = RequestMethod.POST, value = FilteredMetaDataController.RESOURCE_PATH + "/importDetailedMetaData" ) + @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_IMPORT')" ) + public void importDetailedMetaData( @RequestBody JSONObject json, HttpServletResponse response ) throws IOException + { + strategy = ImportStrategy.valueOf( json.getString( "strategy" ) ); + dryRun = json.getBoolean( "dryRun" ); + + TaskId taskId = new TaskId( TaskCategory.METADATA_IMPORT, currentUserService.getCurrentUser() ); + User user = currentUserService.getCurrentUser(); + + MetaData metaData = new ObjectMapper().readValue( json.getString( "metaData" ), MetaData.class ); + + ImportOptions importOptions = new ImportOptions(); + importOptions.setStrategy( strategy.toString() ); + importOptions.setDryRun( dryRun ); + + scheduler.executeTask( new ImportMetaDataTask( user.getUid(), importService, importOptions, taskId, metaData ) ); + } +} === 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-09-18 12:45:52 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ContextUtils.java 2013-10-25 20:37:23 +0000 @@ -97,7 +97,7 @@ } public void configureResponse( HttpServletResponse response, String contentType, CacheStrategy cacheStrategy, - String filename, boolean attachment ) + String filename, boolean attachment ) { if ( contentType != null ) { @@ -296,4 +296,4 @@ byte[] encodedAuthorisation = Base64.encode( authorisation.getBytes() ); headers.add( "Authorization", "Basic " + new String( encodedAuthorisation ) ); } -} +} \ No newline at end of file === added file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/filter.xsl' --- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/filter.xsl 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/filter.xsl 2013-09-14 14:03:39 +0000 @@ -0,0 +1,33 @@ + + + + +
+

+ + + + + + + + + + + + + + + + + + +
ID
Created
Last Updated
MetaData UIDs
+ +
+
+ +
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/model2html.xsl' --- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/model2html.xsl 2013-09-09 12:45:37 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/model2html.xsl 2013-09-14 11:26:52 +0000 @@ -46,6 +46,7 @@ + @@ -60,6 +61,9 @@ + + + === removed file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonConcept.vm' --- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonConcept.vm 2011-09-27 07:36:07 +0000 +++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonConcept.vm 1970-01-01 00:00:00 +0000 @@ -1,6 +0,0 @@ -{ "concept": - { - "id": "$!{concept.id}", - "name": "$encoder.jsonEncode( $!{concept.name} )" - } -} === added file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonConcept.vm' --- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonConcept.vm 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonConcept.vm 2013-10-25 20:37:23 +0000 @@ -0,0 +1,6 @@ +{ "concept": + { + "id": "$!{concept.id}", + "name": "$encoder.jsonEncode( $!{concept.name} )" + } +} === modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/security.xml' --- dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/security.xml 2013-08-22 17:09:11 +0000 +++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/security.xml 2013-09-01 20:44:11 +0000 @@ -269,6 +269,8 @@ F_REPORTTABLE_EXTERNAL F_METADATA_EXPORT F_METADATA_IMPORT + F_METADATA_SUBSET_IMPORT + F_METADATA_SUBSET_EXPORT
=== added file 'dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/dxf2/FilterExportFormAction.java' --- dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/dxf2/FilterExportFormAction.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/dxf2/FilterExportFormAction.java 2013-10-30 12:51:03 +0000 @@ -0,0 +1,133 @@ +package org.hisp.dhis.importexport.action.dxf2; + +/* + * Copyright (c) 2004-2013, 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 com.opensymphony.xwork2.Action; +import org.hisp.dhis.filter.Filter; + +/** + * @author Ovidiu Rosu + */ +public class FilterExportFormAction + implements Action +{ + // ------------------------------------------------------------------------- + // Input + // ------------------------------------------------------------------------- + + private String name; + + public String getName() + { + return name; + } + + public void setName( String name ) + { + this.name = name; + } + + private String uid; + + public String getUid() + { + return uid; + } + + public void setUid( String uid ) + { + this.uid = uid; + } + + private String description; + + public String getDescription() + { + return description; + } + + public void setDescription( String description ) + { + this.description = description; + } + + private String jsonFilter; + + public String getJsonFilter() + { + return jsonFilter; + } + + public void setJsonFilter( String jsonFilter ) + { + this.jsonFilter = jsonFilter; + } + + public String command; + + public String getCommand() + { + return command; + } + + public void setCommand( String command ) + { + this.command = command; + } + +// ------------------------------------------------------------------------- + // Output + // ------------------------------------------------------------------------- + + private Filter filter = new Filter(); + + public Filter getFilter() + { + return filter; + } + + public void setFilter( Filter filter ) + { + this.filter = filter; + } + + // ------------------------------------------------------------------------- + // Action Implementation + // ------------------------------------------------------------------------- + + @Override + public String execute() throws Exception + { + filter.setName( name ); + filter.setUid( uid ); + filter.setDescription( description ); + filter.setJsonFilter( jsonFilter ); + + return SUCCESS; + } +} === added file 'dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/dxf2/FilterListAction.java' --- dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/dxf2/FilterListAction.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/dxf2/FilterListAction.java 2013-08-19 22:52:16 +0000 @@ -0,0 +1,109 @@ +package org.hisp.dhis.importexport.action.dxf2; + +/* + * Copyright (c) 2004-2013, 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 org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator; +import org.hisp.dhis.filter.Filter; +import org.hisp.dhis.filter.FilterService; +import org.hisp.dhis.paging.ActionPagingSupport; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import static org.apache.commons.lang.StringUtils.isNotBlank; + +/** + * @author Ovidiu Rosu + */ +public class FilterListAction + extends ActionPagingSupport +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private FilterService filterService; + + public void setFilterService( FilterService filterService ) + { + this.filterService = filterService; + } + + // ------------------------------------------------------------------------- + // Input & Output + // ------------------------------------------------------------------------- + + private List filters; + + public List getFilters() + { + return filters; + } + + public void setFilters( List filters ) + { + this.filters = filters; + } + + private String key; + + public String getKey() + { + return key; + } + + public void setKey( String key ) + { + this.key = key; + } + + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + + @Override + public String execute() throws Exception + { + if ( isNotBlank( key ) ) // Filter on key only if set + { + this.paging = createPaging( filterService.getFilterCountByName( key ) ); + + filters = new ArrayList( filterService.getFiltersBetweenByName( key, paging.getStartPos(), paging.getPageSize() ) ); + } else + { + this.paging = createPaging( filterService.getFilterCount() ); + + filters = new ArrayList( filterService.getFiltersBetween( paging.getStartPos(), paging.getPageSize() ) ); + } + + Collections.sort( filters, IdentifiableObjectNameComparator.INSTANCE ); + + return SUCCESS; + } +} === added file 'dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/dxf2/GetFilterListSortOrderAction.java' --- dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/dxf2/GetFilterListSortOrderAction.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/dxf2/GetFilterListSortOrderAction.java 2013-08-19 22:52:16 +0000 @@ -0,0 +1,81 @@ +package org.hisp.dhis.importexport.action.dxf2; + +/* + * Copyright (c) 2004-2013, 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 com.opensymphony.xwork2.Action; +import org.hisp.dhis.filter.Filter; +import org.hisp.dhis.filter.FilterService; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Ovidiu Rosu + */ +public class GetFilterListSortOrderAction + implements Action +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private FilterService filterService; + + public void setFilterService( FilterService filterService ) + { + this.filterService = filterService; + } + + // ------------------------------------------------------------------------- + // Output + // ------------------------------------------------------------------------- + + private List filters; + + public List getFilters() + { + return filters; + } + + public void setFilters( List filters ) + { + this.filters = filters; + } + + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + + @Override + public String execute() throws Exception + { + filters = new ArrayList( filterService.getAllFilters() ); + + return SUCCESS; + } +} === added file 'dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/dxf2/SaveFilterListSortOrderAction.java' --- dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/dxf2/SaveFilterListSortOrderAction.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/dxf2/SaveFilterListSortOrderAction.java 2013-08-19 22:52:16 +0000 @@ -0,0 +1,83 @@ +package org.hisp.dhis.importexport.action.dxf2; + +/* + * Copyright (c) 2004-2013, 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 com.opensymphony.xwork2.Action; +import org.hisp.dhis.filter.Filter; +import org.hisp.dhis.filter.FilterService; + +import java.util.List; + +/** + * @author Ovidiu Rosu + */ +public class SaveFilterListSortOrderAction + implements Action +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private FilterService filterService; + + public void setFilterService( FilterService filterService ) + { + this.filterService = filterService; + } + + // ------------------------------------------------------------------------- + // Input + // ------------------------------------------------------------------------- + + private List filters; + + public void setFilters( List filters ) + { + this.filters = filters; + } + + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + + public String execute() + { + int sortOrder = 1; + + for ( String id : filters ) + { + Filter filter = filterService.getFilter( Integer.parseInt( id ) ); + + filter.setSortOrder( sortOrder++ ); + + filterService.updateFilter( filter ); + } + + return SUCCESS; + } +} === modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-web/dhis-web-importexport/src/main/resources/META-INF/dhis/beans.xml 2013-10-01 13:16:44 +0000 +++ dhis-2/dhis-web/dhis-web-importexport/src/main/resources/META-INF/dhis/beans.xml 2013-10-30 12:51:03 +0000 @@ -208,4 +208,24 @@ class="org.hisp.dhis.importexport.action.event.GetImportEventSummariesAction" scope="prototype"> + + + + + + + + + + + + + + + + === modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/resources/org/hisp/dhis/importexport/i18n_module.properties' --- dhis-2/dhis-web/dhis-web-importexport/src/main/resources/org/hisp/dhis/importexport/i18n_module.properties 2013-10-07 17:58:57 +0000 +++ dhis-2/dhis-web/dhis-web-importexport/src/main/resources/org/hisp/dhis/importexport/i18n_module.properties 2013-10-30 12:51:03 +0000 @@ -333,4 +333,114 @@ value_not_negative_integer=Value is not a valid negative integer value_is_zero_and_not_zero_significant=Value is zero and not zero-significant value_not_zero_or_positive_integer=Value is not a valid zero or positive integer -comment_too_long=Comment is too long \ No newline at end of file +comment_too_long=Comment is too long + +intro_filtered_metadata_export=Export filtered meta-data like data elements and organisation units to the standard DHIS 2 exchange format. +filtered_metadata_export=Meta-Data Detailed Export + +apply=Apply +sort=Sort + +add_new_filter=Add new Filter +ad_hoc_export=Ad hoc export +create_new_filter=Create new Filter +filter_sort_order=Filter sort order +edit_filter=Edit Filter +filter_details=Filter Details +validate_filter=Filter name cannot be empty. + +export_with_dependencies=Export with dependencies + +attribute_types=Attribute Types +available_attribute_types=Available Attribute Types +selected_attribute_types=Selected Attribute Types + +categories=Categories +available_categories=Available Categories +selected_categories=Selected Categories + +available_charts=Available Charts +selected_charts=Selected Charts + +concepts=Concepts +available_concepts=Available Concepts +selected_concepts=Selected Concepts + +available_constants=Available Constants +selected_constants=Selected Constants + +available_dataDictionaries=Available Data Dictionaries +selected_dataDictionaries=Selected Data Dictionaries + +available_dataElementGroupSets=Available Data Element Group Sets +selected_dataElementGroupSets=Selected Data Element Group Sets + +available_dataElementGroups=Available Data Element Groups +selected_dataElementGroups=Selected Data Element Groups + +documents=Documents +available_documents=Available Documents +selected_documents=Selected Documents + +available_indicatorGroupSets=Available Indicator Group Sets +selected_indicatorGroupSets=Selected Indicator Group Sets + +available_indicatorGroups=Available Indicator Groups +selected_indicatorGroups=Selected Indicator Groups + +indicator_types=Indicator types +available_indicatorTypes=Available Indicator Types +selected_indicatorTypes=Selected Indicator Types + +map_legend_sets=Map legend sets +available_mapLegendSets=Available Map Legend Sets +selected_mapLegendSets=Selected Map Legend Sets + +maps=Maps +available_maps=Available Maps +selected_maps=Selected Maps + +option_sets=Option sets +available_optionSets=Available Option Sets +selected_optionSets=Selected Option Sets + +available_organisationUnitGroupSets=Available Organisation Unit Group Sets +selected_organisationUnitGroupSets=Selected Organisation Unit Group Sets + +available_organisationUnitGroups=Available Organisation Unit Groups +selected_organisationUnitGroups=Selected Organisation Unit Groups + +available_organisationUnitLevels=Available Organisation Unit Levels +selected_organisationUnitLevels=Selected Organisation Unit Levels + +available_organisationUnits=Available Organisation Units +selected_organisationUnits=Selected Organisation Units + +available_reportTables=Available Report Tables +selected_reportTables=Selected Report Tables + +available_reports=Available Reports +selected_reports=Selected Reports + +sql_views=Sql views +available_sqlViews=Available Sql Views +selected_sqlViews=Selected Sql Views + +available_userGroups=Available User Groups +selected_userGroups=Selected User Groups + +available_userRoles=Available User Roles +selected_userRoles=Selected User Roles + +available_users=Available Users +selected_users=Selected Users + +validation_rule_groups=Validation rule groups +available_validationRuleGroups=Available Validation Rule Groups +selected_validationRuleGroups=Selected Validation Rule Groups + +available_validationRules=Available Validation Rules +selected_validationRules=Selected Validation Rules + +select_all_values=Select All Values +deselect_all_values=Deselect All Values === modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/resources/struts.xml' --- dhis-2/dhis-web/dhis-web-importexport/src/main/resources/struts.xml 2013-10-03 07:24:47 +0000 +++ dhis-2/dhis-web/dhis-web-importexport/src/main/resources/struts.xml 2013-10-30 12:51:03 +0000 @@ -310,6 +310,35 @@ plainTextError + + + /main.vm + /dhis-web-importexport/mainMenu.vm + /dhis-web-importexport/dxf2FilteredMetaDataExport.vm + javascript/filter.js + F_METADATA_EXPORT + + + + /main.vm + /dhis-web-importexport/mainMenu.vm + /dhis-web-importexport/sortFilterForm.vm + F_METADATA_EXPORT + + + + /main.vm + /dhis-web-importexport/mainMenu.vm + /dhis-web-importexport/filterExportForm.vm + javascript/filteredMetaDataExport.js,javascript/utils.js + F_METADATA_EXPORT + + + + dxf2FilteredMetaDataExport.action + F_METADATA_EXPORT + + === added file 'dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/dxf2FilteredMetaDataExport.vm' --- dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/dxf2FilteredMetaDataExport.vm 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/dxf2FilteredMetaDataExport.vm 2013-10-30 12:51:03 +0000 @@ -0,0 +1,108 @@ + + +##@author Ovidiu Rosu + +

$i18n.getString( "filtered_metadata_export" ) #openHelp( "filtered_metadata_export" )

+ + +
+ + + + + +
+ + + + + +
#filterDiv( "dxf2FilteredMetaDataExport" ) +
+ + + + + + + + +
+
+ + + + + + + + + + + + + #foreach( $filter in $filters ) + + + + + #end + +
$i18n.getString( "name" )$i18n.getString( "operations" )
$filter.name + $i18n.getString( 'export' ) + $i18n.getString( 'edit' ) + $i18n.getString( 'remove' ) + $i18n.getString( 'show_details' ) +
+

+ #parse( "/dhis-web-commons/paging/paging.vm" ) +
+ +
+
+ + + === modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/dxf2MetaDataExport.vm' --- dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/dxf2MetaDataExport.vm 2013-07-19 12:50:17 +0000 +++ dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/dxf2MetaDataExport.vm 2013-09-01 20:44:11 +0000 @@ -73,7 +73,6 @@ url += "?assumeTrue=false&" + $("#exportForm").serialize(); log("url" + url); - window.location=url; } === modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/exportDataValueForm.vm' --- dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/exportDataValueForm.vm 2013-09-02 10:37:36 +0000 +++ dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/exportDataValueForm.vm 2013-09-08 17:26:58 +0000 @@ -103,4 +103,4 @@ - + \ No newline at end of file === added file 'dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/filterExportForm.vm' --- dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/filterExportForm.vm 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/filterExportForm.vm 2013-10-30 12:51:03 +0000 @@ -0,0 +1,367 @@ + + +##@author Ovidiu Rosu + +#if ($command == "addNew") +

$i18n.getString( "create_new_filter" )

+#elseif($command == "update") +

$i18n.getString( "edit_filter" )

+#elseif($command == "addAdHoc") +

$i18n.getString( "ad_hoc_export" )

+#end + + +
+ + #if ($command == "addNew" || $command == "addAdHoc") + + #elseif ($command == "update") + + #end + + #if ($command == "addNew" || $command == "update") +
+ + + + + + + + + + + + +
$i18n.getString( "filter_details" )
+ +
+ +
+
+ #end +
+ + +
+ +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+
+ + +
+ + + + + + #if($command == "addNew") + + #elseif ($command == "update") + + #elseif($command == "addAdHoc") + + #end + +
+ + +
+ + + + + + + + +
+
+ + +#if($command == "addAdHoc") + +#end === modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/index.vm' --- dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/index.vm 2013-10-01 13:16:44 +0000 +++ dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/index.vm 2013-10-30 12:51:03 +0000 @@ -9,6 +9,8 @@ #introListImgItem( "displayExternalImportMenu.action" "dhis14_import" "import" ) #introListImgItem( "dxf2MetaDataExport.action" "metadata_export" "export" ) +## @author Ovidiu Rosu + #introListImgItem( "dxf2FilteredMetaDataExport.action" "filtered_metadata_export" "export") #introListImgItem( "displayDataValueExportForm.action" "data_export" "export" ) #introListImgItem( "displayEventExportForm.action" "event_data_export" "export" ) #introListImgItem( "displayExternalExportMenu.action" "export_to_other_systems" "export" ) === added file 'dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/javascript/detailedMetaDataImport.js' --- dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/javascript/detailedMetaDataImport.js 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/javascript/detailedMetaDataImport.js 2013-09-16 13:33:28 +0000 @@ -0,0 +1,434 @@ +//@author Ovidiu Rosu + +// Global Variables +var metaDataArray = [ "AttributeTypes", "Dimensions", "Charts", "Concepts", "Constants", "DataDictionaries", "DataElementGroupSets", + "DataElementGroups", "DataElements", "DataSets", "Documents", "IndicatorGroupSets", "IndicatorGroups", "Indicators", + "IndicatorTypes", "MapLegendSets", "Maps", "OptionSets", "OrganisationUnitGroupSets", "OrganisationUnitGroups", + "OrganisationUnitLevels", "OrganisationUnits", "ReportTables", "Reports", "SqlViews", "UserGroups", "UserRoles", + "Users", "ValidationRuleGroups", "ValidationRules" ]; + +// ----------------------------------------------------------------------------- +// MetaData Category Accordion +// ----------------------------------------------------------------------------- +jQuery( function () +{ + if ( !jQuery.isEmptyObject( metaDataJson ) ) + { + loadMetaDataCategories( metaDataJson ); + $( "#mainDivAccordion" ).accordion( + { + active: false, + collapsible: true, + clearStyle: true, + autoHeight: false + } ); + + selectAllMetaDataCategories(); + selectAllValues(); + loadMetaDataAccordionEvents( metaDataJson ); + } + + loadFile(); +} ); + +// Collapsed MetaData Category information +function loadMetaDataCategories( metaData ) +{ + for ( var i = 0; i < metaDataArray.length; i++ ) + { + if ( metaData.hasOwnProperty( lowercaseFirstLetter( metaDataArray[i] ) ) ) + { + $( "#heading" + metaDataArray[i] ).show(); + $( "#div" + metaDataArray[i] ).show(); + $( "#metaDataCommands" ).show(); + + insertMetaDataCategoryHeadingDesign( metaDataArray[i] ); + preventAccordionCollapse( metaDataArray[i] ); + + $( "#checkboxSelectAll" + metaDataArray[i] ).change( function () + { + var metaDataCategoryName = $( this ).attr( "name" ); + + if ( $( this ).is( ":checked" ) ) + { + selectAllValuesByCategory( metaDataCategoryName ); + } else + { + deselectValuesByCategory( metaDataCategoryName ); + } + } ); + } else + { + metaDataArray.splice( i, 1 ); + i--; + } + } +} + +// Insert MetaData HTML & CSS heading design +function insertMetaDataCategoryHeadingDesign( metaDataCategoryName ) +{ + var design = generateMetaDataHeadingDesign( metaDataCategoryName ); + $( "#heading" + metaDataCategoryName ).append( design ); +} + +// Insert MetaData HTML & CSS for a Category +function insertMetaDataCategoryDesign( metaDataCategoryName ) +{ + if ( $( "#mainDiv" + metaDataCategoryName ).is( ":empty" ) ) + { + var design = generateMetaDataCategoryDesign( metaDataCategoryName ); + $( "#mainDiv" + metaDataCategoryName ).append( design ); + loadMetaData( metaDataCategoryName ); + } else + { + $( "#mainDiv" + metaDataCategoryName ).show(); + deselectAllValues(); + } +} + +// Generate MetaData Heading design +function generateMetaDataHeadingDesign( metaDataCategoryName ) +{ + var design = + '
' + + '' + + '' + + '
' + ; + + return design; +} + +// Generate MetaData HTML & CSS for a Category +function generateMetaDataCategoryDesign( metaDataCategoryName ) +{ + var i18n_available_metadata = getI18nAvailableMetaData( metaDataCategoryName ); + var i18n_selected_metadata = getI18nSelectedMetaData( metaDataCategoryName ); + var design = + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
' + i18n_available_metadata + '' + i18n_filter + '' + i18n_selected_metadata + '
' + + '' + + '' + + '
' + + '
' + + '
' + + '
' + + '
' + + '' + + '
' + ; + + return design; +} + +// Move all selected items +function moveSelected( metaDataCategoryName ) +{ + $( "#available" + metaDataCategoryName + " option:selected" ).each( function () + { + $( "#checkboxSelectAll" + metaDataCategoryName ).attr( "checked", true ); + + var option = jQuery( "