dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #02895
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 951: Impl dxf1 converters for dataelement/indicatorgroupset.
------------------------------------------------------------
revno: 951
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Sun 2009-11-01 21:57:16 +0100
message:
Impl dxf1 converters for dataelement/indicatorgroupset.
added:
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/DataElementGroupSetMemberConverter.java
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/IndicatorGroupSetMemberConverter.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/IndicatorService.java
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/indicator/DefaultIndicatorService.java
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/converter/AbstractIndicatorGroupSetConverter.java
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/NameMappingUtil.java
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/mapping/ObjectMappingGenerator.java
dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/dbms/HibernateDbmsManager.java
dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription.
=== 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<DataElementGroupSet> getAllDataElementGroupSets();
+
+ Collection<DataElementGroupSet> getDataElementGroupSets( Collection<Integer> 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<IndicatorGroupSet> getAllIndicatorGroupSets();
+
+ Collection<IndicatorGroupSet> getIndicatorGroupSets( Collection<Integer> 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<DataElementGroupSet> getDataElementGroupSets( Collection<Integer> identifiers )
+ {
+ if ( identifiers == null )
+ {
+ return getAllDataElementGroupSets();
+ }
+
+ Collection<DataElementGroupSet> groupSets = new ArrayList<DataElementGroupSet>();
+
+ 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<IndicatorGroupSet> getIndicatorGroupSets( Collection<Integer> identifiers )
+ {
+ if ( identifiers == null )
+ {
+ return getAllIndicatorGroupSets();
+ }
+
+ Collection<IndicatorGroupSet> groupSets = new ArrayList<IndicatorGroupSet>();
+
+ 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<Integer> dataElementGroups = new ArrayList<Integer>();
+ private Collection<Integer> dataElementGroupSets = new ArrayList<Integer>();
+
private Collection<Integer> indicators = new ArrayList<Integer>();
private Collection<Integer> indicatorGroups = new ArrayList<Integer>();
+ private Collection<Integer> indicatorGroupSets = new ArrayList<Integer>();
+
private Collection<Integer> indicatorTypes = new ArrayList<Integer>();
private Collection<Integer> dataDictionaries = new ArrayList<Integer>();
@@ -288,6 +292,16 @@
this.dataElementGroups = dataElementGroups;
}
+ public Collection<Integer> getDataElementGroupSets()
+ {
+ return dataElementGroupSets;
+ }
+
+ public void setDataElementGroupSets( Collection<Integer> dataElementGroupSets )
+ {
+ this.dataElementGroupSets = dataElementGroupSets;
+ }
+
public Collection<Integer> getIndicators()
{
return indicators;
@@ -308,6 +322,16 @@
this.indicatorGroups = indicatorGroups;
}
+ public Collection<Integer> getIndicatorGroupSets()
+ {
+ return indicatorGroupSets;
+ }
+
+ public void setIndicatorGroupSets( Collection<Integer> indicatorGroupSets )
+ {
+ this.indicatorGroupSets = indicatorGroupSets;
+ }
+
public Collection<Integer> 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<IndicatorGroupSet>
{
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<DataElementGroupSet> 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<String, String> 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<Object, Integer> dataElementGroupMapping;
+
+ private Map<Object, Integer> dataElementGroupSetMapping;
+
+ // -------------------------------------------------------------------------
+ // Constructor
+ // -------------------------------------------------------------------------
+
+ /**
+ * Constructor for write operations.
+ */
+ public DataElementGroupSetMemberConverter( DataElementService dataElementService )
+ {
+ this.dataElementService = dataElementService;
+ }
+
+ /**
+ * Constructor for read operations.
+ */
+ public DataElementGroupSetMemberConverter( BatchHandler<GroupMemberAssociation> batchHandler,
+ ImportObjectService importObjectService,
+ Map<Object, Integer> dataElementGroupMapping,
+ Map<Object, Integer> dataElementGroupSetMapping )
+ {
+ this.batchHandler = batchHandler;
+ this.importObjectService = importObjectService;
+ this.dataElementGroupMapping = dataElementGroupMapping;
+ this.dataElementGroupSetMapping = dataElementGroupSetMapping;
+ }
+
+ // -------------------------------------------------------------------------
+ // XMLConverter implementation
+ // -------------------------------------------------------------------------
+
+ public void write( XMLWriter writer, ExportParams params )
+ {
+ Collection<DataElementGroupSet> groupSets = dataElementService.getDataElementGroupSets( params.getDataElementGroups() );
+
+ Collection<DataElementGroup> 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<String, String> 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<IndicatorGroupSet> batchHandler,
+ ImportObjectService importObjectService,
+ IndicatorService indicatorService )
+ {
+ this.batchHandler = batchHandler;
+ this.importObjectService = importObjectService;
+ this.indicatorService = indicatorService;
+ }
+
+ // -------------------------------------------------------------------------
+ // XMLConverter implementation
+ // -------------------------------------------------------------------------
+
+ public void write( XMLWriter writer, ExportParams params )
+ {
+ Collection<IndicatorGroupSet> 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<String, String> 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<Object, Integer> indicatorGroupMapping;
+
+ private Map<Object, Integer> indicatorGroupSetMapping;
+
+ // -------------------------------------------------------------------------
+ // Constructor
+ // -------------------------------------------------------------------------
+
+ /**
+ * Constructor for write operations.
+ */
+ public IndicatorGroupSetMemberConverter( IndicatorService indicatorService )
+ {
+ this.indicatorService = indicatorService;
+ }
+
+ /**
+ * Constructor for read operations.
+ */
+ public IndicatorGroupSetMemberConverter( BatchHandler<GroupMemberAssociation> batchHandler,
+ ImportObjectService importObjectService,
+ Map<Object, Integer> indicatorGroupMapping,
+ Map<Object, Integer> indicatorGroupSetMapping )
+ {
+ this.batchHandler = batchHandler;
+ this.importObjectService = importObjectService;
+ this.indicatorGroupMapping = indicatorGroupMapping;
+ this.indicatorGroupSetMapping = indicatorGroupSetMapping;
+ }
+
+ // -------------------------------------------------------------------------
+ // XMLConverter implementation
+ // -------------------------------------------------------------------------
+
+ public void write( XMLWriter writer, ExportParams params )
+ {
+ Collection<IndicatorGroupSet> groupSets = indicatorService.getIndicatorGroupSets( params.getIndicatorGroupSets() );
+
+ Collection<IndicatorGroup> 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<String, String> 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<Object, Integer> getDataElementGroupSetMapping( boolean skipMapping )
+ {
+ BatchHandler<DataElementGroupSet> batchHandler = batchHandlerFactory.createBatchHandler( DataElementGroupSetBatchHandler.class );
+
+ return getMapping( batchHandler, NameMappingUtil.getDataElementGroupSetMap(), skipMapping );
+ }
+
+ // -------------------------------------------------------------------------
// Indicator
// -------------------------------------------------------------------------
@@ -188,6 +203,17 @@
}
// -------------------------------------------------------------------------
+ // IndicatorGroupSet
+ // -------------------------------------------------------------------------
+
+ public Map<Object, Integer> getIndicatorGroupSetMapping( boolean skipMapping )
+ {
+ BatchHandler<IndicatorGroupSet> 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<Map<Object, DataElementCategoryOptionCombo>> categoryOptionComboMap = new ThreadLocal<Map<Object, DataElementCategoryOptionCombo>>();
private static ThreadLocal<Map<Object, String>> dataElementMap = new ThreadLocal<Map<Object, String>>();
private static ThreadLocal<Map<Object, String>> dataElementGroupMap = new ThreadLocal<Map<Object, String>>();
+ private static ThreadLocal<Map<Object, String>> dataElementGroupSetMap = new ThreadLocal<Map<Object,String>>();
private static ThreadLocal<Map<Object, String>> indicatorMap = new ThreadLocal<Map<Object, String>>();
private static ThreadLocal<Map<Object, String>> indicatorGroupMap = new ThreadLocal<Map<Object, String>>();
+ private static ThreadLocal<Map<Object, String>> indicatorGroupSetMap = new ThreadLocal<Map<Object,String>>();
private static ThreadLocal<Map<Object, String>> indicatorTypeMap = new ThreadLocal<Map<Object, String>>();
private static ThreadLocal<Map<Object, String>> dataDictionaryMap = new ThreadLocal<Map<Object,String>>();
private static ThreadLocal<Map<Object, Period>> periodMap = new ThreadLocal<Map<Object, Period>>();
@@ -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<Object, String> getDataElementGroupSetMap()
+ {
+ return dataElementGroupSetMap.get() != null ? new HashMap<Object, String>( dataElementGroupSetMap.get() ) : new HashMap<Object, String>();
+ }
+
+ // -------------------------------------------------------------------------
// 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<Object, String> 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<Object, String> getIndicatorGroupSetMap()
+ {
+ return indicatorGroupSetMap.get() != null ? new HashMap<Object, String>( indicatorGroupSetMap.get() ) : new HashMap<Object, String>();
+ }
+
+ // -------------------------------------------------------------------------
// 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<Object, Integer> getDataElementGroupMapping( boolean skipMapping );
+ Map<Object, Integer> getDataElementGroupSetMapping( boolean skipMapping );
+
Map<Object, Integer> getIndicatorMapping( boolean skipMapping );
Map<Object, Integer> getIndicatorGroupMapping( boolean skipMapping );
+ Map<Object, Integer> getIndicatorGroupSetMapping( boolean skipMapping );
+
Map<Object, Integer> getIndicatorTypeMapping( boolean skipMapping );
Map<Object, Integer> 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 )