------------------------------------------------------------ revno: 19033 committer: Lars Helge Overland <larshe...@gmail.com> branch nick: dhis2 timestamp: Mon 2015-04-27 20:14:06 +0200 message: Making the routine for determining the data set of a data element more defined. It now picks the first data set sort by collectio frequency ascending, name ascending. added: dhis-2/dhis-api/src/test/java/org/hisp/dhis/dataset/ dhis-2/dhis-api/src/test/java/org/hisp/dhis/dataset/comparator/ dhis-2/dhis-api/src/test/java/org/hisp/dhis/dataset/comparator/DataSetFrequencyComparatorTest.java modified: dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/comparator/DataSetFrequencyComparator.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/dataset/comparator/DataSetFrequencyComparator.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/comparator/DataSetFrequencyComparator.java 2015-01-17 07:41:26 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/comparator/DataSetFrequencyComparator.java 2015-04-27 18:14:06 +0000 @@ -34,8 +34,8 @@ /** * Sorts data sets according to the frequency order of their period type, ordered - * from high to low collection frequency. A higher frequency order value implies - * lower data set collection frequency. + * from high to low collection frequency. A lower frequency order value implies + * higher data set collection frequency. Next, sorts by data set name. * * @author Lars Helge Overland */ @@ -57,6 +57,13 @@ return 1; } - return Integer.valueOf( d2.getPeriodType().getFrequencyOrder() ).compareTo( Integer.valueOf( d1.getPeriodType().getFrequencyOrder() ) ); + int frequencyOrder = Integer.valueOf( d1.getPeriodType().getFrequencyOrder() ).compareTo( Integer.valueOf( d2.getPeriodType().getFrequencyOrder() ) ); + + if ( frequencyOrder != 0 ) + { + return frequencyOrder; + } + + return d1.compareTo( d2 ); } } === added directory 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/dataset' === added directory 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/dataset/comparator' === added file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/dataset/comparator/DataSetFrequencyComparatorTest.java' --- dhis-2/dhis-api/src/test/java/org/hisp/dhis/dataset/comparator/DataSetFrequencyComparatorTest.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/dataset/comparator/DataSetFrequencyComparatorTest.java 2015-04-27 18:14:06 +0000 @@ -0,0 +1,79 @@ +package org.hisp.dhis.dataset.comparator; + +/* + * Copyright (c) 2004-2015, 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. + */ + +import java.util.Collections; +import java.util.List; + +import org.hisp.dhis.dataset.DataSet; +import org.hisp.dhis.period.MonthlyPeriodType; +import org.hisp.dhis.period.QuarterlyPeriodType; +import org.hisp.dhis.period.YearlyPeriodType; +import org.junit.Test; + +import com.google.common.collect.Lists; + +import static org.junit.Assert.*; + +public class DataSetFrequencyComparatorTest +{ + @Test + public void testA() + { + DataSet dsA = new DataSet( "DataSetA", new QuarterlyPeriodType() ); + DataSet dsB = new DataSet( "DataSetB", new YearlyPeriodType() ); + DataSet dsC = new DataSet( "DataSetC", new MonthlyPeriodType() ); + DataSet dsD = new DataSet( "DataSetD", new QuarterlyPeriodType() ); + + List<DataSet> list = Lists.newArrayList( dsA, dsC, dsB, dsD ); + + Collections.sort( list, DataSetFrequencyComparator.INSTANCE ); + + assertEquals( dsC, list.get( 0 ) ); + assertEquals( dsA, list.get( 1 ) ); + assertEquals( dsD, list.get( 2 ) ); + assertEquals( dsB, list.get( 3 ) ); + } + + @Test + public void testB() + { + DataSet dsA = new DataSet( "EA: Expenditures Site Level", new QuarterlyPeriodType() ); + DataSet dsB = new DataSet( "MER Results: Facility Based", new QuarterlyPeriodType() ); + DataSet dsC = new DataSet( "MER Results: Facility Based - DoD ONLY", new QuarterlyPeriodType() ); + + List<DataSet> list = Lists.newArrayList( dsB, dsC, dsA ); + + Collections.sort( list, DataSetFrequencyComparator.INSTANCE ); + + assertEquals( dsA, list.get( 0 ) ); + assertEquals( dsB, list.get( 1 ) ); + assertEquals( dsC, list.get( 2 ) ); + } +}
_______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : dhis2-devs@lists.launchpad.net Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp