dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #13804
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4528: Identifying identifiable objects
------------------------------------------------------------
revno: 4528
committer: Bob Jolliffe bobjolliffe@xxxxxxxxx
branch nick: dhis2
timestamp: Tue 2011-09-06 12:51:19 +0100
message:
Identifying identifiable objects
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/AbstractIdentifiableObject.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/AbstractNameableObject.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/NameableObject.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/AbstractIdentifiableObject.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/AbstractIdentifiableObject.java 2011-05-05 21:14:56 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/AbstractIdentifiableObject.java 2011-09-06 11:51:19 +0000
@@ -1,5 +1,10 @@
package org.hisp.dhis.common;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
/*
* Copyright (c) 2004-2010, University of Oslo
* All rights reserved.
@@ -96,4 +101,24 @@
{
this.name = name;
}
+
+ /**
+ * Get a map of uuids to internal identifiers
+ *
+ * @param objects the IdentifiableObjects to put in the map
+ * @return the map
+ */
+ public static Map<String, Integer> getUUIDMap( Collection<NameableObject> objects )
+ {
+ Map<String, Integer> map = new HashMap<String, Integer>();
+ for ( NameableObject object : objects )
+ {
+ String uuid = object.getUuid();
+ int internalId = object.getId();
+
+ map.put( uuid, internalId );
+ }
+
+ return map;
+ }
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/AbstractNameableObject.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/AbstractNameableObject.java 2011-05-05 21:14:56 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/AbstractNameableObject.java 2011-09-06 11:51:19 +0000
@@ -1,5 +1,12 @@
package org.hisp.dhis.common;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
/*
* Copyright (c) 2004-2010, University of Oslo
* All rights reserved.
@@ -26,18 +33,20 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
/**
* @author Bob Jolliffe
*/
public class AbstractNameableObject
extends AbstractIdentifiableObject implements NameableObject
{
+
/**
* Determines if a de-serialized file is compatible with this class.
*/
private static final long serialVersionUID = 714136796552146362L;
+ private final static Log log = LogFactory.getLog( AbstractNameableObject.class );
+
/**
* An alternative name of this Object. Optional but unique.
*/
@@ -111,4 +120,32 @@
{
this.description = description;
}
+
+ /**
+ * Get a map of codes to internal identifiers
+ *
+ * @param objects the NameableObjects to put in the map
+ * @return the map
+ */
+ public static Map<String, Integer> getCodeMap( Collection<NameableObject> objects )
+ {
+ Map<String, Integer> map = new HashMap<String, Integer>();
+ for ( NameableObject object : objects )
+ {
+ String code = object.getCode();
+ int internalId = object.getId();
+
+ // NOTE: its really not good that duplicate codes are possible
+ // Best we can do here is severe log and remove the item
+ if ( map.containsKey( code ) )
+ {
+ log.warn( object.getClass() + ": Duplicate code " + code );
+ map.remove( code );
+ } else
+ {
+ map.put( code, internalId );
+ }
+ }
+ return map;
+ }
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/NameableObject.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/NameableObject.java 2011-04-01 09:57:53 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/NameableObject.java 2011-09-06 11:51:19 +0000
@@ -1,5 +1,9 @@
package org.hisp.dhis.common;
+
+import java.util.Collection;
+import java.util.Map;
+
/*
* Copyright (c) 2011, University of Oslo
* All rights reserved.