Class Profile

  • Direct Known Subclasses:
    AnonProfile

    public class Profile
    extends java.lang.Object
    Class to represent a user of the webapp The profile is responsible for informing its search repository of all web-searchable objects created or deleted on its watch.
    Author:
    Mark Woodbridge, Thomas Riley, Daniela Butano
    • Constructor Summary

      Constructors 
      Constructor Description
      Profile​(ProfileManager manager, java.lang.String username, java.lang.Integer userId, java.lang.String password, java.util.Map<java.lang.String,​SavedQuery> savedQueries, java.util.Map<java.lang.String,​InterMineBag> savedBags, java.util.Map<java.lang.String,​InterMineBag> savedInvalidBags, java.util.Map<java.lang.String,​ApiTemplate> savedTemplates, java.lang.String token, boolean isLocal, boolean isSuperUser)
      Construct a Profile
      Profile​(ProfileManager manager, java.lang.String username, java.lang.Integer userId, java.lang.String password, java.util.Map<java.lang.String,​SavedQuery> savedQueries, java.util.Map<java.lang.String,​InterMineBag> savedBags, java.util.Map<java.lang.String,​ApiTemplate> savedTemplates, boolean isLocal, boolean isSuperUser)
      Construct a profile without an API key
      Profile​(ProfileManager manager, java.lang.String username, java.lang.Integer userId, java.lang.String password, java.util.Map<java.lang.String,​SavedQuery> savedQueries, java.util.Map<java.lang.String,​InterMineBag> savedBags, java.util.Map<java.lang.String,​ApiTemplate> savedTemplates, java.lang.String token, boolean isLocal, boolean isSuperUser)
      Construct a Profile
      Profile​(ProfileManager manager, java.lang.String username, java.lang.Integer userId, java.lang.String password, java.util.Map<java.lang.String,​SavedQuery> savedQueries, BagSet bagset, java.util.Map<java.lang.String,​ApiTemplate> savedTemplates, java.lang.String token, boolean isLocal, boolean isSuperUser)
      Construct a Profile
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      InterMineBag createBag​(java.lang.String name, java.lang.String type, java.lang.String description, java.util.Map<java.lang.String,​java.util.List<FieldDescriptor>> classKeys)
      Create a bag and save it to the userprofile database.
      void deleteBag​(java.lang.String name)
      Delete a bag from the user account, if user is logged in also deletes from the userprofile database.
      void deleteHistory​(java.lang.String name)
      Remove an item from the query history.
      void deleteQuery​(java.lang.String name)
      Delete a query
      void deleteTemplate​(java.lang.String name, TrackerDelegate trackerDelegate, boolean deleteTracks)
      Delete a template and its tags, rename the template tracks adding the prefix "deleted_" to the previous name.
      void disableSaving()
      Disable saving until enableSaving() is called.
      void enableSaving()
      Re-enable saving when saveTemplate(), deleteQuery() etc.
      void fixInvalidBag​(java.lang.String name, java.lang.String newType)
      Fix this bag by changing its type
      java.util.Map<java.lang.String,​StorableBag> getAllBags()
      Get all bags associated with this profile, both valid and invalid.
      java.lang.String getApiKey()  
      java.util.Map<java.lang.String,​InterMineBag> getCurrentSavedBags()
      Get the value of savedBags current
      java.lang.String getDayToken()
      Get a token with at least an hour of validity, and up to 24 hours.
      java.lang.String getEmailAddress()
      Get this user's preferred email address.
      java.util.Map<java.lang.String,​SavedQuery> getHistory()
      Get the session query history.
      java.util.Map<java.lang.String,​InvalidBag> getInvalidBags()  
      java.lang.String getName()
      Return a first part of the username before the "@" sign (used in metabolicMine)
      java.lang.String getPassword()
      Get the value of password
      java.util.Map<java.lang.String,​java.lang.String> getPreferences()
      Get the object representing the preferences of this user.
      ProfileManager getProfileManager()
      Return the ProfileManager that was passed to the constructor.
      java.util.Map<java.lang.String,​InterMineBag> getSavedBags()
      Get the value of savedBags
      java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​InterMineBag>> getSavedBagsByStatus()
      Get the saved bags in a map of "status key" => map of lists
      java.util.Map<java.lang.String,​SavedQuery> getSavedQueries()
      Get the value of savedQueries
      java.util.Map<java.lang.String,​ApiTemplate> getSavedTemplates()
      Get the users saved templates
      SearchRepository getSearchRepository()
      Get the SearchRepository for this Profile.
      java.util.Map<java.lang.String,​InterMineBag> getSharedBags()
      Return the shared bags for the profile.
      java.lang.String getSingleUseKey()
      Return a single use API key for this profile
      boolean getSuperuser()
      Alias of isSuperUser() for jsp purposes.
      ApiTemplate getTemplate​(java.lang.String name)
      get a template
      java.lang.Integer getUserId()
      Get the value of userId
      java.lang.String getUsername()
      Get the value of username
      java.util.Map<java.lang.String,​? extends WebSearchable> getWebSearchablesByType​(java.lang.String type)
      Return a WebSearchable Map for the given type.
      void invalidateTemplateCacheIfRequired()
      When a template or tag is updated, invalidate cache so it can be refreshed
      boolean isLocal()
      Returns true if this is a local account, and not, for example, an OpenID account.
      boolean isLoggedIn()
      Return true if and only if the user is logged is (and the Profile will be written to the userprofile).
      boolean isSuperuser()
      Return true if and only if the user logged is superuser
      boolean prefers​(java.lang.String preference)
      Determine whether a user perfers a certain thing or not.
      void renameBag​(java.lang.String oldName, java.lang.String newName)
      Rename an existing bag, throw exceptions when bag doesn't exist of if new name already exists.
      void renameHistory​(java.lang.String oldName, java.lang.String newName)
      Rename an item in the history.
      void saveBag​(java.lang.String name, InterMineBag bag)
      Stores a new bag in the profile.
      void saveBag​(InterMineBag bag)
      Stores a new bag in the profile.
      void saveHistory​(SavedQuery query)
      Save a query to the query history.
      java.util.Map<java.lang.String,​java.lang.String> saveQueries​(java.util.Map<? extends java.lang.String,​? extends PathQuery> toSave)
      Save the map of queries as given to the user's profile, avoiding all possible name collisions.
      void saveQuery​(java.lang.String name, SavedQuery query)
      Save or update a query.
      void saveTemplate​(java.lang.String name, ApiTemplate template)
      Save a template
      void setApiKey​(java.lang.String token)
      Set the API token for this user, and save it in the backing DB.
      void setSuperuser​(boolean isSuperUser)
      Set the superuser flag and store it in userprofile database
      void setUserId​(java.lang.Integer userId)
      Set the userId
      void updateBagDescription​(java.lang.String name, java.lang.String newDescription)
      Update the description of bag.
      void updateBagType​(java.lang.String name, java.lang.String newType)
      Update the type of bag.
      void updateTemplate​(java.lang.String oldName, ApiTemplate template)
      Update an existing template, throw exceptions when template doesn't exist.
      void updateUserRepositoryWithSharedBags()
      Update the user repository with the sharedbags
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • NO_QUERIES

        public static final java.util.Map<java.lang.String,​SavedQuery> NO_QUERIES
        Empty typed map holding no saved queries - useful when creating profiles.
      • NO_BAGS

        public static final java.util.Map<java.lang.String,​InterMineBag> NO_BAGS
        Empty typed map holding no bags - useful when creating profiles.
      • NO_TEMPLATES

        public static final java.util.Map<java.lang.String,​ApiTemplate> NO_TEMPLATES
        Empty typed map holding no templates - useful when creating profiles.
      • username

        protected java.lang.String username
      • userId

        protected java.lang.Integer userId
      • password

        protected java.lang.String password
      • isSuperUser

        protected boolean isSuperUser
      • savedQueries

        protected java.util.Map<java.lang.String,​SavedQuery> savedQueries
      • savedBags

        protected java.util.Map<java.lang.String,​InterMineBag> savedBags
      • savedTemplates

        protected java.util.Map<java.lang.String,​ApiTemplate> savedTemplates
      • savedInvalidBags

        protected java.util.Map<java.lang.String,​InvalidBag> savedInvalidBags
      • savingDisabled

        protected boolean savingDisabled
      • queryHistory

        protected java.util.Map<java.lang.String,​SavedQuery> queryHistory
    • Constructor Detail

      • Profile

        public Profile​(ProfileManager manager,
                       java.lang.String username,
                       java.lang.Integer userId,
                       java.lang.String password,
                       java.util.Map<java.lang.String,​SavedQuery> savedQueries,
                       java.util.Map<java.lang.String,​InterMineBag> savedBags,
                       java.util.Map<java.lang.String,​ApiTemplate> savedTemplates,
                       java.lang.String token,
                       boolean isLocal,
                       boolean isSuperUser)
        Construct a Profile
        Parameters:
        manager - the manager for this profile
        username - the username for this profile
        userId - the id of this user
        password - the password for this profile
        savedQueries - the saved queries for this profile
        savedBags - the saved bags for this profile
        savedTemplates - the saved templates for this profile
        token - the token to use as an API key
        isLocal - true if the account is local
        isSuperUser - true if the user is a super user
      • Profile

        public Profile​(ProfileManager manager,
                       java.lang.String username,
                       java.lang.Integer userId,
                       java.lang.String password,
                       java.util.Map<java.lang.String,​SavedQuery> savedQueries,
                       java.util.Map<java.lang.String,​InterMineBag> savedBags,
                       java.util.Map<java.lang.String,​InterMineBag> savedInvalidBags,
                       java.util.Map<java.lang.String,​ApiTemplate> savedTemplates,
                       java.lang.String token,
                       boolean isLocal,
                       boolean isSuperUser)
        Construct a Profile
        Parameters:
        manager - the manager for this profile
        username - the username for this profile
        userId - the id of this user
        password - the password for this profile
        savedQueries - the saved queries for this profile
        savedBags - the saved bags for this profile
        savedInvalidBags - the saved bags which type doesn't match with the model
        savedTemplates - the saved templates for this profile
        token - The token to use as an API key
        isLocal - true if the account is local
        isSuperUser - the flag identifying the super user
      • Profile

        public Profile​(ProfileManager manager,
                       java.lang.String username,
                       java.lang.Integer userId,
                       java.lang.String password,
                       java.util.Map<java.lang.String,​SavedQuery> savedQueries,
                       BagSet bagset,
                       java.util.Map<java.lang.String,​ApiTemplate> savedTemplates,
                       java.lang.String token,
                       boolean isLocal,
                       boolean isSuperUser)
        Construct a Profile
        Parameters:
        manager - the manager for this profile
        username - the username for this profile
        userId - the id of this user
        password - the password for this profile
        savedQueries - the saved queries for this profile
        bagset - a bagset (=valid and invalid bags) for this profile
        savedTemplates - the saved templates for this profile
        token - The token to use as an API key
        isLocal - true if the account is local
        isSuperUser - the flag identifying the super user
      • Profile

        public Profile​(ProfileManager manager,
                       java.lang.String username,
                       java.lang.Integer userId,
                       java.lang.String password,
                       java.util.Map<java.lang.String,​SavedQuery> savedQueries,
                       java.util.Map<java.lang.String,​InterMineBag> savedBags,
                       java.util.Map<java.lang.String,​ApiTemplate> savedTemplates,
                       boolean isLocal,
                       boolean isSuperUser)
        Construct a profile without an API key
        Parameters:
        manager - the manager for this profile
        username - the username for this profile
        userId - the id of this user
        password - the password for this profile
        savedQueries - the saved queries for this profile
        savedBags - the saved bags for this profile
        savedTemplates - the saved templates for this profile
        isLocal - true if the account is local
        isSuperUser - the flag identifying the super user
    • Method Detail

      • getProfileManager

        public ProfileManager getProfileManager()
        Return the ProfileManager that was passed to the constructor.
        Returns:
        the ProfileManager
      • getUsername

        public java.lang.String getUsername()
        Get the value of username
        Returns:
        the value of username
      • getEmailAddress

        public java.lang.String getEmailAddress()
        Get this user's preferred email address.
        Returns:
        This user's email address.
      • getName

        public java.lang.String getName()
        Return a first part of the username before the "@" sign (used in metabolicMine)
        Returns:
        String
      • isLoggedIn

        public boolean isLoggedIn()
        Return true if and only if the user is logged is (and the Profile will be written to the userprofile).
        Returns:
        Return true if logged in
      • isSuperuser

        public boolean isSuperuser()
        Return true if and only if the user logged is superuser
        Returns:
        Return true if superuser
      • getSuperuser

        public boolean getSuperuser()
        Alias of isSuperUser() for jsp purposes.
        Returns:
        The same value as isSuperUser().
      • setSuperuser

        public void setSuperuser​(boolean isSuperUser)
                          throws ObjectStoreException
        Set the superuser flag and store it in userprofile database
        Parameters:
        isSuperUser - if true the profile is set as superuser
        Throws:
        ObjectStoreException - if an error occurs during storage of the object
      • getUserId

        public java.lang.Integer getUserId()
        Get the value of userId
        Returns:
        an Integer
      • setUserId

        public void setUserId​(java.lang.Integer userId)
        Set the userId
        Parameters:
        userId - an Integer
      • getPassword

        public java.lang.String getPassword()
        Get the value of password
        Returns:
        the value of password
      • disableSaving

        public void disableSaving()
        Disable saving until enableSaving() is called. This is called before many templates or queries need to be saved or deleted because each call to ProfileManager.saveProfile() is slow.
      • enableSaving

        public void enableSaving()
        Re-enable saving when saveTemplate(), deleteQuery() etc. are called. Also calls ProfileManager.saveProfile() to write this Profile to the database and rebuilds the template description index.
      • getSavedTemplates

        public java.util.Map<java.lang.String,​ApiTemplate> getSavedTemplates()
        Get the users saved templates
        Returns:
        saved templates
      • saveTemplate

        public void saveTemplate​(java.lang.String name,
                                 ApiTemplate template)
                          throws BadTemplateException
        Save a template
        Parameters:
        name - the template name
        template - the template
        Throws:
        BadTemplateException - if the template name is invalid.
      • getTemplate

        public ApiTemplate getTemplate​(java.lang.String name)
        get a template
        Parameters:
        name - the template
        Returns:
        template
      • deleteTemplate

        public void deleteTemplate​(java.lang.String name,
                                   TrackerDelegate trackerDelegate,
                                   boolean deleteTracks)
        Delete a template and its tags, rename the template tracks adding the prefix "deleted_" to the previous name. If trackerDelegate is null, the template tracks are not renamed
        Parameters:
        name - the template name
        trackerDelegate - used to rename the template tracks.
        deleteTracks - true if we want to delete the tracks associated to the template. Actually the tracks have never been deleted but only renamed
      • invalidateTemplateCacheIfRequired

        public void invalidateTemplateCacheIfRequired()
        When a template or tag is updated, invalidate cache so it can be refreshed
      • getSavedQueries

        public java.util.Map<java.lang.String,​SavedQuery> getSavedQueries()
        Get the value of savedQueries
        Returns:
        the value of savedQueries
      • saveQuery

        public void saveQuery​(java.lang.String name,
                              SavedQuery query)
        Save or update a query. If a query with the given name exists in this profile, that query will be overwritten.
        Parameters:
        name - the query name
        query - the query
      • saveQueries

        public java.util.Map<java.lang.String,​java.lang.String> saveQueries​(java.util.Map<? extends java.lang.String,​? extends PathQuery> toSave)
        Save the map of queries as given to the user's profile, avoiding all possible name collisions. This method will not overwrite any existing user data.
        Parameters:
        toSave - The queries to save.
        Returns:
        successes The queries as they were saved.
      • deleteQuery

        public void deleteQuery​(java.lang.String name)
        Delete a query
        Parameters:
        name - the query name
      • getHistory

        public java.util.Map<java.lang.String,​SavedQuery> getHistory()
        Get the session query history.
        Returns:
        map from query name to SavedQuery
      • saveHistory

        public void saveHistory​(SavedQuery query)
        Save a query to the query history.
        Parameters:
        query - the SavedQuery to save to the history
      • deleteHistory

        public void deleteHistory​(java.lang.String name)
        Remove an item from the query history.
        Parameters:
        name - the of the SavedQuery from the history
      • renameHistory

        public void renameHistory​(java.lang.String oldName,
                                  java.lang.String newName)
        Rename an item in the history.
        Parameters:
        oldName - the name of the old item
        newName - the new name
      • getSavedBags

        public java.util.Map<java.lang.String,​InterMineBag> getSavedBags()
        Get the value of savedBags
        Returns:
        the value of savedBags
      • getInvalidBags

        public java.util.Map<java.lang.String,​InvalidBag> getInvalidBags()
        Returns:
        the invalid bags for this profile.
      • getAllBags

        public java.util.Map<java.lang.String,​StorableBag> getAllBags()
        Get all bags associated with this profile, both valid and invalid.
        Returns:
        a map from name to bag.
      • getSavedBagsByStatus

        public java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​InterMineBag>> getSavedBagsByStatus()
        Get the saved bags in a map of "status key" => map of lists
        Returns:
        the map from status to a map containing bag name and bag
      • getCurrentSavedBags

        public java.util.Map<java.lang.String,​InterMineBag> getCurrentSavedBags()
        Get the value of savedBags current
        Returns:
        the value of savedBags
      • saveBag

        public void saveBag​(InterMineBag bag)
        Stores a new bag in the profile. Note that bags are always present in the user profile database, so this just adds the bag to the in-memory list of this profile.
        Parameters:
        bag - the InterMineBag object
      • saveBag

        public void saveBag​(java.lang.String name,
                            InterMineBag bag)
        Stores a new bag in the profile. Note that bags are always present in the user profile database, so this just adds the bag to the in-memory list of this profile.
        Parameters:
        name - the name of the bag
        bag - the InterMineBag object
      • deleteBag

        public void deleteBag​(java.lang.String name)
                       throws ObjectStoreException
        Delete a bag from the user account, if user is logged in also deletes from the userprofile database. If there is no such bag associated with the account, no action is performed.
        Parameters:
        name - the bag name
        Throws:
        ObjectStoreException - if problems deleting bag
      • updateBagDescription

        public void updateBagDescription​(java.lang.String name,
                                         java.lang.String newDescription)
                                  throws BagDoesNotExistException,
                                         ObjectStoreException
        Update the description of bag. If there is no such bag associated with the account, no action is performed.
        Parameters:
        name - the bag name
        newDescription - the description to set
        Throws:
        BagDoesNotExistException - if the bag doesn't exist
        ObjectStoreException - if problems updating bag
      • renameBag

        public void renameBag​(java.lang.String oldName,
                              java.lang.String newName)
                       throws ObjectStoreException
        Rename an existing bag, throw exceptions when bag doesn't exist of if new name already exists. Moves tags from old bag to new bag.
        Parameters:
        oldName - the bag to rename
        newName - new name for the bag
        Throws:
        ObjectStoreException - if problems storing
      • getWebSearchablesByType

        public java.util.Map<java.lang.String,​? extends WebSearchable> getWebSearchablesByType​(java.lang.String type)
        Return a WebSearchable Map for the given type.
        Parameters:
        type - the type (from TagTypes)
        Returns:
        the Map
      • getSearchRepository

        public SearchRepository getSearchRepository()
        Get the SearchRepository for this Profile.
        Returns:
        the SearchRepository for the user
      • getApiKey

        public java.lang.String getApiKey()
        Returns:
        the user's API key token.
      • getDayToken

        public java.lang.String getDayToken()
        Get a token with at least an hour of validity, and up to 24 hours.
        Returns:
        A token for web-service use.
      • setApiKey

        public void setApiKey​(java.lang.String token)
        Set the API token for this user, and save it in the backing DB.
        Parameters:
        token - The API token.
      • isLocal

        public boolean isLocal()
        Returns true if this is a local account, and not, for example, an OpenID account.
        Returns:
        Whether or not this is a local account.
      • getSingleUseKey

        public java.lang.String getSingleUseKey()
        Return a single use API key for this profile
        Returns:
        the single use key
      • getSharedBags

        public java.util.Map<java.lang.String,​InterMineBag> getSharedBags()
        Return the shared bags for the profile.
        Returns:
        a map from bag name to bag
      • updateUserRepositoryWithSharedBags

        public void updateUserRepositoryWithSharedBags()
        Update the user repository with the sharedbags
      • getPreferences

        public java.util.Map<java.lang.String,​java.lang.String> getPreferences()
        Get the object representing the preferences of this user. Changes to this user's preferences can be written directly into this object.
        Returns:
        A representation of the preferences of a user.
      • prefers

        public boolean prefers​(java.lang.String preference)
        Determine whether a user perfers a certain thing or not.
        Parameters:
        preference - The name of the preference.
        Returns:
        Whether this preference is set by this user.