Interface UserService<P extends User>
- All Known Implementing Classes:
DefaultUserService
- Author:
- Nathan Moore (nathanmoore)., Samarth Dhruva (samarthd)
-
Method Summary
Modifier and TypeMethodDescriptionvoidSoft-deletes a record by setting itsUser.archivedtotrueandUser.activetofalse.Creates a new user in the data store.A create operation that will only create the givenuserif one does not already exist matching the givenUser.serviceIdandUser.type.voidHard-deletes the given record.findAllByEmailAndAuthorizationServer(String email, String authServerId) Find all users by email and authorization server id.findAllByUsernameAndAuthorizationServer(String username, String authServerId) Find all users by email and authorization server id.org.springframework.data.domain.Page<P>findAllNotArchived(org.springframework.data.domain.Pageable page) Finds and returns all entities that are notUser.archived.findByClientIdAndUsernameAndNotArchived(String clientId, String username) Finds the entity with the given username under the givenclientIdif notUser.archived.findByEmailAndAuthorizationServer(String email, String authServerId) Find a non-archived user by email and authorization server id.Finds and returns the entity with the given ID.Finds and returns the entity with the given ID if notUser.archived.findByIdIn(List<String> ids) Finds and returns all entities matching the givenids.findByServiceIdAndType(String serviceId, String type) Finds the unique record whoseUser.serviceIdandUser.typematch the given values.findByUsernameAndAuthorizationServer(String username, String authServerId) Find a non-archived user by email and authorization server id.booleanisEmailAlreadyInUse(String email, String authServerId) Check to determine if an email address for the given authorization server ID already exists.booleanisUsernameAlreadyInUse(String username, String authServerId) Check to determine if a username for the given authorization server ID already exists.Replaces the user in the data store with the givenidwithuser.replaceOnlyIfLastUpdatedBefore(String entityId, P user, Instant lastUpdated) A specialized replace operation that does not invoke the "save" create-or-update behavior.
-
Method Details
-
findById
Finds and returns the entity with the given ID.- Parameters:
id- the id of the entity to find- Returns:
- an
Optionalcontaining the entity if found,Optional.empty()otherwise
-
findByIdAndNotArchived
Finds and returns the entity with the given ID if notUser.archived.- Parameters:
id- the id of the entity to find- Returns:
- an
Optionalcontaining the entity if found,Optional.empty()otherwise
-
findByClientIdAndUsernameAndNotArchived
Finds the entity with the given username under the givenclientIdif notUser.archived.NOTE: By default this performs a case insensitive search on
username.- Parameters:
clientId- the client id to match againstusername- the username to match against- Returns:
- an
Optionalcontaining 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 notUser.archived.- Parameters:
page- information about which page of results to return from the database- Returns:
- all entities that are not archived
-
findByIdIn
Finds and returns all entities matching the givenids.- Parameters:
ids- the ids of entities to find. Must not be null nor contain any null values.- Returns:
- a non-null
Iterablecontaining the found entities (may be empty)
-
findByServiceIdAndType
Finds the unique record whoseUser.serviceIdandUser.typematch the given values. Since records are only guaranteed unique if bothUser.serviceIdandUser.typeare 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.serviceIdandUser.typematch the given values
-
create
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 givenuserfailed validation for creation
-
replace
Replaces the user in the data store with the givenidwithuser.- Parameters:
id- the ID of the user to replaceuser- the replacement user- Returns:
- the user after replacement
- Throws:
com.broadleafcommerce.common.error.validation.ValidationException- if theuserfailed validation for replacementcom.broadleafcommerce.data.tracking.core.exception.EntityMissingException- if the user to replace was not found or wasUser.archived
-
save
-
saveAll
-
delete
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
Soft-deletes a record by setting itsUser.archivedtotrueandUser.activetofalse.As part of this operation, the
User.rolesandUser.permissionscollections 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:
-
isUsernameAlreadyInUse
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 validateauthServerId- TheAuthorizationServerid- Returns:
- true if the username is in use, else false
-
isEmailAlreadyInUse
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 validateauthServerId- TheAuthorizationServerid.- Returns:
- true if the email is in use, else false
-
findByEmailAndAuthorizationServer
Find a non-archived user by email and authorization server id.NOTE: By default this performs a case insensitive search on
email.- Parameters:
email- The user e-mail addressauthServerId- TheAuthorizationServerid- Returns:
- The user found or
Optional.empty()
-
findAllByEmailAndAuthorizationServer
Find all users by email and authorization server id. This may include archived Users.NOTE: By default this performs a case insensitive search on
email.- Parameters:
email- The user e-mail addressauthServerId- TheAuthorizationServerid- Returns:
- a List containing the entities found. Entities may be archived.
-
findByUsernameAndAuthorizationServer
Find a non-archived user by email and authorization server id.NOTE: By default this performs a case insensitive search on
username.- Parameters:
username- The user's usernameauthServerId- TheAuthorizationServerid- Returns:
- The user found or
Optional.empty()
-
findAllByUsernameAndAuthorizationServer
Find all users by email and authorization server id. This could include archived Users.NOTE: By default this performs a case insensitive search on
username.- Parameters:
username- The user's usernameauthServerId- TheAuthorizationServerid- Returns:
- a List containing the entities found. Entities may be archived.
-
createServiceUserOnlyIfDoesNotExist
A create operation that will only create the givenuserif one does not already exist matching the givenUser.serviceIdandUser.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.archivedvalue, even if it istrue.This method should create the record with the provided
User.lastUpdatedvalue.- Parameters:
user- the user to create. Must have a non-nullUser.serviceId,User.type, andUser.lastUpdatedpresent.- Returns:
- the user if successfully created, or
nullif the data store rejected it as a duplicate - Throws:
IllegalArgumentException- ifUser.serviceId,User.type, orUser.lastUpdatedare null
-
replaceOnlyIfLastUpdatedBefore
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.archivedvalue, even if it istrue.- Parameters:
entityId- the id of the entity to replaceuser- 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 itsUser.lastUpdatedset to this value.- Returns:
- the user after replacement if successfully replaced, or
nullif the entity was not found or could not be updated due to its lastUpdated value.
-