Package net.sf.basedb.core
Class SyncFilter
java.lang.Object
net.sf.basedb.core.BasicItem
net.sf.basedb.core.ChildItem
net.sf.basedb.core.SyncFilter
- All Implemented Interfaces:
AccessControlled
,Identifiable
,Nameable
public class SyncFilter extends ChildItem implements Nameable
Holds information about a synchronization filter used
by an item list.
- Since:
- 3.5
- Author:
- Nicklas
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SyncFilter.SourceItemTransform
-
Field Summary
Fields Modifier and Type Field Description private static List<Item>
CHAIN_ORDER
private List<PropertyFilter>
filters
private Item
listMemberType
private SortedSet<Integer>
matching
private String
matchingMd5
private int
numFilterRows
private static List<SyncFilter.SourceItemTransform>
TRANSFORM_ORDER
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 SyncFilter(ItemListSyncFilterData syncFilter)
-
Method Summary
Modifier and Type Method Description static Comparator<SyncFilter>
compareByChainOrder()
Create a comparator that sorts sync filters by: Filter group Source item type: BIOSOURCE, SAMPLE, EXTRACT, PHYSICALBIOASSAY, DERIVEDBIOASSAY, RAWBIOASSAY Type of transformation: PARENT_TO_CHILD, NONE, CHILD_TO_PARENT Name Source item must exists is sorted before source item must not exist Idvoid
copyToContext(ItemContext context)
Copy the filter settings in this synchronization filter to the given item context.static SyncFilter
getById(DbControl dc, int id)
Get aSyncFilter
item when you know the id.int
getCurrentMatchingSource(DbControl dc)
Get the number of items that is currently matching this filter.(package private) ItemListSyncFilterData
getData()
Get theBasicData
object that holds all data for this item.String
getDescription()
Get the description for the item.String
getFilterGroup()
Get the group this synchronization filter belongs to.int
getFilterRows()
Get the number of filter rows in this filter.static List<String>
getFormattedAndSortedFilters(Collection<PropertyFilter> filters, Formatter<PropertyFilter> filterFormatter)
Utility method for formatting and sorting a list of property filters.ItemList
getItemList()
Get the item list this filter belongs to.int
getLastSyncMatchingSource()
Get the number of source items that matched this particular filter during the last synchronization.int
getLastSyncMatchingTransformed()
Get the number of transformed items that matched this particular filter during the last synchronization.private Item
getListMemberType()
private SortedSet<Integer>
getMatching(DbControl dc)
String
getName()
Get the name of the item.Collection<PropertyFilter>
getPropertyFilters(int filterRow)
Get the filters in the given filter row.static ItemQuery<SyncFilter>
getQuery(ItemList list)
Get a query configured to retrieve sync filters for the specified item list.(package private) SharedData
getSharedParent()
Get the shareable parent item of this child item.boolean
getSourceItemMustExist()
If set, a source item that matches the filter must exist, otherwise it must not exist.SyncFilter.SourceItemTransform
getSourceItemTransformation()
Get the transformation to use for converting the items matching this filter to list members.Item
getSourceItemType()
Get the source item type that this synchronization filter applies to.(package private) static String
getSyncProperties(ItemListSyncFilterData sf)
Get a string representing the current syncfilter properties that may affect the end result even if the query return the same items.Item
getType()
Get the type of item represented by the object.private void
initFilters()
boolean
isDisabled()
If set, this filter is disabled and is not used when syncing.boolean
isInSync(DbControl dc)
Checks if the items that are currently matching this filter are the same as the items that matched it during the last sync.void
setDescription(String description)
Set the description for the item.void
setDisabled(boolean disabled)
Disabled/enable this filter.void
setFilterGroup(String filterGroup)
Set the group that this synchronization filter belongs to.void
setName(String name)
Set the name of the item.void
setSourceItemMustExist(boolean sourceMustExist)
void
setSyncContext(ItemContext syncContext, SyncFilter.SourceItemTransform transform)
Copy filters and other settings from the given context to this synchronization filter.static String
toMd5(SortedSet<Integer> listOfIds)
Calculate the MD5 sum of all all ID values in the collection.Methods inherited from class net.sf.basedb.core.ChildItem
getPermissionForUse, getPermissionForWriteDeleteAndCreate, getPluginPermissions, initPermissions
Methods inherited from class net.sf.basedb.core.BasicItem
addAnnotatableParents, addUsingItems, addUsingItems, breakCircularReferences, checkBatchAnnotatableUsage, checkPermission, equals, getBasicData, getDbControl, getId, getPermissions, getSessionControl, getUsingItems, getVersion, hashCode, hasPermission, isDetached, isInDatabase, isUsed, onAfterCommit, onAfterInsert, onBeforeCommit, 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
-
Field Details
-
TYPE
The type of item represented by this class.- See Also:
Item.SYNCFILTER
,getType()
-
CHAIN_ORDER
-
TRANSFORM_ORDER
-
listMemberType
-
filters
-
numFilterRows
private int numFilterRows -
matching
-
matchingMd5
-
-
Constructor Details
-
SyncFilter
SyncFilter(ItemListSyncFilterData syncFilter)
-
-
Method Details
-
getById
public static SyncFilter getById(DbControl dc, int id) throws ItemNotFoundException, PermissionDeniedException, BaseExceptionGet aSyncFilter
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
SyncFilter
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 configured to retrieve sync filters for the specified item list.- Parameters:
list
- The item list, null is not allowed- Returns:
- An
ItemQuery
object
-
getFormattedAndSortedFilters
public static List<String> getFormattedAndSortedFilters(Collection<PropertyFilter> filters, Formatter<PropertyFilter> filterFormatter)Utility method for formatting and sorting a list of property filters.- See Also:
PropertyFilterFormatter
-
compareByChainOrder
Create a comparator that sorts sync filters by: Filter group Source item type: BIOSOURCE, SAMPLE, EXTRACT, PHYSICALBIOASSAY, DERIVEDBIOASSAY, RAWBIOASSAY Type of transformation: PARENT_TO_CHILD, NONE, CHILD_TO_PARENT Name Source item must exists is sorted before source item must not exist Id -
getData
ItemListSyncFilterData getData()Description copied from class:BasicItem
Get theBasicData
object that holds all data for this 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.- Specified by:
getType
in interfaceIdentifiable
- Returns:
- A value indicating the type of item
-
getName
Description copied from interface:Nameable
Get the name of the item. -
setName
Description copied from interface:Nameable
Set the name of the item. The name cannot be null and mustn't be longer than the value specified by theNameable.MAX_NAME_LENGTH
constant.- Specified by:
setName
in interfaceNameable
- Parameters:
name
- The new name for the item- Throws:
PermissionDeniedException
- If the logged in user doesn't have write permissionInvalidDataException
- If the name is null or longer than specified by theNameable.MAX_NAME_LENGTH
constant
-
getDescription
Description copied from interface:Nameable
Get the description for the item.- Specified by:
getDescription
in interfaceNameable
- Returns:
- A
String
with a description of the item
-
setDescription
public void setDescription(String description) throws PermissionDeniedException, InvalidDataExceptionDescription copied from interface:Nameable
Set the description for the item. The description can be null but mustn't be longer than the value specified by theNameable.MAX_DESCRIPTION_LENGTH
constant.- Specified by:
setDescription
in interfaceNameable
- Parameters:
description
- The new description for the item- Throws:
PermissionDeniedException
- If the logged in user doesn't have write permissionInvalidDataException
- If the description longer than specified by theNameable.MAX_DESCRIPTION_LENGTH
constant
-
getItemList
Get the item list this filter belongs to.- Returns:
- The
SyncFilter
item - Throws:
PermissionDeniedException
- If the logged in user doesn't havePermission.READ
permissionBaseException
- If there is another error
-
setSyncContext
Copy filters and other settings from the given context to this synchronization filter. This changes the source item type (getSourceItemType()
), transform (getSourceItemTransformation()
) and replaces all existing filters with the filters from the item context.- Parameters:
syncContext
- The context to copy from, or null to only update the transformtransform
- The new transformation or null to keep the current transformation
-
copyToContext
Copy the filter settings in this synchronization filter to the given item context. All filter settings in the item context are replaced with this filter. The context must be for the same item type as the source item type of this filter. -
getFilterGroup
Get the group this synchronization filter belongs to. The group is a string where the first character is one of A-Z followed by a '+' or '-' sign. Filters that belong to the same group are evaluated together and then merged with UNION operation (for groups with '+' sign) or REMOVE operation (for groups with '-' sign). Groups are processed in alphabetical order (A+, A-, B+, B-, .... Z+, Z-)- Since:
- 3.18
-
setFilterGroup
Set the group that this synchronization filter belongs to. SeegetFilterGroup()
for a description of allowed values.- Since:
- 3.18
-
getSourceItemType
Get the source item type that this synchronization filter applies to. This may or may not be the same item type as the member type of the list. If this type is different from the list member type an item transformation is required, but a transformation can also be used for items of the same type. -
getSourceItemTransformation
Get the transformation to use for converting the items matching this filter to list members. -
getSourceItemMustExist
public boolean getSourceItemMustExist()If set, a source item that matches the filter must exist, otherwise it must not exist. Only applies to filters with a source item transformation that is to a parent/child item. -
setSourceItemMustExist
public void setSourceItemMustExist(boolean sourceMustExist) -
isDisabled
public boolean isDisabled()If set, this filter is disabled and is not used when syncing. -
setDisabled
public void setDisabled(boolean disabled)Disabled/enable this filter. -
getLastSyncMatchingSource
public int getLastSyncMatchingSource()Get the number of source items that matched this particular filter during the last synchronization. SeeItemList.getSyncDate()
.- Returns:
- The number of matching source items, or -1 if not known
-
getLastSyncMatchingTransformed
public int getLastSyncMatchingTransformed()Get the number of transformed items that matched this particular filter during the last synchronization. SeeItemList.getSyncDate()
. If this filter doesn't use a transform the same number asgetLastSyncMatchingSource()
is returned.- Returns:
- The number of matching transformed items, or -1 if not known
-
getCurrentMatchingSource
Get the number of items that is currently matching this filter. The method will cause a query to be executed against the database, but the result is cached and re-used if called multiple times. -
isInSync
Checks if the items that are currently matching this filter are the same as the items that matched it during the last sync. The check is done by comparing the MD5 sum of the concatenated ID values. -
getFilterRows
public int getFilterRows()Get the number of filter rows in this filter. -
getPropertyFilters
Get the filters in the given filter row.- Parameters:
filterRow
- The index of the filter row which should be between 0 and number of rows - 1, or use -1 to get all property filters
-
initFilters
private void initFilters() -
getListMemberType
-
getMatching
-
toMd5
Calculate the MD5 sum of all all ID values in the collection. Each ID is converted to a 4-byte array and added to the MD5 byMessageDigest.update(byte[])
The list is assumed to be sorted in ID order so that if two collections contain the same ID values, they should produce the same MD5. -
getSyncProperties
Get a string representing the current syncfilter properties that may affect the end result even if the query return the same items. We save this string at sync time and can then compare it with current settings to se if the item list seems to be up to date.- Since:
- 3.18
-