dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #19324
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8376: Proper naming on category option combos
------------------------------------------------------------
revno: 8376
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-10-04 18:52:13 +0200
message:
Proper naming on category option combos
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/DataElementCategoryOptionCombo.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOperandsAction.java
--
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
=== 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 2012-10-02 18:18:48 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryCombo.java 2012-10-04 16:52:13 +0000
@@ -152,28 +152,60 @@
return list;
}
+ public List<DataElementCategoryOptionCombo> getSortedOptionCombos()
+ {
+ List<DataElementCategoryOptionCombo> list = new ArrayList<DataElementCategoryOptionCombo>();
+
+ CombinationGenerator<DataElementCategoryOption> generator =
+ new CombinationGenerator<DataElementCategoryOption>( getCategoryOptionsAsArray() );
+
+ sortLoop : while ( generator.hasNext() )
+ {
+ List<DataElementCategoryOption> categoryOptions = generator.getNext();
+
+ Set<DataElementCategoryOption> categoryOptionSet = new HashSet<DataElementCategoryOption>( categoryOptions );
+
+ for ( DataElementCategoryOptionCombo optionCombo : optionCombos )
+ {
+ if ( optionCombo.getCategoryOptions() != null && optionCombo.getCategoryOptions().equals( categoryOptionSet ) )
+ {
+ optionCombo.setName( getNameFromCategoryOptions( categoryOptions ) );
+ list.add( optionCombo );
+ continue sortLoop;
+ }
+ }
+ }
+
+ return list;
+ }
+
+ private String getNameFromCategoryOptions( List<DataElementCategoryOption> categoryOptions )
+ {
+ StringBuilder name = new StringBuilder();
+
+ if ( categoryOptions != null && categoryOptions.size() > 0 )
+ {
+ Iterator<DataElementCategoryOption> iterator = categoryOptions.iterator();
+
+ name.append( "(" ).append( iterator.next().getDisplayName() );
+
+ while ( iterator.hasNext() )
+ {
+ name.append( ", " ).append( iterator.next().getDisplayName() );
+ }
+
+ name.append( ")" );
+ }
+
+ return name.toString();
+ }
+
//TODO update category option -> category option combo association
public void generateOptionCombos()
{
this.optionCombos = new HashSet<DataElementCategoryOptionCombo>( generateOptionCombosList() );
}
- public List<DataElementCategoryOptionCombo> getSortedOptionCombos()
- {
- final List<DataElementCategoryOptionCombo> persistedList = new ArrayList<DataElementCategoryOptionCombo>( optionCombos );
- final List<DataElementCategoryOptionCombo> sortedList = generateOptionCombosList();
-
- Collections.sort( persistedList, new Comparator<DataElementCategoryOptionCombo>()
- {
- public int compare( DataElementCategoryOptionCombo o1, DataElementCategoryOptionCombo o2 )
- {
- return new Integer( sortedList.indexOf( o1 ) ).compareTo( new Integer( sortedList.indexOf( o2 ) ) );
- }
- } );
-
- return persistedList;
- }
-
// -------------------------------------------------------------------------
// hashCode, equals and toString
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java 2012-10-02 18:18:48 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java 2012-10-04 16:52:13 +0000
@@ -72,6 +72,12 @@
private Set<DataElementCategoryOption> categoryOptions = new HashSet<DataElementCategoryOption>();
// -------------------------------------------------------------------------
+ // Transient properties
+ // -------------------------------------------------------------------------
+
+ private transient String name;
+
+ // -------------------------------------------------------------------------
// Constructors
// -------------------------------------------------------------------------
@@ -265,6 +271,11 @@
@Override
public String getName()
{
+ if ( name != null )
+ {
+ return name;
+ }
+
StringBuilder name = new StringBuilder();
if ( categoryOptions != null && categoryOptions.size() > 0 )
@@ -287,7 +298,7 @@
@Override
public void setName( String name )
{
- // throw new UnsupportedOperationException( "Cannot set name on DataElementCategoryOptionCombo: " + name );
+ this.name = name;
}
@Override
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java 2012-10-02 18:18:48 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java 2012-10-04 16:52:13 +0000
@@ -419,7 +419,7 @@
operands.add( operand );
}
- for ( DataElementCategoryOptionCombo categoryOptionCombo : dataElement.getCategoryCombo().getOptionCombos() )
+ for ( DataElementCategoryOptionCombo categoryOptionCombo : dataElement.getCategoryCombo().getSortedOptionCombos() )
{
DataElementOperand operand = new DataElementOperand();
operand.updateProperties( dataElement, categoryOptionCombo );
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOperandsAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOperandsAction.java 2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOperandsAction.java 2012-10-04 16:52:13 +0000
@@ -32,11 +32,11 @@
import java.util.List;
import org.apache.commons.lang.StringUtils;
+import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementCategoryService;
import org.hisp.dhis.dataelement.DataElementOperand;
import org.hisp.dhis.dataelement.DataElementService;
-import org.hisp.dhis.dataelement.comparator.DataElementOperandNameComparator;
import org.hisp.dhis.dataset.DataSetService;
import org.hisp.dhis.paging.ActionPagingSupport;
import org.hisp.dhis.system.filter.AggregatableDataElementFilter;
@@ -173,11 +173,11 @@
FilterUtils.filter( dataElements, new DataElementPeriodTypeFilter( periodType ) );
}
+ Collections.sort( dataElements, IdentifiableObjectNameComparator.INSTANCE );
+
operands = new ArrayList<DataElementOperand>( dataElementCategoryService.getOperands( dataElements,
includeTotals ) );
- Collections.sort( operands, new DataElementOperandNameComparator() );
-
if ( usePaging )
{
this.paging = createPaging( operands.size() );