=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java 2009-10-27 16:24:02 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java 2009-11-01 20:57:16 +0000 @@ -369,4 +369,6 @@ DataElementGroupSet getDataElementGroupSetByName( String name ); Collection getAllDataElementGroupSets(); + + Collection getDataElementGroupSets( Collection identifiers ); } === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/IndicatorService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/IndicatorService.java 2009-10-27 17:41:53 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/IndicatorService.java 2009-11-01 20:57:16 +0000 @@ -118,4 +118,6 @@ IndicatorGroupSet getIndicatorGroupSetByName( String name ); Collection getAllIndicatorGroupSets(); + + Collection getIndicatorGroupSets( Collection identifiers ); } === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java 2009-10-27 16:24:02 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java 2009-11-01 20:57:16 +0000 @@ -480,4 +480,21 @@ { return dataElementGroupSetStore.getAll(); } + + public Collection getDataElementGroupSets( Collection identifiers ) + { + if ( identifiers == null ) + { + return getAllDataElementGroupSets(); + } + + Collection groupSets = new ArrayList(); + + for ( Integer id : identifiers ) + { + groupSets.add( getDataElementGroupSet( id ) ); + } + + return groupSets; + } } === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/indicator/DefaultIndicatorService.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/indicator/DefaultIndicatorService.java 2009-10-27 17:41:53 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/indicator/DefaultIndicatorService.java 2009-11-01 20:57:16 +0000 @@ -347,4 +347,21 @@ { return indicatorGroupSetStore.getAll(); } + + public Collection getIndicatorGroupSets( Collection identifiers ) + { + if ( identifiers == null ) + { + return getAllIndicatorGroupSets(); + } + + Collection groupSets = new ArrayList(); + + for ( Integer id : identifiers ) + { + groupSets.add( getIndicatorGroupSet( id ) ); + } + + return groupSets; + } } === modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ExportParams.java' --- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ExportParams.java 2009-03-11 15:16:35 +0000 +++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ExportParams.java 2009-11-01 20:57:16 +0000 @@ -67,10 +67,14 @@ private Collection dataElementGroups = new ArrayList(); + private Collection dataElementGroupSets = new ArrayList(); + private Collection indicators = new ArrayList(); private Collection indicatorGroups = new ArrayList(); + private Collection indicatorGroupSets = new ArrayList(); + private Collection indicatorTypes = new ArrayList(); private Collection dataDictionaries = new ArrayList(); @@ -288,6 +292,16 @@ this.dataElementGroups = dataElementGroups; } + public Collection getDataElementGroupSets() + { + return dataElementGroupSets; + } + + public void setDataElementGroupSets( Collection dataElementGroupSets ) + { + this.dataElementGroupSets = dataElementGroupSets; + } + public Collection getIndicators() { return indicators; @@ -308,6 +322,16 @@ this.indicatorGroups = indicatorGroups; } + public Collection getIndicatorGroupSets() + { + return indicatorGroupSets; + } + + public void setIndicatorGroupSets( Collection indicatorGroupSets ) + { + this.indicatorGroupSets = indicatorGroupSets; + } + public Collection getIndicatorTypes() { return indicatorTypes; === modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/converter/AbstractIndicatorGroupSetConverter.java' --- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/converter/AbstractIndicatorGroupSetConverter.java 2009-10-31 11:36:44 +0000 +++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/converter/AbstractIndicatorGroupSetConverter.java 2009-11-01 20:57:16 +0000 @@ -35,6 +35,7 @@ * @version $Id$ */ public class AbstractIndicatorGroupSetConverter + extends AbstractConverter { protected IndicatorService indicatorService; === added file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/DataElementGroupSetConverter.java' --- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/DataElementGroupSetConverter.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/DataElementGroupSetConverter.java 2009-11-01 20:57:16 +0000 @@ -0,0 +1,121 @@ +package org.hisp.dhis.importexport.dxf.converter; + +/* + * Copyright (c) 2004-2007, 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; +import java.util.Map; + +import org.amplecode.staxwax.reader.XMLReader; +import org.amplecode.staxwax.writer.XMLWriter; +import org.hisp.dhis.dataelement.DataElementGroup; +import org.hisp.dhis.dataelement.DataElementGroupSet; +import org.hisp.dhis.dataelement.DataElementService; +import org.hisp.dhis.importexport.ExportParams; +import org.hisp.dhis.importexport.GroupMemberType; +import org.hisp.dhis.importexport.ImportObjectService; +import org.hisp.dhis.importexport.ImportParams; +import org.hisp.dhis.importexport.XMLConverter; +import org.hisp.dhis.importexport.converter.AbstractDataElementGroupSetConverter; +import org.hisp.dhis.importexport.mapping.NameMappingUtil; + +/** + * @author Lars Helge Overland + * @version $Id$ + */ +public class DataElementGroupSetConverter + extends AbstractDataElementGroupSetConverter implements XMLConverter +{ + public static final String COLLECTION_NAME = "dataElementGroupSets"; + public static final String ELEMENT_NAME = "dataElementGroupSet"; + + private static final String FIELD_ID = "id"; + private static final String FIELD_UUID = "uuid"; + private static final String FIELD_NAME = "name"; + + // ------------------------------------------------------------------------- + // Constructor + // ------------------------------------------------------------------------- + + public DataElementGroupSetConverter( DataElementService dataElementService ) + { + this.dataElementService = dataElementService; + } + + public DataElementGroupSetConverter( DataElementService dataElementService, ImportObjectService importObjectService ) + { + this.dataElementService = dataElementService; + this.importObjectService = importObjectService; + } + + // ------------------------------------------------------------------------- + // XMLConverter implementation + // ------------------------------------------------------------------------- + + @Override + public void write( XMLWriter writer, ExportParams params ) + { + Collection groupSets = dataElementService.getDataElementGroupSets( params.getDataElementGroupSets() ); + + if ( groupSets != null && groupSets.size() > 0 ) + { + writer.openElement( COLLECTION_NAME ); + + for ( DataElementGroupSet groupSet : groupSets ) + { + writer.openElement( ELEMENT_NAME ); + + writer.writeElement( FIELD_ID, String.valueOf( groupSet.getId() ) ); + writer.writeElement( FIELD_UUID, groupSet.getUuid() ); + writer.writeElement( FIELD_NAME, groupSet.getName() ); + + writer.closeElement(); + } + + writer.closeElement(); + } + } + + @Override + public void read( XMLReader reader, ImportParams params ) + { + while ( reader.moveToStartElement( ELEMENT_NAME, COLLECTION_NAME ) ) + { + final Map values = reader.readElements( ELEMENT_NAME ); + + final DataElementGroupSet groupSet = new DataElementGroupSet(); + + groupSet.setId( Integer.parseInt( values.get( FIELD_ID ) ) ); + groupSet.setUuid( values.get( FIELD_UUID ) ); + groupSet.setName( values.get( FIELD_NAME ) ); + + NameMappingUtil.addDataElementGroupSetMapping( groupSet.getId(), groupSet.getName() ); + + read( groupSet, GroupMemberType.NONE, params ); + } + } +} === added file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/DataElementGroupSetMemberConverter.java' --- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/DataElementGroupSetMemberConverter.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/DataElementGroupSetMemberConverter.java 2009-11-01 20:57:16 +0000 @@ -0,0 +1,149 @@ +package org.hisp.dhis.importexport.dxf.converter; + +/* + * Copyright (c) 2004-2007, 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; +import java.util.Map; + +import org.amplecode.quick.BatchHandler; +import org.amplecode.staxwax.reader.XMLReader; +import org.amplecode.staxwax.writer.XMLWriter; +import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.dataelement.DataElementGroup; +import org.hisp.dhis.dataelement.DataElementGroupSet; +import org.hisp.dhis.dataelement.DataElementService; +import org.hisp.dhis.importexport.AssociationType; +import org.hisp.dhis.importexport.ExportParams; +import org.hisp.dhis.importexport.GroupMemberAssociation; +import org.hisp.dhis.importexport.GroupMemberType; +import org.hisp.dhis.importexport.ImportObjectService; +import org.hisp.dhis.importexport.ImportParams; +import org.hisp.dhis.importexport.XMLConverter; +import org.hisp.dhis.importexport.converter.AbstractGroupMemberConverter; + +/** + * @author Lars Helge Overland + * @version $Id$ + */ +public class DataElementGroupSetMemberConverter + extends AbstractGroupMemberConverter implements XMLConverter +{ + public static final String COLLECTION_NAME = "dataElementGroupSetMembers"; + public static final String ELEMENT_NAME = "dataElementGroupSetMember"; + + private static final String FIELD_DATAELEMENT_GROUP = "dataElementGroup"; + private static final String FIELD_DATAELEMENT_GROUP_SET = "dataElementGroupSet"; + + // ------------------------------------------------------------------------- + // Properties + // ------------------------------------------------------------------------- + + private DataElementService dataElementService; + + private Map dataElementGroupMapping; + + private Map dataElementGroupSetMapping; + + // ------------------------------------------------------------------------- + // Constructor + // ------------------------------------------------------------------------- + + /** + * Constructor for write operations. + */ + public DataElementGroupSetMemberConverter( DataElementService dataElementService ) + { + this.dataElementService = dataElementService; + } + + /** + * Constructor for read operations. + */ + public DataElementGroupSetMemberConverter( BatchHandler batchHandler, + ImportObjectService importObjectService, + Map dataElementGroupMapping, + Map dataElementGroupSetMapping ) + { + this.batchHandler = batchHandler; + this.importObjectService = importObjectService; + this.dataElementGroupMapping = dataElementGroupMapping; + this.dataElementGroupSetMapping = dataElementGroupSetMapping; + } + + // ------------------------------------------------------------------------- + // XMLConverter implementation + // ------------------------------------------------------------------------- + + public void write( XMLWriter writer, ExportParams params ) + { + Collection groupSets = dataElementService.getDataElementGroupSets( params.getDataElementGroups() ); + + Collection groups = dataElementService.getDataElementGroups( params.getAllDataElements() ); + + if ( groupSets != null && groupSets.size() > 0 && groups != null && groups.size() > 0 ) + { + writer.openElement( COLLECTION_NAME ); + + for ( DataElementGroupSet groupSet : groupSets ) + { + if ( groupSet.getMembers() != null ) + { + for ( DataElementGroup group : groupSet.getMembers() ) + { + if ( groups.contains( group ) ) + { + writer.openElement( ELEMENT_NAME ); + + writer.writeElement( FIELD_DATAELEMENT_GROUP_SET, String.valueOf( groupSet.getId() ) ); + writer.writeElement( FIELD_DATAELEMENT_GROUP, String.valueOf( group.getId() ) ); + + writer.closeElement(); + } + } + } + } + + writer.closeElement(); + } + } + + public void read( XMLReader reader, ImportParams params ) + { + while ( reader.moveToStartElement( ELEMENT_NAME, COLLECTION_NAME ) ) + { + final Map values = reader.readElements( ELEMENT_NAME ); + + final GroupMemberAssociation association = new GroupMemberAssociation( AssociationType.SET ); + + association.setGroupId( dataElementGroupSetMapping.get( Integer.parseInt( values.get( FIELD_DATAELEMENT_GROUP_SET )) ) ); + association.setMemberId( dataElementGroupMapping.get( Integer.parseInt( values.get( FIELD_DATAELEMENT_GROUP ) ) ) ); + + read( association, GroupMemberType.DATAELEMENTGROUP, params ); + } + } +} === added file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/IndicatorGroupSetConverter.java' --- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/IndicatorGroupSetConverter.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/IndicatorGroupSetConverter.java 2009-11-01 20:57:16 +0000 @@ -0,0 +1,133 @@ +package org.hisp.dhis.importexport.dxf.converter; + +/* + * Copyright (c) 2004-2007, 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; +import java.util.Map; + +import org.amplecode.staxwax.reader.XMLReader; +import org.amplecode.staxwax.writer.XMLWriter; +import org.amplecode.quick.BatchHandler; +import org.hisp.dhis.importexport.ExportParams; +import org.hisp.dhis.importexport.GroupMemberType; +import org.hisp.dhis.importexport.ImportObjectService; +import org.hisp.dhis.importexport.ImportParams; +import org.hisp.dhis.importexport.XMLConverter; +import org.hisp.dhis.importexport.converter.AbstractIndicatorGroupSetConverter; +import org.hisp.dhis.importexport.mapping.NameMappingUtil; +import org.hisp.dhis.indicator.IndicatorGroup; +import org.hisp.dhis.indicator.IndicatorGroupSet; +import org.hisp.dhis.indicator.IndicatorService; + +/** + * @author Lars Helge Overland + * @version $Id$ + */ +public class IndicatorGroupSetConverter + extends AbstractIndicatorGroupSetConverter implements XMLConverter +{ + public static final String COLLECTION_NAME = "indicatorGroups"; + public static final String ELEMENT_NAME = "indicatorGroup"; + + private static final String FIELD_ID = "id"; + private static final String FIELD_UUID = "uuid"; + private static final String FIELD_NAME = "name"; + + // ------------------------------------------------------------------------- + // Constructor + // ------------------------------------------------------------------------- + + /** + * Constructor for write operations. + */ + public IndicatorGroupSetConverter( IndicatorService indicatorService ) + { + this.indicatorService = indicatorService; + } + + /** + * Constructor for read operations. + * + * @param batchHandler the batchHandler to use. + * @param indicatorService the indicatorService to use. + * @param importObjectService the importObjectService to use. + */ + public IndicatorGroupSetConverter( BatchHandler batchHandler, + ImportObjectService importObjectService, + IndicatorService indicatorService ) + { + this.batchHandler = batchHandler; + this.importObjectService = importObjectService; + this.indicatorService = indicatorService; + } + + // ------------------------------------------------------------------------- + // XMLConverter implementation + // ------------------------------------------------------------------------- + + public void write( XMLWriter writer, ExportParams params ) + { + Collection groupSets = indicatorService.getIndicatorGroupSets( params.getIndicatorGroupSets() ); + + if ( groupSets != null && groupSets.size() > 0 ) + { + writer.openElement( COLLECTION_NAME ); + + for ( IndicatorGroupSet groupSet : groupSets ) + { + writer.openElement( ELEMENT_NAME ); + + writer.writeElement( FIELD_ID, String.valueOf( groupSet.getId() ) ); + writer.writeElement( FIELD_UUID, String.valueOf( groupSet.getUuid() ) ); + writer.writeElement( FIELD_NAME, groupSet.getName() ); + + writer.closeElement(); + } + + writer.closeElement(); + } + } + + public void read( XMLReader reader, ImportParams params ) + { + while ( reader.moveToStartElement( ELEMENT_NAME, COLLECTION_NAME ) ) + { + final Map values = reader.readElements( ELEMENT_NAME ); + + final IndicatorGroupSet groupSet = new IndicatorGroupSet(); + + groupSet.setId( Integer.parseInt( values.get( FIELD_ID ) ) ); + groupSet.setUuid( values.get( FIELD_UUID ) ); + groupSet.setName( values.get( FIELD_NAME ) ); + + NameMappingUtil.addIndicatorGroupSetMapping( groupSet.getId(), groupSet.getName() ); + + read( groupSet, GroupMemberType.NONE, params ); + } + } +} === added file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/IndicatorGroupSetMemberConverter.java' --- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/IndicatorGroupSetMemberConverter.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/IndicatorGroupSetMemberConverter.java 2009-11-01 20:57:16 +0000 @@ -0,0 +1,146 @@ +package org.hisp.dhis.importexport.dxf.converter; + +/* + * Copyright (c) 2004-2007, 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; +import java.util.Map; + +import org.amplecode.quick.BatchHandler; +import org.amplecode.staxwax.reader.XMLReader; +import org.amplecode.staxwax.writer.XMLWriter; +import org.hisp.dhis.importexport.AssociationType; +import org.hisp.dhis.importexport.ExportParams; +import org.hisp.dhis.importexport.GroupMemberAssociation; +import org.hisp.dhis.importexport.GroupMemberType; +import org.hisp.dhis.importexport.ImportObjectService; +import org.hisp.dhis.importexport.ImportParams; +import org.hisp.dhis.importexport.XMLConverter; +import org.hisp.dhis.importexport.converter.AbstractGroupMemberConverter; +import org.hisp.dhis.indicator.Indicator; +import org.hisp.dhis.indicator.IndicatorGroup; +import org.hisp.dhis.indicator.IndicatorGroupSet; +import org.hisp.dhis.indicator.IndicatorService; + +/** + * @author Lars Helge Overland + * @version $Id$ + */ +public class IndicatorGroupSetMemberConverter + extends AbstractGroupMemberConverter implements XMLConverter +{ + public static final String COLLECTION_NAME = "indicatorGroupSetMembers"; + public static final String ELEMENT_NAME = "indicatorGroupSetMember"; + + private static final String FIELD_INDICATOR_GROUP = "indicatorGroup"; + private static final String FIELD_INDICATOR_GROUP_SET = "indicatorGroupSet"; + + // ------------------------------------------------------------------------- + // Properties + // ------------------------------------------------------------------------- + + private IndicatorService indicatorService; + + private Map indicatorGroupMapping; + + private Map indicatorGroupSetMapping; + + // ------------------------------------------------------------------------- + // Constructor + // ------------------------------------------------------------------------- + + /** + * Constructor for write operations. + */ + public IndicatorGroupSetMemberConverter( IndicatorService indicatorService ) + { + this.indicatorService = indicatorService; + } + + /** + * Constructor for read operations. + */ + public IndicatorGroupSetMemberConverter( BatchHandler batchHandler, + ImportObjectService importObjectService, + Map indicatorGroupMapping, + Map indicatorGroupSetMapping ) + { + this.batchHandler = batchHandler; + this.importObjectService = importObjectService; + this.indicatorGroupMapping = indicatorGroupMapping; + this.indicatorGroupSetMapping = indicatorGroupSetMapping; + } + + // ------------------------------------------------------------------------- + // XMLConverter implementation + // ------------------------------------------------------------------------- + + public void write( XMLWriter writer, ExportParams params ) + { + Collection groupSets = indicatorService.getIndicatorGroupSets( params.getIndicatorGroupSets() ); + + Collection groups = indicatorService.getIndicatorGroups( params.getIndicators() ); + + if ( groupSets != null && groupSets.size() > 0 && groups != null && groups.size() > 0 ) + { + writer.openElement( COLLECTION_NAME ); + + for ( IndicatorGroupSet groupSet : groupSets ) + { + for ( IndicatorGroup group : groupSet.getMembers() ) + { + if ( groups.contains( group ) ) + { + writer.openElement( ELEMENT_NAME ); + + writer.writeElement( FIELD_INDICATOR_GROUP_SET, String.valueOf( groupSet.getId() ) ); + writer.writeElement( FIELD_INDICATOR_GROUP, String.valueOf( group.getId() ) ); + + writer.closeElement(); + } + } + } + + writer.closeElement(); + } + } + + public void read( XMLReader reader, ImportParams params ) + { + while ( reader.moveToStartElement( ELEMENT_NAME, COLLECTION_NAME ) ) + { + final Map values = reader.readElements( ELEMENT_NAME ); + + final GroupMemberAssociation association = new GroupMemberAssociation( AssociationType.SET ); + + association.setGroupId( indicatorGroupSetMapping.get( Integer.parseInt( values.get( FIELD_INDICATOR_GROUP_SET ) ) ) ); + association.setMemberId( indicatorGroupMapping.get( Integer.parseInt( values.get( FIELD_INDICATOR_GROUP ) ) ) ); + + read( association, GroupMemberType.INDICATORGROUP, params ); + } + } +} === modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/mapping/DefaultObjectMappingGenerator.java' --- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/mapping/DefaultObjectMappingGenerator.java 2009-10-18 22:44:41 +0000 +++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/mapping/DefaultObjectMappingGenerator.java 2009-11-01 20:57:16 +0000 @@ -40,9 +40,11 @@ import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; import org.hisp.dhis.dataelement.DataElementCategoryService; import org.hisp.dhis.dataelement.DataElementGroup; +import org.hisp.dhis.dataelement.DataElementGroupSet; import org.hisp.dhis.dataset.DataSet; import org.hisp.dhis.indicator.Indicator; import org.hisp.dhis.indicator.IndicatorGroup; +import org.hisp.dhis.indicator.IndicatorGroupSet; import org.hisp.dhis.indicator.IndicatorType; import org.hisp.dhis.jdbc.batchhandler.DataDictionaryBatchHandler; import org.hisp.dhis.jdbc.batchhandler.DataElementBatchHandler; @@ -50,10 +52,12 @@ import org.hisp.dhis.jdbc.batchhandler.DataElementCategoryComboBatchHandler; import org.hisp.dhis.jdbc.batchhandler.DataElementCategoryOptionBatchHandler; import org.hisp.dhis.jdbc.batchhandler.DataElementGroupBatchHandler; +import org.hisp.dhis.jdbc.batchhandler.DataElementGroupSetBatchHandler; import org.hisp.dhis.jdbc.batchhandler.DataSetBatchHandler; import org.hisp.dhis.jdbc.batchhandler.GroupSetBatchHandler; import org.hisp.dhis.jdbc.batchhandler.IndicatorBatchHandler; import org.hisp.dhis.jdbc.batchhandler.IndicatorGroupBatchHandler; +import org.hisp.dhis.jdbc.batchhandler.IndicatorGroupSetBatchHandler; import org.hisp.dhis.jdbc.batchhandler.IndicatorTypeBatchHandler; import org.hisp.dhis.jdbc.batchhandler.OrganisationUnitBatchHandler; import org.hisp.dhis.jdbc.batchhandler.OrganisationUnitGroupBatchHandler; @@ -166,6 +170,17 @@ } // ------------------------------------------------------------------------- + // DataElementGroupSet + // ------------------------------------------------------------------------- + + public Map getDataElementGroupSetMapping( boolean skipMapping ) + { + BatchHandler batchHandler = batchHandlerFactory.createBatchHandler( DataElementGroupSetBatchHandler.class ); + + return getMapping( batchHandler, NameMappingUtil.getDataElementGroupSetMap(), skipMapping ); + } + + // ------------------------------------------------------------------------- // Indicator // ------------------------------------------------------------------------- @@ -188,6 +203,17 @@ } // ------------------------------------------------------------------------- + // IndicatorGroupSet + // ------------------------------------------------------------------------- + + public Map getIndicatorGroupSetMapping( boolean skipMapping ) + { + BatchHandler batchHandler = batchHandlerFactory.createBatchHandler( IndicatorGroupSetBatchHandler.class ); + + return getMapping( batchHandler, NameMappingUtil.getIndicatorGroupSetMap(), skipMapping ); + } + + // ------------------------------------------------------------------------- // IndicatorType // ------------------------------------------------------------------------- === modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/mapping/NameMappingUtil.java' --- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/mapping/NameMappingUtil.java 2009-03-03 16:46:36 +0000 +++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/mapping/NameMappingUtil.java 2009-11-01 20:57:16 +0000 @@ -46,8 +46,10 @@ private static ThreadLocal> categoryOptionComboMap = new ThreadLocal>(); private static ThreadLocal> dataElementMap = new ThreadLocal>(); private static ThreadLocal> dataElementGroupMap = new ThreadLocal>(); + private static ThreadLocal> dataElementGroupSetMap = new ThreadLocal>(); private static ThreadLocal> indicatorMap = new ThreadLocal>(); private static ThreadLocal> indicatorGroupMap = new ThreadLocal>(); + private static ThreadLocal> indicatorGroupSetMap = new ThreadLocal>(); private static ThreadLocal> indicatorTypeMap = new ThreadLocal>(); private static ThreadLocal> dataDictionaryMap = new ThreadLocal>(); private static ThreadLocal> periodMap = new ThreadLocal>(); @@ -70,8 +72,10 @@ categoryOptionComboMap.remove(); dataElementMap.remove(); dataElementGroupMap.remove(); + dataElementGroupSetMap.remove(); indicatorMap.remove(); indicatorGroupMap.remove(); + indicatorGroupSetMap.remove(); indicatorTypeMap.remove(); dataDictionaryMap.remove(); periodMap.remove(); @@ -218,6 +222,26 @@ } // ------------------------------------------------------------------------- + // DataElementGroupSet + // ------------------------------------------------------------------------- + + /** + * Adds a map entry with DataElementGroupSet identifier as key and name as value. + */ + public static void addDataElementGroupSetMapping( Object groupId, String groupName ) + { + put( dataElementGroupSetMap, groupId, groupName ); + } + + /** + * Returns a map with all DataElementGroupSet identifier and name entries. + */ + public static Map getDataElementGroupSetMap() + { + return dataElementGroupSetMap.get() != null ? new HashMap( dataElementGroupSetMap.get() ) : new HashMap(); + } + + // ------------------------------------------------------------------------- // Indicator // ------------------------------------------------------------------------- @@ -250,7 +274,7 @@ } /** - * Returns a map with all Indicator identifier and name entries. + * Returns a map with all IndicatorGroup identifier and name entries. */ public static Map getIndicatorGroupMap() { @@ -258,6 +282,26 @@ } // ------------------------------------------------------------------------- + // IndicatorGroupSet + // ------------------------------------------------------------------------- + + /** + * Adds a map entry with IndicatorGroupSet identifier as key and name as value. + */ + public static void addIndicatorGroupSetMapping( Object groupId, String groupName ) + { + put( indicatorGroupSetMap, groupId, groupName ); + } + + /** + * Returns a map with all IndicatorGroupSet identifier and name entries. + */ + public static Map getIndicatorGroupSetMap() + { + return indicatorGroupSetMap.get() != null ? new HashMap( indicatorGroupSetMap.get() ) : new HashMap(); + } + + // ------------------------------------------------------------------------- // IndicatorType // ------------------------------------------------------------------------- === modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/mapping/ObjectMappingGenerator.java' --- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/mapping/ObjectMappingGenerator.java 2009-03-03 16:46:36 +0000 +++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/mapping/ObjectMappingGenerator.java 2009-11-01 20:57:16 +0000 @@ -56,10 +56,14 @@ Map getDataElementGroupMapping( boolean skipMapping ); + Map getDataElementGroupSetMapping( boolean skipMapping ); + Map getIndicatorMapping( boolean skipMapping ); Map getIndicatorGroupMapping( boolean skipMapping ); + Map getIndicatorGroupSetMapping( boolean skipMapping ); + Map getIndicatorTypeMapping( boolean skipMapping ); Map getDataDictionaryMapping( boolean skipMapping ); === modified file 'dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/dbms/HibernateDbmsManager.java' --- dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/dbms/HibernateDbmsManager.java 2009-09-25 21:45:01 +0000 +++ dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/dbms/HibernateDbmsManager.java 2009-11-01 20:57:16 +0000 @@ -115,6 +115,8 @@ emptyTable( "expressiondataelement" ); emptyTable( "calculateddataelement" ); + emptyTable( "dataelementgroupsetmembers" ); + emptyTable( "dataelementgroupset" ); emptyTable( "dataelementgroupmembers" ); emptyTable( "dataelementgroup" ); emptyTable( "dataelementaggregationlevels" ); @@ -132,7 +134,9 @@ emptyTable( "mocksource" ); emptyTable( "source" ); emptyTable( "period" ); - + + emptyTable( "indicatorgroupsetmembers" ); + emptyTable( "indicatorgroupset" ); emptyTable( "indicatorgroupmembers" ); emptyTable( "indicatorgroup" ); emptyTable( "indicator" ); === modified file 'dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java' --- dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java 2009-10-18 22:44:41 +0000 +++ dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java 2009-11-01 20:57:16 +0000 @@ -47,6 +47,7 @@ import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; import org.hisp.dhis.dataelement.DataElementCategoryService; import org.hisp.dhis.dataelement.DataElementGroup; +import org.hisp.dhis.dataelement.DataElementGroupSet; import org.hisp.dhis.dataelement.DataElementService; import org.hisp.dhis.dataset.CompleteDataSetRegistrationService; import org.hisp.dhis.dataset.DataSet; @@ -61,6 +62,7 @@ import org.hisp.dhis.importexport.ImportObjectStatus; import org.hisp.dhis.indicator.Indicator; import org.hisp.dhis.indicator.IndicatorGroup; +import org.hisp.dhis.indicator.IndicatorGroupSet; import org.hisp.dhis.indicator.IndicatorService; import org.hisp.dhis.indicator.IndicatorType; import org.hisp.dhis.mapping.Map; @@ -414,6 +416,19 @@ return group; } + + /** + * @param uniqueCharacter A unique character to identify the object. + */ + public static DataElementGroupSet createDataElementGroupSet( char uniqueCharacter ) + { + DataElementGroupSet groupSet = new DataElementGroupSet(); + + groupSet.setUuid( BASE_UUID + uniqueCharacter ); + groupSet.setName( "DataElementGroupSet" + uniqueCharacter ); + + return groupSet; + } /** * @param uniqueCharacter A unique character to identify the object. @@ -483,6 +498,19 @@ /** * @param uniqueCharacter A unique character to identify the object. + */ + public static IndicatorGroupSet createIndicatorGroupSet( char uniqueCharacter ) + { + IndicatorGroupSet groupSet = new IndicatorGroupSet(); + + groupSet.setUuid( BASE_UUID + uniqueCharacter ); + groupSet.setName( "IndicatorGroupSet" + uniqueCharacter ); + + return groupSet; + } + + /** + * @param uniqueCharacter A unique character to identify the object. * @param periodType The period type. */ public static DataSet createDataSet( char uniqueCharacter, PeriodType periodType )