org.sakaiproject.entitybroker.util
Class EntityDataUtils

java.lang.Object
  extended by org.sakaiproject.entitybroker.util.EntityDataUtils

public class EntityDataUtils
extends Object

Utilities which are useful when working with EntityData objects and their properties

Author:
Aaron Zeckoski (azeckoski @ gmail.com)

Constructor Summary
EntityDataUtils()
           
 
Method Summary
static List<?> convertToEntities(List<?> entities)
          Convert a list of entities / entity data to just entities, will preserve null (i.e. null in => null out)
static Object convertToEntity(Object object)
          Convert an entity/data to just an entity, will preserve null (i.e. null in => null out)
static List<EntityData> convertToEntityData(List<?> entities, EntityReference ref)
          Convert a list of objects to entity data objects (DOES NOT populate them), will preserve null (i.e. null in => null out)
static EntityData convertToEntityData(Object entity, EntityReference ref)
          Convert a single object to an entity data object (DOES NOT populate it), will preserve null (i.e. null in => null out)
static Map<String,Object> extractMapProperties(Map m)
          Get the values from a map and convert them to strings, nulls pass through
static String findMapStringValue(Map<String,?> map, String[] keys)
          Finds a map value for a key (or set of keys) if it exists in the map and returns the string value of it
static Object findMapValue(Map<String,?> map, String[] keys)
          Finds a map value for a key (or set of keys) if it exists in the map and returns the value of it
static Restriction findSearchRestriction(Search search, String key, String[] keys, String valuePrefix)
          Finds if there are any search restrictions with the given properties, if so it returns the Restriction, the value will have the given prefix appended to it's string value if it does not have it, the returned restriction will have the key set to the input key, otherwise returns null
static String getEntityId(Object entity)
          Gets the id field value from an entity if possible
static String getEntityIdField(Class<?> type)
          Gets the fieldname of the identifier field for an entity class type
static EntityData makeEntityData(EntityReference ref, Object entity)
          Make an entity data object out of whatever entity is given, use the given reference, if there is no id then this will attempt to get one otherwise it will use prefix only
static
<T,S> void
putAllNewInMap(Map<T,S> original, Map<T,S> newStuff)
          Puts the values of 2 maps together such that the values from the newStuff map are added to the original map only if they are not already in the the original
static boolean translateSearchReference(Search search, String key, String[] keys, String valuePrefix)
          Adds in a search restriction based on existing restrictions, this is ideally setup to convert restrictions into one that the developers expect
static Search translateStandardSearch(Search search)
          Translate the search into one using the standard search params
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EntityDataUtils

public EntityDataUtils()
Method Detail

convertToEntityData

public static List<EntityData> convertToEntityData(List<?> entities,
                                                   EntityReference ref)
Convert a list of objects to entity data objects (DOES NOT populate them), will preserve null (i.e. null in => null out)


convertToEntityData

public static EntityData convertToEntityData(Object entity,
                                             EntityReference ref)
Convert a single object to an entity data object (DOES NOT populate it), will preserve null (i.e. null in => null out)


convertToEntities

public static List<?> convertToEntities(List<?> entities)
Convert a list of entities / entity data to just entities, will preserve null (i.e. null in => null out)


convertToEntity

public static Object convertToEntity(Object object)
Convert an entity/data to just an entity, will preserve null (i.e. null in => null out)


makeEntityData

public static EntityData makeEntityData(EntityReference ref,
                                        Object entity)
Make an entity data object out of whatever entity is given, use the given reference, if there is no id then this will attempt to get one otherwise it will use prefix only


getEntityId

public static String getEntityId(Object entity)
Gets the id field value from an entity if possible

Parameters:
entity - any entity object
Returns:
the id value OR null if it cannot be found

getEntityIdField

public static String getEntityIdField(Class<?> type)
Gets the fieldname of the identifier field for an entity class type

Parameters:
type - any entity class type
Returns:
the name of the identifier field for this entity OR null if it cannot be determined

translateStandardSearch

public static Search translateStandardSearch(Search search)
Translate the search into one using the standard search params

Parameters:
search -
Returns:
the translated search

translateSearchReference

public static boolean translateSearchReference(Search search,
                                               String key,
                                               String[] keys,
                                               String valuePrefix)
Adds in a search restriction based on existing restrictions, this is ideally setup to convert restrictions into one that the developers expect


findSearchRestriction

public static Restriction findSearchRestriction(Search search,
                                                String key,
                                                String[] keys,
                                                String valuePrefix)
Finds if there are any search restrictions with the given properties, if so it returns the Restriction, the value will have the given prefix appended to it's string value if it does not have it, the returned restriction will have the key set to the input key, otherwise returns null


findMapStringValue

public static String findMapStringValue(Map<String,?> map,
                                        String[] keys)
Finds a map value for a key (or set of keys) if it exists in the map and returns the string value of it

Parameters:
map - any map with strings as keys
keys - an array of keys to try to find in order
Returns:
the string value OR null if it could not be found for any of the given keys

findMapValue

public static Object findMapValue(Map<String,?> map,
                                  String[] keys)
Finds a map value for a key (or set of keys) if it exists in the map and returns the value of it

Parameters:
map - any map with strings as keys
keys - an array of keys to try to find in order
Returns:
the value OR null if it could not be found for any of the given keys

putAllNewInMap

public static <T,S> void putAllNewInMap(Map<T,S> original,
                                        Map<T,S> newStuff)
Puts the values of 2 maps together such that the values from the newStuff map are added to the original map only if they are not already in the the original

Type Parameters:
T -
S -
Parameters:
original -
newStuff -

extractMapProperties

public static Map<String,Object> extractMapProperties(Map m)
Get the values from a map and convert them to strings, nulls pass through

Parameters:
m -
Returns:
the keys of any map as strings and the values as they were


Copyright © 2007-2013 CARET, University of Cambridge. All Rights Reserved.