Class EntityDataUtils
- java.lang.Object
-
- org.sakaiproject.entitybroker.util.EntityDataUtils
-
public class EntityDataUtils extends Object
Utilities which are useful when working withEntityDataobjects and their properties- Author:
- Aaron Zeckoski (azeckoski @ gmail.com)
-
-
Constructor Summary
Constructors Constructor Description EntityDataUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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 ObjectconvertToEntity(Object object)Convert an entity/data to just an entity, will preserve null (i.e. null in => null out)static EntityDataconvertToEntityData(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 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 Map<String,Object>extractMapProperties(Map m)Get the values from a map and convert them to strings, nulls pass throughstatic StringfindMapStringValue(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 itstatic ObjectfindMapValue(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 itstatic RestrictionfindSearchRestriction(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 nullstatic StringgetEntityId(Object entity)Gets the id field value from an entity if possiblestatic StringgetEntityIdField(Class<?> type)Gets the fieldname of the identifier field for an entity class typestatic EntityContentgetResourceDetails(ContentEntity entity)Produces a summary of an content entity for display in entitybroker.static EntityDatamakeEntityData(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 onlystatic <T,S>
voidputAllNewInMap(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 originalstatic booleantranslateSearchReference(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 expectstatic SearchtranslateStandardSearch(Search search)Translate the search into one using the standard search params
-
-
-
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 keyskeys- 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 keyskeys- 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
-
getResourceDetails
public static EntityContent getResourceDetails(ContentEntity entity)
Produces a summary of an content entity for display in entitybroker.- Parameters:
entity- The entity to display.- Returns:
- An EntityContent matching the supplied entity.
-
-