public class RelationServiceImpl extends Object implements RelationService
RelationService.RelatableFinder<R extends Relatable>, RelationService.Validator
Constructor and Description |
---|
RelationServiceImpl(RelationManager relationManager,
RelationInstanceFactory relationInstanceFactory,
RelatableFactory relatableFactory,
RelatableResolver relatableResolver,
PaginationService paginationService,
FavouriteManager favouriteManager,
LikeManager likeManager,
PermissionManager permissionManager,
UserChecker userChecker,
ValidatingRelationDescriptorRegistry relationDescriptorRegistry,
AccessModeService accessModeService) |
Modifier and Type | Method and Description |
---|---|
<S extends Relatable,T extends Relatable> |
create(RelationInstance<S,T> relationInstance)
Creates a directed relation between two relatable entities.
|
<S extends Relatable,T extends Relatable> |
delete(RelationInstance<S,T> relationInstance)
Remove a relation if it exists between a source and a target relatable entity
|
<S extends Relatable,T extends Relatable> |
findSources(T target,
RelationDescriptor<S,T> relationDescriptor)
Create a finder to find sources of a relation.
|
<S extends Relatable,T extends Relatable> |
findTargets(S source,
RelationDescriptor<S,T> relationDescriptor)
Create a finder to find targets of a relation.
|
<S extends Relatable,T extends Relatable> |
isRelated(S source,
RelationDescriptor<S,T> relationDescriptor,
T target)
Determine whether a given source and target are related by the given relation
|
<S extends Relatable,T extends Relatable> |
removeAllRelationsFromEntityWithType(RelationDescriptor<S,T> relationDescriptor,
Relatable relatable)
Remove all relations of the given type where the given entity participates
|
RelationService.Validator |
validator() |
public RelationServiceImpl(RelationManager relationManager, RelationInstanceFactory relationInstanceFactory, RelatableFactory relatableFactory, RelatableResolver relatableResolver, PaginationService paginationService, FavouriteManager favouriteManager, LikeManager likeManager, PermissionManager permissionManager, UserChecker userChecker, ValidatingRelationDescriptorRegistry relationDescriptorRegistry, AccessModeService accessModeService)
public <S extends Relatable,T extends Relatable> RelationInstance<S,T> create(RelationInstance<S,T> relationInstance) throws ServiceException
RelationService
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))
;
create
in interface RelationService
S
- type of the source entityT
- type of the target entityrelationInstance
- the relation to createServiceException
- if validation failspublic <S extends Relatable,T extends Relatable> void delete(RelationInstance<S,T> relationInstance) throws ServiceException
RelationService
delete
in interface RelationService
S
- type of the source entityT
- type of the target entityrelationInstance
- relation to be deletedServiceException
- if validation failspublic RelationService.Validator validator()
validator
in interface RelationService
public <S extends Relatable,T extends Relatable> RelationService.RelatableFinder<T> findTargets(S source, RelationDescriptor<S,T> relationDescriptor)
RelationService
For example, to find spaces that a user has favourites :
relationService.findTargets(user, new SpaceFavouriteRelation()).fetchMany(new SimplePageRequest(0,
10));
findTargets
in interface RelationService
S
- the type of the source entityT
- the type of the target entitysource
- the source entity (LHS) of the relationrelationDescriptor
- the type of relation to findpublic <S extends Relatable,T extends Relatable> RelationService.RelatableFinder<S> findSources(T target, RelationDescriptor<S,T> relationDescriptor)
RelationService
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));
findSources
in interface RelationService
S
- the type of the source entityT
- the type of the target entitytarget
- the target entity (RHS) of the relationrelationDescriptor
- the type of relation to findpublic <S extends Relatable,T extends Relatable> boolean isRelated(S source, RelationDescriptor<S,T> relationDescriptor, T target)
RelationService
isRelated
in interface RelationService
S
- type of the source entityT
- type of the target entitypublic <S extends Relatable,T extends Relatable> void removeAllRelationsFromEntityWithType(RelationDescriptor<S,T> relationDescriptor, Relatable relatable)
RelationService
removeAllRelationsFromEntityWithType
in interface RelationService
S
- the type of the source entity in the relation typeT
- the type of the target entity in the relation typerelationDescriptor
- relation descriptor representing the type of relation to removerelatable
- the entity participating in the relationshipsCopyright © 2003–2020 Atlassian. All rights reserved.