← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15260: CSV import, added support for option sets

 

------------------------------------------------------------
revno: 15260
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-05-13 20:18:04 +0200
message:
  CSV import, added support for option sets
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/resources/org/hisp/dhis/importexport/i18n_module.properties
  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-04-06 12:03:35 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/CsvObjectUtils.java	2014-05-13 18:18:04 +0000
@@ -28,6 +28,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import static org.hisp.dhis.system.util.DateUtils.getMediumDate;
+
 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.charset.Charset;
@@ -37,18 +39,18 @@
 import org.apache.commons.lang.StringUtils;
 import org.hisp.dhis.common.BaseIdentifiableObject;
 import org.hisp.dhis.common.CodeGenerator;
+import org.hisp.dhis.common.ListMap;
 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.option.OptionSet;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
 
 import com.csvreader.CsvReader;
 
-import static org.hisp.dhis.system.util.DateUtils.getMediumDate;
-
 /**
  * @author Lars Helge Overland
  */
@@ -86,6 +88,10 @@
         {
             metaData.setOrganisationUnitGroups( organisationUnitGroupsFromCsv( reader, input ) );
         }
+        else if ( OptionSet.class.equals( clazz ) )
+        {
+            metaData.setOptionSets( getOptionSetsFromCsv( reader, input ) );
+        }
         
         return metaData;
     }
@@ -236,6 +242,37 @@
         
         return list;
     }
+    
+    private static List<OptionSet> getOptionSetsFromCsv( CsvReader reader, InputStream input )
+        throws IOException
+    {
+        ListMap<OptionSet, String> listMap = new ListMap<OptionSet, String>();
+        
+        while ( reader.readRecord() )
+        {
+            String[] values = reader.getValues();
+            
+            if ( values != null && values.length > 0 )
+            {
+                OptionSet object = new OptionSet();
+                setIdentifiableObject( object, values );
+                String option = getSafe( values, 3, null, 2000000 );
+                
+                listMap.putValue( object, option );
+            }
+        }
+        
+        List<OptionSet> optionSets = new ArrayList<OptionSet>();
+        
+        for ( OptionSet optionSet : listMap.keySet() )
+        {
+            List<String> options = new ArrayList<String>( listMap.get( optionSet ) );
+            optionSet.setOptions( options );
+            optionSets.add( optionSet );
+        }
+        
+        return optionSets;
+    }
 
     // -------------------------------------------------------------------------
     // Supportive methods

=== 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-04-12 17:06:39 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/dxf2/MetaDataImportAction.java	2014-05-13 18:18:04 +0000
@@ -28,7 +28,11 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import com.opensymphony.xwork2.Action;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.hisp.dhis.dataelement.CategoryOptionGroup;
 import org.hisp.dhis.dataelement.DataElement;
@@ -39,6 +43,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.option.OptionSet;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
 import org.hisp.dhis.scheduling.TaskCategory;
@@ -50,11 +55,7 @@
 import org.hisp.dhis.user.User;
 import org.springframework.beans.factory.annotation.Autowired;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Map;
+import com.opensymphony.xwork2.Action;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -69,6 +70,7 @@
        put( "categoryoptiongroup", CategoryOptionGroup.class );
        put( "organisationunit", OrganisationUnit.class );
        put( "organisationunitgroup", OrganisationUnitGroup.class );
+       put( "optionset", OptionSet.class );
     }};
     
     // -------------------------------------------------------------------------

=== 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	2014-03-31 06:54:16 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/resources/org/hisp/dhis/importexport/i18n_module.properties	2014-05-13 18:18:04 +0000
@@ -76,6 +76,7 @@
 organisation_unit_group_set=Organisation unit group set
 category_option=Category option
 category_option_group=Category option group
+option_set=Option set
 element=Element
 objects=Objects
 discard_selected=Discard selected

=== 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-04-12 17:06:39 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/dxf2MetaDataImport.vm	2014-05-13 18:18:04 +0000
@@ -19,7 +19,8 @@
         <option value="categoryoption">$i18n.getString( "category_option" )</option>
         <option value="categoryoptiongroup">$i18n.getString( "category_option_group" )</option>
         <option value="organisationunit">$i18n.getString( "organisation_unit" )</option>
-        <option value="organisationunitgroup">$i18n.getString( "organisation_unit_group" )</option>
+        <option value="organisationunitgroup">$i18n.getString( "organisation_unit_group" )</option>
+        <option value="optionset">$i18n.getString( "option_set" )</option>
     </select></td>
 </tr>
 #end