Package org.intermine.api.profile
Class Profile
- java.lang.Object
-
- org.intermine.api.profile.Profile
-
- Direct Known Subclasses:
AnonProfile
public class Profile extends java.lang.ObjectClass 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
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanisSuperUserprotected ProfileManagermanagerstatic java.util.Map<java.lang.String,InterMineBag>NO_BAGSEmpty typed map holding no bags - useful when creating profiles.static java.util.Map<java.lang.String,SavedQuery>NO_QUERIESEmpty typed map holding no saved queries - useful when creating profiles.static java.util.Map<java.lang.String,ApiTemplate>NO_TEMPLATESEmpty typed map holding no templates - useful when creating profiles.protected java.lang.Stringpasswordprotected java.util.Map<java.lang.String,SavedQuery>queryHistoryprotected java.util.Map<java.lang.String,InterMineBag>savedBagsprotected java.util.Map<java.lang.String,InvalidBag>savedInvalidBagsprotected java.util.Map<java.lang.String,SavedQuery>savedQueriesprotected java.util.Map<java.lang.String,ApiTemplate>savedTemplatesprotected booleansavingDisabledprotected java.lang.IntegeruserIdprotected java.lang.Stringusername
-
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 ProfileProfile(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 keyProfile(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 ProfileProfile(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 InterMineBagcreateBag(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.voiddeleteBag(java.lang.String name)Delete a bag from the user account, if user is logged in also deletes from the userprofile database.voiddeleteHistory(java.lang.String name)Remove an item from the query history.voiddeleteQuery(java.lang.String name)Delete a queryvoiddeleteTemplate(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.voiddisableSaving()Disable saving until enableSaving() is called.voidenableSaving()Re-enable saving when saveTemplate(), deleteQuery() etc.voidfixInvalidBag(java.lang.String name, java.lang.String newType)Fix this bag by changing its typejava.util.Map<java.lang.String,StorableBag>getAllBags()Get all bags associated with this profile, both valid and invalid.java.lang.StringgetApiKey()java.util.Map<java.lang.String,InterMineBag>getCurrentSavedBags()Get the value of savedBags currentjava.lang.StringgetDayToken()Get a token with at least an hour of validity, and up to 24 hours.java.lang.StringgetEmailAddress()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.StringgetName()Return a first part of the username before the "@" sign (used in metabolicMine)java.lang.StringgetPassword()Get the value of passwordjava.util.Map<java.lang.String,java.lang.String>getPreferences()Get the object representing the preferences of this user.ProfileManagergetProfileManager()Return the ProfileManager that was passed to the constructor.java.util.Map<java.lang.String,InterMineBag>getSavedBags()Get the value of savedBagsjava.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 listsjava.util.Map<java.lang.String,SavedQuery>getSavedQueries()Get the value of savedQueriesjava.util.Map<java.lang.String,ApiTemplate>getSavedTemplates()Get the users saved templatesSearchRepositorygetSearchRepository()Get the SearchRepository for this Profile.java.util.Map<java.lang.String,InterMineBag>getSharedBags()Return the shared bags for the profile.java.lang.StringgetSingleUseKey()Return a single use API key for this profilebooleangetSuperuser()Alias of isSuperUser() for jsp purposes.ApiTemplategetTemplate(java.lang.String name)get a templatejava.lang.IntegergetUserId()Get the value of userIdjava.lang.StringgetUsername()Get the value of usernamejava.util.Map<java.lang.String,? extends WebSearchable>getWebSearchablesByType(java.lang.String type)Return a WebSearchable Map for the given type.voidinvalidateTemplateCacheIfRequired()When a template or tag is updated, invalidate cache so it can be refreshedbooleanisLocal()Returns true if this is a local account, and not, for example, an OpenID account.booleanisLoggedIn()Return true if and only if the user is logged is (and the Profile will be written to the userprofile).booleanisSuperuser()Return true if and only if the user logged is superuserbooleanprefers(java.lang.String preference)Determine whether a user perfers a certain thing or not.voidrenameBag(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.voidrenameHistory(java.lang.String oldName, java.lang.String newName)Rename an item in the history.voidsaveBag(java.lang.String name, InterMineBag bag)Stores a new bag in the profile.voidsaveBag(InterMineBag bag)Stores a new bag in the profile.voidsaveHistory(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.voidsaveQuery(java.lang.String name, SavedQuery query)Save or update a query.voidsaveTemplate(java.lang.String name, ApiTemplate template)Save a templatevoidsetApiKey(java.lang.String token)Set the API token for this user, and save it in the backing DB.voidsetSuperuser(boolean isSuperUser)Set the superuser flag and store it in userprofile databasevoidsetUserId(java.lang.Integer userId)Set the userIdvoidupdateBagDescription(java.lang.String name, java.lang.String newDescription)Update the description of bag.voidupdateBagType(java.lang.String name, java.lang.String newType)Update the type of bag.voidupdateTemplate(java.lang.String oldName, ApiTemplate template)Update an existing template, throw exceptions when template doesn't exist.voidupdateUserRepositoryWithSharedBags()Update the user repository with the sharedbags
-
-
-
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.
-
manager
protected ProfileManager manager
-
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 profileusername- the username for this profileuserId- the id of this userpassword- the password for this profilesavedQueries- the saved queries for this profilesavedBags- the saved bags for this profilesavedTemplates- the saved templates for this profiletoken- the token to use as an API keyisLocal- true if the account is localisSuperUser- 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 profileusername- the username for this profileuserId- the id of this userpassword- the password for this profilesavedQueries- the saved queries for this profilesavedBags- the saved bags for this profilesavedInvalidBags- the saved bags which type doesn't match with the modelsavedTemplates- the saved templates for this profiletoken- The token to use as an API keyisLocal- true if the account is localisSuperUser- 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 profileusername- the username for this profileuserId- the id of this userpassword- the password for this profilesavedQueries- the saved queries for this profilebagset- a bagset (=valid and invalid bags) for this profilesavedTemplates- the saved templates for this profiletoken- The token to use as an API keyisLocal- true if the account is localisSuperUser- 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 profileusername- the username for this profileuserId- the id of this userpassword- the password for this profilesavedQueries- the saved queries for this profilesavedBags- the saved bags for this profilesavedTemplates- the saved templates for this profileisLocal- true if the account is localisSuperUser- 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 ObjectStoreExceptionSet 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 BadTemplateExceptionSave a template- Parameters:
name- the template nametemplate- 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 nametrackerDelegate- 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 namequery- 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 itemnewName- 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.
-
fixInvalidBag
public void fixInvalidBag(java.lang.String name, java.lang.String newType) throws UnknownBagTypeException, ObjectStoreExceptionFix this bag by changing its type- Parameters:
name- the invalid bag namenewType- The new type of this list- Throws:
UnknownBagTypeException- If the new type is not in the current model.ObjectStoreException- If there is a problem saving state to the DB.
-
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 bagbag- the InterMineBag object
-
createBag
public 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) throws UnknownBagTypeException, ClassKeysNotFoundException, ObjectStoreException
Create a bag and save it to the userprofile database.- Parameters:
name- the bag nametype- the bag typedescription- the bag descriptionclassKeys- the classKeys used to obtain the primary identifier field- Returns:
- the new bag
- Throws:
UnknownBagTypeException- if the bag type is wrongClassKeysNotFoundException- if the classKeys is emptyObjectStoreException- if something goes wrong
-
deleteBag
public void deleteBag(java.lang.String name) throws ObjectStoreExceptionDelete 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
-
updateBagType
public void updateBagType(java.lang.String name, java.lang.String newType) throws UnknownBagTypeException, ObjectStoreExceptionUpdate the type of bag. If there is no such bag associated with the account, no action is performed.- Parameters:
name- the bag namenewType- the type to set- Throws:
UnknownBagTypeException- if the bag type is wrongObjectStoreException- if problems storing bag
-
updateBagDescription
public void updateBagDescription(java.lang.String name, java.lang.String newDescription) throws BagDoesNotExistException, ObjectStoreExceptionUpdate the description of bag. If there is no such bag associated with the account, no action is performed.- Parameters:
name- the bag namenewDescription- the description to set- Throws:
BagDoesNotExistException- if the bag doesn't existObjectStoreException- if problems updating bag
-
renameBag
public void renameBag(java.lang.String oldName, java.lang.String newName) throws ObjectStoreExceptionRename 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 renamenewName- new name for the bag- Throws:
ObjectStoreException- if problems storing
-
updateTemplate
public void updateTemplate(java.lang.String oldName, ApiTemplate template) throws ObjectStoreException, BadTemplateExceptionUpdate an existing template, throw exceptions when template doesn't exist. Moves tags from old template to new template.- Parameters:
oldName- the template to renametemplate- the new template- Throws:
ObjectStoreException- if problems storingBadTemplateException- if bad template
-
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.
-
-