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

« back to all changes in this revision

Viewing changes to local/in/dhis-web-dashboard/src/main/java/org/hisp/dhis/dashboard/action/GetDataElementsAction.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.dashboard.action;
 
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.Collections;
 
32
import java.util.Comparator;
 
33
import java.util.Iterator;
 
34
import java.util.List;
 
35
 
 
36
import org.hisp.dhis.dataelement.DataElement;
 
37
import org.hisp.dhis.dataelement.DataElementCategoryCombo;
 
38
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
 
39
import org.hisp.dhis.dataelement.DataElementCategoryOptionComboService;
 
40
import org.hisp.dhis.dataelement.DataElementGroup;
 
41
import org.hisp.dhis.dataelement.DataElementService;
 
42
import org.hisp.dhis.options.displayproperty.DisplayPropertyHandler;
 
43
 
 
44
import com.opensymphony.xwork.ActionSupport;
 
45
 
 
46
/**
 
47
 * @author Lars Helge Overland
 
48
 * @version $Id$
 
49
 */
 
50
public class GetDataElementsAction
 
51
    extends ActionSupport
 
52
{
 
53
    private final static int ALL = 0;
 
54
 
 
55
    // -------------------------------------------------------------------------
 
56
    // Dependencies
 
57
    // -------------------------------------------------------------------------
 
58
 
 
59
    private DataElementService dataElementService;
 
60
 
 
61
    public void setDataElementService( DataElementService dataElementService )
 
62
    {
 
63
        this.dataElementService = dataElementService;
 
64
    }
 
65
    
 
66
    private DataElementCategoryOptionComboService dataElementCategoryOptionComboService;
 
67
 
 
68
    public void setDataElementCategoryOptionComboService(
 
69
        DataElementCategoryOptionComboService dataElementCategoryOptionComboService )
 
70
    {
 
71
        this.dataElementCategoryOptionComboService = dataElementCategoryOptionComboService;
 
72
    }
 
73
 
 
74
    // -------------------------------------------------------------------------
 
75
    // Comparator
 
76
    // -------------------------------------------------------------------------
 
77
 
 
78
    private Comparator<DataElement> dataElementComparator;
 
79
 
 
80
    public void setDataElementComparator( Comparator<DataElement> dataElementComparator )
 
81
    {
 
82
        this.dataElementComparator = dataElementComparator;
 
83
    }
 
84
 
 
85
    // -------------------------------------------------------------------------
 
86
    // DisplayPropertyHandler
 
87
    // -------------------------------------------------------------------------
 
88
 
 
89
    private DisplayPropertyHandler displayPropertyHandler;
 
90
 
 
91
    public void setDisplayPropertyHandler( DisplayPropertyHandler displayPropertyHandler )
 
92
    {
 
93
        this.displayPropertyHandler = displayPropertyHandler;
 
94
    }
 
95
 
 
96
    // -------------------------------------------------------------------------
 
97
    // Input & output
 
98
    // -------------------------------------------------------------------------
 
99
 
 
100
    private Integer id;
 
101
 
 
102
    public void setId( Integer id )
 
103
    {
 
104
        this.id = id;
 
105
    }
 
106
 
 
107
    private String deOptionValue;
 
108
 
 
109
    public void setDeOptionValue( String deOptionValue )
 
110
    {
 
111
        this.deOptionValue = deOptionValue;
 
112
    }
 
113
 
 
114
    public String getDeOptionValue()
 
115
    {
 
116
        return deOptionValue;
 
117
    }
 
118
 
 
119
    private List<DataElement> dataElements;
 
120
 
 
121
    public List<DataElement> getDataElements()
 
122
    {
 
123
        return dataElements;
 
124
    }
 
125
    
 
126
    private List<String> optionComboNames;
 
127
 
 
128
    public List<String> getOptionComboNames()
 
129
    {
 
130
        return optionComboNames;
 
131
    }
 
132
 
 
133
    private List<String> optionComboIds;
 
134
    
 
135
    public List<String> getOptionComboIds()
 
136
    {
 
137
        return optionComboIds;
 
138
    }
 
139
    
 
140
    // -------------------------------------------------------------------------
 
141
    // Action implementation
 
142
    // -------------------------------------------------------------------------
 
143
 
 
144
    public String execute()
 
145
        throws Exception
 
146
    {
 
147
        optionComboIds = new ArrayList<String>();
 
148
        optionComboNames = new ArrayList<String>();
 
149
        
 
150
        if ( id == ALL )
 
151
        {
 
152
            dataElements = new ArrayList<DataElement>( dataElementService.getAllDataElements() );
 
153
        }
 
154
        else
 
155
        {
 
156
            DataElementGroup dataElementGroup = dataElementService.getDataElementGroup( id );
 
157
 
 
158
            if ( dataElementGroup != null )
 
159
            {
 
160
                dataElements = new ArrayList<DataElement>( dataElementGroup.getMembers() );
 
161
            }
 
162
            else
 
163
            {
 
164
                dataElements = new ArrayList<DataElement>();
 
165
            }
 
166
        }
 
167
 
 
168
        Collections.sort( dataElements, dataElementComparator );
 
169
 
 
170
        displayPropertyHandler.handle( dataElements );
 
171
        
 
172
        if ( deOptionValue != null )
 
173
        {
 
174
                if( deOptionValue.equalsIgnoreCase( "optioncombo" ))
 
175
            {
 
176
                Iterator<DataElement> deIterator = dataElements.iterator();
 
177
                while(deIterator.hasNext())
 
178
                {
 
179
                    DataElement de = deIterator.next();
 
180
                    DataElementCategoryCombo dataElementCategoryCombo = de.getCategoryCombo();
 
181
                    List<DataElementCategoryOptionCombo> optionCombos = new ArrayList<DataElementCategoryOptionCombo>(
 
182
                        dataElementCategoryCombo.getOptionCombos() );
 
183
 
 
184
                    Iterator<DataElementCategoryOptionCombo> optionComboIterator = optionCombos.iterator();
 
185
                    while ( optionComboIterator.hasNext() )
 
186
                    {
 
187
                        DataElementCategoryOptionCombo decoc = optionComboIterator.next();
 
188
                        optionComboIds.add( de.getId()+":"+decoc.getId());
 
189
                        optionComboNames.add( de.getName()+":"+dataElementCategoryOptionComboService.getOptionNames( decoc ));
 
190
                        
 
191
                    }   
 
192
                }
 
193
            }           
 
194
        }
 
195
        
 
196
                       
 
197
        return SUCCESS;
 
198
    }
 
199
}