dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #36552
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18696: Analytics. Fixed bug, sort order was not retained on favorite save. Bug caused by change in Ident...
------------------------------------------------------------
revno: 18696
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-03-26 17:20:03 +0100
message:
Analytics. Fixed bug, sort order was not retained on favorite save. Bug caused by change in IdentifiableObjectManager.getByUid.
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/dimension/DefaultDimensionService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/common/IdentifiableObjectManagerTest.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/common/IdentifiableObjectManager.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java 2015-03-13 15:48:26 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java 2015-03-26 16:20:03 +0000
@@ -79,6 +79,8 @@
<T extends IdentifiableObject> List<T> getByUid( Class<T> clazz, Collection<String> uids );
+ <T extends IdentifiableObject> List<T> getByUidOrdered( Class<T> clazz, List<String> uids );
+
<T extends IdentifiableObject> Collection<T> getLikeName( Class<T> clazz, String name );
<T extends NameableObject> Collection<T> getLikeShortName( Class<T> clazz, String shortName );
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/dimension/DefaultDimensionService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/dimension/DefaultDimensionService.java 2015-03-13 15:48:26 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/dimension/DefaultDimensionService.java 2015-03-26 16:20:03 +0000
@@ -426,11 +426,11 @@
if ( INDICATOR.equals( type ) )
{
- object.getIndicators().addAll( identifiableObjectManager.getByUid( Indicator.class, uids ) );
+ object.getIndicators().addAll( identifiableObjectManager.getByUidOrdered( Indicator.class, uids ) );
}
else if ( DATAELEMENT.equals( type ) )
{
- object.getDataElements().addAll( identifiableObjectManager.getByUid( DataElement.class, uids ) );
+ object.getDataElements().addAll( identifiableObjectManager.getByUidOrdered( DataElement.class, uids ) );
}
else if ( DATAELEMENT_OPERAND.equals( type ) )
{
@@ -438,7 +438,7 @@
}
else if ( DATASET.equals( type ) )
{
- object.getDataSets().addAll( identifiableObjectManager.getByUid( DataSet.class, uids ) );
+ object.getDataSets().addAll( identifiableObjectManager.getByUidOrdered( DataSet.class, uids ) );
}
else if ( PERIOD.equals( type ) )
{
@@ -522,15 +522,15 @@
}
else if ( DATAELEMENT_GROUPSET.equals( type ) )
{
- object.getDataElementGroups().addAll( identifiableObjectManager.getByUid( DataElementGroup.class, uids ) );
+ object.getDataElementGroups().addAll( identifiableObjectManager.getByUidOrdered( DataElementGroup.class, uids ) );
}
else if ( ORGANISATIONUNIT_GROUPSET.equals( type ) )
{
- object.getOrganisationUnitGroups().addAll( identifiableObjectManager.getByUid( OrganisationUnitGroup.class, uids ) );
+ object.getOrganisationUnitGroups().addAll( identifiableObjectManager.getByUidOrdered( OrganisationUnitGroup.class, uids ) );
}
else if ( CATEGORYOPTION_GROUPSET.equals( type ) )
{
- object.getCategoryOptionGroups().addAll( identifiableObjectManager.getByUid( CategoryOptionGroup.class, uids ) );
+ object.getCategoryOptionGroups().addAll( identifiableObjectManager.getByUidOrdered( CategoryOptionGroup.class, uids ) );
}
else if ( TRACKED_ENTITY_ATTRIBUTE.equals( type ) )
{
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java 2015-03-13 15:48:26 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java 2015-03-26 16:20:03 +0000
@@ -351,6 +351,35 @@
}
@Override
+ @SuppressWarnings( "unchecked" )
+ public <T extends IdentifiableObject> List<T> getByUidOrdered( Class<T> clazz, List<String> uids )
+ {
+ GenericIdentifiableObjectStore<T> store = (GenericIdentifiableObjectStore<T>) getIdentifiableObjectStore( clazz );
+
+ if ( store == null )
+ {
+ return new ArrayList<>();
+ }
+
+ List<T> list = new ArrayList<>();
+
+ if ( uids != null )
+ {
+ for ( String uid : uids )
+ {
+ T object = store.getByUid( uid );
+
+ if ( object != null )
+ {
+ list.add( object );
+ }
+ }
+ }
+
+ return list;
+ }
+
+ @Override
public <T extends IdentifiableObject> int getCount( Class<T> clazz )
{
GenericIdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/common/IdentifiableObjectManagerTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/common/IdentifiableObjectManagerTest.java 2015-02-23 13:06:26 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/common/IdentifiableObjectManagerTest.java 2015-03-26 16:20:03 +0000
@@ -569,4 +569,26 @@
assertTrue( cd.contains( dataElementC ) );
assertTrue( cd.contains( dataElementD ) );
}
+
+ @Test
+ public void getByUidOrderedTest()
+ {
+ DataElement dataElementA = createDataElement( 'A' );
+ DataElement dataElementB = createDataElement( 'B' );
+ DataElement dataElementC = createDataElement( 'C' );
+ DataElement dataElementD = createDataElement( 'D' );
+
+ identifiableObjectManager.save( dataElementA );
+ identifiableObjectManager.save( dataElementB );
+ identifiableObjectManager.save( dataElementC );
+ identifiableObjectManager.save( dataElementD );
+
+ List<String> uids = Arrays.asList( dataElementA.getUid(), dataElementC.getUid(), dataElementB.getUid(), dataElementD.getUid() );
+
+ List<DataElement> expected = new ArrayList<>( Arrays.asList( dataElementA, dataElementC, dataElementB, dataElementD ) );
+
+ List<DataElement> actual = new ArrayList<>( identifiableObjectManager.getByUidOrdered( DataElement.class, uids ) );
+
+ assertEquals( expected, actual );
+ }
}