dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #40565
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20590: Centralized method
------------------------------------------------------------
revno: 20590
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-10-08 16:59:36 +0200
message:
Centralized method
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectUtils.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.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/IdentifiableObjectUtils.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectUtils.java 2015-10-08 13:50:01 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectUtils.java 2015-10-08 14:59:36 +0000
@@ -38,6 +38,7 @@
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
+import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.hisp.dhis.calendar.Calendar;
@@ -100,17 +101,18 @@
*/
public static <T extends IdentifiableObject> List<String> getUids( Collection<T> objects )
{
- List<String> uids = new ArrayList<>();
-
- if ( objects != null )
- {
- for ( T object : objects )
- {
- uids.add( object.getUid() );
- }
- }
-
- return uids;
+ return objects != null ? objects.stream().map( o -> o.getUid() ).collect( Collectors.toList() ) : null;
+ }
+
+ /**
+ * Returns a list of internal identifiers for the given collection of IdentifiableObjects.
+ *
+ * @param objects the list of IdentifiableObjects.
+ * @return a list of uids.
+ */
+ public static <T extends IdentifiableObject> List<Integer> getIdentifiers( Collection<T> objects )
+ {
+ return objects != null ? objects.stream().map( o -> o.getId() ).collect( Collectors.toList() ) : null;
}
/**
@@ -166,27 +168,6 @@
}
/**
- * Returns a list of internal identifiers for the given collection of IdentifiableObjects.
- *
- * @param objects the list of IdentifiableObjects.
- * @return a list of uids.
- */
- public static <T extends IdentifiableObject> List<Integer> getIdentifiers( Collection<T> objects )
- {
- List<Integer> uids = new ArrayList<>();
-
- if ( objects != null )
- {
- for ( T object : objects )
- {
- uids.add( object.getId() );
- }
- }
-
- return uids;
- }
-
- /**
* Filters the given list of IdentifiableObjects based on the given key.
*
* @param identifiableObjects the list of IdentifiableObjects.
@@ -332,30 +313,6 @@
}
/**
- * Returns a list of database identifiers from a list of idObjects
- *
- * @param identifiableObjects Collection of idObjects
- * @return List of database identifiers for idObjects
- */
- public static List<Integer> getIdList( Collection<? extends IdentifiableObject> identifiableObjects )
- {
- List<Integer> integers = new ArrayList<>();
-
- if ( identifiableObjects != null )
- {
- for ( IdentifiableObject identifiableObject : identifiableObjects )
- {
- if ( identifiableObject != null )
- {
- integers.add( identifiableObject.getId() );
- }
- }
- }
-
- return integers;
- }
-
- /**
* Returns a mapping between the uid and the name of the given identifiable
* objects.
*
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java 2015-10-01 10:05:20 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java 2015-10-08 14:59:36 +0000
@@ -54,7 +54,7 @@
import java.util.List;
import java.util.Set;
-import static org.hisp.dhis.common.IdentifiableObjectUtils.getIdList;
+import static org.hisp.dhis.common.IdentifiableObjectUtils.getIdentifiers;
import static org.hisp.dhis.commons.util.TextUtils.getCommaDelimitedString;
import static org.hisp.dhis.system.util.DateUtils.getMediumDateString;
@@ -331,7 +331,7 @@
private String getEventSelectQuery( EventSearchParams params, List<OrganisationUnit> organisationUnits )
{
- List<Integer> orgUnitIds = getIdList( organisationUnits );
+ List<Integer> orgUnitIds = getIdentifiers( organisationUnits );
SqlHelper hlp = new SqlHelper();