Class DefaultUserRoleService<P extends UserRole,D extends com.broadleafcommerce.data.tracking.core.mapping.BusinessTypeAware & com.broadleafcommerce.data.tracking.core.mapping.ModelMapperMappable>
- All Implemented Interfaces:
UserRoleService<P>
-
Constructor Summary
ConstructorDescriptionDefaultUserRoleService
(RoleRepository<D> repository, SimplePayloadMapper mapper, com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager validator) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
applyChangesForArchive
(P role) Modifies the given instance for archival.void
Soft-deletes a record by setting itsUserRole.archived
totrue
.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.createRole
(P payload) Creates a new role in the data store.void
Hard-deletes the given record.Finds and returns all entities whoseUserRole.accountRole
flag is true and are notUserRole.archived
.org.springframework.data.domain.Page<P>
findAllAccountRoles
(org.springframework.data.domain.Pageable page) Finds and returns all entities whoseUserRole.accountRole
flag is true and are notUserRole.archived
.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, boolean accountRole, org.springframework.data.domain.Pageable page) Finds and returns all entities that are notUserRole.archived
whose name contains the given value.org.springframework.data.domain.Page<P>
findAllByNameContainingAndNotArchived
(String name, org.springframework.data.domain.Pageable page) Deprecated.Finds and returns a stream of entities that are notUserRole.archived
and whose id matches one of the given values.Finds and returns the entity with the given ID.Finds and returns the entity with the given ID if notUserRole.archived
.protected RoleRepository<D>
protected com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager
replaceOnlyIfLastUpdatedBefore
(@NonNull String entityId, P role, @NonNull Instant lastUpdated) A specialized replace operation that does not invoke the "save" create-or-update behavior.replaceRole
(String id, P payload) Replaces the role in the data store with the givenid
withpayload
.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.
-
Constructor Details
-
DefaultUserRoleService
public DefaultUserRoleService(RoleRepository<D> repository, SimplePayloadMapper mapper, com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager validator)
-
-
Method Details
-
findById
Description copied from interface:UserRoleService
Finds and returns the entity with the given ID.- Specified by:
findById
in interfaceUserRoleService<P extends UserRole>
- Parameters:
id
- the id of the entity to find- Returns:
- an
Optional
containing the entity if found,Optional.empty()
otherwise
-
findByIdAndNotArchived
Description copied from interface:UserRoleService
Finds and returns the entity with the given ID if notUserRole.archived
.- Specified by:
findByIdAndNotArchived
in interfaceUserRoleService<P extends UserRole>
- Parameters:
id
- the id of the entity to find- Returns:
- an
Optional
containing the entity if found,Optional.empty()
otherwise
-
findAllByNameContainingAndNotArchived
@Deprecated public org.springframework.data.domain.Page<P> findAllByNameContainingAndNotArchived(@Nullable String name, org.springframework.data.domain.Pageable page) Deprecated.Description copied from interface:UserRoleService
Finds and returns all entities that are notUserRole.archived
whose name contains the given value.- Specified by:
findAllByNameContainingAndNotArchived
in interfaceUserRoleService<P extends UserRole>
- 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
-
findAllByNameContainingAndNotArchived
public org.springframework.data.domain.Page<P> findAllByNameContainingAndNotArchived(@Nullable String name, boolean accountRole, org.springframework.data.domain.Pageable page) Description copied from interface:UserRoleService
Finds and returns all entities that are notUserRole.archived
whose name contains the given value. A null or empty value for name will return all results.- Specified by:
findAllByNameContainingAndNotArchived
in interfaceUserRoleService<P extends UserRole>
- Parameters:
name
- The name value to match with. A null or empty value will return all results.accountRole
- Indicates if account roles should be returned.page
- 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
Description copied from interface:UserRoleService
Finds and returns a stream of entities that are notUserRole.archived
and whose id matches one of the given values.- Specified by:
findAllStreamByIdInAndNotArchived
in interfaceUserRoleService<P extends UserRole>
- Parameters:
ids
- the ids of the entities to find- Returns:
- a stream of the entities that were found
-
findAllByIdInAndNotArchived
Description copied from interface:UserRoleService
Finds and returns a list of entities that are notUserRole.archived
and whose id matches one of the given values.- Specified by:
findAllByIdInAndNotArchived
in interfaceUserRoleService<P extends UserRole>
- Parameters:
ids
- the ids of the entities to find- Returns:
- a list of the entities that were found
-
createRole
Description copied from interface:UserRoleService
Creates a new role in the data store.- Specified by:
createRole
in interfaceUserRoleService<P extends UserRole>
- Parameters:
payload
- the role to create- Returns:
- the final role after creation
-
replaceRole
Description copied from interface:UserRoleService
Replaces the role in the data store with the givenid
withpayload
.- Specified by:
replaceRole
in interfaceUserRoleService<P extends UserRole>
- Parameters:
id
- the ID of the role to replacepayload
- the replacement role- Returns:
- the final role after replacement
-
delete
Description copied from interface:UserRoleService
Hard-deletes the given record.In all but exceptional cases,
UserRoleService.archive(String)
should be preferred to this operation.- Specified by:
delete
in interfaceUserRoleService<P extends UserRole>
- Parameters:
id
- the id of the entity to delete- See Also:
-
validateNoChildrenOfRoleBeforeDeletion
Given a role that is requested to be deleted or archived, checks that it does not have any child roles in the data store. This protects against descendants being suddenly orphaned.- Parameters:
roleToDeleteId
- the id of the role which should be validated to have no children in the data store- Throws:
InvalidUserRoleDeleteException
- if the role has children in the data store
-
archive
Description copied from interface:UserRoleService
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.- Specified by:
archive
in interfaceUserRoleService<P extends UserRole>
- Parameters:
id
- the id of the entity to archive- See Also:
-
applyChangesForArchive
Modifies the given instance for archival.- Parameters:
role
- the instance to modify
-
createOnlyIfDoesNotExist
Description copied from interface:UserRoleService
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
UserRoleService.createRole(UserRole)
does, since we expect message handlers to receive out-of-order messages that may temporarily have invalid references.- Specified by:
createOnlyIfDoesNotExist
in interfaceUserRoleService<P extends UserRole>
- 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:
-
replaceOnlyIfLastUpdatedBefore
@Nullable public P replaceOnlyIfLastUpdatedBefore(@NonNull @NonNull String entityId, @NonNull P role, @NonNull @NonNull Instant lastUpdated) Description copied from interface:UserRoleService
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
UserRoleService.replaceRole(String, UserRole)
does, since we expect message handlers to receive out-of-order messages that may temporarily have invalid references.- Specified by:
replaceOnlyIfLastUpdatedBefore
in interfaceUserRoleService<P extends UserRole>
- 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:
-
findAllAccountRoles
public org.springframework.data.domain.Page<P> findAllAccountRoles(org.springframework.data.domain.Pageable page) Description copied from interface:UserRoleService
Finds and returns all entities whoseUserRole.accountRole
flag is true and are notUserRole.archived
.- Specified by:
findAllAccountRoles
in interfaceUserRoleService<P extends UserRole>
- Parameters:
page
- information about which page of results to return from the database.- Returns:
- UserRoles where accountRole is true.
-
getRepositoryDomain
- Specified by:
getRepositoryDomain
in interfaceUserRoleService<P extends UserRole>
-
findAllAccountRoles
Description copied from interface:UserRoleService
Finds and returns all entities whoseUserRole.accountRole
flag is true and are notUserRole.archived
.- Specified by:
findAllAccountRoles
in interfaceUserRoleService<P extends UserRole>
- Returns:
- UserRoles where accountRole is true.
-
getRepository
-
getValidator
@NonNull protected com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager getValidator()
-