← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15461: various fixes to importer, should not be used for tracker objects yet

 

------------------------------------------------------------
revno: 15461
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-05-28 21:02:46 +0200
message:
  various fixes to importer, should not be used for tracker objects yet
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/EventReportSchemaDescriptor.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java
  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/resources/META-INF/dhis/beans.xml


--
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/Program.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java	2014-05-26 13:29:12 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java	2014-05-28 19:02:46 +0000
@@ -88,6 +88,7 @@
      */
     private String dateOfIncidentDescription;
 
+    @Scanned
     private Set<OrganisationUnit> organisationUnits = new HashSet<OrganisationUnit>();
 
     private Set<ProgramInstance> programInstances = new HashSet<ProgramInstance>();

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/EventReportSchemaDescriptor.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/EventReportSchemaDescriptor.java	2014-05-28 11:48:43 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/EventReportSchemaDescriptor.java	2014-05-28 19:02:46 +0000
@@ -51,7 +51,7 @@
         Schema schema = new Schema( EventReport.class, SINGULAR, PLURAL );
         schema.setApiEndpoint( API_ENDPOINT );
         schema.setShareable( true );
-        schema.setOrder( 137 );
+        schema.setOrder( 160 );
 
         schema.getAuthorities().add( new Authority( AuthorityType.CREATE_PUBLIC, Lists.newArrayList( "F_EVENTREPORT_PUBLIC_ADD" ) ) );
         schema.getAuthorities().add( new Authority( AuthorityType.EXTERNALIZE, Lists.newArrayList( "F_EVENTREPORT_EXTERNAL" ) ) );

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java	2014-05-28 12:38:13 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java	2014-05-28 19:02:46 +0000
@@ -177,6 +177,8 @@
 
                         ImportTypeSummary importTypeSummary = doImport( user, objects, importOptions );
 
+                        sessionFactory.getCurrentSession().flush();
+
                         if ( importTypeSummary != null )
                         {
                             importSummary.getImportTypeSummaries().add( importTypeSummary );

=== 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-26 14:44:19 +0000
+++ 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
@@ -28,6 +28,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import com.google.common.collect.Sets;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hibernate.SessionFactory;
@@ -56,6 +57,9 @@
 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.ProgramTrackedEntityAttribute;
 import org.hisp.dhis.system.util.CollectionUtils;
 import org.hisp.dhis.system.util.ReflectionUtils;
 import org.hisp.dhis.system.util.functional.Function1;
@@ -114,7 +118,7 @@
     @Autowired
     private AclService aclService;
 
-    @Autowired(required = false)
+    @Autowired( required = false )
     private List<ObjectHandler<T>> objectHandlers;
 
     //-------------------------------------------------------------------------------------------------------
@@ -139,16 +143,19 @@
     // keeping this internal for now, might be split into several classes
     private class NonIdentifiableObjects
     {
-        private Set<AttributeValue> attributeValues = new HashSet<AttributeValue>();
+        private Set<AttributeValue> attributeValues = Sets.newHashSet();
 
         private Expression leftSide;
         private Expression rightSide;
 
-        private Set<DataElementOperand> compulsoryDataElementOperands = new HashSet<DataElementOperand>();
-        private Set<DataElementOperand> greyedFields = new HashSet<DataElementOperand>();
+        private Set<DataElementOperand> compulsoryDataElementOperands = Sets.newHashSet();
+        private Set<DataElementOperand> greyedFields = Sets.newHashSet();
 
         private DataEntryForm dataEntryForm;
 
+        private Set<ProgramStageDataElement> programStageDataElements = Sets.newHashSet();
+        private Set<ProgramTrackedEntityAttribute> programTrackedEntityAttributes = Sets.newHashSet();
+
         public void extract( T object )
         {
             attributeValues = extractAttributeValues( object );
@@ -157,6 +164,8 @@
             dataEntryForm = extractDataEntryForm( object, "dataEntryForm" );
             compulsoryDataElementOperands = extractDataElementOperands( object, "compulsoryDataElementOperands" );
             greyedFields = extractDataElementOperands( object, "greyedFields" );
+            programStageDataElements = extractProgramStageDataElements( object );
+            programTrackedEntityAttributes = extractProgramTrackedEntityAttributes( object );
         }
 
         public void delete( T object )
@@ -399,6 +408,32 @@
                 } );
             }
         }
+
+        private Set<ProgramStageDataElement> extractProgramStageDataElements( T object )
+        {
+            Set<ProgramStageDataElement> programStageDataElements = Sets.newHashSet();
+
+            if ( ReflectionUtils.findGetterMethod( "programStageDataElements", object ) != null )
+            {
+                programStageDataElements = ReflectionUtils.invokeGetterMethod( "programStageDataElements", object );
+                ReflectionUtils.invokeSetterMethod( "programStageDataElements", object, new HashSet<ProgramStageDataElement>() );
+            }
+
+            return programStageDataElements;
+        }
+
+        private Set<ProgramTrackedEntityAttribute> extractProgramTrackedEntityAttributes( T object )
+        {
+            Set<ProgramTrackedEntityAttribute> trackedEntityAttributes = Sets.newHashSet();
+
+            if ( ReflectionUtils.isCollection( "attributes", object, ProgramTrackedEntityAttribute.class ) )
+            {
+                trackedEntityAttributes = ReflectionUtils.invokeGetterMethod( "attributes", object );
+                ReflectionUtils.invokeSetterMethod( "attributes", object, new HashSet<ProgramTrackedEntityAttribute>() );
+            }
+
+            return trackedEntityAttributes;
+        }
     }
 
     //-------------------------------------------------------------------------------------------------------
@@ -924,8 +959,6 @@
                 }
             }
 
-            // if ( !options.isDryRun() ) { }
-            // TODO why do we have to invoke the setter on dryRun?
             if ( !options.isDryRun() )
             {
                 ReflectionUtils.invokeSetterMethod( field.getName(), object, reference );

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/resources/META-INF/dhis/beans.xml	2014-05-28 16:54:51 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/resources/META-INF/dhis/beans.xml	2014-05-28 19:02:46 +0000
@@ -212,6 +212,7 @@
   </bean>
 
   <!-- register tracker importers -->
+
   <bean id="eventReportImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultIdentifiableObjectImporter" scope="prototype">
     <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.eventreport.EventReport" />
   </bean>