← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7403: Minor fixes to importer (ignore DataElementOperands correctly, since they are not idObject)

 

------------------------------------------------------------
revno: 7403
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2012-06-26 15:06:43 +0300
message:
  Minor fixes to importer (ignore DataElementOperands correctly, since they are not idObject)
removed:
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/handlers/HandlerUtils.java
added:
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/handlers/ObjectHandlerUtils.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/Section.java
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/handlers/ObjectHandler.java
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.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-api/src/main/java/org/hisp/dhis/dataset/DataSet.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java	2012-06-25 20:39:32 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java	2012-06-26 12:06:43 +0000
@@ -96,7 +96,6 @@
      * The DataElementOperands for which data must be entered in order for the
      * DataSet to be considered as complete.
      */
-    @Scanned
     private Set<DataElementOperand> compulsoryDataElementOperands = new HashSet<DataElementOperand>();
 
     /**

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/Section.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/Section.java	2012-05-21 13:28:46 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/Section.java	2012-06-26 12:06:43 +0000
@@ -58,7 +58,6 @@
     @Scanned
     private List<DataElement> dataElements = new ArrayList<DataElement>();
 
-    @Scanned
     private Set<DataElementOperand> greyedFields = new HashSet<DataElementOperand>();
 
     private int sortOrder;

=== removed file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/handlers/HandlerUtils.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/handlers/HandlerUtils.java	2012-06-25 20:14:42 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/handlers/HandlerUtils.java	1970-01-01 00:00:00 +0000
@@ -1,64 +0,0 @@
-package org.hisp.dhis.dxf2.metadata.handlers;
-
-import java.util.List;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public class HandlerUtils
-{
-    @SuppressWarnings( "unchecked" )
-    public static <T> void preObjectHandlers( T object, List<ObjectHandler> objectHandlers )
-    {
-        for ( ObjectHandler objectHandler : objectHandlers )
-        {
-            if ( objectHandler.canHandle( object.getClass() ) )
-            {
-                objectHandler.preImportObject( object );
-            }
-        }
-    }
-
-    @SuppressWarnings( "unchecked" )
-    public static <T> void postObjectHandlers( T object, List<ObjectHandler> objectHandlers )
-    {
-        for ( ObjectHandler objectHandler : objectHandlers )
-        {
-            if ( objectHandler.canHandle( object.getClass() ) )
-            {
-                objectHandler.postImportObject( object );
-            }
-        }
-    }
-
-    @SuppressWarnings( "unchecked" )
-    public static <T> void preObjectsHandlers( List<T> objects, List<ObjectHandler> objectHandlers )
-    {
-        if ( objects.size() > 0 )
-        {
-            for ( ObjectHandler objectHandler : objectHandlers )
-            {
-                if ( objectHandler.canHandle( objects.get( 0 ).getClass() ) )
-                {
-                    objectHandler.preImportObjects( objects );
-                }
-            }
-        }
-    }
-
-    @SuppressWarnings( "unchecked" )
-    public static <T> void postObjectsHandlers( List<T> objects, List<ObjectHandler> objectHandlers )
-    {
-        if ( objects.size() > 0 )
-        {
-            for ( ObjectHandler objectHandler : objectHandlers )
-            {
-                if ( objectHandler.canHandle( objects.get( 0 ).getClass() ) )
-                {
-                    objectHandler.postImportObjects( objects );
-                }
-            }
-        }
-    }
-
-}

=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/handlers/ObjectHandler.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/handlers/ObjectHandler.java	2012-05-23 18:35:22 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/handlers/ObjectHandler.java	2012-06-26 12:06:43 +0000
@@ -34,15 +34,13 @@
  */
 public interface ObjectHandler<T>
 {
-    void preImportObject(T object);
-
-    void postImportObject(T object);
-
-    void preImportObjects(List<T> objects);
-
-    void postImportObjects(List<T> objects);
+    void preImportObject( T object );
+
+    void postImportObject( T object );
+
+    void preImportObjects( List<T> objects );
+
+    void postImportObjects( List<T> objects );
 
     boolean canHandle( Class<?> clazz );
 }
-
-

=== added file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/handlers/ObjectHandlerUtils.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/handlers/ObjectHandlerUtils.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/handlers/ObjectHandlerUtils.java	2012-06-26 12:06:43 +0000
@@ -0,0 +1,64 @@
+package org.hisp.dhis.dxf2.metadata.handlers;
+
+import java.util.List;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class ObjectHandlerUtils
+{
+    @SuppressWarnings( "unchecked" )
+    public static <T> void preObjectHandlers( T object, List<ObjectHandler> objectHandlers )
+    {
+        for ( ObjectHandler objectHandler : objectHandlers )
+        {
+            if ( objectHandler.canHandle( object.getClass() ) )
+            {
+                objectHandler.preImportObject( object );
+            }
+        }
+    }
+
+    @SuppressWarnings( "unchecked" )
+    public static <T> void postObjectHandlers( T object, List<ObjectHandler> objectHandlers )
+    {
+        for ( ObjectHandler objectHandler : objectHandlers )
+        {
+            if ( objectHandler.canHandle( object.getClass() ) )
+            {
+                objectHandler.postImportObject( object );
+            }
+        }
+    }
+
+    @SuppressWarnings( "unchecked" )
+    public static <T> void preObjectsHandlers( List<T> objects, List<ObjectHandler> objectHandlers )
+    {
+        if ( objects.size() > 0 )
+        {
+            for ( ObjectHandler objectHandler : objectHandlers )
+            {
+                if ( objectHandler.canHandle( objects.get( 0 ).getClass() ) )
+                {
+                    objectHandler.preImportObjects( objects );
+                }
+            }
+        }
+    }
+
+    @SuppressWarnings( "unchecked" )
+    public static <T> void postObjectsHandlers( List<T> objects, List<ObjectHandler> objectHandlers )
+    {
+        if ( objects.size() > 0 )
+        {
+            for ( ObjectHandler objectHandler : objectHandlers )
+            {
+                if ( objectHandler.canHandle( objects.get( 0 ).getClass() ) )
+                {
+                    objectHandler.postImportObjects( objects );
+                }
+            }
+        }
+    }
+
+}

=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java	2012-06-26 09:13:37 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java	2012-06-26 12:06:43 +0000
@@ -40,8 +40,8 @@
 import org.hisp.dhis.dataelement.DataElementOperandService;
 import org.hisp.dhis.dxf2.importsummary.ImportConflict;
 import org.hisp.dhis.dxf2.metadata.*;
-import org.hisp.dhis.dxf2.metadata.handlers.HandlerUtils;
 import org.hisp.dhis.dxf2.metadata.handlers.ObjectHandler;
+import org.hisp.dhis.dxf2.metadata.handlers.ObjectHandlerUtils;
 import org.hisp.dhis.expression.Expression;
 import org.hisp.dhis.expression.ExpressionService;
 import org.hisp.dhis.importexport.ImportStrategy;
@@ -117,18 +117,20 @@
     private class NonIdentifiableObjects
     {
         private Set<AttributeValue> attributeValues = new HashSet<AttributeValue>();
-        // private Set<DataElementOperand> compulsoryDataElementOperands = new HashSet<DataElementOperand>();
-        private Set<DataElementOperand> greyedFields = new HashSet<DataElementOperand>();
+
         private Expression leftSide;
         private Expression rightSide;
 
+        private Set<DataElementOperand> compulsoryDataElementOperands = new HashSet<DataElementOperand>();
+        private Set<DataElementOperand> greyedFields = new HashSet<DataElementOperand>();
+
         public void extract( T object )
         {
             attributeValues = extractAttributeValues( object );
-            // compulsoryDataElementOperands = extractDataElementOperands( object, "compulsoryDataElementOperands" );
-            greyedFields = extractDataElementOperands( object, "greyedFields" );
             leftSide = extractExpression( object, "leftSide" );
             rightSide = extractExpression( object, "rightSide" );
+            compulsoryDataElementOperands = extractDataElementOperands( object, "compulsoryDataElementOperands" );
+            greyedFields = extractDataElementOperands( object, "greyedFields" );
         }
 
         public void delete( T object )
@@ -136,10 +138,10 @@
             if ( !options.isDryRun() )
             {
                 deleteAttributeValues( object );
-                // deleteDataElementOperands( compulsoryDataElementOperands );
-                deleteDataElementOperands( object, "greyedFields" );
                 deleteExpression( object, "leftSide" );
                 deleteExpression( object, "rightSide" );
+                // deleteDataElementOperands( object, "compulsoryDataElementOperands" );
+                // deleteDataElementOperands( object, "greyedFields" );
             }
         }
 
@@ -148,8 +150,8 @@
             saveAttributeValues( object, attributeValues );
             saveExpression( object, "leftSide", leftSide );
             saveExpression( object, "rightSide", rightSide );
-            // newDataElementOperands( object, "compulsoryDataElementOperands", compulsoryDataElementOperands );
-            saveDataElementOperands( object, "greyedFields", greyedFields );
+            // saveDataElementOperands( object, "compulsoryDataElementOperands", compulsoryDataElementOperands );
+            // saveDataElementOperands( object, "greyedFields", greyedFields );
         }
 
         private Expression extractExpression( T object, String fieldName )
@@ -219,7 +221,7 @@
             }
         }
 
-        private void saveDataElementOperands( T object, String field, Set<DataElementOperand> dataElementOperands )
+        private void saveDataElementOperands( T object, String fieldName, Set<DataElementOperand> dataElementOperands )
         {
             if ( dataElementOperands.size() > 0 )
             {
@@ -232,7 +234,7 @@
                     dataElementOperandService.addDataElementOperand( dataElementOperand );
                 }
 
-                ReflectionUtils.invokeSetterMethod( field, object, dataElementOperands );
+                ReflectionUtils.invokeSetterMethod( fieldName, object, dataElementOperands );
             }
         }
 
@@ -420,18 +422,16 @@
             return summaryType;
         }
 
-        HandlerUtils.preObjectsHandlers( objects, objectHandlers );
+        ObjectHandlerUtils.preObjectsHandlers( objects, objectHandlers );
 
         for ( T object : objects )
         {
-            HandlerUtils.preObjectHandlers( object, objectHandlers );
-
+            ObjectHandlerUtils.preObjectHandlers( object, objectHandlers );
             importObjectLocal( object );
-
-            HandlerUtils.postObjectHandlers( object, objectHandlers );
+            ObjectHandlerUtils.postObjectHandlers( object, objectHandlers );
         }
 
-        HandlerUtils.postObjectsHandlers( objects, objectHandlers );
+        ObjectHandlerUtils.postObjectsHandlers( objects, objectHandlers );
 
         return summaryType;
     }