Class ItemList

All Implemented Interfaces:
AccessControlled, Annotatable, Identifiable, Nameable, Ownable, Removable, Shareable

public class ItemList extends AnnotatedItem
This class represents a list of items. Supported items to put in the list are those that implement the Listable interface.
Since:
3.5
Author:
Nicklas
  • Field Details

  • Constructor Details

  • Method Details

    • getNew

      public static ItemList getNew(DbControl dc, Item memberType) throws BaseException
      Create a new ItemList item.
      Parameters:
      dc - The DbControl which will be used for permission checking and database access
      memberType - The item type of members in this list
      Returns:
      The new ItemList item
      Throws:
      BaseException - If there is an error
    • getById

      public static ItemList getById(DbControl dc, int id) throws ItemNotFoundException, PermissionDeniedException, BaseException
      Get an ItemList item when you know the id.
      Parameters:
      dc - The DbControl which will be used for permission checking and database access.
      id - The id of the item to load
      Returns:
      The ItemList item
      Throws:
      ItemNotFoundException - If an item with the specified id is not found
      PermissionDeniedException - If the logged in user doesn't have Permission.READ permission to the item
      BaseException - If there is another error
    • getQuery

      public static ItemQuery<ItemList> getQuery()
      Get a query that returns item lists.
      Returns:
      An ItemQuery object
    • intersection

      private static Set<Integer> intersection(Collection<ItemList> lists, ItemList.DelayedAdditionManager delayed)
      Create a set with the intersection of the items in the given lists.
      Returns:
      A set with IDs of member items. The set is always a new set, modifications to it will not affect anything else
    • union

      private static Set<Integer> union(Collection<ItemList> lists, ItemList.DelayedAdditionManager delayed)
      Create a set with the union of the items in the given lists.
      Parameters:
      delayed - A temporary delayed additions manager to be used for collecting the union of delayed additions
      Returns:
      A set with IDs of member items. The set is always a new set, modifications to it will not affect anything else
    • count

      private static Set<Integer> count(Collection<ItemList> lists, int minCount, int maxCount, ItemList.DelayedAdditionManager delayed)
      Count the number of times each item is present in the given lists and return those items that are found in >=minCount and <=maxCount lists.

      NOTE!

      Parameters:
      lists - The lists to look in
      minCount - The minimum number of list an item is required to be present in
      maxCount - The maximum number of lists an item is allowed to the present in
      delayed - A temporary delayed additions manager to be used for collecting the union of delayed additions
      Returns:
      A set with IDs of member items. It is always a new set, modifications to it will not affect anything else
    • getData

      ItemListData getData()
      Description copied from class: BasicItem
      Get the BasicData object that holds all data for this item.
      Overrides:
      getData in class AnnotatedItem
    • getAnnotatableParents

      public Set<Annotatable> getAnnotatableParents() throws BaseException
      Always returns null
      Returns:
      A set containing annotatable items, or null
      Throws:
      BaseException - If there is an error
    • getType

      public Item getType()
      Description copied from interface: Identifiable
      Get the type of item represented by the object. The returned value is one of the values defined in the Item enumeration.
      Returns:
      A value indicating the type of item
    • getExternalId

      public String getExternalId()
      Get the external id for this list.
      Returns:
      A string with the external id of this item, or null
    • setExternalId

      public void setExternalId(String externalId) throws PermissionDeniedException, InvalidDataException
      Set the external id for this list. Null is allowed, but the value must not be longer than the value specified by the MAX_EXTERNAL_ID_LENGTH constant. The value doesn't have to be unique.
      Parameters:
      externalId - The new external id for this item
      Throws:
      PermissionDeniedException - If the logged in user doesn't have write permission
      InvalidDataException - If the new value is longer than MAX_EXTERNAL_ID_LENGTH
    • getSize

      public int getSize()
      Get the number of members in this list.
    • getMemberType

      public Item getMemberType()
      Get the item type of members on this list.
      Returns:
      An Item object
    • setMemberType

      private void setMemberType(Item memberType)
    • checkMemberType

      private void checkMemberType(Item otherType)
      Checks if the other type is the same type as the member type of this list.
    • checkMemberType

      private void checkMemberType(Collection<ItemList> lists)
      Checks that the lists have the same member type as this list.
    • getItemSubtype

      public ItemSubtype getItemSubtype()
      Get the subtype of items that can be members in this list. This is a recommendation only and is not enforced.
      Returns:
      A subtype or null if not important
    • setItemSubtype

      public void setItemSubtype(ItemSubtype subtype)
      Set the subtype of items that can be members in this list. The subtype must have the same member type as this list.
      Parameters:
      subtype - A subtype or null if the subtype is not important
    • getRawDataType

      public RawDataType getRawDataType()
      Get the raw data type of raw bioassays that can be members in this list. This is a recommendation only and is not enforced.
      Returns:
      A RawDataType object
    • setRawDataType

      public void setRawDataType(RawDataType rawDataType)
      Set the raw data type of raw bioassays that can be members in this list. This is a recommendation only and is not enforced. The member type must be set to Item.RAWBIOASSAY
      Parameters:
      rawDataType - the RawDataType to use as default.
    • getDisableSyncFilters

      public boolean getDisableSyncFilters()
      If this flag is set synchronization of members with sync filters is disabled. It is always possible to add/remove or modify sync filters but the resyncFilter(DbControl, SynchronizeOption, boolean, ProgressReporter) method will throw an exception if this is set.
    • setDisableSyncFilters

      public void setDisableSyncFilters(boolean disable)
      Disable or enable synchronization of members with sync filters.
    • checkSyncFiltersAllowed

      private void checkSyncFiltersAllowed()
    • getDisableManualMembers

      public boolean getDisableManualMembers()
      If this flag is set manual modification of members is disabled.
    • setDisableManualMembers

      public void setDisableManualMembers(boolean disable)
      Disable or enable manual modification of members.
    • checkManualMembersAllowed

      private void checkManualMembersAllowed()
    • createDelayedAdditionManager

      private ItemList.DelayedAdditionManager createDelayedAdditionManager()
    • delayedAdd

      private boolean delayedAdd(Listable item)
    • delayedRemove

      private boolean delayedRemove(Listable item)
    • add

      public boolean add(Listable item) throws PermissionDeniedException, InvalidDataException
      Add an item to this list.
      Parameters:
      item - The item to add to the list
      Returns:
      TRUE if the item was added, FALSE if it already existed in this list
      Throws:
      PermissionDeniedException - If the logged in user doesn't have write permission
      InvalidDataException - If the item is null or not of the correct member type
    • add

      public int add(Iterator<? extends Listable> it) throws PermissionDeniedException, InvalidDataException
      Add multiple items to this list in one go.
      Parameters:
      it - An iterator that returns all items to be added, null items are ignored
      Returns:
      The numer of added items
      Throws:
      PermissionDeniedException - If the logged in user doesn't have write permission
      InvalidDataException - If the iterator returns an item of a different type than getMemberType()
    • add

      public int add(ItemQuery<? extends Listable> query)
      Add all items that are returned by the query to this list. The query is executed with the AbstractEntityQuery.idList(DbControl) method so this should be a lot more efficient than add(Iterator) when adding lots of items to a list.
      Parameters:
      query - An query that returns all items to be added
      Returns:
      The numer of added items
      Throws:
      PermissionDeniedException - If the logged in user doesn't have write permission
      InvalidDataException - If the query returns an item of a different type than getMemberType()
      Since:
      3.16.3
    • add

      public int add(Collection<? extends Integer> items)
      Add all items in the collection to this list.
      Parameters:
      items - A collection with ID for the items to add
      Returns:
      The numer of added items
      Throws:
      PermissionDeniedException - If the logged in user doesn't have write permission
      Since:
      3.16.3
    • removeItem

      public boolean removeItem(Listable item) throws PermissionDeniedException, InvalidDataException
      Remove an item from the list.
      Parameters:
      item - The item to remove.
      Throws:
      PermissionDeniedException - If the logged in user doesn't have write permission
      InvalidDataException - If the item is null
      Since:
      3.15
    • removeItems

      public int removeItems(Iterator<? extends Listable> it) throws PermissionDeniedException, InvalidDataException
      Remove multiple items from this list in one go.
      Parameters:
      it - An iterator that returns all items to be removed, null items are ignored
      Returns:
      The numer of removed items
      Throws:
      PermissionDeniedException - If the logged in user doesn't have write permission
      InvalidDataException - If the iterator returns an item of a different type than getMemberType()
      Since:
      3.15
    • removeItems

      public int removeItems(ItemQuery<? extends Listable> query)
      Remove all items that are returned by the query from this list. The query is executed with the AbstractEntityQuery.idList(DbControl) method so this should be a lot more efficient than removeItems(Iterator) when removing lots of items from a list.
      Parameters:
      query - An query that returns all items to be removed
      Returns:
      The numer of removed items
      Throws:
      PermissionDeniedException - If the logged in user doesn't have write permission
      InvalidDataException - If the query returns an item of a different type than getMemberType()
      Since:
      3.16.3
    • removeItems

      public int removeItems(Collection<? extends Integer> items)
      Remove all items in the collection from this list.
      Parameters:
      items - A collection with ID for the items to remove
      Returns:
      The numer of removed items
      Throws:
      PermissionDeniedException - If the logged in user doesn't have write permission
      Since:
      3.16.3
    • remove

      Deprecated.
      In 3.15, use removeItem(Listable item) instead
      Remove an item from the list.
      Parameters:
      item - The item to remove.
      Throws:
      PermissionDeniedException - If the logged in user doesn't have write permission
      InvalidDataException - If the item is null
    • isMember

      public boolean isMember(Listable item)
      Check if the given item is a member of this list.
      Since:
      3.15
    • getMembers

      public <T extends BasicItem & Listable> ItemQuery<T> getMembers() throws BaseException
      Get a query that returns all items that are members of this list.
      Returns:
      An ItemQuery object
      Throws:
      BaseException - If the query could not be created and configured.
    • getMemberRestriction

      public Restriction getMemberRestriction()
      Get a restriction that mathces members in this list.
      Since:
      3.19.10
    • getAllItems

      public <T extends BasicItem & Listable> ItemQuery<T> getAllItems() throws BaseException
      Get a query that returns all items that can possibly be members of this list. NOTE! This is just a convenience function that calls BioSource.getQuery(), etc. depending on the member type of the list.
      Returns:
      An ItemQuery object
      Throws:
      BaseException - If the query could not be created and configured
      See Also:
    • addMembers

      private int addMembers(Set<Integer> items, ItemList.DelayedAdditionManager other)
      Add members to this list.
      Parameters:
      items - The items to add
      other - Delayed items to add
      Returns:
      The number of new items
    • removeMembers

      private int removeMembers(Set<Integer> items, ItemList.DelayedAdditionManager other)
      Remove members from this list
      Parameters:
      items - The items to remove
      Returns:
      The number of removed items
    • retainMembers

      private int retainMembers(Set<Integer> items, ItemList.DelayedAdditionManager other)
      Keep only specified members in this list
      Parameters:
      items - The items to keep
      Returns:
      The number of removed items
    • addAll

      public int addAll(ItemList list)
      Add all items from another item list to this list. The new list is the union of the existing list and the added list. The other list must have the same member type as this list.
      Parameters:
      list - The list to add items from
      Returns:
      The number of items added (not including items that already was in this list)
    • addUnion

      public int addUnion(Collection<ItemList> lists)
      Add items that are present in at least ONE OF the given lists to this list. Eg. the added items is the union from the given lists.
      Parameters:
      lists - The lists to add items from
      Returns:
      The number of items added (not including items that already was in this list)
    • addIfPresentIn

      public int addIfPresentIn(int minCount, int maxCount, Collection<ItemList> lists)
      Add items that are present in the specified number of lists to this list.
      • Delegate to addUnion(Collection) if minCount <= 1 && maxCount >= size(lists)
      • Delegate to addIntersection(Collection) if minCount = size(lists) && maxCount >= size(lists).
      • If minCount > size(lists) || minCount > maxCount no items will be added.
      Parameters:
      lists - The lists to add items from
      minCount - The minimum number of lists an item is required to be present in
      maxCount - The maximum number of lists an item is allowed to be present in
      Returns:
      The number of items added (not including items that already was in this list)
    • addIntersection

      public int addIntersection(Collection<ItemList> lists)
      Add items that are present in ALL OF the given lists to this list. Eg. the added items is the intersection from the given lists.
      Parameters:
      lists - The lists to add items from
      Returns:
      The number of items added (not including items that already was in this list)
    • removeAll

      public int removeAll(ItemList list)
      Remove all items from this list that are present in the other list.
      Parameters:
      list - The list that contains the items to remove
      Returns:
      The number of items removed from this list
    • removeUnion

      public int removeUnion(Collection<ItemList> lists)
      Remove items that are present in at least ONE OF the given lists from this list. Eg. the removed items is the union from the given lists.
      Parameters:
      lists - The lists that contains the items to remove
      Returns:
      The number of items removed from this list
    • removeIfPresentIn

      public int removeIfPresentIn(int minCount, int maxCount, Collection<ItemList> lists)
      Remove items that are present in the specified number of lists from this list.
      Parameters:
      lists - The lists with the items
      minCount - The minimum number of lists an item is required to be present in
      maxCount - The maximum number of lists an item is allowed to be present in
      Returns:
      The number of items removed
    • removeIntersection

      public int removeIntersection(Collection<ItemList> lists)
      Remove items that are present in ALL OF the given lists from this list. Eg. the removed items is the intersection from the given lists.
      Parameters:
      lists - The lists that contains the items to remove
      Returns:
      The number of items removed from this list
    • retainAll

      public int retainAll(ItemList list)
      Remove all items from this list that are NOT present in the other list. The new list is the intersection of the existing list and the other list. NOTE! If the other list is null or empty, all items will be removed from this list.
      Parameters:
      list - The list that contains the items to be retained
      Returns:
      The number of items removed from this list
    • retainUnion

      public int retainUnion(Collection<ItemList> lists)
      Retain items that are present in at least ONE OF the given lists in this list. Eg. items that are not found in any of the given lists are removed from this list.
      Parameters:
      lists - The lists that contains the items to retain
      Returns:
      The number of items removed from this list
    • retainIntersection

      public int retainIntersection(Collection<ItemList> lists)
      Retain items that are present in ALL OF the given lists in this list. Eg. items that are not found in all lists of the given lists are removed from this list.
      Parameters:
      lists - The lists that contains the items to retain
      Returns:
      The number of items removed from this list
    • retainIfPresentIn

      public int retainIfPresentIn(int minCount, int maxCount, Collection<ItemList> lists)
      Retain items that are present in the specified number of lists in this list.
      Parameters:
      lists - The lists with the items
      minCount - The minimum number of lists an item is required to be present in
      maxCount - The maximum number of lists an item is allowed to be present in
      Returns:
      The number of items removed
    • getSyncDate

      public Date getSyncDate()
      Get the last sync date+time. Note that manual changes may have been made to the list after this date.
    • getSizeAtLastSync

      public int getSizeAtLastSync()
      Get the size of the list at the last sync. Note that manual changes may have been made to the list since then. A return value of -1 indicates that no sync has been performed.
      Since:
      3.18
    • hasSyncFilters

      public boolean hasSyncFilters()
      Does this item list define any sync filters?
      Since:
      3.6
    • getSyncFilters

      public ItemQuery<SyncFilter> getSyncFilters()
      Get a query returning all synchronization filters for this list
      Returns:
      An ItemQuery object
    • isInSync

      public boolean isInSync(DbControl dc)
      Checks if all enabled sync filters appears to be in sync or not. Note that disabled filters are not checked.
      Since:
      3.6
    • newSyncFilter

      public SyncFilter newSyncFilter(DbControl dc)
      Creates a new sync filter for this list. The sync filter will start using the same item type as the list member type and SyncFilter.SourceItemTransform.NONE. Use SyncFilter.setSyncContext(ItemContext, SourceItemTransform) to apply different sync filter and options.
    • copySyncFiltersAndMembers

      public void copySyncFiltersAndMembers(DbControl dc, ItemList copyFrom)
      Copy all sync filters and list members from the given list. This is only allowed if the list to copy from is having the same member type as the current list. Existing members and sync filters in this list are removed.
    • getDependingLists

      public ItemQuery<ItemList> getDependingLists()
      Get a query that return all item lists that are used by synchronization filters in this list. Synchronization filters that are currently not enabled are ignored.
      Since:
      3.6
    • resyncFilter

      public int resyncFilter(DbControl dc, ItemList.SynchronizeOption syncOptions, boolean applySubtypeFilter, ProgressReporter progress)
      Re-sync with the current synchronization filter. If this list doesn't use a synchronization filter, no change is made.
      Returns:
      The number of members in the list after applying the filter