Package org.intermine.api.bag
Class BagManager
- java.lang.Object
-
- org.intermine.api.bag.BagManager
-
public class BagManager extends java.lang.Object
A BagManager provides access to all global and/or user bags and methods to fetch them by type, etc.- Author:
- Richard Smith, Daniela Butano
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
BagManager.ByTagOrder
Compare lists based on their im:order:n tagclass
BagManager.CaseInsensitiveComparator
Lower-case key comparator
-
Constructor Summary
Constructors Constructor Description BagManager(Profile superProfile, Model model)
The BagManager references the super user profile to fetch global bags.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addTagsToBag(java.util.Collection<java.lang.String> tags, InterMineBag bag, Profile profile)
Add tags to a bag.void
close()
Close the TagManagerInterMineBag
getBag(Profile profile, java.lang.String bagName)
Fetch a global or user or shared bag by name.java.util.Map<java.lang.String,InterMineBag>
getBags(Profile profile)
Fetch all global bags, user bags and shared bags combined in the same map.java.util.Map<java.lang.String,InterMineBag>
getBagsOfType(Profile profile, java.lang.String type)
Fetch global and user bags of the specified type or a subclass of the specified type.java.util.Map<java.lang.String,InterMineBag>
getBagsOfType(Profile profile, java.lang.String type, boolean onlyCurrent)
Fetch global and user bags of the specified type or a subclass of the specified type.java.util.Map<java.lang.String,InterMineBag>
getCompatibleCurrentBags(Profile profile, java.lang.String type)
Fetch global and user bags current of the specified type or a subclass or any superclass of the specified type.java.util.Map<java.lang.String,InterMineBag>
getCurrentBags(Profile profile)
Get the bags this user has access to, as long as they are current.java.util.Collection<InterMineBag>
getCurrentBagsContainingId(Profile profile, java.lang.Integer id)
Fetch the current user or global or shared bags that contain the given id.java.util.Map<java.lang.String,InterMineBag>
getCurrentBagsOfType(Profile profile, java.lang.String type)
Fetch global and user bags current of the specified type or a subclass of the specified type.java.util.Map<java.lang.String,InterMineBag>
getCurrentUserBagsOfType(Profile profile, java.lang.String type)
Fetch user bags current of the specified type or a subclass of the specified type.InterMineBag
getGlobalBag(java.lang.String bagName)
Fetch a global bag by name.java.util.Map<java.lang.String,InterMineBag>
getGlobalBags()
Fetch globally available bags - superuser public bags that are available to everyone.java.util.Collection<InterMineBag>
getGlobalBagsContainingId(java.lang.Integer id)
Fetch global bags that contain the given id.java.util.Map<java.lang.String,InterMineBag>
getGlobalBagsWithTags(java.util.List<java.lang.String> tags)
Fetch globally available bags - superuser public bags that are available to everyone with a particular tag assigned to themjava.util.Map<java.lang.String,InterMineBag>
getSharedBags(Profile profile)
Fetch the shared bags for the given profile.java.util.Collection<InterMineBag>
getSharedBagsContainingId(Profile profile, java.lang.Integer id)
Fetch bags shared by another user that contain the given id.java.util.List<Tag>
getTagsForBag(InterMineBag bag, Profile profile)
Get a list of tags for a given bag.InterMineBag
getUserBag(Profile profile, java.lang.String bagName)
Fetch a user bag by name.java.util.Map<java.lang.String,InterMineBag>
getUserBags(Profile profile)
Fetch bags for the given profile.java.util.Collection<InterMineBag>
getUserBagsContainingId(Profile profile, java.lang.Integer id)
Fetch user bags that contain the given id.protected java.util.Map<java.lang.String,InterMineBag>
getUserBagsWithTag(Profile profile, java.lang.String tag)
Fetch bags from given protocol with a particular tag assigned to them.protected java.util.Map<java.lang.String,InterMineBag>
getUserBagsWithTags(Profile profile, java.util.List<java.lang.String> tags)
Give me profile bags matching a set of tagsjava.util.Set<java.lang.String>
getUsersSharingBag(java.lang.String bagName, java.lang.String bagOwnerUserName)
Return the users sharing the list given in input, not the ownerboolean
isAnyBagInState(Profile profile, BagState state)
Return true if there is at least one user bag for the given profile in the given stateboolean
isAnyBagInStates(Profile profile, java.util.Set<BagState> states)
Return true if there is at least one user bag for the given profile in at least one of the given statesboolean
isAnyBagNotCurrent(Profile profile)
Return true if there is at least one user bag for the given profile in the 'not_current' state.boolean
isAnyBagNotCurrentOrUpgrading(Profile profile)
Return true if there is at least one user bag for the given profile in the 'not_current' state or 'upgrading'.boolean
isAnyBagToUpgrade(Profile profile)
Return true if there is at least one user bag for the given profile in the 'to_upgrade' state.boolean
isPublic(InterMineBag bag)
Return true if the bag is public.java.util.Map<java.lang.String,InterMineBag>
orderBags(java.util.Map<java.lang.String,InterMineBag> bags)
Order a map of bags by im:order:n tagvoid
shareBagWithUser(java.lang.String bagName, java.lang.String bagOwnerUserName, java.lang.String userName)
Share the bag given in input with the user which userName inputvoid
shareBagWithUser(InterMineBag bag, Profile recipient)
Let the recipient gain access to this bag in future uses of the application.void
unshareBagWithUser(java.lang.String bagName, java.lang.String bagOwnerUserName, java.lang.String userName)
Unshare the bag with the user given in inputvoid
unshareBagWithUser(InterMineBag bag, Profile profile)
Un-share the bag with the user given in input
-
-
-
Method Detail
-
getGlobalBags
public java.util.Map<java.lang.String,InterMineBag> getGlobalBags()
Fetch globally available bags - superuser public bags that are available to everyone.- Returns:
- a map from bag name to bag
-
getGlobalBagsWithTags
public java.util.Map<java.lang.String,InterMineBag> getGlobalBagsWithTags(java.util.List<java.lang.String> tags)
Fetch globally available bags - superuser public bags that are available to everyone with a particular tag assigned to them- Parameters:
tags
- tag the tags to filter- Returns:
- a map from bag name to bag
-
getUserBagsWithTag
protected java.util.Map<java.lang.String,InterMineBag> getUserBagsWithTag(Profile profile, java.lang.String tag)
Fetch bags from given protocol with a particular tag assigned to them.- Parameters:
profile
- the user to fetch bags fromtag
- the tag to filter- Returns:
- a map from bag name to bag
-
getUserBagsWithTags
protected java.util.Map<java.lang.String,InterMineBag> getUserBagsWithTags(Profile profile, java.util.List<java.lang.String> tags)
Give me profile bags matching a set of tags- Parameters:
profile
- The profile these bags must belong to.tags
- The tags each bag must have.- Returns:
- The bags of a profile with all of the required tags.
-
addTagsToBag
public void addTagsToBag(java.util.Collection<java.lang.String> tags, InterMineBag bag, Profile profile) throws TagManager.TagNameException, TagManager.TagNamePermissionException
Add tags to a bag.- Parameters:
tags
- A list of tag names to addbag
- The bag to add them toprofile
- The profile this bag belongs to- Throws:
TagManager.TagNamePermissionException
- If the profile is not allowed to apply this tag.TagManager.TagNameException
- If the tag name itself is illegal.
-
isPublic
public boolean isPublic(InterMineBag bag)
Return true if the bag is public.- Parameters:
bag
- The bag in question.- Returns:
- True if tagged with "im:public"
-
getTagsForBag
public java.util.List<Tag> getTagsForBag(InterMineBag bag, Profile profile)
Get a list of tags for a given bag.- Parameters:
bag
- The bag to get tags for.profile
- The profile whose tags we are looking for.- Returns:
- A list of Tag objects
-
getUserBags
public java.util.Map<java.lang.String,InterMineBag> getUserBags(Profile profile)
Fetch bags for the given profile.- Parameters:
profile
- the user to fetch bags for- Returns:
- a map from bag name to bag
-
isAnyBagInStates
public boolean isAnyBagInStates(Profile profile, java.util.Set<BagState> states)
Return true if there is at least one user bag for the given profile in at least one of the given states- Parameters:
profile
- the user to fetch bags forstates
- the states we are querying for.- Returns:
- whether or not there is such a bag.
-
isAnyBagInState
public boolean isAnyBagInState(Profile profile, BagState state)
Return true if there is at least one user bag for the given profile in the given state- Parameters:
profile
- the user to fetch bags forstate
- the state we are querying for.- Returns:
- whether or not there is such a bag.
-
isAnyBagNotCurrent
public boolean isAnyBagNotCurrent(Profile profile)
Return true if there is at least one user bag for the given profile in the 'not_current' state.- Parameters:
profile
- the user to fetch bags for- Returns:
- Whether there is such a bag.
-
isAnyBagNotCurrentOrUpgrading
public boolean isAnyBagNotCurrentOrUpgrading(Profile profile)
Return true if there is at least one user bag for the given profile in the 'not_current' state or 'upgrading'.- Parameters:
profile
- the user to fetch bags for- Returns:
- a map from bag name to bag
-
isAnyBagToUpgrade
public boolean isAnyBagToUpgrade(Profile profile)
Return true if there is at least one user bag for the given profile in the 'to_upgrade' state.- Parameters:
profile
- the user to fetch bags for- Returns:
- a map from bag name to bag
-
getSharedBags
public java.util.Map<java.lang.String,InterMineBag> getSharedBags(Profile profile)
Fetch the shared bags for the given profile.- Parameters:
profile
- the user to fetch bags for- Returns:
- a map from bag name to bag
-
shareBagWithUser
public void shareBagWithUser(java.lang.String bagName, java.lang.String bagOwnerUserName, java.lang.String userName) throws UserNotFoundException, UserAlreadyShareBagException
Share the bag given in input with the user which userName input- Parameters:
bagName
- the bag name to sharebagOwnerUserName
- the owner of the bag to shareuserName
- the user with whom the bag is shared- Throws:
UserNotFoundException
- if the user does't existUserAlreadyShareBagException
- if the bag is already shared by the user
-
shareBagWithUser
public void shareBagWithUser(InterMineBag bag, Profile recipient) throws UserNotFoundException, UserAlreadyShareBagException
Let the recipient gain access to this bag in future uses of the application.- Parameters:
bag
- the bag to sharerecipient
- the user with whom which the bag is shared- Throws:
UserNotFoundException
- if the user does't existUserAlreadyShareBagException
- if the bag is already shared by the user
-
unshareBagWithUser
public void unshareBagWithUser(java.lang.String bagName, java.lang.String bagOwnerUserName, java.lang.String userName)
Unshare the bag with the user given in input- Parameters:
bagName
- the bag to un-sharebagOwnerUserName
- the name of the bag owneruserName
- the user name sharing the bag- Throws:
UserNotFoundException
- if the user does't existBagDoesNotExistException
- if the bag does't exist
-
unshareBagWithUser
public void unshareBagWithUser(InterMineBag bag, Profile profile)
Un-share the bag with the user given in input- Parameters:
bag
- the bag to un-shareprofile
- the user sharing the bag- Throws:
UserNotFoundException
- if the user does't existBagDoesNotExistException
- if the bag does't exist
-
getUsersSharingBag
public java.util.Set<java.lang.String> getUsersSharingBag(java.lang.String bagName, java.lang.String bagOwnerUserName)
Return the users sharing the list given in input, not the owner- Parameters:
bagName
- the bag name the users sharebagOwnerUserName
- the name of the bag owner- Returns:
- the list of users sharing the bag
-
getBags
public java.util.Map<java.lang.String,InterMineBag> getBags(Profile profile)
Fetch all global bags, user bags and shared bags combined in the same map. If user has a bag with the same name as a global bag the user's bag takes precedence.- Parameters:
profile
- the user to fetch bags for- Returns:
- a map from bag name to bag
-
getCurrentBags
public java.util.Map<java.lang.String,InterMineBag> getCurrentBags(Profile profile)
Get the bags this user has access to, as long as they are current.- Parameters:
profile
- the profile of the user accessing to the bags- Returns:
- a map from bag name to bag
-
orderBags
public java.util.Map<java.lang.String,InterMineBag> orderBags(java.util.Map<java.lang.String,InterMineBag> bags)
Order a map of bags by im:order:n tag- Parameters:
bags
- unordered- Returns:
- an ordered Map of InterMineBags
-
getGlobalBag
public InterMineBag getGlobalBag(java.lang.String bagName)
Fetch a global bag by name.- Parameters:
bagName
- the name of bag to fetch- Returns:
- the bag or null if not found
-
getUserBag
public InterMineBag getUserBag(Profile profile, java.lang.String bagName)
Fetch a user bag by name.- Parameters:
profile
- the user to fetch bags forbagName
- the name of bag to fetch- Returns:
- the bag or null if not found
-
getBag
public InterMineBag getBag(Profile profile, java.lang.String bagName)
Fetch a global or user or shared bag by name. If user has a bag with the same name as a global bag, the user's bag takes precedence.- Parameters:
profile
- the user to fetch bags forbagName
- the name of bag to fetch- Returns:
- the bag or null if not found
-
getBagsOfType
public java.util.Map<java.lang.String,InterMineBag> getBagsOfType(Profile profile, java.lang.String type)
Fetch global and user bags of the specified type or a subclass of the specified type.- Parameters:
profile
- the user to fetch bags fortype
- an unqualified class name- Returns:
- a map from bag name to bag
-
getCurrentBagsOfType
public java.util.Map<java.lang.String,InterMineBag> getCurrentBagsOfType(Profile profile, java.lang.String type)
Fetch global and user bags current of the specified type or a subclass of the specified type.- Parameters:
profile
- the user to fetch bags fortype
- an unqualified class name- Returns:
- a map from bag name to bag
-
getCompatibleCurrentBags
public java.util.Map<java.lang.String,InterMineBag> getCompatibleCurrentBags(Profile profile, java.lang.String type)
Fetch global and user bags current of the specified type or a subclass or any superclass of the specified type.- Parameters:
profile
- the user to fetch bags fortype
- an unqualified class name- Returns:
- a map from bag name to bag
-
getBagsOfType
public java.util.Map<java.lang.String,InterMineBag> getBagsOfType(Profile profile, java.lang.String type, boolean onlyCurrent)
Fetch global and user bags of the specified type or a subclass of the specified type.- Parameters:
profile
- the user to fetch bags fortype
- an unqualified class nameonlyCurrent
- if true return only the current bags- Returns:
- a map from bag name to bag
-
getCurrentUserBagsOfType
public java.util.Map<java.lang.String,InterMineBag> getCurrentUserBagsOfType(Profile profile, java.lang.String type)
Fetch user bags current of the specified type or a subclass of the specified type.- Parameters:
profile
- the user to fetch bags fortype
- an unqualified class name- Returns:
- a map from bag name to bag
-
getGlobalBagsContainingId
public java.util.Collection<InterMineBag> getGlobalBagsContainingId(java.lang.Integer id)
Fetch global bags that contain the given id.- Parameters:
id
- the id to search bags for- Returns:
- bags containing the given id
-
getUserBagsContainingId
public java.util.Collection<InterMineBag> getUserBagsContainingId(Profile profile, java.lang.Integer id)
Fetch user bags that contain the given id.- Parameters:
id
- the id to search bags forprofile
- the user to fetch bags from- Returns:
- bags containing the given id
-
getSharedBagsContainingId
public java.util.Collection<InterMineBag> getSharedBagsContainingId(Profile profile, java.lang.Integer id)
Fetch bags shared by another user that contain the given id.- Parameters:
id
- the id to search bags forprofile
- the user to fetch bags from- Returns:
- bags containing the given id
-
getCurrentBagsContainingId
public java.util.Collection<InterMineBag> getCurrentBagsContainingId(Profile profile, java.lang.Integer id)
Fetch the current user or global or shared bags that contain the given id. If user has a bag with the same name as a global bag the user's bag takes precedence. Only current bags are included.- Parameters:
id
- the id to search bags forprofile
- the user to fetch bags from- Returns:
- bags containing the given id
-
close
public void close() throws ObjectStoreException
Close the TagManager- Throws:
ObjectStoreException
- in exceptional circumstances
-
-