Class 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
    • Constructor Detail

      • BagManager

        public BagManager​(Profile superProfile,
                          Model model)
        The BagManager references the super user profile to fetch global bags.
        Parameters:
        superProfile - the super user profile
        model - the object model
    • 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 from
        tag - 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.
      • 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 for
        states - 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 for
        state - 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 share
        bagOwnerUserName - the owner of the bag to share
        userName - the user with whom the bag is shared
        Throws:
        UserNotFoundException - if the user does't exist
        UserAlreadyShareBagException - 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-share
        bagOwnerUserName - the name of the bag owner
        userName - the user name sharing the bag
        Throws:
        UserNotFoundException - if the user does't exist
        BagDoesNotExistException - 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-share
        profile - the user sharing the bag
        Throws:
        UserNotFoundException - if the user does't exist
        BagDoesNotExistException - 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 share
        bagOwnerUserName - 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 for
        bagName - 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 for
        bagName - 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 for
        type - 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 for
        type - 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 for
        type - 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 for
        type - an unqualified class name
        onlyCurrent - 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 for
        type - 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 for
        profile - 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 for
        profile - 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 for
        profile - the user to fetch bags from
        Returns:
        bags containing the given id