Class 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
  • Field Details

  • Constructor Details

  • Method Details

    • getById

      public static SyncFilter getById​(DbControl dc, int id) throws ItemNotFoundException, PermissionDeniedException, BaseException
      Get a SyncFilter 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 SyncFilter 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<SyncFilter> getQuery​(ItemList list)
      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

      public 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 Id
    • getData

      Description copied from class: BasicItem
      Get the BasicData object that holds all data for this item.
      Specified by:
      getData in class BasicItem
    • 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.
      Specified by:
      getType in interface Identifiable
      Returns:
      A value indicating the type of item
    • getSharedParent

      SharedData getSharedParent()
      Description copied from class: ChildItem
      Get the shareable parent item of this child item. This is used by the ChildItem.initPermissions(int, int) method to calculate the logged in user's permissions for the child item.
      Specified by:
      getSharedParent in class ChildItem
      Returns:
      The parent item
    • getName

      public String getName()
      Description copied from interface: Nameable
      Get the name of the item.
      Specified by:
      getName in interface Nameable
      Returns:
      A String with the name of the item
    • setName

      public void setName​(String name) throws PermissionDeniedException, InvalidDataException
      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 the Nameable.MAX_NAME_LENGTH constant.
      Specified by:
      setName in interface Nameable
      Parameters:
      name - The new name for the item
      Throws:
      PermissionDeniedException - If the logged in user doesn't have write permission
      InvalidDataException - If the name is null or longer than specified by the Nameable.MAX_NAME_LENGTH constant
    • getDescription

      public String getDescription()
      Description copied from interface: Nameable
      Get the description for the item.
      Specified by:
      getDescription in interface Nameable
      Returns:
      A String with a description of the item
    • setDescription

      public void setDescription​(String description) throws PermissionDeniedException, InvalidDataException
      Description 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 the Nameable.MAX_DESCRIPTION_LENGTH constant.
      Specified by:
      setDescription in interface Nameable
      Parameters:
      description - The new description for the item
      Throws:
      PermissionDeniedException - If the logged in user doesn't have write permission
      InvalidDataException - If the description longer than specified by the Nameable.MAX_DESCRIPTION_LENGTH constant
    • getItemList

      public ItemList getItemList() throws PermissionDeniedException, BaseException
      Get the item list this filter belongs to.
      Returns:
      The SyncFilter item
      Throws:
      PermissionDeniedException - If the logged in user doesn't have Permission.READ permission
      BaseException - If there is another error
    • setSyncContext

      public void setSyncContext​(ItemContext syncContext, SyncFilter.SourceItemTransform transform)
      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 transform
      transform - The new transformation or null to keep the current transformation
    • copyToContext

      public void copyToContext​(ItemContext context)
      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

      public String 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

      public void setFilterGroup​(String filterGroup)
      Set the group that this synchronization filter belongs to. See getFilterGroup() for a description of allowed values.
      Since:
      3.18
    • getSourceItemType

      public Item 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

      public SyncFilter.SourceItemTransform 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. See ItemList.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. See ItemList.getSyncDate(). If this filter doesn't use a transform the same number as getLastSyncMatchingSource() is returned.
      Returns:
      The number of matching transformed items, or -1 if not known
    • getCurrentMatchingSource

      public int getCurrentMatchingSource​(DbControl dc)
      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

      public 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. 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

      public Collection<PropertyFilter> getPropertyFilters​(int filterRow)
      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

      private Item getListMemberType()
    • getMatching

      private SortedSet<Integer> getMatching​(DbControl dc)
    • toMd5

      public static String toMd5​(SortedSet<Integer> listOfIds)
      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 by MessageDigest.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

      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. 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