Class DefaultUserPermissionService<P extends UserPermission,D extends com.broadleafcommerce.data.tracking.core.mapping.BusinessTypeAware & com.broadleafcommerce.data.tracking.core.mapping.ModelMapperMappable>
java.lang.Object
com.broadleafcommerce.auth.security.service.DefaultUserPermissionService<P,D>
- All Implemented Interfaces:
UserPermissionService<P>
public class DefaultUserPermissionService<P extends UserPermission,D extends com.broadleafcommerce.data.tracking.core.mapping.BusinessTypeAware & com.broadleafcommerce.data.tracking.core.mapping.ModelMapperMappable>
extends Object
implements UserPermissionService<P>
-
Constructor Summary
ConstructorDescriptionDefaultUserPermissionService
(UserPermissionRepository<D> repository, SimplePayloadMapper mapper, com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager validator) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
applyChangesForArchive
(P permission) Modifies the given instance for archival.void
Soft-deletes a record by setting itsUserPermission.archived
totrue
.createOnlyIfDoesNotExist
(P permission, @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.createPermission
(P payload) Creates a new permission in the data store.void
Hard-deletes the given record.org.springframework.data.domain.Page<P>
findAllByNameContainingAndNotArchived
(String name, boolean accountPermission, boolean includeNonUserAssignablePermissions, org.springframework.data.domain.Pageable page) Finds and returns all entities that are notUserPermission.archived
whose name contains the given value.org.springframework.data.domain.Page<P>
findAllByNameContainingAndNotArchived
(String name, org.springframework.data.domain.Pageable page) Finds and returns all entities that are notUserPermission.archived
whose name contains the given value.Finds and returns the entity with the given ID.Finds and returns the entity with the given ID if notUserPermission.archived
.protected com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager
replaceOnlyIfLastUpdatedBefore
(@NonNull String entityId, P permission, @NonNull Instant lastUpdated) A specialized replace operation that does not invoke the "save" create-or-update behavior.replacePermission
(String id, P payload) Replaces the permission in the data store with the givenid
withpayload
.
-
Constructor Details
-
DefaultUserPermissionService
public DefaultUserPermissionService(UserPermissionRepository<D> repository, SimplePayloadMapper mapper, com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager validator)
-
-
Method Details
-
findById
Description copied from interface:UserPermissionService
Finds and returns the entity with the given ID.- Specified by:
findById
in interfaceUserPermissionService<P extends UserPermission>
- 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:UserPermissionService
Finds and returns the entity with the given ID if notUserPermission.archived
.- Specified by:
findByIdAndNotArchived
in interfaceUserPermissionService<P extends UserPermission>
- Parameters:
id
- the id of the entity to find- Returns:
- an
Optional
containing the entity if found,Optional.empty()
otherwise
-
findAllByNameContainingAndNotArchived
public org.springframework.data.domain.Page<P> findAllByNameContainingAndNotArchived(@Nullable String name, org.springframework.data.domain.Pageable page) Description copied from interface:UserPermissionService
Finds and returns all entities that are notUserPermission.archived
whose name contains the given value.- Specified by:
findAllByNameContainingAndNotArchived
in interfaceUserPermissionService<P extends UserPermission>
- 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(String name, boolean accountPermission, boolean includeNonUserAssignablePermissions, org.springframework.data.domain.Pageable page) Description copied from interface:UserPermissionService
Finds and returns all entities that are notUserPermission.archived
whose name contains the given value.- Specified by:
findAllByNameContainingAndNotArchived
in interfaceUserPermissionService<P extends UserPermission>
- Parameters:
name
- the name value to match withaccountPermission
- Should we read account permissions?includeNonUserAssignablePermissions
- Should non user-assignable permissions be included?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
-
createPermission
Description copied from interface:UserPermissionService
Creates a new permission in the data store.- Specified by:
createPermission
in interfaceUserPermissionService<P extends UserPermission>
- Parameters:
payload
- the permission to create- Returns:
- the final permission after creation
-
replacePermission
Description copied from interface:UserPermissionService
Replaces the permission in the data store with the givenid
withpayload
.- Specified by:
replacePermission
in interfaceUserPermissionService<P extends UserPermission>
- Parameters:
id
- the ID of the permission to replacepayload
- the replacement permission- Returns:
- the final permission after replacement
-
delete
Description copied from interface:UserPermissionService
Hard-deletes the given record.In all but exceptional cases,
UserPermissionService.archive(String)
should be preferred to this operation.- Specified by:
delete
in interfaceUserPermissionService<P extends UserPermission>
- Parameters:
id
- the id of the entity to delete- See Also:
-
archive
Description copied from interface:UserPermissionService
Soft-deletes a record by setting itsUserPermission.archived
totrue
.- Specified by:
archive
in interfaceUserPermissionService<P extends UserPermission>
- Parameters:
id
- the id of the entity to archive- See Also:
-
applyChangesForArchive
Modifies the given instance for archival.- Parameters:
permission
- the instance to modify
-
createOnlyIfDoesNotExist
@Nullable public P createOnlyIfDoesNotExist(@NonNull P permission, @NonNull @NonNull Instant lastUpdated) Description copied from interface:UserPermissionService
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 concurrent scenarios where only one operation should succeed.
- Specified by:
createOnlyIfDoesNotExist
in interfaceUserPermissionService<P extends UserPermission>
- Parameters:
permission
- the permission to create. Must have a non-null id present.lastUpdated
- theUserPermission.lastUpdated
to set on the permission- Returns:
- the permission if successfully created, or
null
if creation failed due to the entity already existing.
-
replaceOnlyIfLastUpdatedBefore
@Nullable public P replaceOnlyIfLastUpdatedBefore(@NonNull @NonNull String entityId, @NonNull P permission, @NonNull @NonNull Instant lastUpdated) Description copied from interface:UserPermissionService
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 concurrent scenarios where only one operation should succeed.
- Specified by:
replaceOnlyIfLastUpdatedBefore
in interfaceUserPermissionService<P extends UserPermission>
- Parameters:
entityId
- the id of the entity to replacepermission
- 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 itsUserPermission.lastUpdated
set to this value.- Returns:
- the permission after replacement if successfully replaced, or
null
if the entity was not found or could not be updated due to its lastUpdated value.
-
findByIdsAndNotArchived
- Specified by:
findByIdsAndNotArchived
in interfaceUserPermissionService<P extends UserPermission>
-
getValidator
@NonNull protected com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager getValidator()
-