dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #03657
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1217: sorting dataelements in multidimensional dataentry form
------------------------------------------------------------
revno: 1217
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: trunk
timestamp: Fri 2009-12-11 18:54:58 +0100
message:
sorting dataelements in multidimensional dataentry form
added:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/comparator/CategoryComboSizeComparator.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryCombo.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java
dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/multidimensional/FormAction.java
dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription.
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/comparator/CategoryComboSizeComparator.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/comparator/CategoryComboSizeComparator.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/comparator/CategoryComboSizeComparator.java 2009-12-11 17:54:58 +0000
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2004-2009, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.hisp.dhis.common.comparator;
+
+/**
+ * @author Abyot Asalefew Gizaw
+ * @version $Id$
+ */
+import java.util.Comparator;
+
+import org.hisp.dhis.dataelement.DataElementCategoryCombo;
+
+public class CategoryComboSizeComparator
+ implements Comparator<DataElementCategoryCombo>
+{
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public int compare( DataElementCategoryCombo o1, DataElementCategoryCombo o2 )
+ {
+ return (int) (o1.getOptionCombos().size() - o2.getOptionCombos().size());
+ }
+}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryCombo.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryCombo.java 2009-11-23 11:40:23 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryCombo.java 2009-12-11 17:54:58 +0000
@@ -46,22 +46,22 @@
implements Serializable, DimensionSet
{
public static final String DEFAULT_CATEGORY_COMBO_NAME = "default";
-
+
/**
* The database internal identifier.
*/
private int id;
-
+
/**
* The name.
*/
private String name;
-
+
/**
* A set with categories.
*/
private List<DataElementCategory> categories = new ArrayList<DataElementCategory>();
-
+
/**
* A set of category option combos.
*/
@@ -75,22 +75,22 @@
{
return DimensionType.CATEGORY.name() + SEPARATOR_TYPE + id;
}
-
+
public DimensionType getDimensionType()
{
return DimensionType.CATEGORY;
}
-
+
public List<? extends Dimension> getDimensions()
{
return categories;
}
-
+
public List<? extends DimensionOptionElement> getDimensionOptionElements()
{
return new ArrayList<DimensionOptionElement>( optionCombos );
}
-
+
// -------------------------------------------------------------------------
// Constructors
// -------------------------------------------------------------------------
@@ -98,18 +98,18 @@
public DataElementCategoryCombo()
{
}
-
+
public DataElementCategoryCombo( String name )
{
- this.name = name;
+ this.name = name;
}
-
+
public DataElementCategoryCombo( String name, List<DataElementCategory> categories )
{
this.name = name;
this.categories = categories;
}
-
+
// -------------------------------------------------------------------------
// hashCode, equals and toString
// -------------------------------------------------------------------------
@@ -127,19 +127,19 @@
{
return true;
}
-
+
if ( object == null )
{
return false;
}
-
+
if ( getClass() != object.getClass() )
{
return false;
}
-
+
final DataElementCategoryCombo other = (DataElementCategoryCombo) object;
-
+
return name.equals( other.getName() );
}
@@ -147,49 +147,49 @@
public String toString()
{
return "[" + name + "]";
- }
+ }
// -------------------------------------------------------------------------
// Getters and setters
// -------------------------------------------------------------------------
-
+
public int getId()
{
return id;
}
-
- public void setId( int id )
+
+ public void setId( int id )
{
this.id = id;
}
-
+
public String getName()
{
return name;
}
-
- public void setName( String name )
+
+ public void setName( String name )
{
this.name = name;
- }
+ }
public List<DataElementCategory> getCategories()
{
return categories;
}
-
+
public void setCategories( List<DataElementCategory> categories )
{
this.categories = categories;
}
-
+
public Set<DataElementCategoryOptionCombo> getOptionCombos()
{
return optionCombos;
}
-
+
public void setOptionCombos( Set<DataElementCategoryOptionCombo> optionCombos )
- {
+ {
this.optionCombos = optionCombos;
}
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java 2009-12-11 02:18:27 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java 2009-12-11 17:54:58 +0000
@@ -28,6 +28,7 @@
*/
import java.util.Collection;
+import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -221,9 +222,9 @@
* @param dataElements
* @return grouped dataElements based on their categoryCombo
*/
- Map<DataElementCategoryCombo, Collection<DataElement>> getGroupedDataElementsByCategoryCombo( Collection<DataElement> dataElements );
+ Map<DataElementCategoryCombo, Collection<DataElement>> getGroupedDataElementsByCategoryCombo( List<DataElement> dataElements );
- Collection<DataElementCategoryCombo> getDataElementCategoryCombos( Collection<DataElement> dataElements );
+ List<DataElementCategoryCombo> getDataElementCategoryCombos( List<DataElement> dataElements );
/**
* Returns all DataElements which are associated with one or more DataElementGroupSets.
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java 2009-12-11 02:18:27 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java 2009-12-11 17:54:58 +0000
@@ -35,14 +35,14 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.SortedMap;
-import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.hisp.dhis.common.GenericIdentifiableObjectStore;
+import org.hisp.dhis.common.comparator.CategoryComboSizeComparator;
import org.hisp.dhis.hierarchy.HierarchyViolationException;
import org.hisp.dhis.i18n.I18nService;
import org.hisp.dhis.system.util.Filter;
@@ -50,6 +50,8 @@
import org.hisp.dhis.system.util.UUIdUtils;
import org.springframework.transaction.annotation.Transactional;
+import edu.emory.mathcs.backport.java.util.Collections;
+
/**
* @author Kristian Nordal
* @version $Id: DefaultDataElementService.java 5243 2008-05-25 10:18:58Z
@@ -233,7 +235,7 @@
}
public Map<DataElementCategoryCombo, Collection<DataElement>> getGroupedDataElementsByCategoryCombo(
- Collection<DataElement> dataElements )
+ List<DataElement> dataElements )
{
Map<DataElementCategoryCombo, Collection<DataElement>> mappedDataElements = new HashMap<DataElementCategoryCombo, Collection<DataElement>>();
@@ -255,17 +257,20 @@
return mappedDataElements;
}
- public Collection<DataElementCategoryCombo> getDataElementCategoryCombos( Collection<DataElement> dataElements )
+ public List<DataElementCategoryCombo> getDataElementCategoryCombos( List<DataElement> dataElements )
{
- SortedMap<String, DataElementCategoryCombo> sortedCategoryCombo = new TreeMap<String, DataElementCategoryCombo>();
+ Set<DataElementCategoryCombo> setCategoryCombos = new HashSet<DataElementCategoryCombo>();
for ( DataElement de : dataElements )
{
- sortedCategoryCombo.put( de.getCategoryCombo().getOptionCombos().size() + "-"
- + de.getCategoryCombo().getId(), de.getCategoryCombo() );
+ setCategoryCombos.add( de.getCategoryCombo() );
}
- return sortedCategoryCombo.values();
+ List<DataElementCategoryCombo> listCategoryCombos = new ArrayList<DataElementCategoryCombo>(setCategoryCombos);
+
+ Collections.sort( listCategoryCombos, new CategoryComboSizeComparator() );
+
+ return listCategoryCombos;
}
public Collection<DataElement> getDataElementsWithGroupSets()
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/multidimensional/FormAction.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/multidimensional/FormAction.java 2009-12-11 08:01:25 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/multidimensional/FormAction.java 2009-12-11 17:54:58 +0000
@@ -31,10 +31,12 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.hisp.dhis.common.comparator.CategoryComboSizeComparator;
import org.hisp.dhis.customvalue.CustomValue;
import org.hisp.dhis.customvalue.CustomValueService;
import org.hisp.dhis.dataelement.CalculatedDataElement;
@@ -45,6 +47,7 @@
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
import org.hisp.dhis.dataelement.DataElementCategoryService;
import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.dataelement.comparator.DataElementNameComparator;
import org.hisp.dhis.datalock.DataSetLock;
import org.hisp.dhis.datalock.DataSetLockService;
import org.hisp.dhis.dataset.DataEntryForm;
@@ -65,6 +68,8 @@
import com.opensymphony.xwork2.Action;
+import edu.emory.mathcs.backport.java.util.Collections;
+
/**
* @author Abyot Asalefew
* @version $Id$
@@ -149,7 +154,7 @@
{
this.categoryService = categoryService;
}
-
+
private I18n i18n;
public void setI18n( I18n i18n )
@@ -165,6 +170,17 @@
}
// -------------------------------------------------------------------------
+ // Comparator
+ // -------------------------------------------------------------------------
+
+ private Comparator<DataElement> dataElementComparator;
+
+ public void setDataElementComparator( Comparator<DataElement> dataElementComparator )
+ {
+ this.dataElementComparator = dataElementComparator;
+ }
+
+ // -------------------------------------------------------------------------
// DisplayPropertyHandler
// -------------------------------------------------------------------------
@@ -277,9 +293,9 @@
return allOptionCombos;
}
- private Collection<DataElementCategoryCombo> orderedCategoryCombos = new ArrayList<DataElementCategoryCombo>();
+ private List<DataElementCategoryCombo> orderedCategoryCombos = new ArrayList<DataElementCategoryCombo>();
- public Collection<DataElementCategoryCombo> getOrderedCategoryCombos()
+ public List<DataElementCategoryCombo> getOrderedCategoryCombos()
{
return orderedCategoryCombos;
}
@@ -373,21 +389,23 @@
if ( dataSetLock != null && dataSetLock.getSources().contains( organisationUnit ) )
{
disabled = "disabled";
- }
-
- Collection<DataElement> dataElements = dataSet.getDataElements();
+ }
+
+ List<DataElement> dataElements = new ArrayList<DataElement>( dataSet.getDataElements() );
if ( dataElements.size() == 0 )
{
return SUCCESS;
- }
-
+ }
+
+ Collections.sort( dataElements, dataElementComparator );
+
orderedDataElements = dataElementService.getGroupedDataElementsByCategoryCombo( dataElements );
-
- orderedCategoryCombos.addAll( dataElementService.getDataElementCategoryCombos( dataElements ) );
+
+ orderedCategoryCombos = dataElementService.getDataElementCategoryCombos( dataElements );
for ( DataElementCategoryCombo categoryCombo : orderedCategoryCombos )
- {
+ {
Collection<DataElementCategoryOptionCombo> optionCombos = categoryService.sortOptionCombos( categoryCombo );
allOptionCombos.addAll( optionCombos );
@@ -529,6 +547,7 @@
for ( DataElementCategoryCombo categoryCombo : orderedCategoryCombos )
{
des = (List<DataElement>) orderedDataElements.get( categoryCombo );
+
displayPropertyHandler.handle( des );
orderedDataElements.put( categoryCombo, des );
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml 2009-12-11 02:18:27 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml 2009-12-11 17:54:58 +0000
@@ -94,7 +94,7 @@
class="org.hisp.dhis.de.action.multidimensional.FormAction" scope="prototype">
<property name="dataSetLockService" ref="org.hisp.dhis.datalock.DataSetLockService" />
<property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService" />
- <property name="dataValueService" ref="org.hisp.dhis.datavalue.DataValueService" />
+ <property name="dataValueService" ref="org.hisp.dhis.datavalue.DataValueService" />
<property name="dataEntryScreenManager"
ref="org.hisp.dhis.de.screen.DataEntryScreenManager" />
<property name="standardCommentsManager"