Interface RelationManager

All Known Implementing Classes:
DefaultRelationManager

public interface RelationManager
Manages relations for entities and users. Now in DMZ "Relation" abstraction is used for "marking" different entities as related. So far relations of types "user2content", "user2user" and "content2content" are supported Good examples of relations are Watches (when user marks certain pages as watchable), Likes (user marks content as "Liked") or Favourites (content is marked as favourite by user) (all are "user2content" type of relations).

It is very similar to the content properties, but the very important difference is that for given page we're not interested for all relations, but only if it is related with one particular entity (f.e. to show the page we don't need to know all the users who "favourited" this page, we just need to know if the current user did). At the same time we need to fetch all the contentproperties to render the page properly.

So it was decided to create generic relation service to feed and serve "relational" functionality efficiently.

Each relation contains a source (for example, in favourite relations, source is the user, which favourited some page), target (for example, in favourite relations, target is the page, favourited by user) and some metadata like relation name etc. Depends on type of entities, which participate in relation, relations may be one of the 3 types: user2user (when both source and target are users - for example, following relation), user2content (example: favouriting, watching, Liking etc.) and content2content (when both source and target are content object) (pls. see RelationshipTypeEnum for more details)

Since:
5.9
See Also:
  • Method Details

    • isRelated

      boolean isRelated(RelatableEntity source, RelatableEntity target, RelationDescriptor relationDescriptor)
      Checks if given entities are related. Name of relation is specified by Relation argument.
      Parameters:
      source -
      target -
      relationDescriptor -
      Returns:
      true if entities are related, false otherwise.
    • addRelation

      RelationEntity addRelation(RelatableEntity source, RelatableEntity target, RelationDescriptor relationDescriptor)
      Create a new relation between 2 entities. This method does nothing if relation already exists. Name of relation is specified by Relation argument
      Parameters:
      source -
      target -
      relationDescriptor -
      Returns:
      created (or existent) relation
    • removeRelation

      void removeRelation(RelatableEntity source, RelatableEntity target, RelationDescriptor relationDescriptor)
      Delete relation. This method does nothing if relation already exists. Name of relation is specified by Relation argument
      Parameters:
      source -
      target -
      relationDescriptor -
    • removeAllRelations

      int removeAllRelations(RelatableEntity relatableEntity)
      This method removes all relations (across all names and types), where given entity participates.
      Parameters:
      relatableEntity -
      Returns:
      number of relations which were removed.
    • removeAllRelationsFromEntityWithType

      int removeAllRelationsFromEntityWithType(RelationDescriptor relationDescriptor, RelatableEntity relatableEntity)
      This method remove all relations of the given type where the given entity participates
      Parameters:
      relationDescriptor -
      relatableEntity -
      Returns:
      number of relations which were removed
    • removeAllRelationsFromCurrentAndHistoricalEntities

      int removeAllRelationsFromCurrentAndHistoricalEntities(RelatableEntity relatableEntity)
      This method removes all relations (across all names and types), where given entity participates. It also removes all relations from the historical versions of the given entity if the entity is the most current version of content
      Parameters:
      relatableEntity -
      Returns:
      number of relations which were removed.
    • removeAllRelationsFromCurrentAndHistoricalEntities

      int removeAllRelationsFromCurrentAndHistoricalEntities(Iterable<? extends RelatableEntity> readableEntities)
      This method removes all relations (across all names and types), where given entity participates. It also removes all relations from the historical versions of the given entity if the entity is the most current version of content. This will try to use batch delete as much as possible
      Parameters:
      readableEntities -
      Returns:
      number of relations which were removed.
      Since:
      6.12.0
    • moveRelationsToContent

      void moveRelationsToContent(RelatableEntity fromRelatableEntity, RelatableEntity toRelatableEntity, RelationDescriptor descriptor)
      Moves all the relations of the specified type from one entity to another. The source entity will have all relations of the specified type removed
      Parameters:
      fromRelatableEntity - the entity from which to remove the relations
      toRelatableEntity - the entity to which the relations will be added
      descriptor - the type of relation to move
    • getSources

      @NonNull PageResponse<RelatableEntity> getSources(RelationQuery request, LimitedRequest pageRequest)
      Fetch all related sources for the entity. Fetching parameters (relation name, filtering etc.) is provided by request argument
      Parameters:
      request -
      pageRequest -
      Returns:
      PageResponse
      See Also:
    • getTargets

      @NonNull PageResponse<RelatableEntity> getTargets(RelationQuery request, LimitedRequest pageRequest)
      Fetch all related targets for the entity. Fetching parameters (relation name, filtering etc.) is provided by request argument
      Parameters:
      request -
      pageRequest -
      Returns:
      PageResponse
      See Also:
    • getSourcesCount

      int getSourcesCount(RelationQuery request)
      Get total number of related sources for the entity. Querying parameters (relation name, filtering etc.) is provided by request argument
      Parameters:
      request -
      Returns:
      total number of related sources for the entity
      See Also:
    • getTargetsCount

      int getTargetsCount(RelationQuery request)
      Get total number of related targets for the entity. Querying parameters (relation name, filtering etc.) is provided by request argument
      Parameters:
      request -
      Returns:
      total number of related targets for the entity
      See Also: