dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #38157
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19481: Impl method get( Collection<Class<IdentifiableObject>> classes, String uid ) on id object manager
------------------------------------------------------------
revno: 19481
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-06-22 00:17:33 +0200
message:
Impl method get( Collection<Class<IdentifiableObject>> classes, String uid ) on id object manager
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectUtils.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-06-16 10:59:33 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java 2015-06-21 22:17:33 +0000
@@ -58,6 +58,8 @@
<T extends IdentifiableObject> T get( Class<T> clazz, String uid );
<T extends IdentifiableObject> boolean exists( Class<T> clazz, String uid );
+
+ <T extends IdentifiableObject> T get( Collection<Class<IdentifiableObject>> classes, String uid );
<T extends IdentifiableObject> T getByCode( Class<T> clazz, String code );
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectUtils.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectUtils.java 2015-03-30 10:16:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectUtils.java 2015-06-21 22:17:33 +0000
@@ -34,10 +34,12 @@
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
+import java.util.Set;
import org.hisp.dhis.calendar.Calendar;
import org.hisp.dhis.calendar.DateTimeUnit;
@@ -114,6 +116,25 @@
}
/**
+ *
+ * @param classes
+ * @return
+ */
+ @SafeVarargs
+ @SuppressWarnings("unchecked")
+ public static Set<Class<IdentifiableObject>> asTypedClassSet( Class<? extends IdentifiableObject>... classes )
+ {
+ Set<Class<IdentifiableObject>> set = new HashSet<>();
+
+ for ( Class<? extends IdentifiableObject> clazz : classes )
+ {
+ set.add( (Class<IdentifiableObject>) clazz );
+ }
+
+ return set;
+ }
+
+ /**
* Returns a list of calendar specific period identifiers for the given collection of
* periods and calendar.
*
=== 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-06-16 10:59:33 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java 2015-06-21 22:17:33 +0000
@@ -194,6 +194,23 @@
@Override
@SuppressWarnings( "unchecked" )
+ public <T extends IdentifiableObject> T get( Collection<Class<IdentifiableObject>> classes, String uid )
+ {
+ for ( Class<? extends IdentifiableObject> clazz : classes )
+ {
+ T object = (T) get( clazz, uid );
+
+ if ( object != null )
+ {
+ return object;
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ @SuppressWarnings( "unchecked" )
public <T extends IdentifiableObject> T getByCode( Class<T> clazz, String code )
{
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-04-15 20:26:30 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/common/IdentifiableObjectManagerTest.java 2015-06-21 22:17:33 +0000
@@ -29,14 +29,17 @@
*/
import com.google.common.collect.Sets;
+
import org.hibernate.SessionFactory;
import org.hisp.dhis.DhisSpringTest;
import org.hisp.dhis.acl.AccessStringHelper;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementGroup;
import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.hibernate.exception.CreateAccessDeniedException;
import org.hisp.dhis.hibernate.exception.DeleteAccessDeniedException;
+import org.hisp.dhis.indicator.Indicator;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.user.User;
import org.hisp.dhis.user.UserGroup;
@@ -48,7 +51,9 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.GregorianCalendar;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import static org.junit.Assert.*;
@@ -99,6 +104,24 @@
}
@Test
+ public void testGetWithClasses()
+ {
+ DataElement dataElementA = createDataElement( 'A' );
+ DataElement dataElementB = createDataElement( 'B' );
+
+ dataElementService.addDataElement( dataElementA );
+ dataElementService.addDataElement( dataElementB );
+
+ Set<Class<? extends IdentifiableObject>> classes = new HashSet<>();
+ classes.add( DataElement.class );
+ classes.add( DataSet.class );
+ classes.add( Indicator.class );
+
+ assertEquals( dataElementA, identifiableObjectManager.get( DataDimension.DATA_DIMENSION_CLASSES, dataElementA.getUid() ) );
+ assertEquals( dataElementB, identifiableObjectManager.get( DataDimension.DATA_DIMENSION_CLASSES, dataElementB.getUid() ) );
+ }
+
+ @Test
public void publicAccessSetIfNoUser()
{
DataElement dataElement = createDataElement( 'A' );