Class DefaultUserService<P extends User,​D extends com.broadleafcommerce.data.tracking.core.mapping.BusinessTypeAware & com.broadleafcommerce.data.tracking.core.mapping.ModelMapperMappable>

  • All Implemented Interfaces:
    UserService<P>

    public class DefaultUserService<P extends User,​D extends com.broadleafcommerce.data.tracking.core.mapping.BusinessTypeAware & com.broadleafcommerce.data.tracking.core.mapping.ModelMapperMappable>
    extends Object
    implements UserService<P>
    Author:
    Nathan Moore (nathanmoore)., Samarth Dhruva (samarthd)., Nick Crum (ncrum)
    • Method Detail

      • findAllNotArchived

        public org.springframework.data.domain.Page<P> findAllNotArchived​(org.springframework.data.domain.Pageable page)
        Description copied from interface: UserService
        Finds and returns all entities that are not User.archived.
        Specified by:
        findAllNotArchived in interface UserService<P extends User>
        Parameters:
        page - information about which page of results to return from the database
        Returns:
        all entities that are not archived
      • findByIdIn

        public List<P> findByIdIn​(List<String> ids)
        Description copied from interface: UserService
        Finds and returns all entities matching the given ids.
        Specified by:
        findByIdIn in interface UserService<P extends User>
        Parameters:
        ids - the ids of entities to find. Must not be null nor contain any null values.
        Returns:
        a non-null Iterable containing the found entities (may be empty)
      • findByServiceIdAndType

        public Optional<P> findByServiceIdAndType​(@NonNull
                                                  @NonNull String serviceId,
                                                  @NonNull
                                                  @NonNull String type)
        Description copied from interface: UserService
        Finds the unique record whose User.serviceId and User.type match the given values. Since records are only guaranteed unique if both User.serviceId and User.type are present, this method does not accept null values for either argument.
        Specified by:
        findByServiceIdAndType in interface UserService<P extends User>
        Parameters:
        serviceId - the service id to match against. Must not be null.
        type - the type to match against. Must not be null.
        Returns:
        the record whose User.serviceId and User.type match the given values
      • create

        public P create​(P user)
        Description copied from interface: UserService
        Creates a new user in the data store.
        Specified by:
        create in interface UserService<P extends User>
        Parameters:
        user - the user to create
        Returns:
        the user after creation
      • validateCreate

        protected void validateCreate​(P user)
      • validateEmailAvailable

        protected void validateEmailAvailable​(P user,
                                              org.springframework.validation.Errors errors)
      • validateUsernameAvailable

        protected void validateUsernameAvailable​(P user,
                                                 org.springframework.validation.Errors errors)
      • validateServiceIdAndTypeAvailable

        protected void validateServiceIdAndTypeAvailable​(P user,
                                                         org.springframework.validation.Errors errors)
        Validates that, if both are supplied, the combination of User.serviceId and User.type do not currently exist in the data store. Intended to be used on standard create operations, not createServiceUserOnlyIfDoesNotExist(User).
        Parameters:
        user - the user whose service id and type should be validated
        errors - the errors object bound to the user on which errors can be registered
      • replace

        public P replace​(String id,
                         P user)
        Description copied from interface: UserService
        Replaces the user in the data store with the given id with user.
        Specified by:
        replace in interface UserService<P extends User>
        Parameters:
        id - the ID of the user to replace
        user - the replacement user
        Returns:
        the user after replacement
      • sendUserUpdateEvent

        protected void sendUserUpdateEvent​(@Nullable
                                           P updatedUser)
      • validateReplace

        protected void validateReplace​(P originalUser,
                                       P replaceUser)
      • authServerMatches

        protected boolean authServerMatches​(P firstUser,
                                            P secondUser)
        Verifies that two user instances have the same authorization server. User.getServerId() ()} is a required field and must not be null.
        Parameters:
        firstUser - The first user to compare
        secondUser - The second user to compare
        Returns:
        true if auth servers match, else false
        Throws:
        NullPointerException - If either user's AuthorizationServer is null
      • applyChangesForArchive

        protected void applyChangesForArchive​(P user)
        Modifies the given instance for archival.
        Parameters:
        user - the instance to modify
      • isUsernameAlreadyInUse

        public boolean isUsernameAlreadyInUse​(String username,
                                              String serverId)
        Description copied from interface: UserService
        Check to determine if a username for the given authorization server ID already exists.

        NOTE: By default this performs a case insensitive search on username.
        Specified by:
        isUsernameAlreadyInUse in interface UserService<P extends User>
        Parameters:
        username - The username to validate
        serverId - The AuthorizationServer id
        Returns:
        true if the username is in use, else false
      • isEmailAlreadyInUse

        public boolean isEmailAlreadyInUse​(String email,
                                           String authServerId)
        Description copied from interface: UserService
        Check to determine if an email address for the given authorization server ID already exists.

        NOTE: By default this performs a case insensitive search on email.
        Specified by:
        isEmailAlreadyInUse in interface UserService<P extends User>
        Parameters:
        email - The username to validate
        authServerId - The AuthorizationServer id.
        Returns:
        true if the email is in use, else false
      • createServiceUserOnlyIfDoesNotExist

        @Nullable
        public P createServiceUserOnlyIfDoesNotExist​(@NonNull
                                                     P user)
        Description copied from interface: UserService
        A create operation that will only create the given user if one does not already exist matching the given User.serviceId and User.type.

        This is intended to be used in concurrent scenarios such as a message handler where only one operation should succeed.

        Due to its specialized nature, this method does not perform the eager validations done by the standard UserService.create(User) operation. It will rely on data-store mechanisms to protect against duplicates, and trust that the input is otherwise valid.

        This method should create the record with the provided User.archived value, even if it is true.

        This method should create the record with the provided User.lastUpdated value.

        Specified by:
        createServiceUserOnlyIfDoesNotExist in interface UserService<P extends User>
        Parameters:
        user - the user to create. Must have a non-null User.serviceId, User.type, and User.lastUpdated present.
        Returns:
        the user if successfully created, or null if the data store rejected it as a duplicate
      • replaceOnlyIfLastUpdatedBefore

        @Nullable
        public P replaceOnlyIfLastUpdatedBefore​(@NonNull
                                                @NonNull String entityId,
                                                @NonNull
                                                P user,
                                                @NonNull
                                                @NonNull Instant lastUpdated)
        Description copied from interface: UserService
        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.

        Note that this update should succeed even if the existing record is User.archived.

        Note that this method should also set the provided User.archived value, even if it is true.

        Specified by:
        replaceOnlyIfLastUpdatedBefore in interface UserService<P extends User>
        Parameters:
        entityId - the id of the entity to replace
        user - 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 User.lastUpdated set to this value.
        Returns:
        the user after replacement if successfully replaced, or null if the entity was not found or could not be updated due to its lastUpdated value.
      • fromRepositoryDomain

        protected List<P> fromRepositoryDomain​(Iterable<D> users)
      • getValidator

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