← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6670: More importer bugs squashed. PeriodType now works correctly.

 

------------------------------------------------------------
revno: 6670
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2012-04-21 14:45:47 +0300
message:
  More importer bugs squashed. PeriodType now works correctly.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapView.java
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.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-04-21 09:33:17 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java	2012-04-21 11:45:47 +0000
@@ -519,8 +519,7 @@
         {
             DataSet dataSet = (DataSet) other;
 
-            // FIXME
-            // periodType = dataSet.getPeriodType() == null ? periodType : dataSet.getPeriodType();
+            periodType = dataSet.getPeriodType() == null ? periodType : dataSet.getPeriodType();
             sortOrder = dataSet.getSortOrder() == null ? sortOrder : dataSet.getSortOrder();
             mobile = dataSet.isMobile();
             dataEntryForm = dataSet.getDataEntryForm() == null ? dataEntryForm : dataSet.getDataEntryForm();

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapView.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapView.java	2012-04-11 07:28:51 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapView.java	2012-04-21 11:45:47 +0000
@@ -36,6 +36,8 @@
 import org.hisp.dhis.common.BaseIdentifiableObject;
 import org.hisp.dhis.common.Dxf2Namespace;
 import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.common.adapter.JacksonPeriodDeserializer;
+import org.hisp.dhis.common.adapter.JacksonPeriodSerializer;
 import org.hisp.dhis.common.adapter.JacksonPeriodTypeDeserializer;
 import org.hisp.dhis.common.adapter.JacksonPeriodTypeSerializer;
 import org.hisp.dhis.common.view.DetailedView;
@@ -281,7 +283,8 @@
     }
 
     @JsonProperty
-    @JsonSerialize( as = BaseIdentifiableObject.class )
+    @JsonSerialize( using = JacksonPeriodSerializer.class )
+    @JsonDeserialize( using = JacksonPeriodDeserializer.class )
     @JsonView( {DetailedView.class, ExportView.class} )
     @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE )
     public Period getPeriod()

=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java	2012-04-21 08:25:31 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java	2012-04-21 11:45:47 +0000
@@ -75,12 +75,13 @@
         // Imports.. this could be made even more generic, just need to make sure that everything is imported in
         // the correct order
 
-        // FIXME this is not currently in the "correct" order
-/*        doImport( metaData.getConcepts(), importOptions, importSummary );
+        doImport( metaData.getConcepts(), importOptions, importSummary );
         doImport( metaData.getConstants(), importOptions, importSummary );
         doImport( metaData.getDocuments(), importOptions, importSummary );
         doImport( metaData.getAttributeTypes(), importOptions, importSummary );
         doImport( metaData.getOptionSets(), importOptions, importSummary );
+
+        /*
         doImport( metaData.getCategories(), importOptions, importSummary );
         doImport( metaData.getCategoryCombos(), importOptions, importSummary );
         doImport( metaData.getCategoryOptions(), importOptions, importSummary );
@@ -88,16 +89,13 @@
         doImport( metaData.getDataElements(), importOptions, importSummary );
         doImport( metaData.getDataElementGroups(), importOptions, importSummary );
         doImport( metaData.getDataElementGroupSets(), importOptions, importSummary );
-*/
+        */
 
-/*
         doImport( metaData.getIndicatorTypes(), importOptions, importSummary );
         doImport( metaData.getIndicators(), importOptions, importSummary );
         doImport( metaData.getIndicatorGroups(), importOptions, importSummary );
         doImport( metaData.getIndicatorGroupSets(), importOptions, importSummary );
-*/
 
-/*
         doImport( metaData.getMaps(), importOptions, importSummary );
         doImport( metaData.getMapLegends(), importOptions, importSummary );
         doImport( metaData.getMapLegendSets(), importOptions, importSummary );
@@ -111,15 +109,15 @@
         doImport( metaData.getUsers(), importOptions, importSummary );
         doImport( metaData.getUserGroups(), importOptions, importSummary );
         doImport( metaData.getUserAuthorityGroups(), importOptions, importSummary );
-*/
-
-//        doImport( metaData.getValidationRules(), importOptions, importSummary );
-//        doImport( metaData.getValidationRuleGroups(), importOptions, importSummary );
-
-//        doImport( metaData.getDataDictionaries(), importOptions, importSummary );
-//        doImport( metaData.getReports(), importOptions, importSummary );
-//        doImport( metaData.getReportTables(), importOptions, importSummary );
-//        doImport( metaData.getCharts(), importOptions, importSummary );
+
+        doImport( metaData.getValidationRules(), importOptions, importSummary );
+        doImport( metaData.getValidationRuleGroups(), importOptions, importSummary );
+
+        doImport( metaData.getDataDictionaries(), importOptions, importSummary );
+        doImport( metaData.getReports(), importOptions, importSummary );
+        doImport( metaData.getReportTables(), importOptions, importSummary );
+        doImport( metaData.getCharts(), importOptions, importSummary );
+
         doImport( metaData.getDataSets(), importOptions, importSummary );
 
         return importSummary;

=== 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-04-21 08:25:31 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java	2012-04-21 11:45:47 +0000
@@ -41,6 +41,7 @@
 import org.hisp.dhis.organisationunit.comparator.OrganisationUnitComparator;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodService;
+import org.hisp.dhis.period.PeriodStore;
 import org.hisp.dhis.period.PeriodType;
 import org.hisp.dhis.system.util.ReflectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -68,6 +69,9 @@
     @Autowired
     private PeriodService periodService;
 
+    @Autowired
+    private PeriodStore periodStore;
+
     //-------------------------------------------------------------------------------------------------------
     // Constructor
     //-------------------------------------------------------------------------------------------------------
@@ -107,6 +111,8 @@
 
     protected Map<String, T> shortNameMap;
 
+    private Map<String, PeriodType> periodTypeMap = new HashMap<String, PeriodType>();
+
     //-------------------------------------------------------------------------------------------------------
     // Generic implementations of newObject and updatedObject
     //-------------------------------------------------------------------------------------------------------
@@ -187,7 +193,9 @@
             if ( PeriodType.class.isAssignableFrom( field.getType() ) )
             {
                 PeriodType periodType = ReflectionUtils.invokeGetterMethod( field.getName(), object );
-                periodType = periodService.reloadPeriodType( periodType ); // FIXME
+
+                periodType = periodTypeMap.get( periodType.getName() );
+
                 ReflectionUtils.invokeSetterMethod( field.getName(), object, periodType );
             }
         }
@@ -208,6 +216,8 @@
             return conflicts;
         }
 
+        populatePeriodTypeMap();
+
         reset();
 
         // FIXME a bit too static.. implement "pre handler" for types?
@@ -233,6 +243,7 @@
     @Override
     public ImportConflict importObject( T object, ImportOptions options )
     {
+        populatePeriodTypeMap();
         reset();
 
         return importObjectLocal( object, options );
@@ -254,6 +265,14 @@
     // Protected methods
     //-------------------------------------------------------------------------------------------------------
 
+    protected void populatePeriodTypeMap()
+    {
+        for ( PeriodType periodType : periodStore.getAllPeriodTypes() )
+        {
+            periodTypeMap.put( periodType.getName(), periodType );
+        }
+    }
+
     protected void updateIdMaps( T object )
     {
         if ( object.getUid() != null )