Package org.intermine.api.profile
Class InterMineBag
- java.lang.Object
-
- org.intermine.api.profile.StorableBag
-
- org.intermine.api.profile.InterMineBag
-
- All Implemented Interfaces:
java.lang.Cloneable
,Taggable
,WebSearchable
public class InterMineBag extends StorableBag implements java.lang.Cloneable
An object that represents a bag of objects in our database for the webapp. It is backed by an ObjectStoreBag object, but contains extra data such as name and description.- Author:
- Kim Rutherford, Matthew Wakeling, Daniela Butano
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
BAG_VALUES
name of bag values tableprotected static org.apache.log4j.Logger
LOG
-
Fields inherited from class org.intermine.api.profile.StorableBag
profileId, savedBagId
-
-
Constructor Summary
Constructors Constructor Description InterMineBag(java.lang.String name, java.lang.String type, java.lang.String description, java.util.Date dateCreated, BagState state, ObjectStore os, java.lang.Integer profileId, ObjectStoreWriter uosw, java.util.List<java.lang.String> keyFieldNames)
Constructs a new InterMineIdBag, and saves it in the UserProfile database.InterMineBag(java.lang.String name, java.lang.String type, java.lang.String description, java.util.Date dateCreated, BagState state, ObjectStore os, ObjectStoreWriter uosw, java.util.List<java.lang.String> keyFieldNames)
Constructs a new InterMineBag, and saves it in the UserProfile database.InterMineBag(ObjectStore os, java.lang.Integer savedBagId, ObjectStoreWriter uosw)
Loads an InterMineBag from the UserProfile database.InterMineBag(ObjectStore os, java.lang.Integer savedBagId, ObjectStoreWriter uosw, boolean classDescriptor)
Loads an InterMineBag from the UserProfile database.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addBagValues()
Save the key field values associated to the bag into bagvalues tablevoid
addIdsToBag(java.util.Collection<java.lang.Integer> ids, java.lang.String dataType)
Add the given ids to the bag, this updates the bag contents in the database.void
addIdToBag(java.lang.Integer id, java.lang.String dataType)
Add the given id to the bag, this updates the bag contents in the database.void
addToBagFromQuery(Query query)
Add elements to the bag from a query, this is able to operate entirely in the database without needing to read objects into memory.java.lang.Object
clone()
Create copy of bag.void
delete()
Delete this bag from the userprofile database, bag should not be used after this method has been called.void
deleteAllBagValues()
Remove all the values from the bag-value table.void
deleteBagValues(java.util.List<java.lang.String> values)
Delete a given set of bag values from the bag value table.java.util.Set<ClassDescriptor>
getClassDescriptors()
Return the class descriptors for the type of this bag.java.util.List<BagValue>
getContents()
Returns a List of BagValue (key field value and extra value) of the objects contained by this bag.java.util.List<java.lang.Integer>
getContentsAsIds()
Returns a List which contains the contents of this bag as Integer IDs.int
getCountItemsWithLengthNotNull()
Return the number of items contained in the bag with length not null If the type bag is not a subclass of SequenceFeature, return 0java.util.Date
getDateCreated()
Return the creation date that was passed to the constructor.java.lang.String
getDescription()
Return the description of this bag.java.util.List<java.lang.Integer>
getIdsContained(java.util.Collection<java.lang.Integer> ids)
Returns a List which contains the ids given in input and contained in this bag as Integer IDs.java.util.List<java.lang.String>
getKeyFieldNames()
Return a list containing the keyFieldNames for the bagjava.lang.String
getName()
Returns the value of nameObjectStoreBag
getOsb()
Returns the ObjectStoreBag, so that elements can be added and removed.java.lang.String
getQualifiedType()
Get the fully qualified type of this bagint
getSize()
Returns the size of the bag.java.lang.String
getState()
Return the bag state: current, not current, to upgradejava.lang.String
getTitle()
The user-friendly title for this object.java.lang.String
getType()
Get the type of this bag (a class from InterMine model)ObjectStoreWriter
getUserProfileWriter()
Get a reference to a connection to the database where user data is persisted.protected InvalidBag
invalidate()
Declare that this bag is invalid, and return its InvalidBag representation.boolean
isCurrent()
Return true if the status bag is current, otherwise false (status is not current or to upgrade)boolean
isOfType(java.lang.String testType)
Test whether the given type can be added to this bag, type can be a qualified or un-qualified string.boolean
isToUpgrade()
Return true if the status bag is to_upgrade, otherwise falsevoid
removeIdFromBag(java.lang.Integer id)
Remove the given id from the bag, this updates the bag contents in the databasevoid
removeIdsFromBag(java.util.Collection<java.lang.Integer> ids, boolean updateBagValues)
Remove the given ids from the bag, this updates the bag contents in the databasevoid
setDate(java.util.Date date)
Sets date when bag was created.void
setDescription(java.lang.String description)
void
setKeyFieldNames(java.util.List<java.lang.String> keyFieldNames)
Set the keyFieldNamesvoid
setName(java.lang.String name)
Set the value of namevoid
setOsb(ObjectStoreBag osb)
Sets the ObjectStoreBag.void
setProfileId(java.lang.Integer profileId)
Sets the profileId - moves this bag from one profile to another.void
setState(BagState state)
Set bag statevoid
setType(java.lang.String type)
java.lang.String
toString()
void
upgradeOsb(java.util.Collection<java.lang.Integer> values, boolean updateBagValues)
Upgrades the ObjectStoreBag with a new ObjectStoreBag containing the collection of elements given in input-
Methods inherited from class org.intermine.api.profile.StorableBag
addBagValues, addObserver, deleteSomeBagValues, fireEvent, getContentsOrderByExtraValue, getProfileId, getSavedBagId, getTagType, removeObserver, saveWithBagValues, size, storeSavedBag
-
-
-
-
Field Detail
-
LOG
protected static final org.apache.log4j.Logger LOG
-
BAG_VALUES
public static final java.lang.String BAG_VALUES
name of bag values table- See Also:
- Constant Field Values
-
-
Constructor Detail
-
InterMineBag
public InterMineBag(java.lang.String name, java.lang.String type, java.lang.String description, java.util.Date dateCreated, BagState state, ObjectStore os, java.lang.Integer profileId, ObjectStoreWriter uosw, java.util.List<java.lang.String> keyFieldNames) throws UnknownBagTypeException, ObjectStoreException
Constructs a new InterMineIdBag, and saves it in the UserProfile database.- Parameters:
name
- the name of the bagtype
- the class of objects stored in the bagdescription
- the description of the bagdateCreated
- the Date when this bag was createdstate
- the state of the bagos
- the production ObjectStoreprofileId
- the ID of the user in the userprofile databaseuosw
- the ObjectStoreWriter of the userprofile databasekeyFieldNames
- the list of identifiers defined for this bag- Throws:
UnknownBagTypeException
- if the type bag is unknownObjectStoreException
- if an error occurs
-
InterMineBag
public InterMineBag(java.lang.String name, java.lang.String type, java.lang.String description, java.util.Date dateCreated, BagState state, ObjectStore os, ObjectStoreWriter uosw, java.util.List<java.lang.String> keyFieldNames) throws UnknownBagTypeException, ClassKeysNotFoundException, ObjectStoreException
Constructs a new InterMineBag, and saves it in the UserProfile database.- Parameters:
name
- the name of the bagtype
- the class of objects stored in the bagdescription
- the description of the bagdateCreated
- the Date when this bag was createdstate
- the state of the bagos
- the production ObjectStoreuosw
- the ObjectStoreWriter of the userprofile databasekeyFieldNames
- the list of identifiers defined for this bag- Throws:
UnknownBagTypeException
- if the type bag is unknownClassKeysNotFoundException
- if class keys arent foundObjectStoreException
- if an error occurs
-
InterMineBag
public InterMineBag(ObjectStore os, java.lang.Integer savedBagId, ObjectStoreWriter uosw) throws UnknownBagTypeException, ObjectStoreException
Loads an InterMineBag from the UserProfile database.- Parameters:
os
- the production ObjectStoresavedBagId
- the ID of the bag in the userprofile databaseuosw
- the ObjectStoreWriter of the userprofile database- Throws:
UnknownBagTypeException
- if the type bag is unknownObjectStoreException
- if something goes wrong
-
InterMineBag
public InterMineBag(ObjectStore os, java.lang.Integer savedBagId, ObjectStoreWriter uosw, boolean classDescriptor) throws UnknownBagTypeException, ObjectStoreException
Loads an InterMineBag from the UserProfile database.- Parameters:
os
- the production ObjectStoresavedBagId
- the ID of the bag in the userprofile databaseuosw
- the ObjectStoreWriter of the userprofile databaseclassDescriptor
- if true the classDescriptor will be set- Throws:
UnknownBagTypeException
- if the type bag is unknownObjectStoreException
- if something goes wrong
-
-
Method Detail
-
invalidate
protected InvalidBag invalidate()
Declare that this bag is invalid, and return its InvalidBag representation.- Returns:
- An InvalidBag version of the database record.
-
delete
public void delete() throws ObjectStoreException
Delete this bag from the userprofile database, bag should not be used after this method has been called. Delete the ids from the production database too.- Overrides:
delete
in classStorableBag
- Throws:
ObjectStoreException
- if problem deleting bag
-
getContentsAsIds
public java.util.List<java.lang.Integer> getContentsAsIds()
Returns a List which contains the contents of this bag as Integer IDs.- Returns:
- a List of Integers
-
getIdsContained
public java.util.List<java.lang.Integer> getIdsContained(java.util.Collection<java.lang.Integer> ids)
Returns a List which contains the ids given in input and contained in this bag as Integer IDs.- Parameters:
ids
- the list of ids- Returns:
- a List of Integers
-
getContents
public java.util.List<BagValue> getContents()
Returns a List of BagValue (key field value and extra value) of the objects contained by this bag.- Overrides:
getContents
in classStorableBag
- Returns:
- the list of BagValue
-
upgradeOsb
public void upgradeOsb(java.util.Collection<java.lang.Integer> values, boolean updateBagValues) throws ObjectStoreException
Upgrades the ObjectStoreBag with a new ObjectStoreBag containing the collection of elements given in input- Parameters:
values
- the collection of elements to addupdateBagValues
- id true if we upgrade the bagvalues table- Throws:
ObjectStoreException
- if an error occurs fetching a new ID
-
getSize
public int getSize() throws ObjectStoreException
Description copied from class:StorableBag
Returns the size of the bag.- Specified by:
getSize
in classStorableBag
- Returns:
- the number of elements in the bag
- Throws:
ObjectStoreException
- if something goes wrong
-
getUserProfileWriter
public ObjectStoreWriter getUserProfileWriter()
Description copied from class:StorableBag
Get a reference to a connection to the database where user data is persisted.- Specified by:
getUserProfileWriter
in classStorableBag
- Returns:
- the user-profile object store writer
-
getOsb
public ObjectStoreBag getOsb()
Returns the ObjectStoreBag, so that elements can be added and removed.- Specified by:
getOsb
in classStorableBag
- Returns:
- the ObjectStoreBag
-
setOsb
public void setOsb(ObjectStoreBag osb)
Sets the ObjectStoreBag.- Parameters:
osb
- the ObjectStoreBag
-
setProfileId
public void setProfileId(java.lang.Integer profileId) throws ObjectStoreException
Sets the profileId - moves this bag from one profile to another.- Parameters:
profileId
- the ID of the new userprofile- Throws:
ObjectStoreException
- if something goes wrong
-
getName
public java.lang.String getName()
Returns the value of name- Specified by:
getName
in interfaceTaggable
- Specified by:
getName
in classStorableBag
- Returns:
- the name of the bag
-
setName
public void setName(java.lang.String name) throws ObjectStoreException
Set the value of name- Parameters:
name
- the bag name- Throws:
ObjectStoreException
- if something goes wrong
-
getDescription
public java.lang.String getDescription()
Return the description of this bag.- Specified by:
getDescription
in interfaceWebSearchable
- Specified by:
getDescription
in classStorableBag
- Returns:
- the description
-
getDateCreated
public java.util.Date getDateCreated()
Return the creation date that was passed to the constructor.- Specified by:
getDateCreated
in classStorableBag
- Returns:
- the creation date
-
setDescription
public void setDescription(java.lang.String description) throws ObjectStoreException
- Parameters:
description
- the description to set- Throws:
ObjectStoreException
- if something goes wrong
-
getType
public java.lang.String getType()
Get the type of this bag (a class from InterMine model)- Specified by:
getType
in classStorableBag
- Returns:
- the type of objects in this bag
-
setType
public void setType(java.lang.String type) throws ObjectStoreException
- Parameters:
type
- the type to set- Throws:
ObjectStoreException
- if something goes wrong
-
getQualifiedType
public java.lang.String getQualifiedType()
Get the fully qualified type of this bag- Returns:
- the type of objects in this bag
-
getClassDescriptors
public java.util.Set<ClassDescriptor> getClassDescriptors()
Return the class descriptors for the type of this bag.- Returns:
- the set of class descriptors
-
getTitle
public java.lang.String getTitle()
The user-friendly title for this object.- Specified by:
getTitle
in interfaceWebSearchable
- Returns:
- the title
-
setKeyFieldNames
public void setKeyFieldNames(java.util.List<java.lang.String> keyFieldNames)
Set the keyFieldNames- Parameters:
keyFieldNames
- the list of keyField names
-
getKeyFieldNames
public java.util.List<java.lang.String> getKeyFieldNames()
Return a list containing the keyFieldNames for the bag- Returns:
- keyFieldNames
-
isCurrent
public boolean isCurrent()
Return true if the status bag is current, otherwise false (status is not current or to upgrade)- Returns:
- isCurrent
-
isToUpgrade
public boolean isToUpgrade()
Return true if the status bag is to_upgrade, otherwise false- Returns:
- isToUpgrade
-
getState
public java.lang.String getState()
Return the bag state: current, not current, to upgrade- Specified by:
getState
in classStorableBag
- Returns:
- the status
-
setState
public void setState(BagState state) throws ObjectStoreException
Set bag state- Parameters:
state
- the state to set- Throws:
ObjectStoreException
- if something goes wrong
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
Create copy of bag. Bag is saved to objectstore.- Overrides:
clone
in classjava.lang.Object
- Returns:
- create bag
- Throws:
java.lang.CloneNotSupportedException
- if something goes wrong
-
setDate
public void setDate(java.util.Date date)
Sets date when bag was created.- Parameters:
date
- new date
-
addIdToBag
public void addIdToBag(java.lang.Integer id, java.lang.String dataType) throws ObjectStoreException
Add the given id to the bag, this updates the bag contents in the database. he type can be a qualified or un-qualified class name.- Parameters:
id
- the id to adddataType
- the type of ids being added- Throws:
ObjectStoreException
- if problem storing
-
addIdsToBag
public void addIdsToBag(java.util.Collection<java.lang.Integer> ids, java.lang.String dataType) throws ObjectStoreException
Add the given ids to the bag, this updates the bag contents in the database. The type can be a qualified or un-qualified class name.- Parameters:
ids
- the ids to adddataType
- the type of ids being added- Throws:
ObjectStoreException
- if problem storing
-
isOfType
public boolean isOfType(java.lang.String testType)
Test whether the given type can be added to this bag, type can be a qualified or un-qualified string.- Parameters:
testType
- type to check- Returns:
- true if type can be added to the bag
-
addToBagFromQuery
public void addToBagFromQuery(Query query) throws ObjectStoreException
Add elements to the bag from a query, this is able to operate entirely in the database without needing to read objects into memory. The query should have a single column on the select list returning an object id.- Parameters:
query
- to select object ids- Throws:
ObjectStoreException
- if problem storing
-
removeIdFromBag
public void removeIdFromBag(java.lang.Integer id) throws ObjectStoreException
Remove the given id from the bag, this updates the bag contents in the database- Parameters:
id
- the id to remove- Throws:
ObjectStoreException
- if problem storing
-
removeIdsFromBag
public void removeIdsFromBag(java.util.Collection<java.lang.Integer> ids, boolean updateBagValues) throws ObjectStoreException
Remove the given ids from the bag, this updates the bag contents in the database- Parameters:
ids
- the ids to removeupdateBagValues
- whether or not to update the values- Throws:
ObjectStoreException
- if problem storing
-
addBagValues
public void addBagValues()
Save the key field values associated to the bag into bagvalues table
-
deleteBagValues
public void deleteBagValues(java.util.List<java.lang.String> values)
Delete a given set of bag values from the bag value table. If an empty list is passed in, no values will be deleted. If null is passed in, that is an error, and an IllegalArgumentException will be raised.- Parameters:
values
- The values to delete. May not benull
.
-
deleteAllBagValues
public void deleteAllBagValues()
Description copied from class:StorableBag
Remove all the values from the bag-value table.- Overrides:
deleteAllBagValues
in classStorableBag
-
getCountItemsWithLengthNotNull
public int getCountItemsWithLengthNotNull()
Return the number of items contained in the bag with length not null If the type bag is not a subclass of SequenceFeature, return 0- Returns:
- the number of items with length not null
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-