dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #29175
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14697: CSV import, support for data element groups and org unit groups
------------------------------------------------------------
revno: 14697
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2014-04-06 14:03:35 +0200
message:
CSV import, support for data element groups and org unit groups
modified:
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/CsvObjectUtils.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-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/CsvObjectUtils.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/CsvObjectUtils.java 2014-03-31 12:54:07 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/CsvObjectUtils.java 2014-04-06 12:03:35 +0000
@@ -40,8 +40,10 @@
import org.hisp.dhis.dataelement.CategoryOptionGroup;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementCategoryOption;
+import org.hisp.dhis.dataelement.DataElementGroup;
import org.hisp.dhis.dxf2.metadata.MetaData;
import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
import com.csvreader.CsvReader;
@@ -64,6 +66,10 @@
{
metaData.setDataElements( dataElementsFromCsv( reader, input ) );
}
+ else if ( DataElementGroup.class.equals( clazz ) )
+ {
+ metaData.setDataElementGroups( dataElementGroupsFromCsv( reader, input ) );
+ }
else if ( DataElementCategoryOption.class.equals( clazz ) )
{
metaData.setCategoryOptions( categoryOptionsFromCsv( reader, input ) );
@@ -76,6 +82,10 @@
{
metaData.setOrganisationUnits( organisationUnitsFromCsv( reader, input ) );
}
+ else if ( OrganisationUnitGroup.class.equals( clazz ) )
+ {
+ metaData.setOrganisationUnitGroups( organisationUnitGroupsFromCsv( reader, input ) );
+ }
return metaData;
}
@@ -118,7 +128,7 @@
}
return list;
- }
+ }
private static List<DataElement> dataElementsFromCsv( CsvReader reader, InputStream input )
throws IOException
@@ -151,8 +161,28 @@
return list;
}
+
+ private static List<DataElementGroup> dataElementGroupsFromCsv( CsvReader reader, InputStream input )
+ throws IOException
+ {
+ List<DataElementGroup> list = new ArrayList<DataElementGroup>();
+
+ while ( reader.readRecord() )
+ {
+ String[] values = reader.getValues();
+
+ if ( values != null && values.length > 0 )
+ {
+ DataElementGroup object = new DataElementGroup();
+ setIdentifiableObject( object, values );
+ list.add( object );
+ }
+ }
+
+ return list;
+ }
- public static List<OrganisationUnit> organisationUnitsFromCsv( CsvReader reader, InputStream input )
+ private static List<OrganisationUnit> organisationUnitsFromCsv( CsvReader reader, InputStream input )
throws IOException
{
List<OrganisationUnit> list = new ArrayList<OrganisationUnit>();
@@ -187,6 +217,30 @@
return list;
}
+ private static List<OrganisationUnitGroup> organisationUnitGroupsFromCsv( CsvReader reader, InputStream input )
+ throws IOException
+ {
+ List<OrganisationUnitGroup> list = new ArrayList<OrganisationUnitGroup>();
+
+ while ( reader.readRecord() )
+ {
+ String[] values = reader.getValues();
+
+ if ( values != null && values.length > 0 )
+ {
+ OrganisationUnitGroup object = new OrganisationUnitGroup();
+ setIdentifiableObject( object, values );
+ list.add( object );
+ }
+ }
+
+ return list;
+ }
+
+ // -------------------------------------------------------------------------
+ // Supportive methods
+ // -------------------------------------------------------------------------
+
private static void setIdentifiableObject( BaseIdentifiableObject object, String[] values )
{
object.setName( getSafe( values, 0, null, 230 ) );