← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15463: more fixes to importer

 

------------------------------------------------------------
revno: 15463
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-05-28 22:04:18 +0200
message:
  more fixes to importer
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramValidation.java
  dhis-2/dhis-services/dhis-service-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/program/ProgramValidation.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramValidation.java	2014-05-26 14:19:42 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramValidation.java	2014-05-28 20:04:18 +0000
@@ -86,80 +86,6 @@
     }
 
     // -------------------------------------------------------------------------
-    // hashCode() and equals()
-    // -------------------------------------------------------------------------
-
-    @Override
-    public int hashCode()
-    {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((leftSide == null) ? 0 : leftSide.hashCode());
-        result = prime * result + ((program == null) ? 0 : program.hashCode());
-        result = prime * result + ((rightSide == null) ? 0 : rightSide.hashCode());
-        return result;
-    }
-
-    @Override
-    public boolean equals( Object object )
-    {
-        if ( this == object )
-        {
-            return true;
-        }
-
-        if ( object == null )
-        {
-            return false;
-        }
-
-        if ( !getClass().isAssignableFrom( object.getClass() ) )
-        {
-            return false;
-        }
-
-        ProgramValidation other = (ProgramValidation) object;
-
-        if ( leftSide == null )
-        {
-            if ( other.leftSide != null )
-            {
-                return false;
-            }
-        }
-        else if ( !leftSide.equals( other.leftSide ) )
-        {
-            return false;
-        }
-
-        if ( program == null )
-        {
-            if ( other.program != null )
-            {
-                return false;
-            }
-        }
-        else if ( !program.equals( other.program ) )
-        {
-            return false;
-        }
-
-        if ( rightSide == null )
-        {
-            if ( other.rightSide != null )
-            {
-                return false;
-            }
-        }
-        else if ( !rightSide.equals( other.rightSide ) )
-        {
-            return false;
-        }
-
-        return true;
-    }
-
-    // -------------------------------------------------------------------------
     // Getters && Setters
     // -------------------------------------------------------------------------
 

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java	2014-05-28 19:02:46 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java	2014-05-28 20:04:18 +0000
@@ -38,6 +38,7 @@
 import org.hisp.dhis.attribute.AttributeValue;
 import org.hisp.dhis.common.BaseIdentifiableObject;
 import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.common.IdentifiableObjectManager;
 import org.hisp.dhis.common.NameableObject;
 import org.hisp.dhis.dataelement.DataElementOperand;
 import org.hisp.dhis.dataelement.DataElementOperandService;
@@ -57,9 +58,10 @@
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodService;
 import org.hisp.dhis.period.PeriodType;
-import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramStageDataElement;
+import org.hisp.dhis.program.ProgramStageDataElementService;
 import org.hisp.dhis.program.ProgramTrackedEntityAttribute;
+import org.hisp.dhis.program.ProgramTrackedEntityAttributeService;
 import org.hisp.dhis.system.util.CollectionUtils;
 import org.hisp.dhis.system.util.ReflectionUtils;
 import org.hisp.dhis.system.util.functional.Function1;
@@ -110,6 +112,9 @@
     private DataElementOperandService dataElementOperandService;
 
     @Autowired
+    private IdentifiableObjectManager manager;
+
+    @Autowired
     private ObjectBridge objectBridge;
 
     @Autowired
@@ -183,6 +188,8 @@
                 }
 
                 deleteDataElementOperands( object, "greyedFields" );
+                deleteProgramStageDataElements( object );
+                deleteProgramTrackedEntityAttributes( object );
             }
         }
 
@@ -194,6 +201,8 @@
             saveDataEntryForm( object, "dataEntryForm", dataEntryForm );
             saveDataElementOperands( object, "compulsoryDataElementOperands", compulsoryDataElementOperands );
             saveDataElementOperands( object, "greyedFields", greyedFields );
+            saveProgramStageDataElements( object, programStageDataElements );
+            saveProgramTrackedEntityAttributes( object, programTrackedEntityAttributes );
         }
 
         private void saveDataEntryForm( T object, String fieldName, DataEntryForm dataEntryForm )
@@ -337,6 +346,23 @@
             }
         }
 
+        private void deleteAttributeValues( T object )
+        {
+            if ( !Attribute.class.isAssignableFrom( object.getClass() ) )
+            {
+                Set<AttributeValue> attributeValues = extractAttributeValues( object );
+
+                CollectionUtils.forEach( attributeValues, new Function1<AttributeValue>()
+                {
+                    @Override
+                    public void apply( AttributeValue attributeValue )
+                    {
+                        attributeService.deleteAttributeValue( attributeValue );
+                    }
+                } );
+            }
+        }
+
         private void saveAttributeValues( T object, Set<AttributeValue> attributeValues )
         {
             if ( attributeValues.size() > 0 )
@@ -392,23 +418,6 @@
             } );
         }
 
-        private void deleteAttributeValues( T object )
-        {
-            if ( !Attribute.class.isAssignableFrom( object.getClass() ) )
-            {
-                Set<AttributeValue> attributeValues = extractAttributeValues( object );
-
-                CollectionUtils.forEach( attributeValues, new Function1<AttributeValue>()
-                {
-                    @Override
-                    public void apply( AttributeValue attributeValue )
-                    {
-                        attributeService.deleteAttributeValue( attributeValue );
-                    }
-                } );
-            }
-        }
-
         private Set<ProgramStageDataElement> extractProgramStageDataElements( T object )
         {
             Set<ProgramStageDataElement> programStageDataElements = Sets.newHashSet();
@@ -422,6 +431,25 @@
             return programStageDataElements;
         }
 
+        private void deleteProgramTrackedEntityAttributes( T object )
+        {
+            Set<ProgramTrackedEntityAttribute> programTrackedEntityAttributes = extractProgramTrackedEntityAttributes( object );
+
+            CollectionUtils.forEach( programTrackedEntityAttributes, new Function1<ProgramTrackedEntityAttribute>()
+            {
+                @Override
+                public void apply( ProgramTrackedEntityAttribute programTrackedEntityAttribute )
+                {
+                    sessionFactory.getCurrentSession().delete( programTrackedEntityAttribute );
+                }
+            } );
+        }
+
+        private void saveProgramTrackedEntityAttributes( T object, Set<ProgramTrackedEntityAttribute> programTrackedEntityAttributes )
+        {
+
+        }
+
         private Set<ProgramTrackedEntityAttribute> extractProgramTrackedEntityAttributes( T object )
         {
             Set<ProgramTrackedEntityAttribute> trackedEntityAttributes = Sets.newHashSet();
@@ -434,6 +462,25 @@
 
             return trackedEntityAttributes;
         }
+
+        private void saveProgramStageDataElements( T object, Set<ProgramStageDataElement> programStageDataElements )
+        {
+
+        }
+
+        private void deleteProgramStageDataElements( T object )
+        {
+            Set<ProgramStageDataElement> programStageDataElements = extractProgramStageDataElements( object );
+
+            CollectionUtils.forEach( programStageDataElements, new Function1<ProgramStageDataElement>()
+            {
+                @Override
+                public void apply( ProgramStageDataElement programStageDataElement )
+                {
+                    sessionFactory.getCurrentSession().delete( programStageDataElement );
+                }
+            } );
+        }
     }
 
     //-------------------------------------------------------------------------------------------------------