Package ubic.gemma.persistence.util
Class EntityUtils
- java.lang.Object
-
- ubic.gemma.persistence.util.EntityUtils
-
public class EntityUtils extends Object
- Author:
- paul
-
-
Constructor Summary
Constructors Constructor Description EntityUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringaddGroupAndUserNameRestriction(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 PhenotypeAssociationDaoImplstatic voidaddUserAndGroupParameters(SQLQuery queryObject, SessionFactory sessionFactory)Populates parameters in query created using addGroupAndUserNameRestriction(boolean, boolean).static voidcreateFile(File file)static voiddeleteFile(File file)static <T extends Identifiable>
Map<Long,T>getIdMap(Collection<T> entities)Given a set of entities, create a map of their ids to the entities.static <T extends Identifiable>
List<Long>getIds(Collection<T> entities)static Class<?>getImplClass(Class<?> type)static ObjectgetImplementationForProxy(Object target)Expert only.static boolean[]getPermissions(gemma.gsec.acl.domain.AclObjectIdentity aoi)Checks ACL related properties from the AclObjectIdentity.static booleanisProxy(Object target)static <T,S>
voidpopulateMapSet(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.static voidrenameFile(File file, File newFile)
-
-
-
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 mapS- the type parameter of the set- Parameters:
map- the map to be checkedkey- the keyhash- the hash to be added to the set at the given key of the map
-
getIds
public static <T extends Identifiable> List<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 Identifiable> Map<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
-
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 editshowPublic- 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 fromSecurityUtil, 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:
- is object public
- can user write to object
- is object shared
-
createFile
public static void createFile(File file) throws IOException
- Throws:
IOException
-
deleteFile
public static void deleteFile(File file)
-
-