~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/maintenance/PerformMaintenanceAction.java

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.hisp.dhis.dataadmin.action.maintenance;
 
2
 
 
3
/*
 
4
 * Copyright (c) 2004-2007, University of Oslo
 
5
 * All rights reserved.
 
6
 *
 
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.
 
17
 *
 
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.
 
28
 */
 
29
 
 
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;
 
39
 
 
40
import com.opensymphony.xwork.ActionSupport;
 
41
 
 
42
/**
 
43
 * @author Lars Helge Overland
 
44
 * @version $Id$
 
45
 */
 
46
public class PerformMaintenanceAction
 
47
    extends ActionSupport
 
48
{
 
49
    private static final Log log = LogFactory.getLog( PerformMaintenanceAction.class );
 
50
    
 
51
    // -------------------------------------------------------------------------
 
52
    // Dependencies
 
53
    // -------------------------------------------------------------------------
 
54
    
 
55
    private OrganisationUnitService organisationUnitService;
 
56
 
 
57
    public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
 
58
    {
 
59
        this.organisationUnitService = organisationUnitService;
 
60
    }
 
61
    
 
62
    private MaintenanceService maintenanceService;
 
63
 
 
64
    public void setMaintenanceService( MaintenanceService maintenanceService )
 
65
    {
 
66
        this.maintenanceService = maintenanceService;
 
67
    }
 
68
    
 
69
    private DataSetCompletenessStore completenessStore;
 
70
 
 
71
    public void setCompletenessStore( DataSetCompletenessStore completenessStore )
 
72
    {
 
73
        this.completenessStore = completenessStore;
 
74
    }
 
75
    
 
76
    private DataMartStore dataMartStore;
 
77
 
 
78
    public void setDataMartStore( DataMartStore dataMartStore )
 
79
    {
 
80
        this.dataMartStore = dataMartStore;
 
81
    }
 
82
    
 
83
    private PeriodService periodService;
 
84
 
 
85
    public void setPeriodService( PeriodService periodService )
 
86
    {
 
87
        this.periodService = periodService;
 
88
    }
 
89
    
 
90
    // -------------------------------------------------------------------------
 
91
    // Input
 
92
    // -------------------------------------------------------------------------
 
93
    
 
94
    private boolean hierarchyHistory;
 
95
 
 
96
    public void setHierarchyHistory( boolean hierarchyHistory )
 
97
    {
 
98
        this.hierarchyHistory = hierarchyHistory;
 
99
    }
 
100
 
 
101
    private boolean aggregatedDataValues;
 
102
 
 
103
    public void setAggregatedDataValues( boolean aggregatedDataValues )
 
104
    {
 
105
        this.aggregatedDataValues = aggregatedDataValues;
 
106
    }
 
107
 
 
108
    private boolean aggregatedIndicatorValues;
 
109
 
 
110
    public void setAggregatedIndicatorValues( boolean aggregatedIndicatorValues )
 
111
    {
 
112
        this.aggregatedIndicatorValues = aggregatedIndicatorValues;
 
113
    }
 
114
 
 
115
    private boolean zeroValues;
 
116
 
 
117
    public void setZeroValues( boolean zeroValues )
 
118
    {
 
119
        this.zeroValues = zeroValues;
 
120
    }
 
121
    
 
122
    private boolean dataSetCompleteness;
 
123
 
 
124
    public void setDataSetCompleteness( boolean dataSetCompleteness )
 
125
    {
 
126
        this.dataSetCompleteness = dataSetCompleteness;
 
127
    }
 
128
    
 
129
    private boolean prunePeriods;
 
130
 
 
131
    public void setPrunePeriods( boolean prunePeriods )
 
132
    {
 
133
        this.prunePeriods = prunePeriods;
 
134
    }
 
135
    
 
136
    // -------------------------------------------------------------------------
 
137
    // Action implementation
 
138
    // -------------------------------------------------------------------------
 
139
    
 
140
    public String execute() 
 
141
        throws Exception
 
142
    {
 
143
        if ( hierarchyHistory )
 
144
        {
 
145
            organisationUnitService.clearOrganisationUnitHierarchyHistory();
 
146
        }
 
147
        
 
148
        if ( aggregatedDataValues )
 
149
        {
 
150
            dataMartStore.deleteAggregatedDataValues();
 
151
        }
 
152
        
 
153
        if ( aggregatedIndicatorValues )
 
154
        {
 
155
            dataMartStore.deleteAggregatedIndicatorValues();
 
156
        }
 
157
        
 
158
        if ( zeroValues )
 
159
        {
 
160
            maintenanceService.deleteZeroDataValues();
 
161
        }
 
162
        
 
163
        if ( dataSetCompleteness )
 
164
        {
 
165
            completenessStore.deleteDataSetCompleteness();
 
166
        }
 
167
        
 
168
        if ( prunePeriods )
 
169
        {
 
170
            prunePeriods();
 
171
        }
 
172
        
 
173
        return SUCCESS;
 
174
    }
 
175
 
 
176
    // -------------------------------------------------------------------------
 
177
    // Supportive methods
 
178
    // -------------------------------------------------------------------------
 
179
    
 
180
    private void prunePeriods()
 
181
    {
 
182
        for ( Period period : periodService.getAllPeriods() )
 
183
        {
 
184
            int periodId = period.getId();
 
185
            
 
186
            try
 
187
            {
 
188
                periodService.deletePeriod( period );
 
189
                
 
190
                log.info( "Deleted period with id: " + periodId );
 
191
            }
 
192
            catch ( DeleteNotAllowedException ex )
 
193
            {
 
194
                log.debug( "Period has associated objects and could not be deleted: " + periodId );
 
195
            }
 
196
        }
 
197
        
 
198
        log.info( "Period pruning done" );
 
199
    }
 
200
}