← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14066: Impl CSV import of org units. No hierarchy support yet.

 

------------------------------------------------------------
revno: 14066
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-02-18 11:47:40 +0100
message:
  Impl CSV import of org units. No hierarchy support yet.
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/CsvObjectUtils.java
  dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/dxf2/MetaDataImportAction.java
  dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/dxf2MetaDataImport.vm


--
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-02-17 18:48:08 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/CsvObjectUtils.java	2014-02-18 10:47:40 +0000
@@ -41,9 +41,12 @@
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementCategoryOption;
 import org.hisp.dhis.dxf2.metadata.MetaData;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
 
 import com.csvreader.CsvReader;
 
+import static org.hisp.dhis.system.util.DateUtils.getMediumDate;
+
 /**
  * @author Lars Helge Overland
  */
@@ -69,6 +72,10 @@
         {
             metaData.setCategoryOptionGroups( categoryOptionGroupsFromCsv( reader, input ) );
         }
+        else if ( OrganisationUnit.class.equals( clazz ) )
+        {
+            metaData.setOrganisationUnits( organisationUnitsFromCsv( reader, input ) );
+        }
         
         return metaData;
     }
@@ -144,6 +151,41 @@
         
         return list;
     }
+    
+    public static List<OrganisationUnit> organisationUnitsFromCsv( CsvReader reader, InputStream input )
+        throws IOException
+    {
+        List<OrganisationUnit> list = new ArrayList<OrganisationUnit>();
+        
+        while ( reader.readRecord() )
+        {
+            String[] values = reader.getValues();
+
+            if ( values != null && values.length > 0 )
+            {
+                OrganisationUnit object = new OrganisationUnit();
+                setIdentifiableObject( object, values );
+                object.setShortName( getSafe( values, 3, StringUtils.substring( object.getName(), 0, 50 ) ) );
+                object.setDescription( getSafe( values, 4, null ) );
+                object.setUuid( getSafe( values, 5, null ) );
+                object.setOpeningDate( getMediumDate( getSafe( values, 6, "1970-01-01" ) ) );
+                object.setClosedDate( getMediumDate( getSafe( values, 7, "1970-01-01" ) ) );
+                object.setActive( true );
+                object.setComment( getSafe( values, 8, null ) );
+                object.setFeatureType( getSafe( values, 9, null ) );
+                object.setCoordinates( getSafe( values, 10, null ) );
+                object.setUrl( getSafe( values, 11, null ) );
+                object.setContactPerson( getSafe( values, 12, null ) );
+                object.setAddress( getSafe( values, 13, null ) );
+                object.setEmail( getSafe( values, 14, null ) );
+                object.setPhoneNumber( getSafe( values, 15, null ) );
+
+                list.add( object );
+            }
+        }
+        
+        return list;
+    }
 
     private static void setIdentifiableObject( BaseIdentifiableObject object, String[] values )
     {

=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/dxf2/MetaDataImportAction.java'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/dxf2/MetaDataImportAction.java	2014-02-17 18:48:08 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/dxf2/MetaDataImportAction.java	2014-02-18 10:47:40 +0000
@@ -38,6 +38,7 @@
 import org.hisp.dhis.importexport.ImportStrategy;
 import org.hisp.dhis.importexport.action.util.ImportMetaDataCsvTask;
 import org.hisp.dhis.importexport.action.util.ImportMetaDataTask;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.scheduling.TaskCategory;
 import org.hisp.dhis.scheduling.TaskId;
 import org.hisp.dhis.system.notification.Notifier;
@@ -62,7 +63,8 @@
     private static final Map<String, Class<?>> KEY_CLASS_MAP = new HashMap<String, Class<?>>() {{
        put( "dataelement", DataElement.class );
        put( "categoryoption", DataElementCategoryOption.class );
-       put( "categoryoptiongroup", CategoryOptionGroup.class ); 
+       put( "categoryoptiongroup", CategoryOptionGroup.class );
+       put( "organisationunit", OrganisationUnit.class );
     }};
     
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/dxf2MetaDataImport.vm'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/dxf2MetaDataImport.vm	2014-02-17 18:48:08 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/dxf2MetaDataImport.vm	2014-02-18 10:47:40 +0000
@@ -16,7 +16,8 @@
 	<td><select id="classKey" name="classKey" style="width:190px">
 		<option value="dataelement">$i18n.getString( "data_element" )</option>
         <option value="categoryoption">$i18n.getString( "category_option" )</option>
-        <option value="categoryoptiongroup">$i18n.getString( "category_option_group" )</option>
+        <option value="categoryoptiongroup">$i18n.getString( "category_option_group" )</option>
+        <option value="organisationunit">$i18n.getString( "organisation_unit" )</option>
     </select></td>
 </tr>
 #end