1
package org.hisp.dhis.dataadmin.action.maintenance;
4
* Copyright (c) 2004-2007, University of Oslo
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions are met:
9
* * Redistributions of source code must retain the above copyright notice, this
10
* list of conditions and the following disclaimer.
11
* * Redistributions in binary form must reproduce the above copyright notice,
12
* this list of conditions and the following disclaimer in the documentation
13
* and/or other materials provided with the distribution.
14
* * Neither the name of the HISP project nor the names of its contributors may
15
* be used to endorse or promote products derived from this software without
16
* specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
22
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
import org.apache.commons.logging.Log;
31
import org.apache.commons.logging.LogFactory;
32
import org.hisp.dhis.common.DeleteNotAllowedException;
33
import org.hisp.dhis.completeness.DataSetCompletenessStore;
34
import org.hisp.dhis.datamart.DataMartStore;
35
import org.hisp.dhis.maintenance.MaintenanceService;
36
import org.hisp.dhis.organisationunit.OrganisationUnitService;
37
import org.hisp.dhis.period.Period;
38
import org.hisp.dhis.period.PeriodService;
40
import com.opensymphony.xwork.ActionSupport;
43
* @author Lars Helge Overland
46
public class PerformMaintenanceAction
49
private static final Log log = LogFactory.getLog( PerformMaintenanceAction.class );
51
// -------------------------------------------------------------------------
53
// -------------------------------------------------------------------------
55
private OrganisationUnitService organisationUnitService;
57
public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
59
this.organisationUnitService = organisationUnitService;
62
private MaintenanceService maintenanceService;
64
public void setMaintenanceService( MaintenanceService maintenanceService )
66
this.maintenanceService = maintenanceService;
69
private DataSetCompletenessStore completenessStore;
71
public void setCompletenessStore( DataSetCompletenessStore completenessStore )
73
this.completenessStore = completenessStore;
76
private DataMartStore dataMartStore;
78
public void setDataMartStore( DataMartStore dataMartStore )
80
this.dataMartStore = dataMartStore;
83
private PeriodService periodService;
85
public void setPeriodService( PeriodService periodService )
87
this.periodService = periodService;
90
// -------------------------------------------------------------------------
92
// -------------------------------------------------------------------------
94
private boolean hierarchyHistory;
96
public void setHierarchyHistory( boolean hierarchyHistory )
98
this.hierarchyHistory = hierarchyHistory;
101
private boolean aggregatedDataValues;
103
public void setAggregatedDataValues( boolean aggregatedDataValues )
105
this.aggregatedDataValues = aggregatedDataValues;
108
private boolean aggregatedIndicatorValues;
110
public void setAggregatedIndicatorValues( boolean aggregatedIndicatorValues )
112
this.aggregatedIndicatorValues = aggregatedIndicatorValues;
115
private boolean zeroValues;
117
public void setZeroValues( boolean zeroValues )
119
this.zeroValues = zeroValues;
122
private boolean dataSetCompleteness;
124
public void setDataSetCompleteness( boolean dataSetCompleteness )
126
this.dataSetCompleteness = dataSetCompleteness;
129
private boolean prunePeriods;
131
public void setPrunePeriods( boolean prunePeriods )
133
this.prunePeriods = prunePeriods;
136
// -------------------------------------------------------------------------
137
// Action implementation
138
// -------------------------------------------------------------------------
140
public String execute()
143
if ( hierarchyHistory )
145
organisationUnitService.clearOrganisationUnitHierarchyHistory();
148
if ( aggregatedDataValues )
150
dataMartStore.deleteAggregatedDataValues();
153
if ( aggregatedIndicatorValues )
155
dataMartStore.deleteAggregatedIndicatorValues();
160
maintenanceService.deleteZeroDataValues();
163
if ( dataSetCompleteness )
165
completenessStore.deleteDataSetCompleteness();
176
// -------------------------------------------------------------------------
177
// Supportive methods
178
// -------------------------------------------------------------------------
180
private void prunePeriods()
182
for ( Period period : periodService.getAllPeriods() )
184
int periodId = period.getId();
188
periodService.deletePeriod( period );
190
log.info( "Deleted period with id: " + periodId );
192
catch ( DeleteNotAllowedException ex )
194
log.debug( "Period has associated objects and could not be deleted: " + periodId );
198
log.info( "Period pruning done" );