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>
| Constructor and Description |
|---|
DefaultUserService(AuthorizedClientService<AuthorizedClient> clientService,
UserRepository<D> userRepository,
SimplePayloadMapper mapper,
com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager validator,
UserUpdateProducer userUpdateProducer) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
applyChangesForArchive(P user)
Modifies the given instance for archival.
|
void |
archive(@NonNull String id)
|
protected boolean |
authServerMatches(P firstUser,
P secondUser)
Verifies that two user instances have the same authorization server.
|
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(@NonNull 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 serverId)
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(@NonNull String serviceId,
@NonNull String type)
Finds the unique record whose
User.serviceId and User.type match the given
values. |
Optional<P> |
findByUsernameAndAuthorizationServer(String username,
String serverId)
Find a user by email and authorization server id.
|
protected List<P> |
fromRepositoryDomain(Iterable<D> users) |
protected com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager |
getValidator() |
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 serverId)
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(@NonNull String entityId,
P user,
@NonNull 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) |
protected void |
sendUserUpdateEvent(P updatedUser) |
protected void |
validateCreate(P user) |
protected void |
validateEmailAvailable(P user,
org.springframework.validation.Errors errors) |
protected void |
validateReplace(P originalUser,
P replaceUser) |
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. |
protected void |
validateUsernameAvailable(P user,
org.springframework.validation.Errors errors) |
public DefaultUserService(AuthorizedClientService<AuthorizedClient> clientService, UserRepository<D> userRepository, SimplePayloadMapper mapper, com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager validator, UserUpdateProducer userUpdateProducer)
public Optional<P> findById(String id)
UserServicefindById in interface UserService<P extends User>id - the id of the entity to findOptional containing the entity if found, Optional.empty()
otherwisepublic Optional<P> findByIdAndNotArchived(String id)
UserServiceUser.archived.findByIdAndNotArchived in interface UserService<P extends User>id - the id of the entity to findOptional containing the entity if found, Optional.empty()
otherwisepublic Optional<P> findByClientIdAndUsernameAndNotArchived(String clientId, String username)
UserServiceclientId if not
User.archived.
NOTE: By default this performs a case insensitive search on
username.findByClientIdAndUsernameAndNotArchived in interface UserService<P extends User>clientId - the client id to match againstusername - the username to match againstOptional containing the entity if found, Optional.empty()
otherwisepublic org.springframework.data.domain.Page<P> findAllNotArchived(org.springframework.data.domain.Pageable page)
UserServiceUser.archived.findAllNotArchived in interface UserService<P extends User>page - information about which page of results to return from the databasepublic List<P> findByIdIn(List<String> ids)
UserServiceids.findByIdIn in interface UserService<P extends User>ids - the ids of entities to find. Must not be null nor contain any
null values.Iterable containing the found entities (may be empty)public Optional<P> findByServiceIdAndType(@NonNull @NonNull String serviceId, @NonNull @NonNull String type)
UserServiceUser.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.findByServiceIdAndType in interface UserService<P extends User>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 valuespublic P create(P user)
UserServicecreate in interface UserService<P extends User>user - the user to createprotected void validateCreate(P user)
protected void validateEmailAvailable(P user, org.springframework.validation.Errors errors)
protected void validateUsernameAvailable(P user, org.springframework.validation.Errors errors)
protected void validateServiceIdAndTypeAvailable(P user, org.springframework.validation.Errors errors)
User.serviceId and
User.type do not currently exist in the data store. Intended to be used on standard
create operations, not createServiceUserOnlyIfDoesNotExist(User).user - the user whose service id and type should be validatederrors - the errors object bound to the user on which errors can be registeredpublic P replace(String id, P user)
UserServiceid with user.replace in interface UserService<P extends User>id - the ID of the user to replaceuser - the replacement userprotected void sendUserUpdateEvent(@Nullable
P updatedUser)
protected boolean authServerMatches(P firstUser, P secondUser)
User.getServerId() ()} is a required field and must not be null.firstUser - The first user to comparesecondUser - The second user to compareNullPointerException - If either user's AuthorizationServer is nullpublic List<P> saveAll(List<P> users)
saveAll in interface UserService<P extends User>public void delete(@NonNull
@NonNull String id)
UserService
In all but exceptional cases, UserService.archive(String) should be preferred to this operation.
delete in interface UserService<P extends User>id - the id of the entity to deleteUserService.archive(String)public void archive(@NonNull
@NonNull String id)
UserServiceUser.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.
archive in interface UserService<P extends User>id - the id of the entity to archiveUserService.delete(String)protected void applyChangesForArchive(P user)
user - the instance to modifypublic boolean isUsernameAlreadyInUse(String username, String serverId)
UserService
NOTE: By default this performs a case insensitive search on
username.isUsernameAlreadyInUse in interface UserService<P extends User>username - The username to validateserverId - The AuthorizationServer idpublic boolean isEmailAlreadyInUse(String email, String authServerId)
UserService
NOTE: By default this performs a case insensitive search on
email.isEmailAlreadyInUse in interface UserService<P extends User>email - The username to validateauthServerId - The AuthorizationServer id.public Optional<P> findByEmailAndAuthorizationServer(String email, String serverId)
UserService
NOTE: By default this performs a case insensitive search on
email.findByEmailAndAuthorizationServer in interface UserService<P extends User>email - The user e-mail addressserverId - The AuthorizationServer idOptional.empty()public Optional<P> findByUsernameAndAuthorizationServer(String username, String serverId)
UserService
NOTE: By default this performs a case insensitive search on
username.findByUsernameAndAuthorizationServer in interface UserService<P extends User>username - The user's usernameserverId - The AuthorizationServer idOptional.empty()@Nullable public P createServiceUserOnlyIfDoesNotExist(@NonNull P user)
UserServiceuser 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.
createServiceUserOnlyIfDoesNotExist in interface UserService<P extends User>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
duplicate@Nullable public P replaceOnlyIfLastUpdatedBefore(@NonNull @NonNull String entityId, @NonNull P user, @NonNull @NonNull Instant lastUpdated)
UserServiceThis 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.
replaceOnlyIfLastUpdatedBefore in interface UserService<P extends User>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.@NonNull protected com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager getValidator()
Copyright © 2021. All rights reserved.