Class DefaultUserRoleService<P extends UserRole,D extends com.broadleafcommerce.data.tracking.core.mapping.BusinessTypeAware & com.broadleafcommerce.data.tracking.core.mapping.ModelMapperMappable>

java.lang.Object
com.broadleafcommerce.auth.security.service.DefaultUserRoleService<P,D>
All Implemented Interfaces:
UserRoleService<P>

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 Details

    • DefaultUserRoleService

      public DefaultUserRoleService(RoleRepository<D> repository, SimplePayloadMapper mapper, com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager validator)
  • Method Details

    • findById

      public Optional<P> findById(String id)
      Description copied from interface: UserRoleService
      Finds and returns the entity with the given ID.
      Specified by:
      findById in interface UserRoleService<P extends UserRole>
      Parameters:
      id - the id of the entity to find
      Returns:
      an Optional containing the entity if found, Optional.empty() otherwise
    • findByIdAndNotArchived

      public Optional<P> findByIdAndNotArchived(String id)
      Description copied from interface: UserRoleService
      Finds and returns the entity with the given ID if not UserRole.archived.
      Specified by:
      findByIdAndNotArchived in interface UserRoleService<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 not UserRole.archived whose name contains the given value.
      Specified by:
      findAllByNameContainingAndNotArchived in interface UserRoleService<P extends UserRole>
      Parameters:
      name - the name value to match with
      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
    • 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 not UserRole.archived whose name contains the given value. A null or empty value for name will return all results.
      Specified by:
      findAllByNameContainingAndNotArchived in interface UserRoleService<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

      public Stream<P> findAllStreamByIdInAndNotArchived(Collection<String> ids)
      Description copied from interface: UserRoleService
      Finds and returns a stream of entities that are not UserRole.archived and whose id matches one of the given values.
      Specified by:
      findAllStreamByIdInAndNotArchived in interface UserRoleService<P extends UserRole>
      Parameters:
      ids - the ids of the entities to find
      Returns:
      a stream of the entities that were found
    • findAllByIdInAndNotArchived

      public List<P> findAllByIdInAndNotArchived(Collection<String> ids)
      Description copied from interface: UserRoleService
      Finds and returns a list of entities that are not UserRole.archived and whose id matches one of the given values.
      Specified by:
      findAllByIdInAndNotArchived in interface UserRoleService<P extends UserRole>
      Parameters:
      ids - the ids of the entities to find
      Returns:
      a list of the entities that were found
    • createRole

      public P createRole(P payload)
      Description copied from interface: UserRoleService
      Creates a new role in the data store.
      Specified by:
      createRole in interface UserRoleService<P extends UserRole>
      Parameters:
      payload - the role to create
      Returns:
      the final role after creation
    • replaceRole

      public P replaceRole(String id, P payload)
      Description copied from interface: UserRoleService
      Replaces the role in the data store with the given id with payload.
      Specified by:
      replaceRole in interface UserRoleService<P extends UserRole>
      Parameters:
      id - the ID of the role to replace
      payload - the replacement role
      Returns:
      the final role after replacement
    • delete

      public void delete(@NonNull @NonNull String id)
      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 interface UserRoleService<P extends UserRole>
      Parameters:
      id - the id of the entity to delete
      See Also:
    • validateNoChildrenOfRoleBeforeDeletion

      protected void validateNoChildrenOfRoleBeforeDeletion(@NonNull @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. 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

      public void archive(@NonNull @NonNull String id)
      Description copied from interface: UserRoleService
      Soft-deletes a record by setting its UserRole.archived to true.

      As part of this operation, the UserRole.permissions collections should be cleared such that those relationships are deleted.

      Specified by:
      archive in interface UserRoleService<P extends UserRole>
      Parameters:
      id - the id of the entity to archive
      See Also:
    • applyChangesForArchive

      protected void applyChangesForArchive(P role)
      Modifies the given instance for archival.
      Parameters:
      role - the instance to modify
    • createOnlyIfDoesNotExist

      @Nullable public P createOnlyIfDoesNotExist(@NonNull P role, @NonNull @NonNull Instant lastUpdated)
      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 interface UserRoleService<P extends UserRole>
      Parameters:
      role - the role to create. Must have a non-null id present.
      lastUpdated - the UserRole.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 interface UserRoleService<P extends UserRole>
      Parameters:
      entityId - the id of the entity to replace
      role - the replacement entity
      lastUpdated - 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.
      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 whose UserRole.accountRole flag is true and are not UserRole.archived.
      Specified by:
      findAllAccountRoles in interface UserRoleService<P extends UserRole>
      Parameters:
      page - information about which page of results to return from the database.
      Returns:
      UserRoles where accountRole is true.
    • getRepositoryDomain

      public String getRepositoryDomain()
      Specified by:
      getRepositoryDomain in interface UserRoleService<P extends UserRole>
    • findAllAccountRoles

      public List<P> findAllAccountRoles()
      Description copied from interface: UserRoleService
      Finds and returns all entities whose UserRole.accountRole flag is true and are not UserRole.archived.
      Specified by:
      findAllAccountRoles in interface UserRoleService<P extends UserRole>
      Returns:
      UserRoles where accountRole is true.
    • getRepository

      protected RoleRepository<D> getRepository()
    • getValidator

      @NonNull protected com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager getValidator()