← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14881: Pushed prune periods maintenance function down to service layer

 

------------------------------------------------------------
revno: 14881
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-04-16 17:03:22 +0200
message:
  Pushed prune periods maintenance function down to service layer
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/maintenance/MaintenanceService.java
  dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/maintenance/DefaultMaintenanceService.java
  dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/maintenance/PerformMaintenanceAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/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/maintenance/MaintenanceService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/maintenance/MaintenanceService.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/maintenance/MaintenanceService.java	2014-04-16 15:03:22 +0000
@@ -43,4 +43,9 @@
      * @return the number of affected rows.
      */
     int deleteZeroDataValues();
+    
+    /**
+     * Deletes periods which do not have data values associated with them.
+     */
+    void prunePeriods();
 }

=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/maintenance/DefaultMaintenanceService.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/maintenance/DefaultMaintenanceService.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/maintenance/DefaultMaintenanceService.java	2014-04-16 15:03:22 +0000
@@ -1,5 +1,11 @@
 package org.hisp.dhis.maintenance;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.common.DeleteNotAllowedException;
+import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.PeriodService;
+
 /*
  * Copyright (c) 2004-2014, University of Oslo
  * All rights reserved.
@@ -35,6 +41,8 @@
 public class DefaultMaintenanceService
     implements MaintenanceService
 {
+    private static final Log log = LogFactory.getLog( DefaultMaintenanceService.class );
+    
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -45,6 +53,14 @@
     {
         this.maintenanceStore = maintenanceStore;
     }
+    
+    private PeriodService periodService;
+
+    public void setPeriodService( PeriodService periodService )
+    {
+        this.periodService = periodService;
+    }
+
     // -------------------------------------------------------------------------
     // MaintenanceService implementation
     // -------------------------------------------------------------------------
@@ -53,4 +69,23 @@
     {
         return maintenanceStore.deleteZeroDataValues();
     }
+    
+    public void prunePeriods()
+    {
+        for ( Period period : periodService.getAllPeriods() )
+        {
+            int periodId = period.getId();
+            
+            try
+            {
+                periodService.deletePeriod( period );
+                
+                log.info( "Deleted period with id: " + periodId );
+            }
+            catch ( DeleteNotAllowedException ex )
+            {
+                log.debug( "Period has associated objects and could not be deleted: " + periodId );
+            }
+        }
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml	2014-01-30 16:10:35 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml	2014-04-16 15:03:22 +0000
@@ -45,6 +45,7 @@
 
   <bean id="org.hisp.dhis.maintenance.MaintenanceService" class="org.hisp.dhis.maintenance.DefaultMaintenanceService">
     <property name="maintenanceStore" ref="org.hisp.dhis.maintenance.MaintenanceStore" />
+    <property name="periodService" ref="org.hisp.dhis.period.PeriodService" />
   </bean>
   
   <!-- Statistics -->

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/maintenance/PerformMaintenanceAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/maintenance/PerformMaintenanceAction.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/maintenance/PerformMaintenanceAction.java	2014-04-16 15:03:22 +0000
@@ -34,13 +34,10 @@
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.aggregation.AggregatedDataValueService;
 import org.hisp.dhis.analytics.AnalyticsTableService;
-import org.hisp.dhis.common.DeleteNotAllowedException;
 import org.hisp.dhis.completeness.DataSetCompletenessService;
 import org.hisp.dhis.dataelement.DataElementCategoryService;
 import org.hisp.dhis.datamart.DataMartManager;
 import org.hisp.dhis.maintenance.MaintenanceService;
-import org.hisp.dhis.period.Period;
-import org.hisp.dhis.period.PeriodService;
 import org.hisp.dhis.user.CurrentUserService;
 
 import com.opensymphony.xwork2.Action;
@@ -98,13 +95,6 @@
         this.dataMartManager = dataMartManager;
     }
 
-    private PeriodService periodService;
-
-    public void setPeriodService( PeriodService periodService )
-    {
-        this.periodService = periodService;
-    }
-    
     private CurrentUserService currentUserService;
 
     public void setCurrentUserService( CurrentUserService currentUserService )
@@ -231,7 +221,7 @@
         
         if ( prunePeriods )
         {
-            prunePeriods();
+            maintenanceService.prunePeriods();
             
             log.info( "'" + username + "': Pruned periods" );
         }
@@ -245,29 +235,4 @@
         
         return SUCCESS;
     }
-
-    // -------------------------------------------------------------------------
-    // Supportive methods
-    // -------------------------------------------------------------------------
-    
-    private void prunePeriods()
-    {
-        for ( Period period : periodService.getAllPeriods() )
-        {
-            int periodId = period.getId();
-            
-            try
-            {
-                periodService.deletePeriod( period );
-                
-                log.info( "Deleted period with id: " + periodId );
-            }
-            catch ( DeleteNotAllowedException ex )
-            {
-                log.debug( "Period has associated objects and could not be deleted: " + periodId );
-            }
-        }
-        
-        log.info( "Period pruning done" );
-    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/META-INF/dhis/beans.xml	2013-10-03 09:11:19 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/META-INF/dhis/beans.xml	2014-04-16 15:03:22 +0000
@@ -12,7 +12,6 @@
     <property name="completenessService" ref="compulsoryDataCompletenessService" />
     <property name="aggregatedDataValueService" ref="org.hisp.dhis.aggregation.AggregatedDataValueService" />
     <property name="dataMartManager" ref="org.hisp.dhis.datamart.DataMartManager" />
-    <property name="periodService" ref="org.hisp.dhis.period.PeriodService" />
     <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
     <property name="categoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
   </bean>