← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6997: re-enabled export of dataElementOperands and expressions, importing not currently supported (but ...

 

------------------------------------------------------------
revno: 6997
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2012-05-21 15:28:46 +0200
message:
  re-enabled export of dataElementOperands and expressions, importing not currently supported (but will not break importer anymore)
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-api/src/main/java/org/hisp/dhis/validation/ValidationRule.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-05-21 09:25:15 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java	2012-05-21 13:28:46 +0000
@@ -417,12 +417,10 @@
         this.indicators = indicators;
     }
 
-    /*
     @JsonProperty
     @JsonView( {DetailedView.class, ExportView.class} )
     @JacksonXmlElementWrapper( localName = "compulsoryDataElementOperands", namespace = Dxf2Namespace.NAMESPACE )
     @JacksonXmlProperty( localName = "compulsoryDataElementOperand", namespace = Dxf2Namespace.NAMESPACE )
-    */
     public Set<DataElementOperand> getCompulsoryDataElementOperands()
     {
         return compulsoryDataElementOperands;

=== 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 09:25:15 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/Section.java	2012-05-21 13:28:46 +0000
@@ -233,12 +233,10 @@
         this.sortOrder = sortOrder;
     }
 
-    /*
     @JsonProperty
     @JsonView( {DetailedView.class, ExportView.class} )
     @JacksonXmlElementWrapper( localName = "greyedFields", namespace = Dxf2Namespace.NAMESPACE )
     @JacksonXmlProperty( localName = "greyedField", namespace = Dxf2Namespace.NAMESPACE )
-    */
     public Set<DataElementOperand> getGreyedFields()
     {
         return greyedFields;

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRule.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRule.java	2012-05-17 09:11:30 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRule.java	2012-05-21 13:28:46 +0000
@@ -86,7 +86,7 @@
     }
 
     public ValidationRule( String name, String description, String type,
-                           Operator operator, Expression leftSide, Expression rightSide )
+        Operator operator, Expression leftSide, Expression rightSide )
     {
         this.name = name;
         this.description = description;
@@ -207,11 +207,9 @@
         this.type = type;
     }
 
-    /*
     @JsonProperty
     @JsonView( {DetailedView.class, ExportView.class} )
     @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE )
-    */
     public Expression getLeftSide()
     {
         return leftSide;
@@ -222,11 +220,9 @@
         this.leftSide = leftSide;
     }
 
-    /*
     @JsonProperty
     @JsonView( {DetailedView.class, ExportView.class} )
     @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE )
-    */
     public Expression getRightSide()
     {
         return rightSide;

=== 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-05-17 20:26:32 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java	2012-05-21 13:28:46 +0000
@@ -37,17 +37,19 @@
 import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.common.NameableObject;
 import org.hisp.dhis.common.annotation.Scanned;
+import org.hisp.dhis.dataelement.DataElementOperand;
 import org.hisp.dhis.dxf2.importsummary.ImportConflict;
 import org.hisp.dhis.dxf2.importsummary.ImportCount;
 import org.hisp.dhis.dxf2.metadata.ImportOptions;
 import org.hisp.dhis.dxf2.metadata.Importer;
 import org.hisp.dhis.dxf2.metadata.ObjectBridge;
 import org.hisp.dhis.dxf2.utils.OrganisationUnitUtils;
+import org.hisp.dhis.expression.Expression;
 import org.hisp.dhis.importexport.ImportStrategy;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.comparator.OrganisationUnitComparator;
 import org.hisp.dhis.period.Period;
-import org.hisp.dhis.period.PeriodStore;
+import org.hisp.dhis.period.PeriodService;
 import org.hisp.dhis.period.PeriodType;
 import org.hisp.dhis.system.util.ReflectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -70,7 +72,7 @@
     //-------------------------------------------------------------------------------------------------------
 
     @Autowired
-    private PeriodStore periodStore;
+    private PeriodService periodService;
 
     @Autowired
     private AttributeService attributeService;
@@ -208,7 +210,14 @@
 
         for ( T object : objects )
         {
+            log.info( "Importing object " + object + " (" + object.getClass().getSimpleName() + ")" );
+
             Set<AttributeValue> attributeValues = getAndClearAttributeValues( object );
+            Set<DataElementOperand> greyedFields = getAndClearDataElementOperands( object, "greyedFields" );
+            Set<DataElementOperand> compulsoryDataElementOperands = getAndClearDataElementOperands( object, "compulsoryDataElementOperands" );
+            Expression leftSide = getAndClearExpression( object, "leftSide" );
+            Expression rightSide = getAndClearExpression( object, "rightSide" );
+
             List<ImportConflict> conflicts = importObjectLocal( object, options );
 
             if ( !options.isDryRun() )
@@ -227,11 +236,43 @@
         return importConflicts;
     }
 
-    private void setAttributeValues( T object, Set<AttributeValue> attributeValues )
-    {
-        ReflectionUtils.invokeSetterMethod( "attributeValues", object, attributeValues );
-    }
-
+    // FIXME add type check
+    private Expression getAndClearExpression( T object, String field )
+    {
+        Expression expression = null;
+
+        if ( ReflectionUtils.findGetterMethod( field, object ) != null )
+        {
+            expression = ReflectionUtils.invokeGetterMethod( field, object );
+
+            if ( expression != null )
+            {
+                ReflectionUtils.invokeSetterMethod( field, object, new Object[]{null} );
+            }
+        }
+
+        return expression;
+    }
+
+    // FIXME add type check
+    private Set<DataElementOperand> getAndClearDataElementOperands( T object, String field )
+    {
+        Set<DataElementOperand> dataElementOperands = new HashSet<DataElementOperand>();
+
+        if ( ReflectionUtils.findGetterMethod( field, object ) != null )
+        {
+            dataElementOperands = ReflectionUtils.invokeGetterMethod( field, object );
+
+            if ( dataElementOperands.size() > 0 )
+            {
+                ReflectionUtils.invokeSetterMethod( field, object, new HashSet<DataElementOperand>() );
+            }
+        }
+
+        return dataElementOperands;
+    }
+
+    // FIXME add type check
     private Set<AttributeValue> getAndClearAttributeValues( T object )
     {
         Set<AttributeValue> attributeValues = new HashSet<AttributeValue>();
@@ -242,7 +283,7 @@
 
             if ( attributeValues.size() > 0 )
             {
-                setAttributeValues( object, new HashSet<AttributeValue>() );
+                ReflectionUtils.invokeSetterMethod( "attributeValues", object, new HashSet<AttributeValue>() );
             }
         }
 
@@ -277,7 +318,7 @@
                 sessionFactory.getCurrentSession().flush();
             }
 
-            setAttributeValues( object, attributeValues );
+            ReflectionUtils.invokeSetterMethod( "attributeValues", object, attributeValues );
 
             if ( !dryRun )
             {
@@ -517,7 +558,7 @@
         else if ( Period.class.isAssignableFrom( identifiableObject.getClass() ) )
         {
             Period period = (Period) identifiableObject;
-            period = periodStore.reloadForceAddPeriod( period );
+            period = periodService.reloadPeriod( period );
 
             if ( !options.isDryRun() )
             {
@@ -544,7 +585,7 @@
                 if ( ref != null )
                 {
                     identifiableObjects.put( field, ref );
-                    ReflectionUtils.invokeSetterMethod( field.getName(), identifiableObject, new Object[]{ null } );
+                    ReflectionUtils.invokeSetterMethod( field.getName(), identifiableObject, new Object[]{null} );
                 }
             }