Interface UserRoleService<P extends UserRole>
-
- All Known Implementing Classes:
DefaultUserRoleService
public interface UserRoleService<P extends UserRole>
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
archive(String id)
Soft-deletes a record by setting itsUserRole.archived
totrue
.P
createOnlyIfDoesNotExist(P role, Instant lastUpdated)
A specialized create operation for creating an entity with a pre-defined id with the minimum guarantee that concurrent requests to this method for the same entity ID will fail.P
createRole(P payload)
Creates a new role in the data store.void
delete(String id)
Hard-deletes the given record.List<P>
findAllByIdInAndNotArchived(Collection<String> ids)
Finds and returns a list of entities that are notUserRole.archived
and whose id matches one of the given values.org.springframework.data.domain.Page<P>
findAllByNameContainingAndNotArchived(String name, org.springframework.data.domain.Pageable page)
Finds and returns all entities that are notUserRole.archived
whose name contains the given value.Stream<P>
findAllStreamByIdInAndNotArchived(Collection<String> ids)
Finds and returns a stream of entities that are notUserRole.archived
and whose id matches one of the given values.Optional<P>
findById(String id)
Finds and returns the entity with the given ID.Optional<P>
findByIdAndNotArchived(String id)
Finds and returns the entity with the given ID if notUserRole.archived
.P
replaceOnlyIfLastUpdatedBefore(String entityId, P role, Instant lastUpdated)
A specialized replace operation that does not invoke the "save" create-or-update behavior.P
replaceRole(String id, P payload)
Replaces the role in the data store with the givenid
withpayload
.
-
-
-
Method Detail
-
findById
Optional<P> findById(String id)
Finds and returns the entity with the given ID.- Parameters:
id
- the id of the entity to find- Returns:
- an
Optional
containing the entity if found,Optional.empty()
otherwise
-
findByIdAndNotArchived
Optional<P> findByIdAndNotArchived(String id)
Finds and returns the entity with the given ID if notUserRole.archived
.- Parameters:
id
- the id of the entity to find- Returns:
- an
Optional
containing the entity if found,Optional.empty()
otherwise
-
findAllByNameContainingAndNotArchived
org.springframework.data.domain.Page<P> findAllByNameContainingAndNotArchived(@Nullable String name, org.springframework.data.domain.Pageable page)
Finds and returns all entities that are notUserRole.archived
whose name contains the given value.- Parameters:
name
- the name value to match withpage
- information about which page of results to return from the database- Returns:
- all entities that are not archived whose name matches the given value
-
findAllStreamByIdInAndNotArchived
Stream<P> findAllStreamByIdInAndNotArchived(Collection<String> ids)
Finds and returns a stream of entities that are notUserRole.archived
and whose id matches one of the given values.- Parameters:
ids
- the ids of the entities to find- Returns:
- a stream of the entities that were found
-
findAllByIdInAndNotArchived
List<P> findAllByIdInAndNotArchived(Collection<String> ids)
Finds and returns a list of entities that are notUserRole.archived
and whose id matches one of the given values.- Parameters:
ids
- the ids of the entities to find- Returns:
- a list of the entities that were found
-
createRole
P createRole(P payload)
Creates a new role in the data store.- Parameters:
payload
- the role to create- Returns:
- the final role after creation
- Throws:
com.broadleafcommerce.common.error.validation.ValidationException
- if the givenpayload
failed validation for creation
-
delete
void delete(String id)
Hard-deletes the given record.In all but exceptional cases,
archive(String)
should be preferred to this operation.- Parameters:
id
- the id of the entity to delete- Throws:
com.broadleafcommerce.data.tracking.core.exception.EntityMissingException
- if the entity to delete was not foundInvalidUserRoleDeleteException
- if the role has children- See Also:
archive(String)
-
archive
void archive(String id)
Soft-deletes a record by setting itsUserRole.archived
totrue
.As part of this operation, the
UserRole.permissions
collections should be cleared such that those relationships are deleted.- Parameters:
id
- the id of the entity to archive- Throws:
com.broadleafcommerce.data.tracking.core.exception.EntityMissingException
- if the entity to archive was not foundInvalidUserRoleDeleteException
- if the role has children- See Also:
delete(String)
-
replaceRole
P replaceRole(String id, P payload)
Replaces the role in the data store with the givenid
withpayload
.- Parameters:
id
- the ID of the role to replacepayload
- the replacement role- Returns:
- the final role after replacement
- Throws:
com.broadleafcommerce.common.error.validation.ValidationException
- if thepayload
failed validation for replacementcom.broadleafcommerce.data.tracking.core.exception.EntityMissingException
- if the role to replace was not found or wasUserRole.archived
-
createOnlyIfDoesNotExist
@Nullable P createOnlyIfDoesNotExist(P role, Instant lastUpdated)
A specialized create operation for creating an entity with a pre-defined id with the minimum guarantee that concurrent requests to this method for the same entity ID will fail.This is intended to be used in a message handler, a highly concurrent scenario where only one operation should succeed.
Furthermore, this operation must not validate the request as
createRole(UserRole)
does, since we expect message handlers to receive out-of-order messages that may temporarily have invalid references.- Parameters:
role
- the role to create. Must have a non-null id present.lastUpdated
- theUserRole.lastUpdated
to set on the role- Returns:
- the role if successfully created, or
null
if creation failed due to the entity already existing. - See Also:
AdminRolePersistenceHandler
-
replaceOnlyIfLastUpdatedBefore
@Nullable P replaceOnlyIfLastUpdatedBefore(String entityId, P role, Instant lastUpdated)
A specialized replace operation that does not invoke the "save" create-or-update behavior. This operation should directly attempt an atomic update that the data store will reject if the entity is not found or has a lastUpdated ahead of the current change.This is intended to be used in a message handler, a highly concurrent scenario where only one operation should succeed.
Furthermore, this operation must not validate the request as
replaceRole(String, UserRole)
does, since we expect message handlers to receive out-of-order messages that may temporarily have invalid references.- Parameters:
entityId
- the id of the entity to replacerole
- the replacement entitylastUpdated
- the timestamp of the current change. This will be compared to the lastUpdated on the existing entity for determination of whether the replacement should occur. Furthermore, the replacement will have itsUserRole.lastUpdated
set to this value.- Returns:
- the role after replacement if successfully replaced, or
null
if the entity was not found or could not be updated due to its lastUpdated value. - See Also:
AdminRolePersistenceHandler
-
-