1
package org.hisp.dhis.dashboard.action;
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 java.util.ArrayList;
31
import java.util.Collections;
32
import java.util.Comparator;
33
import java.util.Iterator;
34
import java.util.List;
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;
44
import com.opensymphony.xwork.ActionSupport;
47
* @author Lars Helge Overland
50
public class GetDataElementsAction
53
private final static int ALL = 0;
55
// -------------------------------------------------------------------------
57
// -------------------------------------------------------------------------
59
private DataElementService dataElementService;
61
public void setDataElementService( DataElementService dataElementService )
63
this.dataElementService = dataElementService;
66
private DataElementCategoryOptionComboService dataElementCategoryOptionComboService;
68
public void setDataElementCategoryOptionComboService(
69
DataElementCategoryOptionComboService dataElementCategoryOptionComboService )
71
this.dataElementCategoryOptionComboService = dataElementCategoryOptionComboService;
74
// -------------------------------------------------------------------------
76
// -------------------------------------------------------------------------
78
private Comparator<DataElement> dataElementComparator;
80
public void setDataElementComparator( Comparator<DataElement> dataElementComparator )
82
this.dataElementComparator = dataElementComparator;
85
// -------------------------------------------------------------------------
86
// DisplayPropertyHandler
87
// -------------------------------------------------------------------------
89
private DisplayPropertyHandler displayPropertyHandler;
91
public void setDisplayPropertyHandler( DisplayPropertyHandler displayPropertyHandler )
93
this.displayPropertyHandler = displayPropertyHandler;
96
// -------------------------------------------------------------------------
98
// -------------------------------------------------------------------------
102
public void setId( Integer id )
107
private String deOptionValue;
109
public void setDeOptionValue( String deOptionValue )
111
this.deOptionValue = deOptionValue;
114
public String getDeOptionValue()
116
return deOptionValue;
119
private List<DataElement> dataElements;
121
public List<DataElement> getDataElements()
126
private List<String> optionComboNames;
128
public List<String> getOptionComboNames()
130
return optionComboNames;
133
private List<String> optionComboIds;
135
public List<String> getOptionComboIds()
137
return optionComboIds;
140
// -------------------------------------------------------------------------
141
// Action implementation
142
// -------------------------------------------------------------------------
144
public String execute()
147
optionComboIds = new ArrayList<String>();
148
optionComboNames = new ArrayList<String>();
152
dataElements = new ArrayList<DataElement>( dataElementService.getAllDataElements() );
156
DataElementGroup dataElementGroup = dataElementService.getDataElementGroup( id );
158
if ( dataElementGroup != null )
160
dataElements = new ArrayList<DataElement>( dataElementGroup.getMembers() );
164
dataElements = new ArrayList<DataElement>();
168
Collections.sort( dataElements, dataElementComparator );
170
displayPropertyHandler.handle( dataElements );
172
if ( deOptionValue != null )
174
if( deOptionValue.equalsIgnoreCase( "optioncombo" ))
176
Iterator<DataElement> deIterator = dataElements.iterator();
177
while(deIterator.hasNext())
179
DataElement de = deIterator.next();
180
DataElementCategoryCombo dataElementCategoryCombo = de.getCategoryCombo();
181
List<DataElementCategoryOptionCombo> optionCombos = new ArrayList<DataElementCategoryOptionCombo>(
182
dataElementCategoryCombo.getOptionCombos() );
184
Iterator<DataElementCategoryOptionCombo> optionComboIterator = optionCombos.iterator();
185
while ( optionComboIterator.hasNext() )
187
DataElementCategoryOptionCombo decoc = optionComboIterator.next();
188
optionComboIds.add( de.getId()+":"+decoc.getId());
189
optionComboNames.add( de.getName()+":"+dataElementCategoryOptionComboService.getOptionNames( decoc ));