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>

    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 Detail

      • DefaultUserRoleService

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

      • findAllByNameContainingAndNotArchived

        public org.springframework.data.domain.Page<P> findAllByNameContainingAndNotArchived​(@Nullable
                                                                                             String name,
                                                                                             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.
        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
      • 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
      • 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
      • 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:
        AdminRolePersistenceHandler
      • 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:
        AdminRolePersistenceHandler
      • getValidator

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