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
ConstructorsConstructorDescriptionDefaultUserRoleService(RoleRepository<D> repository, SimplePayloadMapper mapper, com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager validator) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidapplyChangesForArchive(P role) Modifies the given instance for archival.voidSoft-deletes a record by setting itsUserRole.archivedtotrue.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.voidHard-deletes the given record.Finds and returns all entities whoseUserRole.accountRoleflag 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.accountRoleflag is true and are notUserRole.archived.Finds and returns a list of entities that are notUserRole.archivedand 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.archivedwhose 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.archivedand 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.EntityValidatorManagerreplaceOnlyIfLastUpdatedBefore(@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 givenidwithpayload.protected voidvalidateNoChildrenOfRoleBeforeDeletion(@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:UserRoleServiceFinds and returns the entity with the given ID.- Specified by:
findByIdin interfaceUserRoleService<P extends UserRole>- Parameters:
id- the id of the entity to find- Returns:
- an
Optionalcontaining the entity if found,Optional.empty()otherwise
-
findByIdAndNotArchived
Description copied from interface:UserRoleServiceFinds and returns the entity with the given ID if notUserRole.archived.- Specified by:
findByIdAndNotArchivedin interfaceUserRoleService<P extends UserRole>- Parameters:
id- the id of the entity to find- Returns:
- an
Optionalcontaining 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:UserRoleServiceFinds and returns all entities that are notUserRole.archivedwhose name contains the given value.- Specified by:
findAllByNameContainingAndNotArchivedin 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:UserRoleServiceFinds and returns all entities that are notUserRole.archivedwhose name contains the given value. A null or empty value for name will return all results.- Specified by:
findAllByNameContainingAndNotArchivedin 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:UserRoleServiceFinds and returns a stream of entities that are notUserRole.archivedand whose id matches one of the given values.- Specified by:
findAllStreamByIdInAndNotArchivedin 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:UserRoleServiceFinds and returns a list of entities that are notUserRole.archivedand whose id matches one of the given values.- Specified by:
findAllByIdInAndNotArchivedin 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:UserRoleServiceCreates a new role in the data store.- Specified by:
createRolein interfaceUserRoleService<P extends UserRole>- Parameters:
payload- the role to create- Returns:
- the final role after creation
-
replaceRole
Description copied from interface:UserRoleServiceReplaces the role in the data store with the givenidwithpayload.- Specified by:
replaceRolein 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:UserRoleServiceHard-deletes the given record.In all but exceptional cases,
UserRoleService.archive(String)should be preferred to this operation.- Specified by:
deletein 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:UserRoleServiceSoft-deletes a record by setting itsUserRole.archivedtotrue.As part of this operation, the
UserRole.permissionscollections should be cleared such that those relationships are deleted.- Specified by:
archivein 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:UserRoleServiceA 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:
createOnlyIfDoesNotExistin interfaceUserRoleService<P extends UserRole>- Parameters:
role- the role to create. Must have a non-null id present.lastUpdated- theUserRole.lastUpdatedto set on the role- Returns:
- the role if successfully created, or
nullif 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:UserRoleServiceA 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:
replaceOnlyIfLastUpdatedBeforein 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.lastUpdatedset to this value.- Returns:
- the role after replacement if successfully replaced, or
nullif 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:UserRoleServiceFinds and returns all entities whoseUserRole.accountRoleflag is true and are notUserRole.archived.- Specified by:
findAllAccountRolesin 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:
getRepositoryDomainin interfaceUserRoleService<P extends UserRole>
-
findAllAccountRoles
Description copied from interface:UserRoleServiceFinds and returns all entities whoseUserRole.accountRoleflag is true and are notUserRole.archived.- Specified by:
findAllAccountRolesin interfaceUserRoleService<P extends UserRole>- Returns:
- UserRoles where accountRole is true.
-
getRepository
-
getValidator
@NonNull protected com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager getValidator()
-