Class 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

      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 Object convertToEntity​(Object object)
      Convert an entity/data to just an entity, will preserve null (i.e. null in => null out)
      static org.sakaiproject.entitybroker.entityprovider.extension.EntityData convertToEntityData​(Object entity, org.sakaiproject.entitybroker.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<org.sakaiproject.entitybroker.entityprovider.extension.EntityData> convertToEntityData​(List<?> entities, org.sakaiproject.entitybroker.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 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 org.sakaiproject.entitybroker.entityprovider.search.Restriction findSearchRestriction​(org.sakaiproject.entitybroker.entityprovider.search.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 EntityContent getResourceDetails​(org.sakaiproject.content.api.ContentEntity entity)
      Produces a summary of an content entity for display in entitybroker.
      static org.sakaiproject.entitybroker.entityprovider.extension.EntityData makeEntityData​(org.sakaiproject.entitybroker.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​(org.sakaiproject.entitybroker.entityprovider.search.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 org.sakaiproject.entitybroker.entityprovider.search.Search translateStandardSearch​(org.sakaiproject.entitybroker.entityprovider.search.Search search)
      Translate the search into one using the standard search params
    • Constructor Detail

      • EntityDataUtils

        public EntityDataUtils()
    • Method Detail

      • convertToEntityData

        public static List<org.sakaiproject.entitybroker.entityprovider.extension.EntityData> convertToEntityData​(List<?> entities,
                                                                                                                  org.sakaiproject.entitybroker.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 org.sakaiproject.entitybroker.entityprovider.extension.EntityData convertToEntityData​(Object entity,
                                                                                                            org.sakaiproject.entitybroker.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 org.sakaiproject.entitybroker.entityprovider.extension.EntityData makeEntityData​(org.sakaiproject.entitybroker.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 org.sakaiproject.entitybroker.entityprovider.search.Search translateStandardSearch​(org.sakaiproject.entitybroker.entityprovider.search.Search search)
        Translate the search into one using the standard search params
        Parameters:
        search -
        Returns:
        the translated search
      • translateSearchReference

        public static boolean translateSearchReference​(org.sakaiproject.entitybroker.entityprovider.search.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 org.sakaiproject.entitybroker.entityprovider.search.Restriction findSearchRestriction​(org.sakaiproject.entitybroker.entityprovider.search.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
      • getResourceDetails

        public static EntityContent getResourceDetails​(org.sakaiproject.content.api.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.