dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #14159
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4691: Re-implemented method sortOptionCombos in a simpler way
Merge authors:
Lars Helge Øverland (larshelge)
------------------------------------------------------------
revno: 4691 [merge]
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2011-09-26 19:37:55 +0200
message:
Re-implemented method sortOptionCombos in a simpler way
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/DataElementCategoryService.java
dhis-2/dhis-api/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryComboTest.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java
dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/impl/DefaultDataSetReportService.java
dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/LoadFormAction.java
dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/section/GreySectionAction.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 2011-09-26 16:24:46 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryCombo.java 2011-09-26 17:08:55 +0000
@@ -28,6 +28,8 @@
*/
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -151,13 +153,29 @@
return list;
}
+
+ //TODO update category option -> category option combo association
public void generateOptionCombos()
{
this.optionCombos = new HashSet<DataElementCategoryOptionCombo>( generateOptionCombosList() );
}
- //TODO update category option -> category option combo association
+ 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/DataElementCategoryService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryService.java 2011-04-12 12:15:54 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryService.java 2011-09-26 17:37:55 +0000
@@ -28,7 +28,6 @@
*/
import java.util.Collection;
-import java.util.List;
import org.hisp.dhis.hierarchy.HierarchyViolationException;
@@ -289,15 +288,6 @@
Collection<DataElementCategoryOptionCombo> getAllDataElementCategoryOptionCombos();
/**
- * Sorts the DataElementCategoryOptionCombos in the given
- * DataElementCategoryCombo.
- *
- * @param categoryCombo the DataElementCategoryCombo.
- *
- */
- List<DataElementCategoryOptionCombo> sortOptionCombos( DataElementCategoryCombo categoryCombo );
-
- /**
* Generates and persists a default DataElementCategory,
* DataElmentCategoryOption, DataElementCategoryCombo and
* DataElementCategoryOptionCombo.
=== modified file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryComboTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryComboTest.java 2011-09-26 16:24:46 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryComboTest.java 2011-09-26 17:08:55 +0000
@@ -27,13 +27,14 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNotNull;
+
import java.util.List;
import org.junit.Before;
import org.junit.Test;
-import static junit.framework.Assert.*;
-
/**
* @author Lars Helge Overland
*/
@@ -92,7 +93,7 @@
}
@Test
- public void testGenerate()
+ public void testGenerateOptionCombosList()
{
List<DataElementCategoryOptionCombo> list = categoryCombo.generateOptionCombosList();
@@ -109,6 +110,16 @@
assertEquals( createCategoryOptionCombo( categoryCombo, categoryOptionB, categoryOptionD, categoryOptionF ), list.get( 7 ) );
}
+ @Test
+ public void test()
+ {
+ List<DataElementCategoryOptionCombo> list = categoryCombo.generateOptionCombosList();
+
+ categoryCombo.generateOptionCombos();
+
+ assertEquals( list, categoryCombo.getSortedOptionCombos() );
+ }
+
private static DataElementCategoryOptionCombo createCategoryOptionCombo( DataElementCategoryCombo categoryCombo, DataElementCategoryOption... categoryOptions )
{
DataElementCategoryOptionCombo categoryOptionCombo = new DataElementCategoryOptionCombo();
=== 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 2011-09-26 15:36:02 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java 2011-09-26 17:37:55 +0000
@@ -29,15 +29,11 @@
import java.util.ArrayList;
import java.util.Collection;
-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 org.apache.commons.collections.CollectionUtils;
-import org.hisp.dhis.common.CombinationGenerator;
import org.hisp.dhis.common.GenericIdentifiableObjectStore;
import org.hisp.dhis.system.util.Filter;
import org.hisp.dhis.system.util.FilterUtils;
@@ -479,168 +475,6 @@
updateDataElementCategoryCombo( categoryCombo );
}
- public List<DataElementCategoryOptionCombo> sortOptionCombos( DataElementCategoryCombo categoryCombo )
- {
- List<DataElementCategoryOptionCombo> optionCombos = new ArrayList<DataElementCategoryOptionCombo>(
- categoryCombo.getOptionCombos() );
-
- int totalColumns = optionCombos.size();
-
- Map<Integer, Collection<DataElementCategoryOption>> orderedOptions = prepareOptionsForCombination( categoryCombo );
-
- List<DataElementCategoryOptionCombo> orderdCategoryOptionCombos = new ArrayList<DataElementCategoryOptionCombo>();
-
- for ( int i = 0; i < totalColumns; i++ )
- {
- List<DataElementCategoryOption> options = new ArrayList<DataElementCategoryOption>( categoryCombo
- .getCategories().size() );
-
- List<DataElementCategory> copyOforderedCategories = categoryCombo.getCategories();
-
- Iterator<DataElementCategory> categoryIterator = copyOforderedCategories.iterator();
-
- while ( categoryIterator.hasNext() )
- {
- DataElementCategory category = categoryIterator.next();
- Iterator<DataElementCategoryOption> optionIterator = orderedOptions.get( category.getId() ).iterator();
- DataElementCategoryOption option = optionIterator.next();
- options.add( option );
- optionIterator.remove();
- }
-
- for ( DataElementCategoryOptionCombo optionCombo : optionCombos )
- {
- if ( optionCombo.getCategoryOptions().containsAll( options ) )
- {
- orderdCategoryOptionCombos.add( optionCombo );
- break;
- }
- }
- }
-
- return orderdCategoryOptionCombos;
- }
-
- private Map<Integer, Collection<DataElementCategoryOption>> prepareOptionsForCombination(
- DataElementCategoryCombo categoryCombo )
- {
- // Get categories for a given category
-
- List<DataElementCategory> categories = new ArrayList<DataElementCategory>( categoryCombo.getCategories() );
-
- /*
- * Get the total number of option combinations that will come into
- * existence when combining categories having their own options
- *
- * Eg. Category SEX with Options MALE and FEMALE Category AGE with
- * Options <5years, 5-15years, >15years When combining these two
- * categories we are going to have a total of 6 option combinations
- * MALE_<5years,MALE_5-15years,MALE_>15years
- * FEMALE_<5years,FEMALE_5-15years,FEMALE_>15years
- *
- * 6 OptionCombinations = 2(from SEX) * 3(from AGE)
- *
- * generalizing this we can have total option combinations by
- * multiplying the number of options in each category
- */
- int totalOptionCombos = 1;
-
- for ( DataElementCategory category : categories )
- {
- totalOptionCombos = totalOptionCombos * category.getCategoryOptions().size();
- }
-
- // ---------------------------------------------------------------------
- // Determine the number of times each category is going to repeat
- // ---------------------------------------------------------------------
-
- /*
- * Example again Category IPD_OPD, Options I and D Category Sex, Options
- * F and M Category Age, Options 0-5,5-10,11+
- *
- * Category combination is IPD_OPD+Sex+Age
- *
- * Option combinations ... with the following arrangement in Data Entry
- *
- * I | I | I | I | I | I | O | O | O | O | O | O F | F | F | F | F | F |
- * M | M | M | M | M | M
- * 0-5|5-10|11+|0-5|5-10|11+1|0-5|5-10|11+|0-5|5-10|11+1
- *
- * If we rearrange our categories like IPD_OPD+Age+Sex - then we will
- * have the same option combinations, but with different arrangement.
- *
- * I | I | I | I | I | I | O | O | O | O | O | O 0-5| 0-5|5-10|5-10|
- * 11+| 11+|0-5| 0-5|5-10|5-10| 11+|11+ F | M | F | M | F | M |F | M | F
- * | M | F | M
- *
- * If we assume that we will draw a data entry table header, the top a
- * category is in the order list, then the more ColSpan its options are
- * going to have
- */
- int categoryColSpan = totalOptionCombos;
-
- Map<Integer, Integer> categoryRepeat = new HashMap<Integer, Integer>();
-
- for ( DataElementCategory category : categories )
- {
- categoryColSpan = categoryColSpan / category.getCategoryOptions().size();
-
- categoryRepeat.put( category.getId(), categoryColSpan );
- }
-
- /*
- * If we see the above example, any option from AGE appear only twice
- * while an option from SEX appears three times....generalizing this we
- * can say set the following formula let
- *
- * appearance = appearance of any option from a given category
- * category_options = number of options from the category containing the
- * option and option_combinations = total number of option combinations
- *
- * appearance = option_combinaitions/category_options
- *
- * each option becoming part of the option combinations for 'appearance'
- * number of times, then totally a category will be represented in the
- * option combinations option_combinaitions number of times.
- *
- * Then we can prepare list of categories containing collection of its
- * options where each option is repeated 'appearance' times. By doing
- * this, we can iterate through these categories every time removing an
- * option from the category but putting it in the option combinations.
- */
- Map<Integer, Collection<DataElementCategoryOption>> optionsMap = new HashMap<Integer, Collection<DataElementCategoryOption>>();
-
- /*
- * For each category create a collection of options by repeating each of
- * its options 'appearance' number of times. The size of the collection
- * should be equal to total number of options combinations.
- */
- for ( DataElementCategory cat : categories )
- {
- Collection<DataElementCategoryOption> requiredOptions = new ArrayList<DataElementCategoryOption>();
- Collection<DataElementCategoryOption> options = cat.getCategoryOptions();
-
- int count = 0;
-
- while ( count < totalOptionCombos )
- {
- for ( DataElementCategoryOption option : options )
- {
- for ( int i = 0; i < categoryRepeat.get( cat.getId() ); i++ )
- {
- requiredOptions.add( option );
-
- count++;
- }
- }
- }
-
- optionsMap.put( cat.getId(), requiredOptions );
- }
-
- return optionsMap;
- }
-
public int getDataElementCategoryCount()
{
return dataElementCategoryStore.getCount();
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/impl/DefaultDataSetReportService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/impl/DefaultDataSetReportService.java 2011-08-25 08:52:40 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/impl/DefaultDataSetReportService.java 2011-09-26 17:37:55 +0000
@@ -52,7 +52,6 @@
import org.hisp.dhis.dataelement.DataElementCategoryCombo;
import org.hisp.dhis.dataelement.DataElementCategoryOption;
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
-import org.hisp.dhis.dataelement.DataElementCategoryService;
import org.hisp.dhis.dataelement.comparator.DataElementCategoryOptionComboNameComparator;
import org.hisp.dhis.dataelement.comparator.DataElementNameComparator;
import org.hisp.dhis.dataentryform.DataEntryForm;
@@ -109,13 +108,6 @@
this.aggregatedDataValueService = aggregatedDataValueService;
}
- private DataElementCategoryService categoryService;
-
- public void setCategoryService( DataElementCategoryService categoryService )
- {
- this.categoryService = categoryService;
- }
-
private SystemSettingManager systemSettingManager;
public void setSystemSettingManager( SystemSettingManager systemSettingManager )
@@ -162,7 +154,7 @@
grid.addHeader( new GridHeader( i18n.getString( "dataelement" ), false, true ) ); // Data element header
- List<DataElementCategoryOptionCombo> optionCombos = categoryService.sortOptionCombos( categoryCombo );
+ List<DataElementCategoryOptionCombo> optionCombos = categoryCombo.getSortedOptionCombos();
for ( DataElementCategoryOptionCombo optionCombo : optionCombos ) // Value headers
{
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml 2011-09-16 16:54:03 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml 2011-09-26 17:37:55 +0000
@@ -164,7 +164,6 @@
<property name="dataValueService" ref="org.hisp.dhis.datavalue.DataValueService" />
<property name="systemSettingManager" ref="org.hisp.dhis.options.SystemSettingManager" />
<property name="aggregatedDataValueService" ref="org.hisp.dhis.aggregation.AggregatedDataValueService" />
- <property name="categoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
<property name="aggregationService" ref="org.hisp.dhis.aggregation.AggregationService" />
</bean>
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/LoadFormAction.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/LoadFormAction.java 2011-09-26 15:24:25 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/LoadFormAction.java 2011-09-26 17:37:55 +0000
@@ -40,7 +40,6 @@
import org.hisp.dhis.dataelement.DataElementCategoryCombo;
import org.hisp.dhis.dataelement.DataElementCategoryOption;
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
-import org.hisp.dhis.dataelement.DataElementCategoryService;
import org.hisp.dhis.dataelement.DataElementOperand;
import org.hisp.dhis.dataelement.DataElementService;
import org.hisp.dhis.dataelement.comparator.DataElementSortOrderComparator;
@@ -86,13 +85,6 @@
this.dataSetService = dataSetService;
}
- private DataElementCategoryService categoryService;
-
- public void setCategoryService( DataElementCategoryService categoryService )
- {
- this.categoryService = categoryService;
- }
-
private I18n i18n;
public void setI18n( I18n i18n )
@@ -238,7 +230,7 @@
for ( DataElementCategoryCombo categoryCombo : orderedCategoryCombos )
{
- List<DataElementCategoryOptionCombo> optionCombos = categoryService.sortOptionCombos( categoryCombo );
+ List<DataElementCategoryOptionCombo> optionCombos = categoryCombo.getSortedOptionCombos();
orderdCategoryOptionCombos.put( categoryCombo.getId(), optionCombos );
=== 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 2011-09-15 13:30:54 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml 2011-09-26 17:37:55 +0000
@@ -36,7 +36,6 @@
<property name="dataEntryFormService" ref="org.hisp.dhis.dataentryform.DataEntryFormService" />
<property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService" />
<property name="dataSetService" ref="org.hisp.dhis.dataset.DataSetService" />
- <property name="categoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
</bean>
<bean id="org.hisp.dhis.de.action.SaveValueAction" class="org.hisp.dhis.de.action.SaveValueAction" scope="prototype">
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/section/GreySectionAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/section/GreySectionAction.java 2011-05-08 08:17:20 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/section/GreySectionAction.java 2011-09-26 17:37:55 +0000
@@ -133,9 +133,9 @@
return colRepeat;
}
- private Collection<DataElementCategoryOptionCombo> optionCombos = new ArrayList<DataElementCategoryOptionCombo>();
+ private List<DataElementCategoryOptionCombo> optionCombos = new ArrayList<DataElementCategoryOptionCombo>();
- public Collection<DataElementCategoryOptionCombo> getOptionCombos()
+ public List<DataElementCategoryOptionCombo> getOptionCombos()
{
return optionCombos;
}
@@ -176,7 +176,7 @@
if ( sectionIsMultiDimensional )
{
- optionCombos = categoryService.sortOptionCombos( categoryCombo );
+ optionCombos = categoryCombo.getSortedOptionCombos();
for ( DataElementCategory dec : categoryCombo.getCategories() )
{