← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1457: Added category concept to dxf

 

------------------------------------------------------------
revno: 1457
committer: Bob Jolliffe <bobj@bobj-laptop>
branch nick: trunk
timestamp: Sat 2010-02-20 03:06:21 +0000
message:
  Added category concept to dxf
  Fixed unit test for xsl transform (hack to copy files into temporary external dir)
  Removed dhis2_test_dir on test teardown
modified:
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/DataElementCategoryConverter.java
  dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dxf/DXFImportServiceTest.java
  tools/dhis2deb/Makefile


--
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-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/DataElementCategoryConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/DataElementCategoryConverter.java	2009-08-12 21:06:37 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/DataElementCategoryConverter.java	2010-02-20 03:06:21 +0000
@@ -55,6 +55,8 @@
     
     private static final String FIELD_ID = "id";
     private static final String FIELD_NAME = "name";
+    private static final String FIELD_CONCEPT = "concept";
+
     
     // -------------------------------------------------------------------------
     // Constructor
@@ -102,7 +104,8 @@
                 
                 writer.writeElement( FIELD_ID, String.valueOf( category.getId() ) );
                 writer.writeElement( FIELD_NAME, category.getName() );
-                
+                writer.writeElement( FIELD_CONCEPT, category.getConceptName() );
+
                 writer.closeElement();
             }
             
@@ -120,7 +123,8 @@
             
             category.setId( Integer.parseInt( values.get( FIELD_ID ) ) );
             category.setName( values.get( FIELD_NAME ) );
-            
+            category.setConceptName( values.get( FIELD_CONCEPT ) );
+
             NameMappingUtil.addCategoryMapping( category.getId(), category.getName() );
             
             read( category, GroupMemberType.NONE, params );

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dxf/DXFImportServiceTest.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dxf/DXFImportServiceTest.java	2010-02-19 18:38:02 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dxf/DXFImportServiceTest.java	2010-02-20 03:06:21 +0000
@@ -27,9 +27,18 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 import static junit.framework.Assert.assertEquals;
 
 import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.channels.FileChannel;
 
 import org.hisp.dhis.DhisTest;
 import org.hisp.dhis.datadictionary.DataDictionaryService;
@@ -44,6 +53,7 @@
 import org.hisp.dhis.dbms.DbmsManager;
 import org.hisp.dhis.expression.ExpressionService;
 import org.hisp.dhis.external.location.LocationManager;
+import org.hisp.dhis.external.location.LocationManagerException;
 import org.hisp.dhis.importexport.GroupMemberType;
 import org.hisp.dhis.importexport.ImportDataValueService;
 import org.hisp.dhis.importexport.ImportObjectService;
@@ -87,34 +97,54 @@
 public class DXFImportServiceTest
     extends DhisTest
 {
+
     private final int dataASize = 3;
+
     private final int dataBSize = 5;
+
     private final int dataCSize = 5;
-    
+
     private ImportService importService;
-    
+
     private InputStream inputStreamA;
+
     private InputStream inputStreamAx;
+
     private InputStream inputStreamAz;
-    private InputStream inputStreamB;    
-    private InputStream inputStreamC;    
-    private InputStream inputStreamD;    
-    private InputStream inputStreamE;    
-    private InputStream inputStreamF;    
+
+    private InputStream inputStreamB;
+
+    private InputStream inputStreamC;
+
+    private InputStream inputStreamD;
+
+    private InputStream inputStreamE;
+
+    private InputStream inputStreamF;
+
     private InputStream inputStreamG;
+
     private InputStream inputStreamH;
+
     private InputStream inputStreamSDMX;
 
+    private InputStream inputStreamTransforms;
+
+    private InputStream inputStreamSimpleXsl;
+
+    private final static String TRANSFORMS = "transforms.xml";
+
+    private final static String SIMPLEXSL = "changeroot.xsl";
+
     private ImportObjectService importObjectService;
-    
+
     private ImportDataValueService importDataValueService;
-    
+
     // -------------------------------------------------------------------------
     // Fixture
     // -------------------------------------------------------------------------
-
     @Override
-    public void setUpTest()
+    public void setUpTest() throws LocationManagerException, IOException
     {
         ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
 
@@ -122,45 +152,68 @@
         inputStreamAx = classLoader.getResourceAsStream( "dxfA.xml" );
         inputStreamAz = classLoader.getResourceAsStream( "dxfA.xml.gz" );
         inputStreamB = classLoader.getResourceAsStream( "dxfB.zip" );
-        inputStreamC = classLoader.getResourceAsStream( "dxfC.zip" );        
+        inputStreamC = classLoader.getResourceAsStream( "dxfC.zip" );
         inputStreamD = classLoader.getResourceAsStream( "dxfD.zip" );
-        inputStreamE = classLoader.getResourceAsStream( "dxfE.zip" );        
-        inputStreamF = classLoader.getResourceAsStream( "dxfF.zip" );      
+        inputStreamE = classLoader.getResourceAsStream( "dxfE.zip" );
+        inputStreamF = classLoader.getResourceAsStream( "dxfF.zip" );
         inputStreamG = classLoader.getResourceAsStream( "dxfG.zip" );
         inputStreamH = classLoader.getResourceAsStream( "changeroot.xml" );
-        inputStreamSDMX = classLoader.getResourceAsStream( "formattedCSDS2.xml");
-
-        setExternalTestDir( (LocationManager) getBean( LocationManager.ID ) );
-//        importService = (ImportService) getBean( "org.hisp.dhis.importexport.DXFImportService" );
+        inputStreamSDMX = classLoader.getResourceAsStream( "formattedCSDS2.xml" );
+
+        inputStreamTransforms = classLoader.getResourceAsStream( TRANSFORMS );
+        inputStreamSimpleXsl = classLoader.getResourceAsStream( SIMPLEXSL );
+
         importService = (ImportService) getBean( "org.hisp.dhis.importexport.XMLImportService" );
-        
+
         categoryService = (DataElementCategoryService) getBean( DataElementCategoryService.ID );
-        
+
         dataElementService = (DataElementService) getBean( DataElementService.ID );
-        
+
         dataDictionaryService = (DataDictionaryService) getBean( DataDictionaryService.ID );
-        
+
         indicatorService = (IndicatorService) getBean( IndicatorService.ID );
-        
+
         dataSetService = (DataSetService) getBean( DataSetService.ID );
-        
+
         organisationUnitService = (OrganisationUnitService) getBean( OrganisationUnitService.ID );
-        
+
         organisationUnitGroupService = (OrganisationUnitGroupService) getBean( OrganisationUnitGroupService.ID );
-        
+
         dataValueService = (DataValueService) getBean( DataValueService.ID );
-        
+
         validationRuleService = (ValidationRuleService) getBean( ValidationRuleService.ID );
-        
+
         expressionService = (ExpressionService) getBean( ExpressionService.ID );
-        
+
         importObjectService = (ImportObjectService) getBean( ImportObjectService.ID );
-        
+
         importDataValueService = (ImportDataValueService) getBean( ImportDataValueService.ID );
-        
+
         dbmsManager = (DbmsManager) getBean( DbmsManager.ID );
+
+        locationManager = (LocationManager) getBean( LocationManager.ID );
+        setExternalTestDir( locationManager );
+
+        // horrible hack to copy some files into external test dir
+        File extDir = null;
+        extDir = locationManager.getFileForWriting( "." );
+        if ( ( extDir != null ) && ( extDir.isDirectory() ) )
+        {
+            OutputStream transforms = null;
+            OutputStream simplexsl = null;
+            String transformPath = extDir.getPath() + "/transform";
+            File transformDir = new File( transformPath );
+            transformDir.mkdir();
+            transforms = new FileOutputStream( transformPath + "/" + TRANSFORMS );
+            simplexsl = new FileOutputStream( transformPath + "/" + SIMPLEXSL );
+            copy( inputStreamTransforms, transforms );
+            copy( inputStreamSimpleXsl, simplexsl );
+            transforms.close();
+            simplexsl.close();
+        }
+
     }
-    
+
     @Override
     public void tearDownTest()
         throws Exception
@@ -168,31 +221,35 @@
         inputStreamA.close();
         inputStreamAx.close();
         inputStreamAz.close();
-        inputStreamB.close();        
-        inputStreamC.close();        
-        inputStreamD.close();        
-        inputStreamE.close();        
+        inputStreamB.close();
+        inputStreamC.close();
+        inputStreamD.close();
+        inputStreamE.close();
         inputStreamF.close();
         inputStreamH.close();
         inputStreamSDMX.close();
+
+        inputStreamTransforms.close();
+        inputStreamSimpleXsl.close();
+
+        // clean up the mess ...
+        removeExternalTestDir();
     }
-    
+
     @Override
     public boolean emptyDatabaseAfterTest()
     {
         return true;
     }
-    
+
     // -------------------------------------------------------------------------
     // Tests
     // -------------------------------------------------------------------------
-    
     // TODO Improve test on duplicate GroupMemberAssociations
-
-
     @Test
     public void testSimpleImportWithTransform()
     {
+
         ImportParams importParams = ImportExportUtils.getImportParams( ImportStrategy.NEW_AND_UPDATES, false, false, false );
 
         importService.importData( importParams, inputStreamH );
@@ -212,15 +269,16 @@
 
         assertEquals( organisationUnitService.getAllOrganisationUnits().size(), 1 );
 
-        assertEquals( dataValueService.getAllDataValues().size(), 64 );    }
+        assertEquals( dataValueService.getAllDataValues().size(), 64 );
+    }
 
     @Test
     public void testImportMetaData()
-    {        
+    {
         ImportParams importParams = ImportExportUtils.getImportParams( ImportStrategy.NEW_AND_UPDATES, false, false, false );
-        
+
         importService.importData( importParams, inputStreamA );
-        
+
         assertObjects( dataASize );
     }
 
@@ -248,11 +306,11 @@
     public void testImportMetaDataWithPreview()
     {
         ImportParams importParams = ImportExportUtils.getImportParams( ImportStrategy.NEW_AND_UPDATES, true, false, false );
-        
+
         importService.importData( importParams, inputStreamA );
-        
+
         assertImportObjects( ImportObjectStatus.NEW, dataASize );
-        
+
         assertGroupMembers( dataASize );
     }
 
@@ -260,19 +318,19 @@
     public void testImportMetaDataWithPreviewAndDuplicates()
     {
         ImportParams importParams = ImportExportUtils.getImportParams( ImportStrategy.NEW_AND_UPDATES, false, false, false );
-        
+
         importService.importData( importParams, inputStreamA );
-        
+
         assertObjects( dataASize );
-        
+
         importParams = ImportExportUtils.getImportParams( ImportStrategy.NEW_AND_UPDATES, true, false, false );
-        
+
         importService.importData( importParams, inputStreamB );
-        
+
         assertImportObjects( ImportObjectStatus.NEW, dataBSize - dataASize );
-        
+
         assertImportObjects( ImportObjectStatus.UPDATE, 0 );
-        
+
         assertGroupMembers( dataBSize );
     }
 
@@ -280,19 +338,19 @@
     public void testImportMetaDataWithPreviewAndUpdates()
     {
         ImportParams importParams = ImportExportUtils.getImportParams( ImportStrategy.NEW_AND_UPDATES, false, false, false );
-        
+
         importService.importData( importParams, inputStreamA );
-        
+
         assertObjects( dataASize );
 
         importParams = ImportExportUtils.getImportParams( ImportStrategy.NEW_AND_UPDATES, true, false, false );
-        
+
         importService.importData( importParams, inputStreamC );
-        
+
         assertUpdateableImportObjects( ImportObjectStatus.UPDATE, dataASize );
-        
+
         assertImportObjects( ImportObjectStatus.NEW, dataCSize - dataASize );
-        
+
         assertGroupMembers( dataCSize );
     }
 
@@ -300,36 +358,36 @@
     public void testImportDataValues()
     {
         ImportParams importParams = ImportExportUtils.getImportParams( ImportStrategy.NEW_AND_UPDATES, false, true, false );
-        
+
         importService.importData( importParams, inputStreamD );
-        
+
         assertEquals( dataElementService.getAllDataElements().size(), 2 );
-        
+
         assertEquals( organisationUnitService.getAllOrganisationUnits().size(), 2 );
-        
+
         assertEquals( dataValueService.getAllDataValues().size(), 8 );
     }
-    
+
     @Test
     public void testImportDataValuesWithUpdates()
     {
         ImportParams importParams = ImportExportUtils.getImportParams( ImportStrategy.NEW_AND_UPDATES, false, true, false );
-        
+
         importService.importData( importParams, inputStreamE );
-        
+
         assertEquals( 12, dataValueService.getAllDataValues().size() );
-        
+
         for ( DataValue dataValue : dataValueService.getAllDataValues() )
         {
             assertEquals( "10", dataValue.getValue() );
         }
-        
+
         dbmsManager.clearSession();
 
         importService.importData( importParams, inputStreamG );
 
         assertEquals( 12, dataValueService.getAllDataValues().size() );
-        
+
         for ( DataValue dataValue : dataValueService.getAllDataValues() )
         {
             assertEquals( "20", dataValue.getValue() );
@@ -340,13 +398,13 @@
     public void testImportDataValuesWithPreview()
     {
         ImportParams importParams = ImportExportUtils.getImportParams( ImportStrategy.NEW_AND_UPDATES, true, true, false );
-        
+
         importService.importData( importParams, inputStreamD );
-        
+
         assertEquals( importObjectService.getImportObjects( ImportObjectStatus.NEW, DataElement.class ).size(), 2 );
-        
+
         assertEquals( importObjectService.getImportObjects( ImportObjectStatus.NEW, OrganisationUnit.class ).size(), 2 );
-        
+
         assertEquals( importDataValueService.getImportDataValues( ImportObjectStatus.NEW ).size(), 8 );
     }
 
@@ -354,24 +412,24 @@
     public void testImportDataValuesWithPreviewAndDuplicates()
     {
         ImportParams importParams = ImportExportUtils.getImportParams( ImportStrategy.NEW_AND_UPDATES, false, true, false );
-        
+
         importService.importData( importParams, inputStreamD );
-        
+
         assertEquals( dataElementService.getAllDataElements().size(), 2 );
-        
+
         assertEquals( organisationUnitService.getAllOrganisationUnits().size(), 2 );
-        
+
         assertEquals( dataValueService.getAllDataValues().size(), 8 );
-        
+
         importParams = ImportExportUtils.getImportParams( ImportStrategy.NEW_AND_UPDATES, true, true, false );
-        
+
         importService.importData( importParams, inputStreamE );
-        
+
         assertEquals( importObjectService.getImportObjects( ImportObjectStatus.NEW, DataElement.class ).size(), 1 );
-        
+
         assertEquals( importObjectService.getImportObjects( ImportObjectStatus.NEW, OrganisationUnit.class ).size(), 0 );
-        
-        assertEquals( importDataValueService.getImportDataValues( ImportObjectStatus.NEW ).size(), 12 );        
+
+        assertEquals( importDataValueService.getImportDataValues( ImportObjectStatus.NEW ).size(), 12 );
     }
 
     @Test
@@ -382,9 +440,9 @@
         importService.importData( importParams, inputStreamD );
 
         assertEquals( dataElementService.getAllDataElements().size(), 2 );
-        
+
         assertEquals( organisationUnitService.getAllOrganisationUnits().size(), 2 );
-        
+
         assertEquals( dataValueService.getAllDataValues().size(), 8 );
 
         importParams = ImportExportUtils.getImportParams( ImportStrategy.NEW_AND_UPDATES, true, true, false );
@@ -392,105 +450,119 @@
         importService.importData( importParams, inputStreamF );
 
         assertEquals( importObjectService.getImportObjects( ImportObjectStatus.NEW, DataElement.class ).size(), 1 );
-        
+
         assertEquals( importObjectService.getImportObjects( ImportObjectStatus.NEW, OrganisationUnit.class ).size(), 0 );
-        
+
         assertEquals( importObjectService.getImportObjects( ImportObjectStatus.UPDATE, DataElement.class ).size(), 2 );
-        
-        assertEquals( importDataValueService.getImportDataValues( ImportObjectStatus.NEW ).size(), 12 );        
+
+        assertEquals( importDataValueService.getImportDataValues( ImportObjectStatus.NEW ).size(), 12 );
     }
-    
+
     // -------------------------------------------------------------------------
     // Supportive methods
     // -------------------------------------------------------------------------
-    
     private void assertObjects( int expectedSize )
     {
         assertEquals( categoryService.getAllDataElementCategoryOptions().size(), 5 ); // Including default
-        
+
         assertEquals( categoryService.getAllDataElementCategories().size(), 3 ); // Including default
-        
+
         assertEquals( categoryService.getAllDataElementCategoryCombos().size(), 3 ); // Including default
-        
+
         assertEquals( categoryService.getAllDataElementCategoryOptionCombos().size(), 5 ); // Including default
-        
+
         assertEquals( dataElementService.getAllDataElements().size(), expectedSize );
-        
+
         assertEquals( dataElementService.getAllDataElementGroups().size(), expectedSize );
-        
+
         for ( DataElementGroup group : dataElementService.getAllDataElementGroups() )
         {
             assertEquals( group.getMembers().size(), expectedSize );
         }
-        
+
         assertEquals( indicatorService.getAllIndicatorTypes().size(), expectedSize );
-        
+
         assertEquals( indicatorService.getAllIndicators().size(), expectedSize );
-        
+
         assertEquals( indicatorService.getAllIndicatorGroups().size(), expectedSize );
-        
+
         for ( IndicatorGroup group : indicatorService.getAllIndicatorGroups() )
         {
             assertEquals( group.getMembers().size(), expectedSize );
         }
-        
+
         assertEquals( dataSetService.getAllDataSets().size(), expectedSize );
-        
+
         for ( DataSet dataSet : dataSetService.getAllDataSets() )
         {
             assertEquals( dataSet.getDataElements().size(), expectedSize );
         }
-        
+
         assertEquals( organisationUnitService.getAllOrganisationUnits().size(), expectedSize );
-        
+
         assertEquals( organisationUnitGroupService.getAllOrganisationUnitGroups().size(), expectedSize );
-        
+
         for ( OrganisationUnitGroup group : organisationUnitGroupService.getAllOrganisationUnitGroups() )
         {
             assertEquals( group.getMembers().size(), expectedSize );
         }
-        
+
         assertEquals( organisationUnitGroupService.getAllOrganisationUnitGroupSets().size(), expectedSize );
-        
+
         assertEquals( validationRuleService.getAllValidationRules().size(), expectedSize );
     }
 
     private void assertImportObjects( ImportObjectStatus status, int expectedSize )
     {
         assertUpdateableImportObjects( status, expectedSize );
-        
+
         assertEquals( importObjectService.getImportObjects( status, DataElementGroup.class ).size(), expectedSize );
-        
+
         assertEquals( importObjectService.getImportObjects( status, IndicatorType.class ).size(), expectedSize );
 
         assertEquals( importObjectService.getImportObjects( status, IndicatorGroup.class ).size(), expectedSize );
-        
+
         assertEquals( importObjectService.getImportObjects( status, DataSet.class ).size(), expectedSize );
-                
+
         assertEquals( importObjectService.getImportObjects( status, OrganisationUnitGroup.class ).size(), expectedSize );
 
         assertEquals( importObjectService.getImportObjects( status, OrganisationUnitGroupSet.class ).size(), expectedSize );
 
-        assertEquals( importObjectService.getImportObjects( status, ValidationRule.class  ).size(), expectedSize );        
+        assertEquals( importObjectService.getImportObjects( status, ValidationRule.class ).size(), expectedSize );
     }
-    
+
     private void assertUpdateableImportObjects( ImportObjectStatus status, int expectedSize )
     {
         assertEquals( importObjectService.getImportObjects( status, DataElement.class ).size(), expectedSize );
-        
+
         assertEquals( importObjectService.getImportObjects( status, Indicator.class ).size(), expectedSize );
-        
+
         assertEquals( importObjectService.getImportObjects( status, OrganisationUnit.class ).size(), expectedSize );
     }
-    
+
     private void assertGroupMembers( int expectedSize )
     {
         assertEquals( importObjectService.getImportObjects( GroupMemberType.DATAELEMENTGROUP ).size(), expectedSize * expectedSize );
-        
+
         assertEquals( importObjectService.getImportObjects( GroupMemberType.INDICATORGROUP ).size(), expectedSize * expectedSize );
-        
+
         assertEquals( importObjectService.getImportObjects( GroupMemberType.DATASET ).size(), expectedSize * expectedSize );
-        
+
         assertEquals( importObjectService.getImportObjects( GroupMemberType.ORGANISATIONUNITGROUP ).size(), expectedSize * expectedSize );
     }
+
+    // utility method to copy streams
+    public void copy( InputStream in, OutputStream out ) throws IOException
+    {
+        byte buffer[] = new byte[1024 * 1024]; // 1MB
+        while ( true )
+        {
+            int count = in.read( buffer );
+            if ( count == -1 )
+            {
+                break;
+            }
+            out.write( buffer, 0, count );
+        }
+    }
 }

=== modified file 'tools/dhis2deb/Makefile'
--- tools/dhis2deb/Makefile	2009-12-21 09:33:26 +0000
+++ tools/dhis2deb/Makefile	2010-02-20 03:06:21 +0000
@@ -1,4 +1,4 @@
-DHIS_WAR=~/development/src/dhis2/dhis-2/dhis-web/dhis-web-portal/target/dhis.war
+DHIS_WAR=~/src/dhis/dhis2-trunk/dhis2/dhis-2/dhis-web/dhis-web-portal/target/dhis.war
 
 dhis2.deb: dhis2/* dhis2/dhis2_home/* dhis2/DEBIAN/*
 	dpkg-deb --build dhis2