← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6667: Exposed reloadPeriodType through store/service (currently not working for import). Added TableAlt...

 

------------------------------------------------------------
revno: 6667
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2012-04-21 11:25:31 +0300
message:
  Exposed reloadPeriodType through store/service (currently not working for import). Added TableAlteror stmt for removing unused table 'indicator_indicatorgroupsetmembers'
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodStore.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
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/period/DefaultPeriodService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/period/hibernate/HibernatePeriodStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ConstantController.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-18 20:24:12 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java	2012-04-21 08:25:31 +0000
@@ -517,11 +517,12 @@
         {
             DataSet dataSet = (DataSet) other;
 
-            periodType = periodType != null ? periodType : dataSet.getPeriodType();
-            sortOrder = sortOrder != null ? sortOrder : dataSet.getSortOrder();
+            // FIXME
+            // periodType = dataSet.getPeriodType() == null ? periodType : dataSet.getPeriodType();
+            sortOrder = dataSet.getSortOrder() == null ? sortOrder : dataSet.getSortOrder();
             mobile = dataSet.isMobile();
-            dataEntryForm = dataEntryForm != null ? dataEntryForm : dataSet.getDataEntryForm();
-            version = version != null ? version : dataSet.getVersion();
+            dataEntryForm = dataSet.getDataEntryForm() == null ? dataEntryForm : dataSet.getDataEntryForm();
+            version = dataSet.getVersion() == null ? version : dataSet.getVersion();
             expiryDays = dataSet.getExpiryDays();
 
             removeAllDataElements();

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodService.java	2012-02-07 13:00:52 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodService.java	2012-04-21 08:25:31 +0000
@@ -299,7 +299,6 @@
      */
     PeriodType getPeriodTypeByName( String name );
     
-    
     /**
      * Returns a PeriodType represented by the given Class.
      * 
@@ -308,4 +307,12 @@
      */
     PeriodType getPeriodTypeByClass( Class<? extends PeriodType> periodType );  
     
+    /**
+     * Checks if the given periodType is associated with the current session and loads
+     * it if not. Null is returned if the period does not exist.
+     *
+     * @param periodType the Period to reload.
+     * @return a Period.
+     */
+    PeriodType reloadPeriodType( PeriodType periodType );
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodStore.java	2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodStore.java	2012-04-21 08:25:31 +0000
@@ -27,15 +27,15 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+
 import java.util.Collection;
 import java.util.Date;
 
-import org.hisp.dhis.dataelement.DataElement;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-
 /**
  * Defines the functionality for persisting Periods and PeriodTypes.
- * 
+ *
  * @author Torgeir Lorange Ostby
  * @version $Id: PeriodStore.java 5983 2008-10-17 17:42:44Z larshelg $
  */
@@ -49,7 +49,7 @@
 
     /**
      * Adds a Period.
-     * 
+     *
      * @param period the Period to add.
      * @return a generated unique id of the added Period.
      */
@@ -57,14 +57,14 @@
 
     /**
      * Deletes a Period.
-     * 
+     *
      * @param period the Period to delete.
      */
     void deletePeriod( Period period );
 
     /**
      * Returns a Period.
-     * 
+     *
      * @param id the id of the Period to return.
      * @return the Period with the given id, or null if no match.
      */
@@ -72,9 +72,9 @@
 
     /**
      * Returns a Period.
-     * 
-     * @param startDate the start date of the Period.
-     * @param endDate the end date of the Period.
+     *
+     * @param startDate  the start date of the Period.
+     * @param endDate    the end date of the Period.
      * @param periodType the PeriodType of the Period
      * @return the Period matching the dates and periodtype, or null if no match.
      */
@@ -82,27 +82,27 @@
 
     /**
      * Returns all persisted Periods.
-     * 
+     *
      * @return all persisted Periods.
      */
     Collection<Period> getAllPeriods();
 
     /**
      * Returns a Period.
-     * 
-     * @param startDate the start date of the Period.
-     * @param endDate the end date of the Period.
+     *
+     * @param startDate  the start date of the Period.
+     * @param endDate    the end date of the Period.
      * @param periodType the PeriodType of the Period
      * @return the Period matching the dates and periodtype, or null if no match.
      */
     Period getPeriodFromDates( Date startDate, Date endDate, PeriodType periodType );
-    
+
     /**
      * Returns all Periods with start date after or equal the specified start
      * date and end date before or equal the specified end date.
-     * 
+     *
      * @param startDate the ultimate start date.
-     * @param endDate the ultimate end date.
+     * @param endDate   the ultimate end date.
      * @return a collection of all Periods with start date after or equal the
      *         specified start date and end date before or equal the specified
      *         end date, or an empty collection if no Periods match.
@@ -110,13 +110,13 @@
     Collection<Period> getPeriodsBetweenDates( Date startDate, Date endDate );
 
     /**
-     * Returns all Periods of the specified PeriodType with start date after or 
-     * equal the specified start date and end date before or equal the specified 
+     * Returns all Periods of the specified PeriodType with start date after or
+     * equal the specified start date and end date before or equal the specified
      * end date.
-     * 
+     *
      * @param periodType the PeriodType.
-     * @param startDate the ultimate start date.
-     * @param endDate the ultimate end date.
+     * @param startDate  the ultimate start date.
+     * @param endDate    the ultimate end date.
      * @return a collection of all Periods with start date after or equal the
      *         specified start date and end date before or equal the specified
      *         end date, or an empty collection if no Periods match.
@@ -124,53 +124,53 @@
     Collection<Period> getPeriodsBetweenDates( PeriodType periodType, Date startDate, Date endDate );
 
     Collection<Period> getPeriodsBetweenOrSpanningDates( Date startDate, Date endDate );
-    
+
     /**
      * Returns all intersecting Periods between the startDate and endDate based on PeriodType
      * For example if the startDate is 2007-05-01 and endDate is 2007-08-01 and periodType is Quartely
      * then it retuns the periods for Q2,Q3
-     *  
+     *
      * @param periodType is the ultimate period type
-     * @param startDate is intercepting startDate
-     * @param endDate is intercepting endDate
+     * @param startDate  is intercepting startDate
+     * @param endDate    is intercepting endDate
      * @return
      */
-    Collection<Period> getIntersectingPeriodsByPeriodType(PeriodType periodType, Date startDate, Date endDate);
-    
+    Collection<Period> getIntersectingPeriodsByPeriodType( PeriodType periodType, Date startDate, Date endDate );
+
     /**
      * Returns Periods where at least one its days is between the given start date and end date.
-     * 
+     *
      * @param startDate the start date.
-     * @param endDate the end date.
+     * @param endDate   the end date.
      * @return Periods where at least one its days is between the given start date and end date.
      */
     Collection<Period> getIntersectingPeriods( Date startDate, Date endDate );
-    
+
     /**
      * Returns all Periods with a given PeriodType.
-     * 
+     *
      * @param periodType the PeriodType of the Periods to return.
      * @return all Periods with the given PeriodType, or an empty collection if
      *         no Periods match.
      */
     Collection<Period> getPeriodsByPeriodType( PeriodType periodType );
-    
+
     /**
      * Returns all intersecting Periods for the given Period which have assosiated DataValues for
      * the given collection of DataElements and Sources.
-     * 
-     * @param period the Period.
+     *
+     * @param period       the Period.
      * @param dataElements the collection of DataElements.
-     * @param sources the collection of Sources.
+     * @param sources      the collection of Sources.
      * @return all intersecting Periods for the given Period which have assosiated DataValues for
      *         the given collection of DataElements and Sources.
      */
     Collection<Period> getPeriods( Period period, Collection<DataElement> dataElements, Collection<OrganisationUnit> sources );
-    
+
     /**
      * Checks if the given period is associated with the current session and loads
      * it if not. Null is returned if the period does not exist.
-     * 
+     *
      * @param period the Period.
      * @return the Period.
      */
@@ -180,19 +180,19 @@
      * Checks if the given period is associated with the current session and loads
      * it if not. The period is persisted if it does not exist. The persisted Period
      * is returned.
-     * 
+     *
      * @param period the Period.
      * @return the persisted Period.
      */
     Period reloadForceAddPeriod( Period period );
-    
+
     // -------------------------------------------------------------------------
     // PeriodType
     // -------------------------------------------------------------------------
 
     /**
      * Adds a PeriodType.
-     * 
+     *
      * @param periodType the PeriodType to add.
      * @return a generated unique id of the added PeriodType.
      */
@@ -200,14 +200,14 @@
 
     /**
      * Deletes a PeriodType.
-     * 
+     *
      * @param periodType the PeriodType to delete.
      */
     void deletePeriodType( PeriodType periodType );
 
     /**
      * Returns a PeriodType.
-     * 
+     *
      * @param id the id of the PeriodType to return.
      * @return the PeriodType with the given id, or null if no match.
      */
@@ -215,7 +215,7 @@
 
     /**
      * Returns the persisted instance of a given PeriodType.
-     * 
+     *
      * @param periodType the PeriodType class of the instance to return.
      * @return
      */
@@ -223,9 +223,18 @@
 
     /**
      * Returns all PeriodTypes.
-     * 
+     *
      * @return a collection of all PeriodTypes, or an empty collection if there
      *         are no PeriodTypes.
      */
     Collection<PeriodType> getAllPeriodTypes();
+
+    /**
+     * Checks if the given periodType is associated with the current session and loads
+     * it if not. Null is returned if the period does not exist.
+     *
+     * @param periodType the PeriodType.
+     * @return the Period.
+     */
+    PeriodType reloadPeriodType( PeriodType periodType );
 }

=== 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-20 18:44:27 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java	2012-04-21 08:25:31 +0000
@@ -76,7 +76,7 @@
         // 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 );
@@ -88,10 +88,16 @@
         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 );
@@ -105,12 +111,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-20 18:31:48 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java	2012-04-21 08:25:31 +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.PeriodType;
 import org.hisp.dhis.system.util.ReflectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 
@@ -138,6 +139,7 @@
 
         updateIdentifiableObjectCollections( object, identifiableObjectCollections );
 
+        updatePeriodTypes( object );
         manager.update( object );
         updateIdMaps( object );
 
@@ -168,6 +170,8 @@
         updateIdentifiableObjectCollections( object, scanIdentifiableObjectCollections( object ) );
 
         oldObject.mergeWith( object );
+        updatePeriodTypes( oldObject );
+
         manager.update( oldObject );
 
         log.info( "Update successful." );
@@ -175,6 +179,20 @@
         return null;
     }
 
+    // FIXME to static ATM, should be refactor out.. "type handler", not idObject
+    private void updatePeriodTypes( T object )
+    {
+        for ( Field field : object.getClass().getDeclaredFields() )
+        {
+            if ( PeriodType.class.isAssignableFrom( field.getType() ) )
+            {
+                PeriodType periodType = ReflectionUtils.invokeGetterMethod( field.getName(), object );
+                periodType = periodService.reloadPeriodType( periodType ); // FIXME
+                ReflectionUtils.invokeSetterMethod( field.getName(), object, periodType );
+            }
+        }
+    }
+
     //-------------------------------------------------------------------------------------------------------
     // Importer<T> Implementation
     //-------------------------------------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/period/DefaultPeriodService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/period/DefaultPeriodService.java	2012-02-16 15:07:04 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/period/DefaultPeriodService.java	2012-04-21 08:25:31 +0000
@@ -27,15 +27,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -44,6 +35,8 @@
 import org.hisp.dhis.system.util.FilterUtils;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.*;
+
 /**
  * @author Kristian Nordal
  * @version $Id: DefaultPeriodService.java 5983 2008-10-17 17:42:44Z larshelg $
@@ -61,7 +54,7 @@
     public void setPeriodStore( PeriodStore periodStore )
     {
         this.periodStore = periodStore;
-    }   
+    }
 
     // -------------------------------------------------------------------------
     // Period
@@ -151,16 +144,16 @@
     {
         return periodStore.getIntersectingPeriods( startDate, endDate );
     }
-    
+
     public Collection<Period> getIntersectionPeriods( Collection<Period> periods )
     {
         Set<Period> intersecting = new HashSet<Period>();
-        
+
         for ( Period period : periods )
         {
             intersecting.addAll( getIntersectingPeriods( period.getStartDate(), period.getEndDate() ) );
         }
-        
+
         return intersecting;
     }
 
@@ -205,7 +198,7 @@
     }
 
     public Collection<Period> getPeriods( Period period, Collection<DataElement> dataElements,
-        Collection<OrganisationUnit> sources )
+                                          Collection<OrganisationUnit> sources )
     {
         return periodStore.getPeriods( period, dataElements, sources );
     }
@@ -227,7 +220,7 @@
         List<Period> periods = new ArrayList<Period>( historyLength );
 
         lastPeriod = periodStore.reloadForceAddPeriod( lastPeriod );
-        
+
         CalendarPeriodType periodType = (CalendarPeriodType) lastPeriod.getPeriodType();
 
         Period p = new Period();
@@ -289,4 +282,9 @@
     {
         return periodStore.getPeriodType( periodType );
     }
+
+    public PeriodType reloadPeriodType( PeriodType periodType )
+    {
+        return periodStore.reloadPeriodType( periodType );
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/period/hibernate/HibernatePeriodStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/period/hibernate/HibernatePeriodStore.java	2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/period/hibernate/HibernatePeriodStore.java	2012-04-21 08:25:31 +0000
@@ -296,11 +296,7 @@
         return session.createCriteria( PeriodType.class ).setCacheable( true ).list();
     }
 
-    // -------------------------------------------------------------------------
-    // Supportive methods
-    // -------------------------------------------------------------------------
-
-    private PeriodType reloadPeriodType( PeriodType periodType )
+    public PeriodType reloadPeriodType( PeriodType periodType )
     {
         Session session = sessionFactory.getCurrentSession();
 
@@ -313,7 +309,7 @@
 
         if ( reloadedPeriodType == null )
         {
-            throw new IllegalArgumentException( "The PeriodType referenced by the " + "Period is not in database: "
+            throw new IllegalArgumentException( "The PeriodType referenced by the Period is not in database: "
                 + periodType.getName() );
         }
 

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java	2012-04-20 07:51:28 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java	2012-04-21 08:25:31 +0000
@@ -103,6 +103,7 @@
         executeSql( "DROP TABLE datasetlocksource" );
         executeSql( "DROP TABLE datasetlock" );
         executeSql( "DROP TABLE datasetlockexceptions" );
+        executeSql( "DROP TABLE indicator_indicatorgroupsetmembers" );
         executeSql( "ALTER TABLE dataelementcategoryoption drop column categoryid" );
         executeSql( "ALTER TABLE reporttable DROP column dimension_type" );
         executeSql( "ALTER TABLE reporttable DROP column dimensiontype" );

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ConstantController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ConstantController.java	2012-03-22 15:04:58 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ConstantController.java	2012-04-21 08:25:31 +0000
@@ -33,6 +33,7 @@
 import org.hisp.dhis.constant.Constant;
 import org.hisp.dhis.constant.ConstantService;
 import org.hisp.dhis.constant.Constants;
+import org.hisp.dhis.dxf2.metadata.MetaData;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.security.access.prepost.PreAuthorize;