From fce11ce7eb290ca1602321b99debd3e869087086 Mon Sep 17 00:00:00 2001 From: Daniel Fiala Date: Sun, 25 Aug 2024 21:05:47 +0200 Subject: [PATCH] feat(user): started adding new user interfaces --- .../core/feature/impl/CreateUserImpl.java | 5 +- .../BasicUserAccountManagerProcessor.java | 4 +- .../zenei/user/EmailAddressManager.java | 4 -- .../user/EmailAddressReactiveProvider.java | 18 ++++++ .../zenei/user/PhoneNumberManager.java | 1 + .../dev/cloudeko/zenei/user/UserAccount.java | 50 ++++++--------- .../zenei/user/UserAccountManager.java | 63 ------------------- .../zenei/user/UserAccountProvider.java | 17 +++++ .../zenei/user/UserAccountQueryProvider.java | 13 ++++ .../user/UserAccountReactiveProvider.java | 63 +++++++++++++++++++ .../dev/cloudeko/zenei/user/UserManager.java | 44 +++++++++++++ ...> DefaultUserAccountReactiveProvider.java} | 10 ++- 12 files changed, 184 insertions(+), 108 deletions(-) delete mode 100644 extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/EmailAddressManager.java create mode 100644 extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/EmailAddressReactiveProvider.java delete mode 100644 extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/UserAccountManager.java create mode 100644 extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/UserAccountProvider.java create mode 100644 extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/UserAccountQueryProvider.java create mode 100644 extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/UserAccountReactiveProvider.java create mode 100644 extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/UserManager.java rename extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/runtime/{DefaultUserAccountManager.java => DefaultUserAccountReactiveProvider.java} (91%) diff --git a/extensions/core/runtime/src/main/java/dev/cloudeko/zenei/extension/core/feature/impl/CreateUserImpl.java b/extensions/core/runtime/src/main/java/dev/cloudeko/zenei/extension/core/feature/impl/CreateUserImpl.java index e323448..8cc5833 100644 --- a/extensions/core/runtime/src/main/java/dev/cloudeko/zenei/extension/core/feature/impl/CreateUserImpl.java +++ b/extensions/core/runtime/src/main/java/dev/cloudeko/zenei/extension/core/feature/impl/CreateUserImpl.java @@ -12,9 +12,8 @@ import dev.cloudeko.zenei.extension.core.model.user.UserPassword; import dev.cloudeko.zenei.extension.core.repository.UserPasswordRepository; import dev.cloudeko.zenei.extension.core.repository.UserRepository; -import dev.cloudeko.zenei.user.BasicUserAccount; import dev.cloudeko.zenei.user.runtime.DefaultUserAccount; -import dev.cloudeko.zenei.user.runtime.DefaultUserAccountManager; +import dev.cloudeko.zenei.user.runtime.DefaultUserAccountReactiveProvider; import jakarta.enterprise.context.ApplicationScoped; import jakarta.transaction.Transactional; import lombok.AllArgsConstructor; @@ -36,7 +35,7 @@ public class CreateUserImpl implements CreateUser { private final UserRepository userRepository; private final UserPasswordRepository userPasswordRepository; - private final DefaultUserAccountManager userAccountManager; + private final DefaultUserAccountReactiveProvider userAccountManager; @Override @Transactional diff --git a/extensions/zenei-user-account/deployment/src/main/java/dev/cloudeko/zenei/user/deployment/BasicUserAccountManagerProcessor.java b/extensions/zenei-user-account/deployment/src/main/java/dev/cloudeko/zenei/user/deployment/BasicUserAccountManagerProcessor.java index 94aac8e..10b006e 100644 --- a/extensions/zenei-user-account/deployment/src/main/java/dev/cloudeko/zenei/user/deployment/BasicUserAccountManagerProcessor.java +++ b/extensions/zenei-user-account/deployment/src/main/java/dev/cloudeko/zenei/user/deployment/BasicUserAccountManagerProcessor.java @@ -1,7 +1,7 @@ package dev.cloudeko.zenei.user.deployment; import dev.cloudeko.zenei.user.runtime.DefaultUserAccountInitializer; -import dev.cloudeko.zenei.user.runtime.DefaultUserAccountManager; +import dev.cloudeko.zenei.user.runtime.DefaultUserAccountReactiveProvider; import dev.cloudeko.zenei.user.runtime.DefaultUserAccountRecorder; import dev.cloudeko.zenei.user.runtime.DefaultUserAccountRepository; import io.quarkus.arc.deployment.AdditionalBeanBuildItem; @@ -80,7 +80,7 @@ AdditionalBeanBuildItem setupBeans() { @BuildStep AdditionalBeanBuildItem setupManager() { - return new AdditionalBeanBuildItem(DefaultUserAccountManager.class); + return new AdditionalBeanBuildItem(DefaultUserAccountReactiveProvider.class); } private static final class ReactiveClientBuildItem extends SimpleBuildItem { diff --git a/extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/EmailAddressManager.java b/extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/EmailAddressManager.java deleted file mode 100644 index 74cb89a..0000000 --- a/extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/EmailAddressManager.java +++ /dev/null @@ -1,4 +0,0 @@ -package dev.cloudeko.zenei.user; - -public interface EmailAddressManager { -} diff --git a/extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/EmailAddressReactiveProvider.java b/extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/EmailAddressReactiveProvider.java new file mode 100644 index 0000000..dc313f8 --- /dev/null +++ b/extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/EmailAddressReactiveProvider.java @@ -0,0 +1,18 @@ +package dev.cloudeko.zenei.user; + +import io.smallrye.mutiny.Uni; + +import java.util.List; + +public interface EmailAddressReactiveProvider, ID> { + + Uni> listEmailAddresses(ID id); + + Uni getEmailAddress(ID id, String emailAddress); + + Uni addEmailAddress(ID id, EmailAddress emailAddress); + + Uni updateEmailAddress(ID id, EmailAddress emailAddress); + + Uni removeEmailAddress(ID id, String emailAddress); +} diff --git a/extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/PhoneNumberManager.java b/extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/PhoneNumberManager.java index e1da245..674eeef 100644 --- a/extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/PhoneNumberManager.java +++ b/extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/PhoneNumberManager.java @@ -1,4 +1,5 @@ package dev.cloudeko.zenei.user; public interface PhoneNumberManager { + } diff --git a/extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/UserAccount.java b/extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/UserAccount.java index d42004c..6201d6e 100644 --- a/extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/UserAccount.java +++ b/extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/UserAccount.java @@ -1,47 +1,37 @@ package dev.cloudeko.zenei.user; import java.time.LocalDateTime; +import java.util.List; -public abstract class UserAccount { +public abstract interface UserAccount { - private ID id; - private LocalDateTime createdAt; - private LocalDateTime updatedAt; + ID getId(); - public UserAccount() { - } + String getUsername(); - public UserAccount(ID id) { - this(id, null, null); - } + void setUsername(String username); - public UserAccount(ID id, LocalDateTime createdAt, LocalDateTime updatedAt) { - this.id = id; - this.createdAt = createdAt; - this.updatedAt = updatedAt; + default EmailAddress getPrimaryEmailAddress() { + return getEmailAddresses().stream().filter(EmailAddress::isPrimaryEmail).findFirst().orElse(null); } - public ID getId() { - return id; - } + List getEmailAddresses(); - public void setId(ID id) { - this.id = id; - } + void setEmailAddresses(List emailAddresses); - public LocalDateTime getCreatedAt() { - return createdAt; + default PhoneNumber getPrimaryPhoneNumber() { + return getPhoneNumbers().stream().filter(PhoneNumber::isPrimaryPhoneNumber).findFirst().orElse(null); } - public void setCreatedAt(LocalDateTime createdAt) { - this.createdAt = createdAt; - } + List getPhoneNumbers(); - public LocalDateTime getUpdatedAt() { - return updatedAt; - } + void setPhoneNumbers(List phoneNumbers); - public void setUpdatedAt(LocalDateTime updatedAt) { - this.updatedAt = updatedAt; - } + LocalDateTime getCreatedAt(); + + void setCreatedAt(LocalDateTime createdAt); + + LocalDateTime getUpdatedAt(); + + void setUpdatedAt(LocalDateTime updatedAt); } diff --git a/extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/UserAccountManager.java b/extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/UserAccountManager.java deleted file mode 100644 index f644d64..0000000 --- a/extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/UserAccountManager.java +++ /dev/null @@ -1,63 +0,0 @@ -package dev.cloudeko.zenei.user; - -import io.smallrye.mutiny.Uni; - -import java.util.List; -import java.util.Optional; - -public interface UserAccountManager { - - Uni findUserByIdentifier(ID id); - - default Optional findUserByIdentifierBlocking(ID id) { - return Optional.ofNullable(findUserByIdentifier(id).await().indefinitely()); - } - - Uni findUserByPrimaryEmailAddress(String email); - - default Optional findUserByPrimaryEmailAddressBlocking(String email) { - return Optional.ofNullable(findUserByPrimaryEmailAddress(email).await().indefinitely()); - } - - Uni findUserByPrimaryPhoneNumber(String phoneNumber); - - default Optional findUserByPrimaryPhoneNumberBlocking(String phoneNumber) { - return Optional.ofNullable(findUserByPrimaryPhoneNumber(phoneNumber).await().indefinitely()); - } - - Uni findUserByUsername(String username); - - default Optional findUserByUsernameBlocking(String username) { - return Optional.ofNullable(findUserByUsername(username).await().indefinitely()); - } - - Uni> listUsers(); - - default List listUsersBlocking() { - return listUsers().await().indefinitely(); - } - - Uni> listUsers(int page, int pageSize); - - default List listUsersBlocking(int page, int pageSize) { - return listUsers(page, pageSize).await().indefinitely(); - } - - Uni createUser(ENTITY entity); - - default ENTITY createUserBlocking(ENTITY entity) { - return createUser(entity).await().indefinitely(); - } - - Uni updateUser(ENTITY entity); - - default ENTITY updateUserBlocking(ENTITY entity) { - return updateUser(entity).await().indefinitely(); - } - - Uni deleteUser(ID identifier); - - default boolean deleteUserBlocking(ID identifier) { - return deleteUser(identifier).await().indefinitely(); - } -} diff --git a/extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/UserAccountProvider.java b/extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/UserAccountProvider.java new file mode 100644 index 0000000..5a83a8e --- /dev/null +++ b/extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/UserAccountProvider.java @@ -0,0 +1,17 @@ +package dev.cloudeko.zenei.user; + +import io.smallrye.mutiny.Uni; + +import java.util.List; +import java.util.Optional; + +public interface UserAccountProvider { + + Optional> findUserByIdentifierBlocking(ID id); + + UserAccount createUserBlocking(UserAccount entity); + + UserAccount updateUserBlocking(UserAccount entity); + + boolean deleteUserBlocking(ID id); +} diff --git a/extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/UserAccountQueryProvider.java b/extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/UserAccountQueryProvider.java new file mode 100644 index 0000000..29787b8 --- /dev/null +++ b/extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/UserAccountQueryProvider.java @@ -0,0 +1,13 @@ +package dev.cloudeko.zenei.user; + +import java.util.List; +import java.util.Optional; + +public interface UserAccountQueryProvider { + + Optional> findUserByUsernameBlocking(String username); + + List> listUsersBlocking(); + + List> listUsersBlocking(int page, int pageSize); +} \ No newline at end of file diff --git a/extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/UserAccountReactiveProvider.java b/extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/UserAccountReactiveProvider.java new file mode 100644 index 0000000..74aa852 --- /dev/null +++ b/extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/UserAccountReactiveProvider.java @@ -0,0 +1,63 @@ +package dev.cloudeko.zenei.user; + +import io.smallrye.mutiny.Uni; + +import java.util.List; +import java.util.Optional; + +public interface UserAccountReactiveProvider { + + Uni> findUserByIdentifier(ID id); + + default Optional> findUserByIdentifierBlocking(ID id) { + return Optional.ofNullable(findUserByIdentifier(id).await().indefinitely()); + } + + Uni> findUserByPrimaryEmailAddress(String email); + + default Optional> findUserByPrimaryEmailAddressBlocking(String email) { + return Optional.ofNullable(findUserByPrimaryEmailAddress(email).await().indefinitely()); + } + + Uni> findUserByPrimaryPhoneNumber(String phoneNumber); + + default Optional> findUserByPrimaryPhoneNumberBlocking(String phoneNumber) { + return Optional.ofNullable(findUserByPrimaryPhoneNumber(phoneNumber).await().indefinitely()); + } + + Uni> findUserByUsername(String username); + + default Optional> findUserByUsernameBlocking(String username) { + return Optional.ofNullable(findUserByUsername(username).await().indefinitely()); + } + + Uni>> listUsers(); + + default List> listUsersBlocking() { + return listUsers().await().indefinitely(); + } + + Uni>> listUsers(int page, int pageSize); + + default List> listUsersBlocking(int page, int pageSize) { + return listUsers(page, pageSize).await().indefinitely(); + } + + Uni> createUser(UserAccount entity); + + default UserAccount createUserBlocking(UserAccount entity) { + return createUser(entity).await().indefinitely(); + } + + Uni> updateUser(UserAccount entity); + + default UserAccount updateUserBlocking(UserAccount entity) { + return updateUser(entity).await().indefinitely(); + } + + Uni deleteUser(ID id); + + default boolean deleteUserBlocking(ID id) { + return deleteUser(id).await().indefinitely(); + } +} diff --git a/extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/UserManager.java b/extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/UserManager.java new file mode 100644 index 0000000..920d772 --- /dev/null +++ b/extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/UserManager.java @@ -0,0 +1,44 @@ +package dev.cloudeko.zenei.user; + +import io.smallrye.mutiny.Uni; + +import java.util.List; +import java.util.Optional; + +public interface UserManager extends UserAccountProvider, UserAccountReactiveProvider { + + @Override + default Optional> findUserByIdentifierBlocking(ID id) { + return Optional.ofNullable(findUserByIdentifier(id).await().indefinitely()); + } + + @Override + default Optional> findUserByUsernameBlocking(String username) { + return Optional.ofNullable(findUserByUsername(username).await().indefinitely()); + } + + @Override + default List> listUsersBlocking() { + return listUsers().await().indefinitely(); + } + + @Override + default List> listUsersBlocking(int page, int pageSize) { + return listUsers(page, pageSize).await().indefinitely(); + } + + @Override + default UserAccount createUserBlocking(UserAccount entity) { + return createUser(entity).await().indefinitely(); + } + + @Override + default UserAccount updateUserBlocking(UserAccount entity) { + return updateUser(entity).await().indefinitely(); + } + + @Override + default boolean deleteUserBlocking(ID id) { + return deleteUser(id).await().indefinitely(); + } +} diff --git a/extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/runtime/DefaultUserAccountManager.java b/extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/runtime/DefaultUserAccountReactiveProvider.java similarity index 91% rename from extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/runtime/DefaultUserAccountManager.java rename to extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/runtime/DefaultUserAccountReactiveProvider.java index 1a2d545..54a3349 100644 --- a/extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/runtime/DefaultUserAccountManager.java +++ b/extensions/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/runtime/DefaultUserAccountReactiveProvider.java @@ -1,22 +1,20 @@ package dev.cloudeko.zenei.user.runtime; -import dev.cloudeko.zenei.user.EmailAddress; -import dev.cloudeko.zenei.user.UserAccountManager; +import dev.cloudeko.zenei.user.UserAccountReactiveProvider; import io.smallrye.mutiny.Multi; import io.smallrye.mutiny.Uni; import org.jboss.logging.Logger; -import java.util.ArrayList; import java.util.List; -public class DefaultUserAccountManager implements UserAccountManager { +public class DefaultUserAccountReactiveProvider implements UserAccountReactiveProvider { - private static final Logger log = Logger.getLogger(DefaultUserAccountManager.class); + private static final Logger log = Logger.getLogger(DefaultUserAccountReactiveProvider.class); private final DefaultUserAccountRepository userAccountRepository; private final DefaultUserAccountEmailAddressRepository emailAddressRepository; - public DefaultUserAccountManager(DefaultUserAccountRepository userAccountRepository, + public DefaultUserAccountReactiveProvider(DefaultUserAccountRepository userAccountRepository, DefaultUserAccountEmailAddressRepository emailAddressRepository) { this.userAccountRepository = userAccountRepository; this.emailAddressRepository = emailAddressRepository;