Package net.sf.basedb.core
Class ItemList
- All Implemented Interfaces:
AccessControlled
,Annotatable
,Identifiable
,Nameable
,Ownable
,Removable
,Shareable
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
-
Nested Class Summary
Modifier and TypeClassDescription(package private) static class
Handles items that should be added as members to the list, but since they were created in the same transaction doesn't have any ID until later in the commit phase.static enum
Options for synchronizing an existing item list with a current settings in anItemContext
. -
Field Summary
Modifier and TypeFieldDescriptionprivate ItemList.DelayedAdditionManager
static final int
The maximum length of the external id variable that can be stored in the database.static final Item
The type of item represented by this class.Fields inherited from interface net.sf.basedb.core.Nameable
MAX_DESCRIPTION_LENGTH, MAX_NAME_LENGTH
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
add
(Collection<? extends Integer> items) Add all items in the collection to this list.int
Add multiple items to this list in one go.int
Add all items that are returned by the query to this list.boolean
Add an item to this list.int
Add all items from another item list to this list.int
addIfPresentIn
(int minCount, int maxCount, Collection<ItemList> lists) Add items that are present in the specified number of lists to this list.int
addIntersection
(Collection<ItemList> lists) Add items that are present in ALL OF the given lists to this list.private int
addMembers
(Set<Integer> items, ItemList.DelayedAdditionManager other) Add members to this list.int
addUnion
(Collection<ItemList> lists) Add items that are present in at least ONE OF the given lists to this list.private void
private void
checkMemberType
(Collection<ItemList> lists) Checks that the lists have the same member type as this list.private void
checkMemberType
(Item otherType) Checks if the other type is the same type as the member type of this list.private void
void
copySyncFiltersAndMembers
(DbControl dc, ItemList copyFrom) Copy all sync filters and list members from the given list.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.private ItemList.DelayedAdditionManager
private boolean
delayedAdd
(Listable item) private boolean
delayedRemove
(Listable item) Get a query that returns all items that can possibly be members of this list.Always returns nullstatic ItemList
Get anItemList
item when you know the id.(package private) ItemListData
getData()
Get theBasicData
object that holds all data for this item.Get a query that return all item lists that are used by synchronization filters in this list.boolean
If this flag is set manual modification of members is disabled.boolean
If this flag is set synchronization of members with sync filters is disabled.Get the external id for this list.Get the subtype of items that can be members in this list.Get a restriction that mathces members in this list.Get a query that returns all items that are members of this list.Get the item type of members on this list.static ItemList
Create a newItemList
item.getQuery()
Get a query that returns item lists.Get the raw data type of raw bioassays that can be members in this list.int
getSize()
Get the number of members in this list.int
Get the size of the list at the last sync.Get the last sync date+time.Get a query returning all synchronization filters for this listgetType()
Get the type of item represented by the object.boolean
Does this item list define any sync filters?intersection
(Collection<ItemList> lists, ItemList.DelayedAdditionManager delayed) Create a set with the intersection of the items in the given lists.boolean
Checks if all enabled sync filters appears to be in sync or not.boolean
Check if the given item is a member of this list.Creates a new sync filter for this list.void
Deprecated.int
Remove all items from this list that are present in the other list.int
removeIfPresentIn
(int minCount, int maxCount, Collection<ItemList> lists) Remove items that are present in the specified number of lists from this list.int
removeIntersection
(Collection<ItemList> lists) Remove items that are present in ALL OF the given lists from this list.boolean
removeItem
(Listable item) Remove an item from the list.int
removeItems
(Collection<? extends Integer> items) Remove all items in the collection from this list.int
removeItems
(Iterator<? extends Listable> it) Remove multiple items from this list in one go.int
removeItems
(ItemQuery<? extends Listable> query) Remove all items that are returned by the query from this list.private int
removeMembers
(Set<Integer> items, ItemList.DelayedAdditionManager other) Remove members from this listint
removeUnion
(Collection<ItemList> lists) Remove items that are present in at least ONE OF the given lists from this list.int
resyncFilter
(DbControl dc, ItemList.SynchronizeOption syncOptions, boolean applySubtypeFilter, ProgressReporter progress) Re-sync with the current synchronization filter.int
Remove all items from this list that are NOT present in the other list.int
retainIfPresentIn
(int minCount, int maxCount, Collection<ItemList> lists) Retain items that are present in the specified number of lists in this list.int
retainIntersection
(Collection<ItemList> lists) Retain items that are present in ALL OF the given lists in this list.private int
retainMembers
(Set<Integer> items, ItemList.DelayedAdditionManager other) Keep only specified members in this listint
retainUnion
(Collection<ItemList> lists) Retain items that are present in at least ONE OF the given lists in this list.void
setDisableManualMembers
(boolean disable) Disable or enable manual modification of members.void
setDisableSyncFilters
(boolean disable) Disable or enable synchronization of members with sync filters.void
setExternalId
(String externalId) Set the external id for this list.void
setItemSubtype
(ItemSubtype subtype) Set the subtype of items that can be members in this list.private void
setMemberType
(Item memberType) void
setRawDataType
(RawDataType rawDataType) Set the raw data type of raw bioassays that can be members in this list.union
(Collection<ItemList> lists, ItemList.DelayedAdditionManager delayed) Create a set with the union of the items in the given lists.Methods inherited from class net.sf.basedb.core.AnnotatedItem
getAnnotationSet, getProtocol, isAnnotated, removeAnnotations
Methods inherited from class net.sf.basedb.core.CommonItem
getDescription, getName, getRemovedBy, isRemoved, setDescription, setName, setRemoved
Methods inherited from class net.sf.basedb.core.SharedItem
getItemKey, getProjectKey, initPermissions, isShared, onBeforeCommit, setItemKey, setProjectKey
Methods inherited from class net.sf.basedb.core.OwnedItem
getOwner, isOwner, setOwner, takeOwnership
Methods inherited from class net.sf.basedb.core.BasicItem
addAnnotatableParents, addUsingItems, addUsingItems, breakCircularReferences, checkBatchAnnotatableUsage, checkPermission, equals, getBasicData, getDbControl, getId, getPermissions, getPluginPermissions, getSessionControl, getUsingItems, getVersion, hashCode, hasPermission, isDetached, isInDatabase, isUsed, onAfterCommit, onAfterInsert, onRollback, setDbControl, setProjectDefaults, toString, validate
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface net.sf.basedb.core.AccessControlled
checkPermission, getPermissions, hasPermission
Methods inherited from interface net.sf.basedb.core.Identifiable
getId, getVersion
Methods inherited from interface net.sf.basedb.core.Ownable
getOwner, isOwner, setOwner, takeOwnership
-
Field Details
-
TYPE
The type of item represented by this class.- See Also:
-
MAX_EXTERNAL_ID_LENGTH
public static final int MAX_EXTERNAL_ID_LENGTHThe maximum length of the external id variable that can be stored in the database. Check the length against this value before calling thesetExternalId(String)
method to avoid exceptions.- See Also:
-
delayed
-
-
Constructor Details
-
ItemList
ItemList(ItemListData listData)
-
-
Method Details
-
getNew
Create a newItemList
item.- Parameters:
dc
- TheDbControl
which will be used for permission checking and database accessmemberType
- 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 anItemList
item when you know the id.- Parameters:
dc
- TheDbControl
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 foundPermissionDeniedException
- If the logged in user doesn't havePermission.READ
permission to the itemBaseException
- If there is another error
-
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!
- 'minCount=1' and 'maxCount=number of lists' is the same
as
union(Collection, DelayedAdditionManager)
- 'minCount=maxCount=number of lists' is the same
as
intersection(Collection, DelayedAdditionManager)
.
- Parameters:
lists
- The lists to look inminCount
- The minimum number of list an item is required to be present inmaxCount
- The maximum number of lists an item is allowed to the present indelayed
- 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
- 'minCount=1' and 'maxCount=number of lists' is the same
as
-
getData
ItemListData getData()Description copied from class:BasicItem
Get theBasicData
object that holds all data for this item.- Overrides:
getData
in classAnnotatedItem
-
getAnnotatableParents
Always returns null- Returns:
- A set containing annotatable items, or null
- Throws:
BaseException
- If there is an error
-
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 theItem
enumeration.- Returns:
- A value indicating the type of item
-
getExternalId
Get the external id for this list.- Returns:
- A string with the external id of this item, or null
-
setExternalId
Set the external id for this list. Null is allowed, but the value must not be longer than the value specified by theMAX_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 permissionInvalidDataException
- If the new value is longer thanMAX_EXTERNAL_ID_LENGTH
-
getSize
public int getSize()Get the number of members in this list. -
getMemberType
Get the item type of members on this list.- Returns:
- An Item object
-
setMemberType
-
checkMemberType
Checks if the other type is the same type as the member type of this list. -
checkMemberType
Checks that the lists have the same member type as this list. -
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
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
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
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 toItem.RAWBIOASSAY
- Parameters:
rawDataType
- theRawDataType
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 theresyncFilter(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
-
delayedAdd
-
delayedRemove
-
add
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 permissionInvalidDataException
- 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 permissionInvalidDataException
- If the iterator returns an item of a different type thangetMemberType()
-
add
Add all items that are returned by the query to this list. The query is executed with theAbstractEntityQuery.idList(DbControl)
method so this should be a lot more efficient thanadd(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 permissionInvalidDataException
- If the query returns an item of a different type thangetMemberType()
- Since:
- 3.16.3
-
add
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
Remove an item from the list.- Parameters:
item
- The item to remove.- Throws:
PermissionDeniedException
- If the logged in user doesn't have write permissionInvalidDataException
- 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 permissionInvalidDataException
- If the iterator returns an item of a different type thangetMemberType()
- Since:
- 3.15
-
removeItems
Remove all items that are returned by the query from this list. The query is executed with theAbstractEntityQuery.idList(DbControl)
method so this should be a lot more efficient thanremoveItems(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 permissionInvalidDataException
- If the query returns an item of a different type thangetMemberType()
- Since:
- 3.16.3
-
removeItems
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 public void remove(Listable item) throws PermissionDeniedException, InvalidDataException Deprecated.In 3.15, useremoveItem(Listable item)
insteadRemove an item from the list.- Parameters:
item
- The item to remove.- Throws:
PermissionDeniedException
- If the logged in user doesn't have write permissionInvalidDataException
- If the item is null
-
isMember
Check if the given item is a member of this list.- Since:
- 3.15
-
getMembers
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
Get a restriction that mathces members in this list.- Since:
- 3.19.10
-
getAllItems
Get a query that returns all items that can possibly be members of this list. NOTE! This is just a convenience function that callsBioSource.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
Add members to this list.- Parameters:
items
- The items to addother
- Delayed items to add- Returns:
- The number of new items
-
removeMembers
Remove members from this list- Parameters:
items
- The items to remove- Returns:
- The number of removed items
-
retainMembers
Keep only specified members in this list- Parameters:
items
- The items to keep- Returns:
- The number of removed items
-
addAll
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
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
Add items that are present in the specified number of lists to this list.- Delegate to
addUnion(Collection)
ifminCount <= 1 && maxCount >= size(lists)
- Delegate to
addIntersection(Collection)
ifminCount = size(lists) && maxCount >= size(lists)
. - If
minCount > size(lists) || minCount > maxCount
no items will be added.
- Parameters:
lists
- The lists to add items fromminCount
- The minimum number of lists an item is required to be present inmaxCount
- 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)
- Delegate to
-
addIntersection
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
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
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
Remove items that are present in the specified number of lists from this list.- Delegate to
removeUnion(Collection)
ifminCount <= 1 && maxCount >= size(lists)
- Delegate to
removeIntersection(Collection)
ifminCount = size(lists) && maxCount >= size(lists)
. - If
minCount > size(lists) || minCount > maxCount
no items will be removed.
- Parameters:
lists
- The lists with the itemsminCount
- The minimum number of lists an item is required to be present inmaxCount
- The maximum number of lists an item is allowed to be present in- Returns:
- The number of items removed
- Delegate to
-
removeIntersection
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
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
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
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
Retain items that are present in the specified number of lists in this list.- Delegate to
retainUnion(Collection)
ifminCount <= 1 && maxCount >= size(lists)
- Delegate to
retainIntersection(Collection)
ifminCount = size(lists) && maxCount >= size(lists)
. - If
minCount > size(lists) || minCount > maxCount
no items will be removed.
- Parameters:
lists
- The lists with the itemsminCount
- The minimum number of lists an item is required to be present inmaxCount
- The maximum number of lists an item is allowed to be present in- Returns:
- The number of items removed
- Delegate to
-
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
Get a query returning all synchronization filters for this list- Returns:
- An
ItemQuery
object
-
isInSync
Checks if all enabled sync filters appears to be in sync or not. Note that disabled filters are not checked.- Since:
- 3.6
-
newSyncFilter
Creates a new sync filter for this list. The sync filter will start using the same item type as the list member type andSyncFilter.SourceItemTransform.NONE
. UseSyncFilter.setSyncContext(ItemContext, SourceItemTransform)
to apply different sync filter and options. -
copySyncFiltersAndMembers
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
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
-
removeItem(Listable item)
instead