Interface RemoteRelationService

  • All Known Implementing Classes:
    RemoteRelationServiceImpl

    @ExperimentalApi
    public interface RemoteRelationService
    Relation service, which allows to manage relations between entities. "Relations" are used when it's needed to mark related content. 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).

    For example, to create a favourite relation between a user and the DEV Space :

         relationService.create(RelationInstance.builder(user, new SpaceFavouriteRelation(), space).build));
     assertTrue(relationService.isRelated(user, new SpaceFavouriteRelation(), space));
         
     
    and to find the favourite spaces of a user :
         relationService.findTargets(user, new SpaceFavouriteRelation()).fetchMany(new SimplePageRequest(0, 10));
     
    Since:
    5.9
    See Also:
    RelationInstance, Relatable, RelationDescriptor
    • Method Detail

      • create

        @Deprecated
        <S extends Relatable,​T extends Relatable> com.atlassian.util.concurrent.Promise<Void> create​(RelationInstance<S,​T> relationInstance)
                                                                                                    throws ServiceException
        Deprecated.
        since 7.0.1. Use createCompletionStage(RelationInstance) instead.
        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));
         
        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
      • createCompletionStage

        <S extends Relatable,​T extends RelatableCompletionStage<Void> createCompletionStage​(RelationInstance<S,​T> relationInstance)
                                                                                             throws ServiceException
        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));
         
        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
        Since:
        7.0.1
      • deleteCompletionStage

        <S extends Relatable,​T extends RelatableCompletionStage<Void> deleteCompletionStage​(RelationInstance<S,​T> relationInstance)
                                                                                             throws ServiceException
        Remove a relation if it exists between a source and a target relatable entity
        Type Parameters:
        S - type of the source entity
        T - type of the target entity
        Parameters:
        relationInstance - relation to be deleted
        Throws:
        ServiceException - if validation fails
        Since:
        7.0.1
      • isRelatedCompletionStage

        <S extends Relatable,​T extends RelatableCompletionStage<Boolean> isRelatedCompletionStage​(S source,
                                                                                                          RelationDescriptor<S,​T> relationDescriptor,
                                                                                                          T target)
        Determine whether a given source and target are related by the given relation
        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
        Since:
        7.0.1