public class DefaultUserRoleService<P extends UserRole,D extends com.broadleafcommerce.data.tracking.core.mapping.BusinessTypeAware & com.broadleafcommerce.data.tracking.core.mapping.ModelMapperMappable> extends Object implements UserRoleService<P>
Constructor and Description |
---|
DefaultUserRoleService(RoleRepository<D> repository,
SimplePayloadMapper mapper,
com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager validator) |
Modifier and Type | Method and Description |
---|---|
protected void |
applyChangesForArchive(P role)
Modifies the given instance for archival.
|
void |
archive(@NonNull String id)
Soft-deletes a record by setting its
UserRole.archived to true . |
P |
createOnlyIfDoesNotExist(P role,
@NonNull 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(@NonNull String id)
Hard-deletes the given record.
|
List<P> |
findAllByIdInAndNotArchived(Collection<String> ids)
Finds and returns a list of entities that are not
UserRole.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 not
UserRole.archived whose name contains the
given value. |
Stream<P> |
findAllStreamByIdInAndNotArchived(Collection<String> ids)
Finds and returns a stream of entities that are not
UserRole.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 not
UserRole.archived . |
protected com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager |
getValidator() |
P |
replaceOnlyIfLastUpdatedBefore(@NonNull String entityId,
P role,
@NonNull 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 given
id with payload . |
protected void |
validateNoChildrenOfRoleBeforeDeletion(@NonNull String roleToDeleteId)
Given a role that is requested to be deleted or archived, checks that it does not have any
child roles in the data store.
|
public DefaultUserRoleService(RoleRepository<D> repository, SimplePayloadMapper mapper, com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager validator)
public Optional<P> findById(String id)
UserRoleService
findById
in interface UserRoleService<P extends UserRole>
id
- the id of the entity to findOptional
containing the entity if found, Optional.empty()
otherwisepublic Optional<P> findByIdAndNotArchived(String id)
UserRoleService
UserRole.archived
.findByIdAndNotArchived
in interface UserRoleService<P extends UserRole>
id
- the id of the entity to findOptional
containing the entity if found, Optional.empty()
otherwisepublic org.springframework.data.domain.Page<P> findAllByNameContainingAndNotArchived(@Nullable String name, org.springframework.data.domain.Pageable page)
UserRoleService
UserRole.archived
whose name contains the
given value.findAllByNameContainingAndNotArchived
in interface UserRoleService<P extends UserRole>
name
- the name value to match withpage
- information about which page of results to return from the databasepublic Stream<P> findAllStreamByIdInAndNotArchived(Collection<String> ids)
UserRoleService
UserRole.archived
and whose id
matches one of the given values.findAllStreamByIdInAndNotArchived
in interface UserRoleService<P extends UserRole>
ids
- the ids of the entities to findpublic List<P> findAllByIdInAndNotArchived(Collection<String> ids)
UserRoleService
UserRole.archived
and whose id
matches one of the given values.findAllByIdInAndNotArchived
in interface UserRoleService<P extends UserRole>
ids
- the ids of the entities to findpublic P createRole(P payload)
UserRoleService
createRole
in interface UserRoleService<P extends UserRole>
payload
- the role to createpublic P replaceRole(String id, P payload)
UserRoleService
id
with payload
.replaceRole
in interface UserRoleService<P extends UserRole>
id
- the ID of the role to replacepayload
- the replacement rolepublic void delete(@NonNull @NonNull String id)
UserRoleService
In all but exceptional cases, UserRoleService.archive(String)
should be preferred to this operation.
delete
in interface UserRoleService<P extends UserRole>
id
- the id of the entity to deleteUserRoleService.archive(String)
protected void validateNoChildrenOfRoleBeforeDeletion(@NonNull @NonNull String roleToDeleteId)
roleToDeleteId
- the id of the role which should be validated to have no children in the
data storeInvalidUserRoleDeleteException
- if the role has children in the data storepublic void archive(@NonNull @NonNull String id)
UserRoleService
UserRole.archived
to true
.
As part of this operation, the UserRole.permissions
collections should be cleared
such that those relationships are deleted.
archive
in interface UserRoleService<P extends UserRole>
id
- the id of the entity to archiveUserRoleService.delete(String)
protected void applyChangesForArchive(P role)
role
- the instance to modify@Nullable public P createOnlyIfDoesNotExist(@NonNull P role, @NonNull @NonNull Instant lastUpdated)
UserRoleService
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
UserRoleService.createRole(UserRole)
does, since we expect message handlers to receive out-of-order
messages that may temporarily have invalid references.
createOnlyIfDoesNotExist
in interface UserRoleService<P extends UserRole>
role
- the role to create. Must have a non-null id present.lastUpdated
- the UserRole.lastUpdated
to set on the rolenull
if creation failed due to the
entity already existing.AdminRolePersistenceHandler
@Nullable public P replaceOnlyIfLastUpdatedBefore(@NonNull @NonNull String entityId, @NonNull P role, @NonNull @NonNull Instant lastUpdated)
UserRoleService
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
UserRoleService.replaceRole(String, UserRole)
does, since we expect message handlers to receive
out-of-order messages that may temporarily have invalid references.
replaceOnlyIfLastUpdatedBefore
in interface UserRoleService<P extends UserRole>
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 its UserRole.lastUpdated
set to
this value.null
if the entity
was not found or could not be updated due to its lastUpdated value.AdminRolePersistenceHandler
@NonNull protected com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager getValidator()
Copyright © 2021. All rights reserved.