Class RelationServiceImpl

    • Method Detail

      • create

        public <S extends Relatable,​T extends RelatableRelationInstance<S,​T> create​(RelationInstance<S,​T> relationInstance)
                                                                                           throws ServiceException
        Description copied from interface: RelationService
        Creates a directed relation between two relatable entities.

        For example, when a user favourites a space a SpaceFavouriteRelation is created from the user to the space:

             relationService.create(RelationInstance.builder(user, new SpaceFavouriteRelation(), space).build));
         
        Specified by:
        create in interface RelationService
        Type Parameters:
        S - type of the source entity
        T - type of the target entity
        Parameters:
        relationInstance - the relation to create
        Returns:
        the newly created relationInstance
        Throws:
        ServiceException - if validation fails
      • findTargets

        public <S extends Relatable,​T extends RelatableRelationService.RelatableFinder<T> findTargets​(S source,
                                                                                                              RelationDescriptor<S,​T> relationDescriptor)
        Description copied from interface: RelationService
        Create a finder to find targets of a relation. This method is used to find all targets for given relation and given source. For example, it can be used in operations like "findAllFavouriteContentForGivenUser" (user2content relation) or "findAllUsersThisUserIsFollowingTo" (user2user relation)

        For example, to find spaces that a user has favourites :

             relationService.findTargets(user, new SpaceFavouriteRelation()).fetchMany(new SimplePageRequest(0,
         10));
         
        Specified by:
        findTargets in interface RelationService
        Type Parameters:
        S - the type of the source entity
        T - the type of the target entity
        Parameters:
        source - the source entity (LHS) of the relation
        relationDescriptor - the type of relation to find
        Returns:
        a finder to find targets of a relation.
      • findSources

        public <S extends Relatable,​T extends RelatableRelationService.RelatableFinder<S> findSources​(T target,
                                                                                                              RelationDescriptor<S,​T> relationDescriptor)
        Description copied from interface: RelationService
        Create a finder to find sources of a relation.

        This method is used to find all sources for given relation and given source. For example, it can be used in operations like "findAllUsersWhoFavouritedThisPage" (user2content relation) or "findAllFollowers" (user2user relation)

        For example, to find users that favourite a particular space :

             relationService.findSources(space, new SpaceFavouriteRelation()).fetchMany(new SimplePageRequest(0,
         10));
         
        Specified by:
        findSources in interface RelationService
        Type Parameters:
        S - the type of the source entity
        T - the type of the target entity
        Parameters:
        target - the target entity (RHS) of the relation
        relationDescriptor - the type of relation to find
        Returns:
        a finder to find targets of a relation.
      • isRelated

        public <S extends Relatable,​T extends Relatable> boolean isRelated​(S source,
                                                                                 RelationDescriptor<S,​T> relationDescriptor,
                                                                                 T target)
        Description copied from interface: RelationService
        Determine whether a given source and target are related by the given relation
        Specified by:
        isRelated in interface RelationService
        Type Parameters:
        S - type of the source entity
        T - type of the target entity
        Returns:
        true if the relation exists between the given source and target
      • removeAllRelationsFromEntityWithType

        public <S extends Relatable,​T extends Relatable> void removeAllRelationsFromEntityWithType​(RelationDescriptor<S,​T> relationDescriptor,
                                                                                                         Relatable relatable)
        Description copied from interface: RelationService
        Remove all relations of the given type where the given entity participates
        Specified by:
        removeAllRelationsFromEntityWithType in interface RelationService
        Type Parameters:
        S - the type of the source entity in the relation type
        T - the type of the target entity in the relation type
        Parameters:
        relationDescriptor - relation descriptor representing the type of relation to remove
        relatable - the entity participating in the relationships