public interface UserService<P extends User>
Modifier and Type | Method and Description |
---|---|
void |
archive(String id)
|
P |
create(P user)
Creates a new user in the data store.
|
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 . |
void |
delete(String id)
Hard-deletes the given record.
|
org.springframework.data.domain.Page<P> |
findAllNotArchived(org.springframework.data.domain.Pageable page)
Finds and returns all entities that are not
User.archived . |
Optional<P> |
findByClientIdAndUsernameAndNotArchived(String clientId,
String username)
Finds the entity with the given username under the given
clientId if not
User.archived . |
Optional<P> |
findByEmailAndAuthorizationServer(String email,
String authServerId)
Find a user by email and authorization server id.
|
Optional<P> |
findById(String id)
Finds and returns the entity with the given ID.
|
Optional<P> |
findByIdAndNotArchived(String id)
Finds and returns the entity with the given ID if not
User.archived . |
List<P> |
findByIdIn(List<String> ids)
Finds and returns all entities matching the given
ids . |
Optional<P> |
findByServiceIdAndType(String serviceId,
String type)
Finds the unique record whose
User.serviceId and User.type match the given
values. |
Optional<P> |
findByUsernameAndAuthorizationServer(String username,
String authServerId)
Find a user by email and authorization server id.
|
boolean |
isEmailAlreadyInUse(String email,
String authServerId)
Check to determine if an email address for the given authorization server ID already exists.
|
boolean |
isUsernameAlreadyInUse(String username,
String authServerId)
Check to determine if a username for the given authorization server ID already exists.
|
P |
replace(String id,
P user)
Replaces the user in the data store with the given
id with user . |
P |
replaceOnlyIfLastUpdatedBefore(String entityId,
P user,
Instant lastUpdated)
A specialized replace operation that does not invoke the "save" create-or-update behavior.
|
P |
save(P user) |
List<P> |
saveAll(List<P> users) |
Optional<P> findById(String id)
id
- the id of the entity to findOptional
containing the entity if found, Optional.empty()
otherwiseOptional<P> findByIdAndNotArchived(String id)
User.archived
.id
- the id of the entity to findOptional
containing the entity if found, Optional.empty()
otherwiseOptional<P> findByClientIdAndUsernameAndNotArchived(String clientId, String username)
clientId
if not
User.archived
.
NOTE: By default this performs a case insensitive search on
username
.
clientId
- the client id to match againstusername
- the username to match againstOptional
containing the entity if found, Optional.empty()
otherwiseorg.springframework.data.domain.Page<P> findAllNotArchived(org.springframework.data.domain.Pageable page)
User.archived
.page
- information about which page of results to return from the databaseList<P> findByIdIn(List<String> ids)
ids
.ids
- the ids of entities to find. Must not be null nor contain any
null values.Iterable
containing the found entities (may be empty)Optional<P> findByServiceIdAndType(String serviceId, String type)
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.serviceId
- the service id to match against. Must not be null.type
- the type to match against. Must not be null.User.serviceId
and User.type
match the given valuesP create(P user)
user
- the user to createcom.broadleafcommerce.common.error.validation.ValidationException
- if the given user
failed validation for creationP replace(String id, P user)
id
with user
.id
- the ID of the user to replaceuser
- the replacement usercom.broadleafcommerce.common.error.validation.ValidationException
- if the user
failed validation for replacementcom.broadleafcommerce.data.tracking.core.exception.EntityMissingException
- if the user to replace was not found or was
User.archived
void delete(String id)
In all but exceptional cases, archive(String)
should be preferred to this operation.
id
- the id of the entity to deletecom.broadleafcommerce.data.tracking.core.exception.EntityMissingException
- if the entity to delete was not foundarchive(String)
void archive(String id)
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.
id
- the id of the entity to archivecom.broadleafcommerce.data.tracking.core.exception.EntityMissingException
- if the entity to archive was not founddelete(String)
boolean isUsernameAlreadyInUse(String username, String authServerId)
NOTE: By default this performs a case insensitive search on
username
.
username
- The username to validateauthServerId
- The AuthorizationServer
idboolean isEmailAlreadyInUse(String email, String authServerId)
NOTE: By default this performs a case insensitive search on
email
.
email
- The username to validateauthServerId
- The AuthorizationServer
id.Optional<P> findByEmailAndAuthorizationServer(String email, String authServerId)
NOTE: By default this performs a case insensitive search on
email
.
email
- The user e-mail addressauthServerId
- The AuthorizationServer
idOptional.empty()
Optional<P> findByUsernameAndAuthorizationServer(String username, String authServerId)
NOTE: By default this performs a case insensitive search on
username
.
username
- The user's usernameauthServerId
- The AuthorizationServer
idOptional.empty()
@Nullable P createServiceUserOnlyIfDoesNotExist(P user)
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.
user
- the user to create. Must have a non-null User.serviceId
,
User.type
, and User.lastUpdated
present.null
if the data store rejected it as a
duplicateIllegalArgumentException
- if User.serviceId
, User.type
, or
User.lastUpdated
are null@Nullable P replaceOnlyIfLastUpdatedBefore(String entityId, P user, Instant lastUpdated)
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
.
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 its User.lastUpdated
set to this
value.null
if the entity
was not found or could not be updated due to its lastUpdated value.Copyright © 2021. All rights reserved.