← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11905: added new method getIdList in IdObjectUtils, returns a list of integers based on a collection of ...

 

------------------------------------------------------------
revno: 11905
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-09-04 10:34:55 +0200
message:
  added new method getIdList in IdObjectUtils, returns a list of integers based on a collection of idObjects
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/event/DefaultEventStore.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	2013-08-23 15:56:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectUtils.java	2013-09-04 08:34:55 +0000
@@ -29,7 +29,12 @@
  */
 
 import java.text.SimpleDateFormat;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
 
 /**
  * @author Lars Helge Overland
@@ -66,17 +71,17 @@
 
         return null;
     }
-    
+
     /**
      * Returns a list of uids for the given collection of IdentifiableObjects.
-     * 
+     *
      * @param objects the list of IdentifiableObjects.
      * @return a list of uids.
      */
     public static <T extends IdentifiableObject> List<String> getUids( Collection<T> objects )
     {
         List<String> uids = new ArrayList<String>();
-        
+
         if ( objects != null )
         {
             for ( T object : objects )
@@ -84,10 +89,10 @@
                 uids.add( object.getUid() );
             }
         }
-        
+
         return uids;
     }
-    
+
     /**
      * Filters the given list of IdentifiableObjects based on the given key.
      *
@@ -97,7 +102,7 @@
      * @return a filtered list of IdentifiableObjects.
      */
     public static <T extends IdentifiableObject> List<T> filterNameByKey( List<T> identifiableObjects, String key,
-                                                                          boolean ignoreCase )
+        boolean ignoreCase )
     {
         List<T> objects = new ArrayList<T>();
         ListIterator<T> iterator = identifiableObjects.listIterator();
@@ -120,17 +125,17 @@
 
         return objects;
     }
-    
+
     /**
      * Returns a list of IdentifiableObjects.
-     * 
+     *
      * @param objects the IdentifiableObjects to include in the list.
      * @return a list of IdentifiableObjects.
      */
     public static List<IdentifiableObject> getList( IdentifiableObject... objects )
     {
         List<IdentifiableObject> list = new ArrayList<IdentifiableObject>();
-        
+
         if ( objects != null )
         {
             for ( IdentifiableObject object : objects )
@@ -138,13 +143,13 @@
                 list.add( object );
             }
         }
-        
+
         return list;
     }
-    
+
     /**
      * Returns a list with erasure IdentifiableObject based on the given collection.
-     * 
+     *
      * @param collection the collection.
      * @return a list of IdentifiableObjects.
      */
@@ -154,12 +159,12 @@
         list.addAll( collection );
         return list;
     }
-    
+
     /**
      * Returns a list typed with the desired erasure based on the given collection.
      * This operation implies an unchecked cast and it is the responsibility of
      * the caller to make sure the cast is valid.
-     * 
+     *
      * @param collection the collection.
      * @return a list.
      */
@@ -167,7 +172,7 @@
     public static <T extends IdentifiableObject> List<T> asTypedList( Collection<IdentifiableObject> collection )
     {
         List<T> list = new ArrayList<T>();
-        
+
         if ( collection != null )
         {
             for ( IdentifiableObject object : collection )
@@ -175,13 +180,13 @@
                 list.add( (T) object );
             }
         }
-        
+
         return list;
     }
 
     /**
      * Removes duplicates from the given list while maintaining the order.
-     * 
+     *
      * @param list the list.
      */
     public static <T extends IdentifiableObject> List<T> removeDuplicates( List<T> list )
@@ -215,7 +220,7 @@
         {
             for ( IdentifiableObject object : objects )
             {
-                if ( object != null && object.getLastUpdated() != null && ( latest == null || object.getLastUpdated().after( latest ) ) )
+                if ( object != null && object.getLastUpdated() != null && (latest == null || object.getLastUpdated().after( latest )) )
                 {
                     latest = object.getLastUpdated();
                 }
@@ -224,10 +229,10 @@
 
         return latest != null && objects != null ? objects.size() + SEPARATOR + LONG_DATE_FORMAT.format( latest ) : null;
     }
-    
+
     /**
      * Generates a tag reflecting the date of when the object was last updated.
-     * 
+     *
      * @param object the identifiable object.
      * @return a string tag.
      */
@@ -235,4 +240,22 @@
     {
         return object != null ? LONG_DATE_FORMAT.format( object.getLastUpdated() ) : null;
     }
+
+    /**
+     * 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<Integer>();
+
+        for ( IdentifiableObject identifiableObject : identifiableObjects )
+        {
+            integers.add( identifiableObject.getId() );
+        }
+
+        return integers;
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/DefaultEventStore.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/DefaultEventStore.java	2013-09-03 18:28:38 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/DefaultEventStore.java	2013-09-04 08:34:55 +0000
@@ -42,6 +42,8 @@
 import java.util.Date;
 import java.util.List;
 
+import static org.hisp.dhis.common.IdentifiableObjectUtils.getIdList;
+
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
@@ -138,18 +140,6 @@
         return events;
     }
 
-    private List<Integer> getIdList( List<? extends IdentifiableObject> identifiableObjects )
-    {
-        List<Integer> integers = new ArrayList<Integer>();
-
-        for ( IdentifiableObject identifiableObject : identifiableObjects )
-        {
-            integers.add( identifiableObject.getId() );
-        }
-
-        return integers;
-    }
-
     private String buildSql( List<Integer> programIds, List<Integer> programStageIds, List<Integer> orgUnitIds, Date startDate, Date endDate )
     {
         String sql = "select p.uid as p_uid, ps.uid as ps_uid, psi.uid as psi_uid, ou.uid as ou_uid, psi.executiondate as psi_executiondate," +