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>
- Author:
- Nathan Moore (nathanmoore)., Samarth Dhruva (samarthd)., Nick Crum (ncrum)
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultUserService(AuthorizedClientService<AuthorizedClient> clientService, UserRepository<D> userRepository, SimplePayloadMapper mapper, com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager validator, UserUpdateProducer userUpdateProducer) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidapplyChangesForArchive(P user) Modifies the given instance for archival.voidSoft-deletes a record by setting itsUser.archivedtotrueandUser.activetofalse.protected booleanauthServerMatches(P firstUser, P secondUser) Verifies that two user instances have the same authorization server.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 serverId) Find all users by email and authorization server id.findAllByUsernameAndAuthorizationServer(String username, String serverId) 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 serverId) 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(@NonNull String serviceId, @NonNull String type) Finds the unique record whoseUser.serviceIdandUser.typematch the given values.findByUsernameAndAuthorizationServer(String username, String serverId) Find a non-archived user by email and authorization server id.fromRepositoryDomain(Iterable<D> users) protected com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManagerbooleanisEmailAlreadyInUse(String email, String authServerId) Check to determine if an email address for the given authorization server ID already exists.booleanisUsernameAlreadyInUse(String username, String serverId) 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(@NonNull String entityId, P user, @NonNull Instant lastUpdated) A specialized replace operation that does not invoke the "save" create-or-update behavior.protected voidsendUserUpdateEvent(P updatedUser) protected voidvalidateCreate(P user) protected voidvalidateEmailAvailable(P user, org.springframework.validation.Errors errors) protected voidvalidateReplace(P originalUser, P replaceUser) protected voidvalidateServiceIdAndTypeAvailable(P user, org.springframework.validation.Errors errors) Validates that, if both are supplied, the combination ofUser.serviceIdandUser.typedo not currently exist in the data store.protected voidvalidateUsernameAvailable(P user, org.springframework.validation.Errors errors)
-
Constructor Details
-
DefaultUserService
public DefaultUserService(AuthorizedClientService<AuthorizedClient> clientService, UserRepository<D> userRepository, SimplePayloadMapper mapper, com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager validator, UserUpdateProducer userUpdateProducer)
-
-
Method Details
-
findById
Description copied from interface:UserServiceFinds and returns the entity with the given ID.- Specified by:
findByIdin interfaceUserService<P extends User>- Parameters:
id- the id of the entity to find- Returns:
- an
Optionalcontaining the entity if found,Optional.empty()otherwise
-
findByIdAndNotArchived
Description copied from interface:UserServiceFinds and returns the entity with the given ID if notUser.archived.- Specified by:
findByIdAndNotArchivedin interfaceUserService<P extends User>- Parameters:
id- the id of the entity to find- Returns:
- an
Optionalcontaining the entity if found,Optional.empty()otherwise
-
findByClientIdAndUsernameAndNotArchived
Description copied from interface:UserServiceFinds the entity with the given username under the givenclientIdif notUser.archived.NOTE: By default this performs a case insensitive search on
username.- Specified by:
findByClientIdAndUsernameAndNotArchivedin interfaceUserService<P extends User>- Parameters:
clientId- the client id to match againstusername- the username to match against- Returns:
- an
Optionalcontaining the entity if found,Optional.empty()otherwise
-
findAllNotArchived
public org.springframework.data.domain.Page<P> findAllNotArchived(org.springframework.data.domain.Pageable page) Description copied from interface:UserServiceFinds and returns all entities that are notUser.archived.- Specified by:
findAllNotArchivedin interfaceUserService<P extends User>- Parameters:
page- information about which page of results to return from the database- Returns:
- all entities that are not archived
-
findByIdIn
Description copied from interface:UserServiceFinds and returns all entities matching the givenids.- Specified by:
findByIdInin interfaceUserService<P extends User>- 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
public Optional<P> findByServiceIdAndType(@NonNull @NonNull String serviceId, @NonNull @NonNull String type) Description copied from interface:UserServiceFinds 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.- Specified by:
findByServiceIdAndTypein interfaceUserService<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.serviceIdandUser.typematch the given values
-
create
Description copied from interface:UserServiceCreates a new user in the data store.- Specified by:
createin interfaceUserService<P extends User>- Parameters:
user- the user to create- Returns:
- the user after creation
-
validateCreate
-
validateEmailAvailable
-
validateUsernameAvailable
-
validateServiceIdAndTypeAvailable
protected void validateServiceIdAndTypeAvailable(P user, org.springframework.validation.Errors errors) Validates that, if both are supplied, the combination ofUser.serviceIdandUser.typedo not currently exist in the data store. Intended to be used on standard create operations, notcreateServiceUserOnlyIfDoesNotExist(User).- Parameters:
user- the user whose service id and type should be validatederrors- the errors object bound to theuseron which errors can be registered
-
replace
Description copied from interface:UserServiceReplaces the user in the data store with the givenidwithuser.- Specified by:
replacein interfaceUserService<P extends User>- Parameters:
id- the ID of the user to replaceuser- the replacement user- Returns:
- the user after replacement
-
sendUserUpdateEvent
-
validateReplace
-
authServerMatches
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 comparesecondUser- The second user to compare- Returns:
- true if auth servers match, else false
- Throws:
NullPointerException- If either user's AuthorizationServer is null
-
save
- Specified by:
savein interfaceUserService<P extends User>
-
saveAll
- Specified by:
saveAllin interfaceUserService<P extends User>
-
delete
Description copied from interface:UserServiceHard-deletes the given record.In all but exceptional cases,
UserService.archive(String)should be preferred to this operation.- Specified by:
deletein interfaceUserService<P extends User>- Parameters:
id- the id of the entity to delete- See Also:
-
archive
Description copied from interface:UserServiceSoft-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.- Specified by:
archivein interfaceUserService<P extends User>- Parameters:
id- the id of the entity to archive- See Also:
-
applyChangesForArchive
Modifies the given instance for archival.- Parameters:
user- the instance to modify
-
isUsernameAlreadyInUse
Description copied from interface:UserServiceCheck 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:
isUsernameAlreadyInUsein interfaceUserService<P extends User>- Parameters:
username- The username to validateserverId- TheAuthorizationServerid- Returns:
- true if the username is in use, else false
-
isEmailAlreadyInUse
Description copied from interface:UserServiceCheck 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:
isEmailAlreadyInUsein interfaceUserService<P extends User>- Parameters:
email- The username to validateauthServerId- TheAuthorizationServerid.- Returns:
- true if the email is in use, else false
-
findByEmailAndAuthorizationServer
Description copied from interface:UserServiceFind a non-archived user by email and authorization server id.NOTE: By default this performs a case insensitive search on
email.- Specified by:
findByEmailAndAuthorizationServerin interfaceUserService<P extends User>- Parameters:
email- The user e-mail addressserverId- TheAuthorizationServerid- Returns:
- The user found or
Optional.empty()
-
findAllByEmailAndAuthorizationServer
Description copied from interface:UserServiceFind all users by email and authorization server id. This may include archived Users.NOTE: By default this performs a case insensitive search on
email.- Specified by:
findAllByEmailAndAuthorizationServerin interfaceUserService<P extends User>- Parameters:
email- The user e-mail addressserverId- TheAuthorizationServerid- Returns:
- a List containing the entities found. Entities may be archived.
-
findByUsernameAndAuthorizationServer
Description copied from interface:UserServiceFind a non-archived user by email and authorization server id.NOTE: By default this performs a case insensitive search on
username.- Specified by:
findByUsernameAndAuthorizationServerin interfaceUserService<P extends User>- Parameters:
username- The user's usernameserverId- TheAuthorizationServerid- Returns:
- The user found or
Optional.empty()
-
findAllByUsernameAndAuthorizationServer
Description copied from interface:UserServiceFind all users by email and authorization server id. This could include archived Users.NOTE: By default this performs a case insensitive search on
username.- Specified by:
findAllByUsernameAndAuthorizationServerin interfaceUserService<P extends User>- Parameters:
username- The user's usernameserverId- TheAuthorizationServerid- Returns:
- a List containing the entities found. Entities may be archived.
-
createServiceUserOnlyIfDoesNotExist
Description copied from interface:UserServiceA 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
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.archivedvalue, even if it istrue.This method should create the record with the provided
User.lastUpdatedvalue.- Specified by:
createServiceUserOnlyIfDoesNotExistin interfaceUserService<P extends User>- 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
-
replaceOnlyIfLastUpdatedBefore
@Nullable public P replaceOnlyIfLastUpdatedBefore(@NonNull @NonNull String entityId, @NonNull P user, @NonNull @NonNull Instant lastUpdated) Description copied from interface:UserServiceA 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.- Specified by:
replaceOnlyIfLastUpdatedBeforein interfaceUserService<P extends User>- 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.
-
fromRepositoryDomain
-
getValidator
@NonNull protected com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager getValidator()
-