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

« back to all changes in this revision

Viewing changes to dhis-2/dhis-web/dhis-web-gis/src/main/java/org/hisp/dhis/gis/action/legend/AddLegendSetAction.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.gis.action.legend;
 
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 java.util.ArrayList;
 
31
import java.util.HashSet;
 
32
import java.util.List;
 
33
import java.util.Set;
 
34
 
 
35
import org.hisp.dhis.gis.Legend;
 
36
import org.hisp.dhis.gis.LegendService;
 
37
import org.hisp.dhis.gis.LegendSet;
 
38
import org.hisp.dhis.indicator.Indicator;
 
39
import org.hisp.dhis.indicator.IndicatorGroup;
 
40
import org.hisp.dhis.indicator.IndicatorService;
 
41
 
 
42
import com.opensymphony.xwork.Action;
 
43
 
 
44
/**
 
45
 * @author Tran Thanh Tri
 
46
 * @version $Id: Feature.java 28-04-2008 16:06:00 $
 
47
 */
 
48
public class AddLegendSetAction
 
49
    implements Action
 
50
{
 
51
    private LegendService legendService;
 
52
 
 
53
    private IndicatorService indicatorService;
 
54
 
 
55
    /*--------------------------------------------------------
 
56
     * Input
 
57
     *--------------------------------------------------------*/
 
58
 
 
59
    private String name;
 
60
 
 
61
    private List<String> selectedList = new ArrayList<String>();
 
62
 
 
63
    private List<String> selectedIndicatorList = new ArrayList<String>();
 
64
 
 
65
    /*--------------------------------------------------------
 
66
     * Ouput
 
67
     *--------------------------------------------------------*/
 
68
 
 
69
    private Set<Legend> legends = new HashSet<Legend>();
 
70
 
 
71
    private Set<Indicator> indicators = new HashSet<Indicator>();
 
72
 
 
73
    private Set<IndicatorGroup> indicatorGroups = new HashSet<IndicatorGroup>();
 
74
 
 
75
    /*--------------------------------------------------------
 
76
     * Getter & Setter
 
77
     *--------------------------------------------------------*/
 
78
 
 
79
    public Set<IndicatorGroup> getIndicatorGroups()
 
80
    {
 
81
        return indicatorGroups;
 
82
    }
 
83
 
 
84
    public Set<Indicator> getIndicators()
 
85
    {
 
86
        return indicators;
 
87
    }
 
88
 
 
89
    public Set<Legend> getLegends()
 
90
    {
 
91
        return legends;
 
92
    }
 
93
 
 
94
    public void setLegendService( LegendService legendService )
 
95
    {
 
96
        this.legendService = legendService;
 
97
    }
 
98
 
 
99
    public void setName( String name )
 
100
    {
 
101
        this.name = name;
 
102
    }
 
103
 
 
104
    public void setSelectedList( List<String> selectedList )
 
105
    {
 
106
        this.selectedList = selectedList;
 
107
    }
 
108
 
 
109
    public void setSelectedIndicatorList( List<String> selectedIndicatorList )
 
110
    {
 
111
        this.selectedIndicatorList = selectedIndicatorList;
 
112
    }
 
113
 
 
114
    public void setIndicatorService( IndicatorService indicatorService )
 
115
    {
 
116
        this.indicatorService = indicatorService;
 
117
    }
 
118
 
 
119
    public String execute()
 
120
        throws Exception
 
121
    {
 
122
        indicators = new HashSet<Indicator>( indicatorService.getAllIndicators() );
 
123
 
 
124
        Set<LegendSet> legendSets = legendService.getAllLegendSet();
 
125
 
 
126
        for ( LegendSet legendSet : legendSets )
 
127
        {
 
128
            indicators.removeAll( legendSet.getIndicators() );
 
129
        }
 
130
 
 
131
        indicatorGroups = new HashSet<IndicatorGroup>( indicatorService.getAllIndicatorGroups() );
 
132
 
 
133
        legends = legendService.getAllLegend();
 
134
 
 
135
        if ( name == null )
 
136
        {
 
137
            return INPUT;
 
138
        }
 
139
        else
 
140
        {
 
141
            name = name.trim();
 
142
            if ( name.length() == 0 )
 
143
            {
 
144
                return INPUT;
 
145
            }
 
146
        }
 
147
 
 
148
        LegendSet legendset = new LegendSet( name );
 
149
 
 
150
        for ( String id : selectedIndicatorList )
 
151
        {
 
152
            Indicator indicator = indicatorService.getIndicator( Integer.parseInt( id ) );
 
153
 
 
154
            legendset.addIndicator( indicator );
 
155
 
 
156
        }
 
157
 
 
158
        for ( String id : selectedList )
 
159
        {
 
160
            Legend legend = legendService.getLegend( Integer.parseInt( id ) );
 
161
            legendset.addLegend( legend );
 
162
        }
 
163
 
 
164
        legendService.addLegendSet( legendset );
 
165
 
 
166
        name = null;
 
167
 
 
168
        return SUCCESS;
 
169
    }
 
170
 
 
171
}