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

« back to all changes in this revision

Viewing changes to dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/DataMartExportDeletionHandler.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.datamart;
 
2
 
 
3
import org.hisp.dhis.dataelement.DataElement;
 
4
import org.hisp.dhis.indicator.Indicator;
 
5
import org.hisp.dhis.source.Source;
 
6
import org.hisp.dhis.system.deletion.DeletionHandler;
 
7
 
 
8
/*
 
9
 * Copyright (c) 2004-2007, University of Oslo
 
10
 * All rights reserved.
 
11
 *
 
12
 * Redistribution and use in source and binary forms, with or without
 
13
 * modification, are permitted provided that the following conditions are met:
 
14
 * * Redistributions of source code must retain the above copyright notice, this
 
15
 *   list of conditions and the following disclaimer.
 
16
 * * Redistributions in binary form must reproduce the above copyright notice,
 
17
 *   this list of conditions and the following disclaimer in the documentation
 
18
 *   and/or other materials provided with the distribution.
 
19
 * * Neither the name of the HISP project nor the names of its contributors may
 
20
 *   be used to endorse or promote products derived from this software without
 
21
 *   specific prior written permission.
 
22
 *
 
23
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 
24
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 
25
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
26
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 
27
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 
28
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 
29
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 
30
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
31
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 
32
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
33
 */
 
34
 
 
35
/**
 
36
 * @author Lars Helge Overland
 
37
 * @version $Id$
 
38
 */
 
39
public class DataMartExportDeletionHandler
 
40
    extends DeletionHandler
 
41
{
 
42
    // -------------------------------------------------------------------------
 
43
    // Dependencies
 
44
    // -------------------------------------------------------------------------
 
45
 
 
46
    private DataMartExportService dataMartExportService;
 
47
 
 
48
    public void setDataMartExportService( DataMartExportService dataMartExportService )
 
49
    {
 
50
        this.dataMartExportService = dataMartExportService;
 
51
    }
 
52
 
 
53
    // -------------------------------------------------------------------------
 
54
    // DeletionHandler implementation
 
55
    // -------------------------------------------------------------------------
 
56
 
 
57
    @Override
 
58
    public String getClassName()
 
59
    {
 
60
        return DataMartExport.class.getSimpleName();
 
61
    }
 
62
    
 
63
    @Override
 
64
    public boolean allowDeleteDataElement( DataElement dataElement )
 
65
    {
 
66
        for ( DataMartExport export : dataMartExportService.getAllDataMartExports() )
 
67
        {
 
68
            if ( export.getDataElements().remove( dataElement ) )
 
69
            {
 
70
                dataMartExportService.saveDataMartExport( export );
 
71
            }
 
72
        }
 
73
        
 
74
        return true;
 
75
    }
 
76
    
 
77
    @Override
 
78
    public boolean allowDeleteIndicator( Indicator indicator )
 
79
    {
 
80
        for ( DataMartExport export : dataMartExportService.getAllDataMartExports() )
 
81
        {
 
82
            if ( export.getIndicators().remove( indicator ) )
 
83
            {
 
84
                dataMartExportService.saveDataMartExport( export );
 
85
            }
 
86
        }
 
87
        
 
88
        return true;
 
89
    }
 
90
    
 
91
    @Override
 
92
    public boolean allowDeleteSource( Source source )
 
93
    {
 
94
        for ( DataMartExport export : dataMartExportService.getAllDataMartExports() )
 
95
        {
 
96
            if ( export.getOrganisationUnits().remove( source ) )
 
97
            {
 
98
                dataMartExportService.saveDataMartExport( export );
 
99
            }
 
100
        }
 
101
        
 
102
        return true;
 
103
    }
 
104
}