Class 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 table
      protected static org.apache.log4j.Logger LOG  
    • 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 table
      void 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 0
      java.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 bag
      java.lang.String getName()
      Returns the value of name
      ObjectStoreBag getOsb()
      Returns the ObjectStoreBag, so that elements can be added and removed.
      java.lang.String getQualifiedType()
      Get the fully qualified type of this bag
      int getSize()
      Returns the size of the bag.
      java.lang.String getState()
      Return the bag state: current, not current, to upgrade
      java.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 false
      void removeIdFromBag​(java.lang.Integer id)
      Remove the given id from the bag, this updates the bag contents in the database
      void removeIdsFromBag​(java.util.Collection<java.lang.Integer> ids, boolean updateBagValues)
      Remove the given ids from the bag, this updates the bag contents in the database
      void 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 keyFieldNames
      void setName​(java.lang.String name)
      Set the value of name
      void 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 state
      void 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 java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • 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 bag
        type - the class of objects stored in the bag
        description - the description of the bag
        dateCreated - the Date when this bag was created
        state - the state of the bag
        os - the production ObjectStore
        profileId - the ID of the user in the userprofile database
        uosw - the ObjectStoreWriter of the userprofile database
        keyFieldNames - the list of identifiers defined for this bag
        Throws:
        UnknownBagTypeException - if the type bag is unknown
        ObjectStoreException - 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 bag
        type - the class of objects stored in the bag
        description - the description of the bag
        dateCreated - the Date when this bag was created
        state - the state of the bag
        os - the production ObjectStore
        uosw - the ObjectStoreWriter of the userprofile database
        keyFieldNames - the list of identifiers defined for this bag
        Throws:
        UnknownBagTypeException - if the type bag is unknown
        ClassKeysNotFoundException - if class keys arent found
        ObjectStoreException - if an error occurs
    • 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 class StorableBag
        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 class StorableBag
        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 add
        updateBagValues - id true if we upgrade the bagvalues table
        Throws:
        ObjectStoreException - if an error occurs fetching a new ID
      • 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 class StorableBag
        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 class StorableBag
        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 interface Taggable
        Specified by:
        getName in class StorableBag
        Returns:
        the name of the bag
      • getDateCreated

        public java.util.Date getDateCreated()
        Return the creation date that was passed to the constructor.
        Specified by:
        getDateCreated in class StorableBag
        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 class StorableBag
        Returns:
        the type of objects in this bag
      • 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 interface WebSearchable
        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 class StorableBag
        Returns:
        the status
      • clone

        public java.lang.Object clone()
                               throws java.lang.CloneNotSupportedException
        Create copy of bag. Bag is saved to objectstore.
        Overrides:
        clone in class java.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 add
        dataType - 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 add
        dataType - 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 remove
        updateBagValues - 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 be null.
      • deleteAllBagValues

        public void deleteAllBagValues()
        Description copied from class: StorableBag
        Remove all the values from the bag-value table.
        Overrides:
        deleteAllBagValues in class StorableBag
      • 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 class java.lang.Object