=== 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-06-27 16:04:20 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/CsvObjectUtils.java 2014-06-29 22:17:35 +0000 @@ -42,6 +42,7 @@ import org.hisp.dhis.common.ListMap; import org.hisp.dhis.dataelement.CategoryOptionGroup; import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.dataelement.DataElementCategoryCombo; import org.hisp.dhis.dataelement.DataElementCategoryOption; import org.hisp.dhis.dataelement.DataElementDomain; import org.hisp.dhis.dataelement.DataElementGroup; @@ -57,7 +58,7 @@ */ public class CsvObjectUtils { - public static MetaData fromCsv( InputStream input, Class clazz ) + public static MetaData fromCsv( InputStream input, Class clazz, DataElementCategoryCombo categoryCombo ) throws IOException { CsvReader reader = new CsvReader( input, Charset.forName( "UTF-8" ) ); @@ -67,7 +68,7 @@ if ( DataElement.class.equals( clazz ) ) { - metaData.setDataElements( dataElementsFromCsv( reader, input ) ); + metaData.setDataElements( dataElementsFromCsv( reader, input, categoryCombo ) ); } else if ( DataElementGroup.class.equals( clazz ) ) { @@ -137,7 +138,7 @@ return list; } - private static List dataElementsFromCsv( CsvReader reader, InputStream input ) + private static List dataElementsFromCsv( CsvReader reader, InputStream input, DataElementCategoryCombo categoryCombo ) throws IOException { List list = new ArrayList(); @@ -160,10 +161,22 @@ object.setType( getSafe( values, 7, DataElement.VALUE_TYPE_INT, 16 ) ); object.setNumberType( getSafe( values, 8, DataElement.VALUE_TYPE_NUMBER, 16 ) ); object.setTextType( getSafe( values, 9, null, 16 ) ); - object.setAggregationOperator( getSafe( values, 10, DataElement.AGGREGATION_OPERATOR_SUM, 16 ) ); - object.setUrl( getSafe( values, 11, null, 255 ) ); - object.setZeroIsSignificant( Boolean.valueOf( getSafe( values, 12, "false", null ) ) ); + object.setAggregationOperator( getSafe( values, 10, DataElement.AGGREGATION_OPERATOR_SUM, 16 ) ); + String categoryComboUid = getSafe( values, 11, null, 11 ); + object.setUrl( getSafe( values, 12, null, 255 ) ); + object.setZeroIsSignificant( Boolean.valueOf( getSafe( values, 13, "false", null ) ) ); + if ( categoryComboUid != null ) + { + DataElementCategoryCombo cc = new DataElementCategoryCombo(); + cc.setUid( categoryComboUid ); + object.setCategoryCombo( cc ); + } + else + { + object.setCategoryCombo( categoryCombo ); + } + list.add( object ); } } @@ -204,6 +217,7 @@ { OrganisationUnit object = new OrganisationUnit(); setIdentifiableObject( object, values ); + String parentUid = getSafe( values, 3, null, 11 ); object.setShortName( getSafe( values, 4, object.getName(), 50 ) ); object.setDescription( getSafe( values, 5, null, null ) ); object.setUuid( getSafe( values, 6, null, 36 ) ); @@ -218,9 +232,7 @@ object.setAddress( getSafe( values, 14, null, 255 ) ); object.setEmail( getSafe( values, 15, null, 150 ) ); object.setPhoneNumber( getSafe( values, 16, null, 150 ) ); - - String parentUid = getSafe( values, 3, null, 11 ); - + if ( parentUid != null ) { OrganisationUnit parent = new OrganisationUnit(); @@ -303,9 +315,9 @@ * @param values the string array. * @param index the array index of the string to get. * @param defaultValue the default value in case index is out of bounds. - * @param max the max number of characters to return for the string. + * @param maxChars the max number of characters to return for the string. */ - private static String getSafe( String[] values, int index, String defaultValue, Integer max ) + private static String getSafe( String[] values, int index, String defaultValue, Integer maxChars ) { String string = null; @@ -322,7 +334,7 @@ if ( string != null ) { - return max != null ? StringUtils.substring( string, 0, max ) : string; + return maxChars != null ? StringUtils.substring( string, 0, maxChars ) : string; } return null; === 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-05-13 18:18:04 +0000 +++ dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/dxf2/MetaDataImportAction.java 2014-06-29 22:17:35 +0000 @@ -34,6 +34,7 @@ import java.util.HashMap; import java.util.Map; +import org.hisp.dhis.common.IdentifiableObjectManager; import org.hisp.dhis.dataelement.CategoryOptionGroup; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.dataelement.DataElementCategoryOption; @@ -79,6 +80,9 @@ @Autowired private ImportService importService; + + @Autowired + private IdentifiableObjectManager identifiableObjectManager; @Autowired private CurrentUserService currentUserService; @@ -159,7 +163,8 @@ if ( "csv".equals( importFormat ) && classKey != null && KEY_CLASS_MAP.get( classKey ) != null ) { - scheduler.executeTask( new ImportMetaDataCsvTask( userId, importService, importOptions, in, taskId, KEY_CLASS_MAP.get( classKey ) ) ); + scheduler.executeTask( new ImportMetaDataCsvTask( userId, importService, identifiableObjectManager, + importOptions, in, taskId, KEY_CLASS_MAP.get( classKey ) ) ); } else { === modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/util/ImportMetaDataCsvTask.java' --- dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/util/ImportMetaDataCsvTask.java 2014-03-18 08:10:10 +0000 +++ dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/util/ImportMetaDataCsvTask.java 2014-06-29 22:17:35 +0000 @@ -33,6 +33,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.hisp.dhis.common.IdentifiableObjectManager; +import org.hisp.dhis.dataelement.DataElementCategoryCombo; import org.hisp.dhis.dxf2.metadata.ImportOptions; import org.hisp.dhis.dxf2.metadata.ImportService; import org.hisp.dhis.dxf2.metadata.MetaData; @@ -49,6 +51,8 @@ private ImportService importService; + private IdentifiableObjectManager identifiableObjectManager; + private ImportOptions importOptions; private InputStream inputStream; @@ -59,11 +63,14 @@ private Class clazz; - public ImportMetaDataCsvTask( String userUid, ImportService importService, ImportOptions importOptions, InputStream inputStream, + public ImportMetaDataCsvTask( String userUid, ImportService importService, + IdentifiableObjectManager identifiableObjectManager, + ImportOptions importOptions, InputStream inputStream, TaskId taskId, Class clazz ) { this.userUid = userUid; this.importService = importService; + this.identifiableObjectManager = identifiableObjectManager; this.importOptions = importOptions; this.inputStream = inputStream; this.taskId = taskId; @@ -75,9 +82,12 @@ { MetaData metaData = null; + DataElementCategoryCombo categoryCombo = identifiableObjectManager.getByName( + DataElementCategoryCombo.class, DataElementCategoryCombo.DEFAULT_CATEGORY_COMBO_NAME ); + try { - metaData = CsvObjectUtils.fromCsv( inputStream, clazz ); + metaData = CsvObjectUtils.fromCsv( inputStream, clazz, categoryCombo ); } catch ( IOException ex ) {