Package net.sf.basedb.core
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 theListable
interface.- Since:
- 3.5
- Author:
- Nicklas
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
ItemList.DelayedAdditionManager
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 class
ItemList.SynchronizeOption
Options for synchronizing an existing item list with a current settings in anItemContext
.
-
Field Summary
Fields Modifier and Type Field Description private ItemList.DelayedAdditionManager
delayed
static int
MAX_EXTERNAL_ID_LENGTH
The maximum length of the external id variable that can be stored in the database.static Item
TYPE
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
Constructors Constructor Description ItemList(ItemListData listData)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description int
add(Iterator<? extends Listable> it)
Add multiple items to this list in one go.boolean
add(Listable item)
Add an item to this list.int
addAll(ItemList list)
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
checkManualMembersAllowed()
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
checkSyncFiltersAllowed()
void
copySyncFiltersAndMembers(DbControl dc, ItemList copyFrom)
Copy all sync filters and list members from the given list.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.private ItemList.DelayedAdditionManager
createDelayedAdditionManager()
private boolean
delayedAdd(Listable item)
private boolean
delayedRemove(Listable item)
ItemQuery<? extends Listable>
getAllItems()
Get a query that returns all items that can possibly be members of this list.Set<Annotatable>
getAnnotatableParents()
Always returns nullstatic ItemList
getById(DbControl dc, int id)
Get anItemList
item when you know the id.(package private) ItemListData
getData()
Get theBasicData
object that holds all data for this item.ItemQuery<ItemList>
getDependingLists()
Get a query that return all item lists that are used by synchronization filters in this list.boolean
getDisableManualMembers()
If this flag is set manual modification of members is disabled.boolean
getDisableSyncFilters()
If this flag is set synchronization of members with sync filters is disabled.String
getExternalId()
Get the external id for this list.ItemSubtype
getItemSubtype()
Get the subtype of items that can be members in this list.ItemQuery<? extends Listable>
getMembers()
Get a query that returns all items that are members of this list.Item
getMemberType()
Get the item type of members on this list.static ItemList
getNew(DbControl dc, Item memberType)
Create a newItemList
item.static ItemQuery<ItemList>
getQuery()
Get a query that returns item lists.RawDataType
getRawDataType()
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.Date
getSyncDate()
Get the last sync date+time.ItemQuery<SyncFilter>
getSyncFilters()
Get a query returning all synchronization filters for this listItem
getType()
Get the type of item represented by the object.boolean
hasSyncFilters()
Does this item list define any sync filters?private static Set<Integer>
intersection(Collection<ItemList> lists, ItemList.DelayedAdditionManager delayed)
Create a set with the intersection of the items in the given lists.boolean
isInSync(DbControl dc)
Checks if all enabled sync filters appears to be in sync or not.boolean
isMember(Listable item)
Check if the given item is a member of this list.SyncFilter
newSyncFilter(DbControl dc)
Creates a new sync filter for this list.void
remove(Listable item)
Deprecated.In 3.15, useremoveItem(Listable item)
insteadint
removeAll(ItemList list)
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(Iterator<? extends Listable> it)
Remove multiple items from this list in one go.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
retainAll(ItemList list)
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.private static Set<Integer>
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 Detail
-
TYPE
public static final Item TYPE
The type of item represented by this class.- See Also:
Item.ITEMLIST
,getType()
-
MAX_EXTERNAL_ID_LENGTH
public static final int MAX_EXTERNAL_ID_LENGTH
The 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:
- Constant Field Values
-
delayed
private ItemList.DelayedAdditionManager delayed
-
-
Constructor Detail
-
ItemList
ItemList(ItemListData listData)
-
-
Method Detail
-
getNew
public static ItemList getNew(DbControl dc, Item memberType) throws BaseException
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
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!
- '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
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 theItem
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 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
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 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
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 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()
-
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 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
-
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
public boolean isMember(Listable item)
Check if the given item is a member of this list.- Since:
- 3.15
-
getMembers
public ItemQuery<? extends Listable> 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.
-
getAllItems
public ItemQuery<? extends Listable> 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 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:
Item.getQuery()
-
addMembers
private int addMembers(Set<Integer> items, ItemList.DelayedAdditionManager other)
Add members to this list.- Parameters:
items
- The items to addother
- 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)
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
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.- 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
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.- 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
public Date getSyncDate()
Get the last sync date+time. Note that manual changes may have been made to the list after this date.
-
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 andSyncFilter.SourceItemTransform.NONE
. UseSyncFilter.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
-
-