Class OptimizedCanonicalityChecker

java.lang.Object
com.atlassian.crowd.manager.application.canonicality.OptimizedCanonicalityChecker
All Implemented Interfaces:
CanonicalityChecker

public class OptimizedCanonicalityChecker extends Object implements CanonicalityChecker
Optimized implementation of CanonicalityChecker. This implementation is efficient for multiple calls, as it pre-fetches data. Limits number of queries to one per directory and entity type combination. Keeps only shadowed names to decrease memory usage. Does not implement CanonicalityChecker.groupByCanonicalId(Set, EntityDescriptor) - can't be used for parent queries.
  • Constructor Details

  • Method Details

    • removeNonCanonicalEntities

      public void removeNonCanonicalEntities(com.google.common.collect.Multimap<Long,String> allNames, EntityDescriptor entity)
      Description copied from interface: CanonicalityChecker

      Given a username is duplicated in several user directories under the same application.

      The user in the first directory, according to directory ordering is considered to be the canonical user for the given username, and the other users are shadowed and thus not to be returned from searches.

      This method removes all entities which were found for a given directory, but were not canonical in it (they existed in a preceding directory, not necessarily in the allEntities map). The allEntities map will be mutated in the process. For example: Given the following directories and entities:
      • Directory 1 - Users A, B, C
      • Directory 2 - Users C, D, E
      At this point users A, B and C are known as canonical in the Directory 1 and will be removed from the succeeding directories. This will leave users D and E in Directory 2. However their canonicality in Directory 2 is uncertain as they may exist in Directory 1, but may have not been matched by the query that was used to retrieve the users. Because of this Directory 1 will be queried for users D and E and the results that were found will be removed from all succeeding directories. If user D is found in Directory 1 this will give us the following result:
      • Directory 1 - Users A, B, C
      • Directory 2 - User E
      User D was not included in the result set due to being canonical in Directory 1, but not matching the query used to retrieve the entities.
      Specified by:
      removeNonCanonicalEntities in interface CanonicalityChecker
      Parameters:
      allNames - a directoryId to list of entities map containing the entities to check for canonicality.
      entity - the EntityDescriptor used to look up the entities that will be determined as canonical
    • groupByCanonicalId

      public com.google.common.collect.SetMultimap<Long,String> groupByCanonicalId(Set<String> names, EntityDescriptor entity)
      Description copied from interface: CanonicalityChecker
      Returns names grouped by their canonical directory id. Case-sensitivity of the provided names is preserved. Names not found won't be returned.
      Specified by:
      groupByCanonicalId in interface CanonicalityChecker
      Parameters:
      names - names to be grouped
      entity - entity to which the names are referring to
      Returns:
      names grouped by their canonical directory id
    • getDirectories

      public List<Directory> getDirectories()
      Specified by:
      getDirectories in interface CanonicalityChecker
      Returns:
      ordered list of directories for which the canonicality is computed