Class EntityUtils


  • public class EntityUtils
    extends Object
    Author:
    paul
    • Constructor Detail

      • EntityUtils

        public EntityUtils()
    • Method Detail

      • populateMapSet

        public static <T,​S> void populateMapSet​(Map<T,​Set<S>> map,
                                                      T key,
                                                      S hash)
        Checks if the given map already contains a Set for the given key, and if it does, adds the given has code to it. If a key does not exist in the map, it creates a new set, and adds the has into it.
        Type Parameters:
        T - the key type parameter of the map
        S - the type parameter of the set
        Parameters:
        map - the map to be checked
        key - the key
        hash - the hash to be added to the set at the given key of the map
      • getIds

        public static <T extends IdentifiableList<Long> getIds​(Collection<T> entities)
        Parameters:
        entities - entities
        Returns:
        returns a collection of IDs. Avoids using reflection by requiring that the given entities all implement the Identifiable interface.
      • getIdMap

        public static <T extends IdentifiableMap<Long,​T> getIdMap​(Collection<T> entities)
        Given a set of entities, create a map of their ids to the entities. Note: If more than one entity share the same ID, there is no guarantee on which will be kept in the final mapping.
        Type Parameters:
        T - the type
        Parameters:
        entities - where id is called "id"
        Returns:
        the created map
      • getImplClass

        public static Class<?> getImplClass​(Class<?> type)
      • getImplementationForProxy

        public static Object getImplementationForProxy​(Object target)
        Expert only. Must be called within a session? Not sure why this is necessary. Obtain the implementation for a proxy. If target is not an instanceof HibernateProxy, target is returned.
        Parameters:
        target - The object to be un-proxied.
        Returns:
        the underlying implementation.
      • isProxy

        public static boolean isProxy​(Object target)
        Parameters:
        target - target
        Returns:
        true if the target is a hibernate proxy.
      • addGroupAndUserNameRestriction

        public static String addGroupAndUserNameRestriction​(boolean showOnlyEditable,
                                                            boolean showPublic)
        Have to add 'and' to start of this if it's a later clause Author: nicolas with fixes to generalize by paul, same code appears in the PhenotypeAssociationDaoImpl
        Parameters:
        showOnlyEditable - only show those the user has access to edit
        showPublic - also show public items (wont work if showOnlyEditable is true)
        Returns:
        clause
      • addUserAndGroupParameters

        public static void addUserAndGroupParameters​(SQLQuery queryObject,
                                                     SessionFactory sessionFactory)
        Populates parameters in query created using addGroupAndUserNameRestriction(boolean, boolean).
        Parameters:
        queryObject - the query object created using the sql query with group and username restrictions.
        sessionFactory - session factory from the DAO that is using this method.
      • getPermissions

        public static boolean[] getPermissions​(gemma.gsec.acl.domain.AclObjectIdentity aoi)
        Checks ACL related properties from the AclObjectIdentity. Some of the code is adapted from SecurityUtil, but allows usage without an Acl object.
        Parameters:
        aoi - the acl object identity of an object whose permissions are to be checked.
        Returns:
        an array of booleans that represent permissions of currently logged in user as follows:
        1. is object public
        2. can user write to object
        3. is object shared
        (note that actual indexing in the array starts at 0).
      • deleteFile

        public static void deleteFile​(File file)
      • renameFile

        public static void renameFile​(File file,
                                      File newFile)