Interface UserService<P extends User>

  • All Known Implementing Classes:
    DefaultUserService

    public interface UserService<P extends User>
    Provides services for interacting with Users and JpaUsers
    Author:
    Nathan Moore (nathanmoore)., Samarth Dhruva (samarthd)
    • Method Detail

      • findById

        Optional<P> findById​(String id)
        Finds and returns the entity with the given ID.
        Parameters:
        id - the id of the entity to find
        Returns:
        an Optional containing the entity if found, Optional.empty() otherwise
      • findByIdAndNotArchived

        Optional<P> findByIdAndNotArchived​(String id)
        Finds and returns the entity with the given ID if not User.archived.
        Parameters:
        id - the id of the entity to find
        Returns:
        an Optional containing the entity if found, Optional.empty() otherwise
      • findByClientIdAndUsernameAndNotArchived

        Optional<P> findByClientIdAndUsernameAndNotArchived​(String clientId,
                                                            String username)
        Finds the entity with the given username under the given clientId if not User.archived.

        NOTE: By default this performs a case insensitive search on username.
        Parameters:
        clientId - the client id to match against
        username - the username to match against
        Returns:
        an Optional containing the entity if found, Optional.empty() otherwise
      • findAllNotArchived

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

        List<P> findByIdIn​(List<String> ids)
        Finds and returns all entities matching the given ids.
        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

        Optional<P> findByServiceIdAndType​(String serviceId,
                                           String type)
        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.
        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

        P create​(P user)
        Creates a new user in the data store.
        Parameters:
        user - the user to create
        Returns:
        the user after creation
        Throws:
        com.broadleafcommerce.common.error.validation.ValidationException - if the given user failed validation for creation
      • replace

        P replace​(String id,
                  P user)
        Replaces the user in the data store with the given id with user.
        Parameters:
        id - the ID of the user to replace
        user - the replacement user
        Returns:
        the user after replacement
        Throws:
        com.broadleafcommerce.common.error.validation.ValidationException - if the user failed validation for replacement
        com.broadleafcommerce.data.tracking.core.exception.EntityMissingException - if the user to replace was not found or was User.archived
      • save

        P save​(P user)
      • delete

        void delete​(String id)
        Hard-deletes the given record.

        In all but exceptional cases, archive(String) should be preferred to this operation.

        Parameters:
        id - the id of the entity to delete
        Throws:
        com.broadleafcommerce.data.tracking.core.exception.EntityMissingException - if the entity to delete was not found
        See Also:
        archive(String)
      • archive

        void archive​(String id)
        Soft-deletes a record by setting its User.archived to true and User.active to false.

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

        Parameters:
        id - the id of the entity to archive
        Throws:
        com.broadleafcommerce.data.tracking.core.exception.EntityMissingException - if the entity to archive was not found
        See Also:
        delete(String)
      • isUsernameAlreadyInUse

        boolean isUsernameAlreadyInUse​(String username,
                                       String authServerId)
        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.
        Parameters:
        username - The username to validate
        authServerId - The AuthorizationServer id
        Returns:
        true if the username is in use, else false
      • isEmailAlreadyInUse

        boolean isEmailAlreadyInUse​(String email,
                                    String authServerId)
        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.
        Parameters:
        email - The username to validate
        authServerId - The AuthorizationServer id.
        Returns:
        true if the email is in use, else false
      • findByEmailAndAuthorizationServer

        Optional<P> findByEmailAndAuthorizationServer​(String email,
                                                      String authServerId)
        Find a user by email and authorization server id.

        NOTE: By default this performs a case insensitive search on email.
        Parameters:
        email - The user e-mail address
        authServerId - The AuthorizationServer id
        Returns:
        The user found or Optional.empty()
      • findByUsernameAndAuthorizationServer

        Optional<P> findByUsernameAndAuthorizationServer​(String username,
                                                         String authServerId)
        Find a user by email and authorization server id.

        NOTE: By default this performs a case insensitive search on username.
        Parameters:
        username - The user's username
        authServerId - The AuthorizationServer id
        Returns:
        The user found or Optional.empty()
      • createServiceUserOnlyIfDoesNotExist

        @Nullable
        P createServiceUserOnlyIfDoesNotExist​(P user)
        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 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.

        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
        Throws:
        IllegalArgumentException - if User.serviceId, User.type, or User.lastUpdated are null
      • replaceOnlyIfLastUpdatedBefore

        @Nullable
        P replaceOnlyIfLastUpdatedBefore​(String entityId,
                                         P user,
                                         Instant lastUpdated)
        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.

        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.