diff --git a/.gitignore b/.gitignore index 82eca336e352c9026decda294ff678968050edfc..2a0148e22111eff3ddd5f76ad5d7ba04082cd6be 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /target/ !.mvn/wrapper/maven-wrapper.jar +*.log ### STS ### .apt_generated diff --git a/pom.xml b/pom.xml index 2f5577d9f6a245c126f622e5b6c86c22db4954b6..b28a877db7c8154b2ec819d803a4681d91f8c823 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ UTF-8 UTF-8 - 1.10 + 10 2.3.2 @@ -101,7 +101,7 @@ libs-snapshot-local.biz.nynja.protos - blueprint-java-intracoldev + account-service-intracoldev 1.0-SNAPSHOT @@ -114,13 +114,18 @@ com.fasterxml.jackson.core jackson-databind - 2.9.5 + 2.9.5 com.fasterxml.jackson.core jackson-core - 2.9.5 + 2.9.5 + + + + org.codehaus.groovy + groovy-all diff --git a/src/main/java/biz/nynja/account/grpc/StartupScriptsListener.java b/src/main/java/biz/nynja/account/grpc/StartupScriptsListener.java new file mode 100644 index 0000000000000000000000000000000000000000..aa644211a11622519d9923e4f344404f7327ef34 --- /dev/null +++ b/src/main/java/biz/nynja/account/grpc/StartupScriptsListener.java @@ -0,0 +1,54 @@ +package biz.nynja.account.grpc; + +import java.util.Arrays; +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.event.ContextRefreshedEvent; +import org.springframework.context.event.EventListener; +import org.springframework.stereotype.Component; + +import com.datastax.driver.core.Session; + +import biz.nynja.account.grpc.configuration.CassandraConfig; + +/** + * This acts as {@link CassandraConfig} startupScripts executor + * but activated after the spring has setup the needed tables though JPA + * @author dragomir.todorov + * + */ +@Component +public class StartupScriptsListener { + + private String keyspace; + + @Autowired + private Session session; + + @EventListener(ContextRefreshedEvent.class) + public void contextRefreshedEvent() { + keyspace = session.getLoggedKeyspace(); + + for (String script : getStartupScripts()) { + session.execute(script); + } + } + + private List getStartupScripts() { + String scriptAccountViewByProfileId = "CREATE MATERIALIZED VIEW IF NOT EXISTS " + keyspace + + ".accountbyprofileid AS SELECT * FROM account " + "WHERE profileid IS NOT NULL " + + "PRIMARY KEY (profileid, accountid);"; + + String scriptAccountViewByAuthProvider = "CREATE MATERIALIZED VIEW IF NOT EXISTS " + keyspace + + ".accountbyauthenticationprovider AS SELECT * FROM account " + + "WHERE authenticationprovider IS NOT NULL " + "PRIMARY KEY (authenticationprovider, accountid);"; + + String scriptAccountViewByАccountName = "CREATE MATERIALIZED VIEW IF NOT EXISTS " + keyspace + + ".accountbyaccountname AS SELECT * FROM account " + "WHERE accountname IS NOT NULL " + + "PRIMARY KEY (accountname, accountid);"; + + return Arrays.asList(scriptAccountViewByProfileId, scriptAccountViewByAuthProvider, + scriptAccountViewByАccountName); + } +} \ No newline at end of file diff --git a/src/main/java/biz/nynja/account/grpc/components/Validator.java b/src/main/java/biz/nynja/account/grpc/components/Validator.java new file mode 100644 index 0000000000000000000000000000000000000000..edcda5f38d578702b9e852ed0d257e5ec18350f2 --- /dev/null +++ b/src/main/java/biz/nynja/account/grpc/components/Validator.java @@ -0,0 +1,212 @@ +/** + * Copyright (C) 2018 Nynja Inc. All rights reserved. + */ +package biz.nynja.account.grpc.components; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.HashMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.annotation.PostConstruct; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; +import org.springframework.stereotype.Component; + +import biz.nynja.account.grpc.CreateAccountRequest; +import biz.nynja.account.grpc.ErrorResponse.Cause; +import biz.nynja.account.grpc.models.CountryInfo; +import biz.nynja.account.grpc.repositories.UserInfoByEmailRepository; +import biz.nynja.account.grpc.repositories.UserInfoByPhoneRepository; +import biz.nynja.account.grpc.repositories.UserInfoByUsernameRepository; + +/** + * Component which contains all validation methods. + */ + +@Component +public class Validator { + + private static final Logger logger = LoggerFactory.getLogger(Validator.class); + + private HashMap countryInfoMap; + + @Autowired + private UserInfoByEmailRepository userInfoByEmailRepository; + + @Autowired + private UserInfoByPhoneRepository userInfoByPhoneRepository; + + @Autowired + private UserInfoByUsernameRepository userInfoByUsernameRepository; + + @PostConstruct + public void loadPhonesBook() { + + CountryInfo countryInfo = null; + BufferedReader reader = null; + countryInfoMap = new HashMap<>(); + + logger.debug("Loading phones information from file."); + try { + Resource resource = new ClassPathResource("countries.txt"); + InputStream resourceInputStream = resource.getInputStream(); + logger.debug("Phones information loaded."); + reader = new BufferedReader(new InputStreamReader(resourceInputStream)); + String line; + while ((line = reader.readLine()) != null) { + String[] args = line.split(";"); + countryInfo = new CountryInfo(); + countryInfo.setCountryCode(args[1]); + countryInfo.setCountryPhoneCode(args[0]); + countryInfo.setCountryName(args[2]); + if (args.length > 3) { + countryInfo.setPhoneFormat(args[3]); + } + countryInfoMap.put(args[1], countryInfo); + } + } catch (IOException e) { + logger.error("Error during load phones information: {}", e.getMessage()); + } finally { + try { + reader.close(); + } catch (IOException e) { + logger.error("Close reader error: {}", e.getMessage()); + } + } + + } + + public boolean isPhoneNumberValid(String phoneNumber, String countryCode) { + + logger.debug("Checking phoneNumber: {} for country: {}", phoneNumber, countryCode); + CountryInfo countryInfo = countryInfoMap.get(countryCode); + if (countryInfo == null) { + logger.debug("Country: {} not found!", countryCode); + } + + char[] digits = countryInfo.getCountryPhoneCode().toCharArray(); + StringBuilder builder = new StringBuilder(); + for (char digit : digits) { + builder.append("[" + digit + "]"); + } + String codePattern = builder.toString(); + + String phoneLength = null; + if (countryInfo.getPhoneFormat() != null) { + phoneLength = "{" + countryInfo.getPhoneFormat().replaceAll("\\s", "").length() + "}"; + } else { + phoneLength = "+"; + } + + final String PHONE_PATTERN = "((?:\\+?([0][0])?" + codePattern + ")?||([0][0]" + codePattern + ")?)(\\d" + + phoneLength + ")$"; + logger.debug("Generated phone pattern for country: {}, {}", countryCode, PHONE_PATTERN); + + Pattern pattern = Pattern.compile(PHONE_PATTERN); + Matcher matcher = pattern.matcher(phoneNumber); + + boolean isValid = matcher.matches(); + logger.debug("PhoneNumber: {} for country: {} is valid: {}", phoneNumber, countryCode, isValid); + + return isValid; + } + + public boolean isUsernameValid(String username) { + + logger.debug("Checking username: {}", username); + + final String USERNAME_PATTERN = "^[A-Za-z0-9_]{2,32}$"; + + Pattern pattern = Pattern.compile(USERNAME_PATTERN); + Matcher matcher = pattern.matcher(username); + + boolean isValid = matcher.matches(); + logger.debug("Username: {} is valid: {}", username, isValid); + + return isValid; + } + + public boolean isEmailValid(String email) { + + logger.debug("Checking email: {}", email); + + final String EMAIL_PATTERN = "^(?!\\.)[\\w!#$%&’*+/=?`{|}~^.-]{0,63}[\\w!#$%&’*+/=?`{|}~^-]{1}@(?!\\.)[a-zA-Z0-9-.]{0,229}[a-zA-Z0-9]{1}.[a-zA-Z0-9]{2,25}$"; + + Pattern pattern = Pattern.compile(EMAIL_PATTERN); + Matcher matcher = pattern.matcher(email); + + boolean isValid = matcher.matches(); + logger.debug("Email: {} is valid: {}", email, isValid); + + return isValid; + } + + public boolean isFirstNameValid(String firstName) { + logger.debug("Checking First Name: {}", firstName); + + int len = firstName.length(); + boolean isValid = 2 <= len && len <= 32; + + logger.debug("First Name: {} is valid: {}", firstName, isValid); + return isValid; + } + + public boolean isLastNameValid(String lastName) { + logger.debug("Checking Last Name: {}", lastName); + + int len = lastName.length(); + boolean isValid = 0 <= len && len <= 32; + + logger.debug("Last Name: {} is valid: {}", lastName, isValid); + return isValid; + } + + public Cause validateCreateAccountRequest(CreateAccountRequest request) { + + if (request.getUsername() != null && !request.getUsername().trim().isEmpty() + && !isUsernameValid(request.getUsername())) { + return Cause.USERNAME_INVALID; + } else if (request.getUsername() != null && !request.getUsername().trim().isEmpty() + && !userInfoByUsernameRepository.findByUsername(request.getUsername()).isEmpty()) { + return Cause.USERNAME_ALREADY_USED; + } + + if (request.getEmailAddress() != null && !request.getEmailAddress().trim().isEmpty() + && !isEmailValid(request.getEmailAddress())) { + return Cause.EMAIL_INVALID; + } else if (request.getEmailAddress() != null && !request.getEmailAddress().trim().isEmpty() + && !userInfoByEmailRepository.findByEmailAddress(request.getEmailAddress()).isEmpty()) { + return Cause.EMAIL_ALREADY_USED; + } + + if (request.getPhoneNumber() != null && !request.getPhoneNumber().trim().isEmpty() + && !isPhoneNumberValid(request.getPhoneNumber(), request.getCountryCode())) { + return Cause.PHONE_NUMBER_INVALID; + } else if (request.getPhoneNumber() != null && !request.getPhoneNumber().trim().isEmpty() + && !userInfoByPhoneRepository.findByPhoneNumber(request.getPhoneNumber()).isEmpty()) { + return Cause.PHONE_NUMBER_ALREADY_USED; + } + + if (request.getFirstName() != null && request.getFirstName().trim().isEmpty()) { + return Cause.MISSING_FIRST_NAME; + } else if (!isFirstNameValid(request.getFirstName())) { + return Cause.INVALID_FIRST_NAME; + } + + if (request.getLastName() != null && !request.getLastName().trim().isEmpty() + && !isLastNameValid(request.getLastName())) { + return Cause.INVALID_LAST_NAME; + } + + return null; + } + +} diff --git a/src/main/java/biz/nynja/account/grpc/configuration/CassandraConfig.java b/src/main/java/biz/nynja/account/grpc/configuration/CassandraConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..0aad4ca65db9edfde8038d258ec8a31f8e2449b8 --- /dev/null +++ b/src/main/java/biz/nynja/account/grpc/configuration/CassandraConfig.java @@ -0,0 +1,57 @@ +/** + * Copyright (C) 2018 Nynja Inc. All rights reserved. + */ +package biz.nynja.account.grpc.configuration; + +import java.util.Arrays; +import java.util.List; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.cassandra.config.AbstractCassandraConfiguration; +import org.springframework.data.cassandra.config.SchemaAction; +import org.springframework.data.cassandra.core.cql.keyspace.CreateKeyspaceSpecification; +import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories; + +import biz.nynja.account.grpc.StartupScriptsListener; + +@Configuration +@EnableCassandraRepositories +@ConditionalOnMissingClass("org.springframework.test.context.junit4.SpringRunner") +public class CassandraConfig extends AbstractCassandraConfiguration { + + @Value("${spring.data.cassandra.keyspace-name}") + private String keyspace; + + @Override + protected String getKeyspaceName() { + return keyspace; + } + + @Override + public SchemaAction getSchemaAction() { + return SchemaAction.CREATE_IF_NOT_EXISTS; + } + + @Override + protected List getKeyspaceCreations() { + CreateKeyspaceSpecification specification = CreateKeyspaceSpecification.createKeyspace(getKeyspaceName()) + .ifNotExists().withSimpleReplication(); + return Arrays.asList(specification); + } + + @Override + public String[] getEntityBasePackages() { + return new String[] { "biz.nynja.account.grpc.models" }; + } + + /** + * See {@link StartupScriptsListener} for scripts + * that require JPA annotated tables + */ + @Override + protected List getStartupScripts() { + return super.getStartupScripts(); + } +} \ No newline at end of file diff --git a/src/main/java/biz/nynja/account/grpc/healthindicators/GrpcServerHealthIndicator.java b/src/main/java/biz/nynja/account/grpc/healthindicators/GrpcServerHealthIndicator.java index cf6cd2da85216c971a23846ed7d01bf3a0170c82..a20f92095717ceba9f0ef45fb12b3a20b5a8b6a5 100644 --- a/src/main/java/biz/nynja/account/grpc/healthindicators/GrpcServerHealthIndicator.java +++ b/src/main/java/biz/nynja/account/grpc/healthindicators/GrpcServerHealthIndicator.java @@ -14,7 +14,7 @@ import org.springframework.boot.actuate.health.HealthIndicator; import org.springframework.stereotype.Component; import biz.nynja.account.grpc.services.AccountServiceImpl; -import biz.nynja.blueprint.grpc.AccountServiceGrpc; +import biz.nynja.account.grpc.AccountServiceGrpc; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import io.grpc.health.v1.HealthCheckRequest; diff --git a/src/main/java/biz/nynja/account/grpc/models/Account.java b/src/main/java/biz/nynja/account/grpc/models/Account.java new file mode 100644 index 0000000000000000000000000000000000000000..415fc55e4edf03a6c707fcec9d0f315f9bfe498c --- /dev/null +++ b/src/main/java/biz/nynja/account/grpc/models/Account.java @@ -0,0 +1,305 @@ +/** + * Copyright (C) 2018 Nynja Inc. All rights reserved. + */ +package biz.nynja.account.grpc.models; + +import java.nio.ByteBuffer; +import java.util.Set; +import java.util.UUID; + +import org.springframework.data.cassandra.core.mapping.PrimaryKey; +import org.springframework.data.cassandra.core.mapping.Table; + +import biz.nynja.account.grpc.AccountDetails; +import biz.nynja.account.grpc.AccountDetails.Builder; +import biz.nynja.account.grpc.CreatePendingAccountRequest; + +@Table +public class Account { + + @PrimaryKey + private UUID accountId; + private UUID profileId; + private String accountMark; + private String authenticationProvider; + private String authenticationProviderType; + private String firstName; + private String lastName; + private ByteBuffer avatar; + private String accountName; + private String username; + private String qrCode; + private String accountStatus; + private Long creationTimestamp; + private Long lastUpdateTimestamp; + private Set communicationProviders; + + public UUID getAccountId() { + return accountId; + } + + public void setAccountId(UUID accountId) { + this.accountId = accountId; + } + + public UUID getProfileId() { + return profileId; + } + + public void setProfileId(UUID profileId) { + this.profileId = profileId; + } + + public String getAccountMark() { + return accountMark; + } + + public void setAccountMark(String accountMark) { + this.accountMark = accountMark; + } + + public String getAuthenticationProvider() { + return authenticationProvider; + } + + public void setAuthenticationProvider(String authenticationProvider) { + this.authenticationProvider = authenticationProvider; + } + + public String getAuthenticationProviderType() { + return authenticationProviderType; + } + + public void setAuthenticationProviderType(String authenticationProviderType) { + this.authenticationProviderType = authenticationProviderType; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public ByteBuffer getAvatar() { + return avatar; + } + + public void setAvatar(ByteBuffer avatar) { + this.avatar = avatar; + } + + public String getAccountName() { + return accountName; + } + + public void setAccountName(String accountName) { + this.accountName = accountName; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getQrCode() { + return qrCode; + } + + public void setQrCode(String qrCode) { + this.qrCode = qrCode; + } + + public String getAccountStatus() { + return accountStatus; + } + + public void setAccountStatus(String accountStatus) { + this.accountStatus = accountStatus; + } + + public Long getCreationTimestamp() { + return creationTimestamp; + } + + public void setCreationTimestamp(Long creationTimestamp) { + this.creationTimestamp = creationTimestamp; + } + + public Long getLastUpdateTimestamp() { + return lastUpdateTimestamp; + } + + public void setLastUpdateTimestamp(Long lastUpdateTimestamp) { + this.lastUpdateTimestamp = lastUpdateTimestamp; + } + + public Set getCommunicationProviders() { + return communicationProviders; + } + + public void setCommunicationProviders(Set communicationProviders) { + this.communicationProviders = communicationProviders; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((accountId == null) ? 0 : accountId.hashCode()); + result = prime * result + ((accountMark == null) ? 0 : accountMark.hashCode()); + result = prime * result + ((accountName == null) ? 0 : accountName.hashCode()); + result = prime * result + ((accountStatus == null) ? 0 : accountStatus.hashCode()); + result = prime * result + ((authenticationProvider == null) ? 0 : authenticationProvider.hashCode()); + result = prime * result + ((authenticationProviderType == null) ? 0 : authenticationProviderType.hashCode()); + result = prime * result + ((avatar == null) ? 0 : avatar.hashCode()); + result = prime * result + ((communicationProviders == null) ? 0 : communicationProviders.hashCode()); + result = prime * result + ((creationTimestamp == null) ? 0 : creationTimestamp.hashCode()); + result = prime * result + ((firstName == null) ? 0 : firstName.hashCode()); + result = prime * result + ((lastName == null) ? 0 : lastName.hashCode()); + result = prime * result + ((lastUpdateTimestamp == null) ? 0 : lastUpdateTimestamp.hashCode()); + result = prime * result + ((profileId == null) ? 0 : profileId.hashCode()); + result = prime * result + ((qrCode == null) ? 0 : qrCode.hashCode()); + result = prime * result + ((username == null) ? 0 : username.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Account other = (Account) obj; + if (accountId == null) { + if (other.accountId != null) + return false; + } else if (!accountId.equals(other.accountId)) + return false; + if (accountMark == null) { + if (other.accountMark != null) + return false; + } else if (!accountMark.equals(other.accountMark)) + return false; + if (accountName == null) { + if (other.accountName != null) + return false; + } else if (!accountName.equals(other.accountName)) + return false; + if (accountStatus == null) { + if (other.accountStatus != null) + return false; + } else if (!accountStatus.equals(other.accountStatus)) + return false; + if (authenticationProvider == null) { + if (other.authenticationProvider != null) + return false; + } else if (!authenticationProvider.equals(other.authenticationProvider)) + return false; + if (authenticationProviderType == null) { + if (other.authenticationProviderType != null) + return false; + } else if (!authenticationProviderType.equals(other.authenticationProviderType)) + return false; + if (avatar == null) { + if (other.avatar != null) + return false; + } else if (!avatar.equals(other.avatar)) + return false; + if (communicationProviders == null) { + if (other.communicationProviders != null) + return false; + } else if (!communicationProviders.equals(other.communicationProviders)) + return false; + if (creationTimestamp == null) { + if (other.creationTimestamp != null) + return false; + } else if (!creationTimestamp.equals(other.creationTimestamp)) + return false; + if (firstName == null) { + if (other.firstName != null) + return false; + } else if (!firstName.equals(other.firstName)) + return false; + if (lastName == null) { + if (other.lastName != null) + return false; + } else if (!lastName.equals(other.lastName)) + return false; + if (lastUpdateTimestamp == null) { + if (other.lastUpdateTimestamp != null) + return false; + } else if (!lastUpdateTimestamp.equals(other.lastUpdateTimestamp)) + return false; + if (profileId == null) { + if (other.profileId != null) + return false; + } else if (!profileId.equals(other.profileId)) + return false; + if (qrCode == null) { + if (other.qrCode != null) + return false; + } else if (!qrCode.equals(other.qrCode)) + return false; + if (username == null) { + if (other.username != null) + return false; + } else if (!username.equals(other.username)) + return false; + return true; + } + + @Override + public String toString() { + return new StringBuilder("Account [accountId=").append(accountId).append(", profileId=").append(profileId) + .append(", accountMark=").append(accountMark).append(", authenticationProvider=") + .append(authenticationProvider).append(", authenticationProviderType=") + .append(authenticationProviderType).append(", firstName=").append(firstName).append(", lastName=") + .append(lastName).append(", avatar=").append(avatar).append(", accountName=").append(accountName) + .append(", username=").append(username).append(", qrCode=").append(qrCode).append(", accountStatus=") + .append(accountStatus).append(", creationTimestamp=").append(creationTimestamp) + .append(", lastUpdateTimestamp=").append(lastUpdateTimestamp).append(", communicationProviders=") + .append(communicationProviders).append("]").toString(); + } + + public static Account createPendingAccountFromProto(CreatePendingAccountRequest request) { + Account account = new Account(); + account.setAuthenticationProviderType(request.getAuthenticationType().toString()); + account.setAuthenticationProvider(request.getAuthenticationProvider()); + return account; + } + + public AccountDetails toProto() { + + Builder builder = AccountDetails.newBuilder().setAccountId(getAccountId().toString()) + .setProfileId(getProfileId().toString()).setAccountMark(getAccountMark()) + .setAccountName(getAccountName()).setFirstName(getFirstName()).setLastName(getLastName()) + .setUsername(getUsername()).setAccountStatus(getAccountStatus()).setQrCode(getQrCode()); + + if (avatar != null) { + builder.setAvatar(com.google.protobuf.ByteString.copyFrom(avatar)); + } + if (communicationProviders != null) { + for (AuthenticationProvider ap : communicationProviders) { + builder.addCommunicationProviders(ap.toProto()); + } + } + + return builder.build(); + + } +} diff --git a/src/main/java/biz/nynja/account/grpc/models/AccountByCommunicationProvider.java b/src/main/java/biz/nynja/account/grpc/models/AccountByCommunicationProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..5c4768057ffea96ad21a2778aec4ff527c609c6e --- /dev/null +++ b/src/main/java/biz/nynja/account/grpc/models/AccountByCommunicationProvider.java @@ -0,0 +1,140 @@ +/** + * Copyright (C) 2018 Nynja Inc. All rights reserved. + */ +package biz.nynja.account.grpc.models; + +import java.nio.ByteBuffer; +import java.util.UUID; + +import org.springframework.data.cassandra.core.cql.PrimaryKeyType; +import org.springframework.data.cassandra.core.mapping.Column; +import org.springframework.data.cassandra.core.mapping.PrimaryKeyColumn; +import org.springframework.data.cassandra.core.mapping.Table; + +@Table("account_by_communication_provider") +public class AccountByCommunicationProvider { + + @PrimaryKeyColumn(name = "communication_provider", ordinal = 0, type = PrimaryKeyType.PARTITIONED) + private String communicationProvider; + @PrimaryKeyColumn(name = "communication_provider_type", ordinal = 1, type = PrimaryKeyType.PARTITIONED) + private String communicationProviderType; + @PrimaryKeyColumn(name = "account_id", ordinal = 2, type = PrimaryKeyType.CLUSTERED) + private UUID accountId; + @Column("account_name") + private String accountName; + @Column("first_name") + private String firstName; + private ByteBuffer avatar; + + public String getCommunicationProvider() { + return communicationProvider; + } + + public void setCommunicationProvider(String communicationProvider) { + this.communicationProvider = communicationProvider; + } + + public String getCommunicationProviderType() { + return communicationProviderType; + } + + public void setCommunicationProviderType(String communicationProviderType) { + this.communicationProviderType = communicationProviderType; + } + + public UUID getAccountId() { + return accountId; + } + + public void setAccountId(UUID accountId) { + this.accountId = accountId; + } + + public String getAccountName() { + return accountName; + } + + public void setAccountName(String accountName) { + this.accountName = accountName; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public ByteBuffer getAvatar() { + return avatar; + } + + public void setAvatar(ByteBuffer avatar) { + this.avatar = avatar; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((accountId == null) ? 0 : accountId.hashCode()); + result = prime * result + ((accountName == null) ? 0 : accountName.hashCode()); + result = prime * result + ((avatar == null) ? 0 : avatar.hashCode()); + result = prime * result + ((communicationProvider == null) ? 0 : communicationProvider.hashCode()); + result = prime * result + ((communicationProviderType == null) ? 0 : communicationProviderType.hashCode()); + result = prime * result + ((firstName == null) ? 0 : firstName.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + AccountByCommunicationProvider other = (AccountByCommunicationProvider) obj; + if (accountId == null) { + if (other.accountId != null) + return false; + } else if (!accountId.equals(other.accountId)) + return false; + if (accountName == null) { + if (other.accountName != null) + return false; + } else if (!accountName.equals(other.accountName)) + return false; + if (avatar == null) { + if (other.avatar != null) + return false; + } else if (!avatar.equals(other.avatar)) + return false; + if (communicationProvider == null) { + if (other.communicationProvider != null) + return false; + } else if (!communicationProvider.equals(other.communicationProvider)) + return false; + if (communicationProviderType == null) { + if (other.communicationProviderType != null) + return false; + } else if (!communicationProviderType.equals(other.communicationProviderType)) + return false; + if (firstName == null) { + if (other.firstName != null) + return false; + } else if (!firstName.equals(other.firstName)) + return false; + return true; + } + + @Override + public String toString() { + return new StringBuilder("AccountsByCommunicationProvider [communicationProvider=") + .append(communicationProvider).append(", communicationProviderType=").append(communicationProviderType) + .append(", accountId=").append(accountId).append(", accountName=").append(accountName) + .append(", firstName=").append(firstName).append(", avatar=").append(avatar).append("]").toString(); + } + +} diff --git a/src/main/java/biz/nynja/account/grpc/models/AccountByProfileId.java b/src/main/java/biz/nynja/account/grpc/models/AccountByProfileId.java new file mode 100644 index 0000000000000000000000000000000000000000..dc8abfd2f674e055693cbe294a78a22fcf093991 --- /dev/null +++ b/src/main/java/biz/nynja/account/grpc/models/AccountByProfileId.java @@ -0,0 +1,295 @@ +/** + * Copyright (C) 2018 Nynja Inc. All rights reserved. + */ +package biz.nynja.account.grpc.models; + +import java.nio.ByteBuffer; +import java.util.Set; +import java.util.UUID; + +import biz.nynja.account.grpc.AccountDetails.Builder; + +public class AccountByProfileId { + + private UUID profileId; + private UUID accountId; + private String accountMark; + private String authenticationProvider; + private String authenticationProviderType; + private String firstName; + private String lastName; + private ByteBuffer avatar; + private String accountName; + private String username; + private String accountStatus; + private Long creationTimestamp; + private Long lastUpdateTimestamp; + private Set communicationProviders; + private String qrCode; + + public UUID getAccountId() { + return accountId; + } + + public void setAccountId(UUID accountId) { + this.accountId = accountId; + } + + public UUID getProfileId() { + return profileId; + } + + public void setProfileId(UUID profileId) { + this.profileId = profileId; + } + + public String getAccountMark() { + return accountMark; + } + + public void setAccountMark(String accountMark) { + this.accountMark = accountMark; + } + + public String getAuthenticationProvider() { + return authenticationProvider; + } + + public void setAuthenticationProvider(String authenticationProvider) { + this.authenticationProvider = authenticationProvider; + } + + public String getAuthenticationProviderType() { + return authenticationProviderType; + } + + public void setAuthenticationProviderType(String authenticationProviderType) { + this.authenticationProviderType = authenticationProviderType; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public ByteBuffer getAvatar() { + return avatar; + } + + public void setAvatar(ByteBuffer avatar) { + this.avatar = avatar; + } + + public String getAccountName() { + return accountName; + } + + public void setAccountName(String accountName) { + this.accountName = accountName; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getAccountStatus() { + return accountStatus; + } + + public void setAccountStatus(String accountStatus) { + this.accountStatus = accountStatus; + } + + public Long getCreationTimestamp() { + return creationTimestamp; + } + + public void setCreationTimestamp(Long creationTimestamp) { + this.creationTimestamp = creationTimestamp; + } + + public Long getLastUpdateTimestamp() { + return lastUpdateTimestamp; + } + + public void setLastUpdateTimestamp(Long lastUpdateTimestamp) { + this.lastUpdateTimestamp = lastUpdateTimestamp; + } + + public Set getCommunicationProviders() { + return communicationProviders; + } + + public void setCommunicationProviders(Set communicationProviders) { + this.communicationProviders = communicationProviders; + } + + public String getQrCode() { + return qrCode; + } + + public void setQrCode(String qrCode) { + this.qrCode = qrCode; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((accountId == null) ? 0 : accountId.hashCode()); + result = prime * result + ((accountMark == null) ? 0 : accountMark.hashCode()); + result = prime * result + ((accountName == null) ? 0 : accountName.hashCode()); + result = prime * result + ((accountStatus == null) ? 0 : accountStatus.hashCode()); + result = prime * result + ((authenticationProvider == null) ? 0 : authenticationProvider.hashCode()); + result = prime * result + ((authenticationProviderType == null) ? 0 : authenticationProviderType.hashCode()); + result = prime * result + ((avatar == null) ? 0 : avatar.hashCode()); + result = prime * result + ((communicationProviders == null) ? 0 : communicationProviders.hashCode()); + result = prime * result + ((creationTimestamp == null) ? 0 : creationTimestamp.hashCode()); + result = prime * result + ((firstName == null) ? 0 : firstName.hashCode()); + result = prime * result + ((lastName == null) ? 0 : lastName.hashCode()); + result = prime * result + ((lastUpdateTimestamp == null) ? 0 : lastUpdateTimestamp.hashCode()); + result = prime * result + ((profileId == null) ? 0 : profileId.hashCode()); + result = prime * result + ((qrCode == null) ? 0 : qrCode.hashCode()); + result = prime * result + ((username == null) ? 0 : username.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + AccountByProfileId other = (AccountByProfileId) obj; + if (accountId == null) { + if (other.accountId != null) + return false; + } else if (!accountId.equals(other.accountId)) + return false; + if (accountMark == null) { + if (other.accountMark != null) + return false; + } else if (!accountMark.equals(other.accountMark)) + return false; + if (accountName == null) { + if (other.accountName != null) + return false; + } else if (!accountName.equals(other.accountName)) + return false; + if (accountStatus == null) { + if (other.accountStatus != null) + return false; + } else if (!accountStatus.equals(other.accountStatus)) + return false; + if (authenticationProvider == null) { + if (other.authenticationProvider != null) + return false; + } else if (!authenticationProvider.equals(other.authenticationProvider)) + return false; + if (authenticationProviderType == null) { + if (other.authenticationProviderType != null) + return false; + } else if (!authenticationProviderType.equals(other.authenticationProviderType)) + return false; + if (avatar == null) { + if (other.avatar != null) + return false; + } else if (!avatar.equals(other.avatar)) + return false; + if (communicationProviders == null) { + if (other.communicationProviders != null) + return false; + } else if (!communicationProviders.equals(other.communicationProviders)) + return false; + if (creationTimestamp == null) { + if (other.creationTimestamp != null) + return false; + } else if (!creationTimestamp.equals(other.creationTimestamp)) + return false; + if (firstName == null) { + if (other.firstName != null) + return false; + } else if (!firstName.equals(other.firstName)) + return false; + if (lastName == null) { + if (other.lastName != null) + return false; + } else if (!lastName.equals(other.lastName)) + return false; + if (lastUpdateTimestamp == null) { + if (other.lastUpdateTimestamp != null) + return false; + } else if (!lastUpdateTimestamp.equals(other.lastUpdateTimestamp)) + return false; + if (profileId == null) { + if (other.profileId != null) + return false; + } else if (!profileId.equals(other.profileId)) + return false; + if (qrCode == null) { + if (other.qrCode != null) + return false; + } else if (!qrCode.equals(other.qrCode)) + return false; + if (username == null) { + if (other.username != null) + return false; + } else if (!username.equals(other.username)) + return false; + return true; + } + + @Override + public String toString() { + return new StringBuilder("Account [accountId=").append(accountId).append(", profileId=").append(profileId) + .append(", accountMark=").append(accountMark).append(", authenticationProvider=") + .append(authenticationProvider).append(", authenticationProviderType=") + .append(authenticationProviderType).append(", firstName=").append(firstName).append(", lastName=") + .append(lastName).append(", avatar=").append(avatar).append(", accountName=").append(accountName) + .append(", username=").append(username).append(", accountStatus=").append(accountStatus) + .append(", creationTimestamp=").append(creationTimestamp).append(", lastUpdateTimestamp=") + .append(lastUpdateTimestamp).append(", communicationProviders=").append(communicationProviders) + .append("]").toString(); + } + + public biz.nynja.account.grpc.AccountDetails toProto() { + + Builder builder = biz.nynja.account.grpc.AccountDetails.newBuilder().setAccountId(getAccountId().toString()) + .setProfileId(getProfileId().toString()).setAccountMark(getAccountMark()) + .setAccountName(getAccountName()).setFirstName(getFirstName()).setLastName(getLastName()) + .setUsername(getUsername()).setAccountStatus(getAccountStatus()); + + if (getQrCode() != null) { + builder.setQrCode(getQrCode()); + } + if (avatar != null) { + builder.setAvatar(com.google.protobuf.ByteString.copyFrom(avatar)); + } + if (communicationProviders != null) { + for (AuthenticationProvider ap : communicationProviders) { + builder.addCommunicationProviders(ap.toProto()); + } + } + + return builder.build(); + + } + +} diff --git a/src/main/java/biz/nynja/account/grpc/models/AccountInfo.java b/src/main/java/biz/nynja/account/grpc/models/AccountInfo.java deleted file mode 100644 index b87e2696f80b86ce01c8974eb8156a958a0b7c56..0000000000000000000000000000000000000000 --- a/src/main/java/biz/nynja/account/grpc/models/AccountInfo.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Copyright (C) 2018 Nynja Inc. All rights reserved. - */ -package biz.nynja.account.grpc.models; - -import org.springframework.data.cassandra.core.mapping.PrimaryKey; -import org.springframework.data.cassandra.core.mapping.Table; - -import biz.nynja.blueprint.grpc.RegisterRequest; - -/** - * Account bean as represented in the corresponding Cassandra table. - */ -@Table -public class AccountInfo { - - @PrimaryKey - private Long id; - private String email; - private String password; - - public AccountInfo() { - } - - public AccountInfo(long id, String email, String password) { - this.id = id; - this.email = email; - this.password = password; - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - @Override - public String toString() { - return "AccountInfo [id=" + id + ", email=" + email + ", password=" + password + "]"; - } - - public static AccountInfo fromProto(RegisterRequest proto) { - AccountInfo accountInfo = new AccountInfo(); - accountInfo.setId(proto.getId()); - accountInfo.setEmail(proto.getEmail()); - accountInfo.setPassword(proto.getPassword()); - return accountInfo; - } - - public biz.nynja.blueprint.grpc.AccountInfo toProto() { - return biz.nynja.blueprint.grpc.AccountInfo.newBuilder().setId(Long.toString(getId())).setEmail(getEmail()) - .build(); - } -} diff --git a/src/main/java/biz/nynja/account/grpc/models/AuthenticationProvider.java b/src/main/java/biz/nynja/account/grpc/models/AuthenticationProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..a4a1346387687065edf61624dd829c9435811155 --- /dev/null +++ b/src/main/java/biz/nynja/account/grpc/models/AuthenticationProvider.java @@ -0,0 +1,104 @@ +/** + * Copyright (C) 2018 Nynja Inc. All rights reserved. + */ +package biz.nynja.account.grpc.models; + +import org.springframework.data.cassandra.core.mapping.UserDefinedType; + +import biz.nynja.account.grpc.AuthProviderDetails; +import biz.nynja.account.grpc.AuthenticationType; + +@UserDefinedType +public class AuthenticationProvider { + + private String type; + private String value; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((type == null) ? 0 : type.hashCode()); + result = prime * result + ((value == null) ? 0 : value.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + AuthenticationProvider other = (AuthenticationProvider) obj; + if (type == null) { + if (other.type != null) + return false; + } else if (!type.equals(other.type)) + return false; + if (value == null) { + if (other.value != null) + return false; + } else if (!value.equals(other.value)) + return false; + return true; + } + + @Override + public String toString() { + return new StringBuilder("AuthenticationProvider [type=").append(type).append(", value=").append(value) + .append("]").toString(); + } + + public static AuthenticationProvider createAuthenticationProviderFromProto( + AuthProviderDetails authProviderDetails) { + AuthenticationProvider authenticationProvider = new AuthenticationProvider(); + authenticationProvider.setType(authProviderDetails.getAuthenticationType().toString()); + authenticationProvider.setValue(authProviderDetails.getAuthenticationProvider()); + return authenticationProvider; + } + + public static AuthenticationProvider createAuthenticationProviderFromStrings(String type, String value) { + AuthenticationProvider authenticationProvider = new AuthenticationProvider(); + authenticationProvider.setType(type); + authenticationProvider.setValue(value); + return authenticationProvider; + } + + public AuthProviderDetails toProto() { + AuthenticationType protoType = null; + switch (getType()) { + case "PHONE": + protoType = AuthenticationType.PHONE; + break; + case "EMAIL": + protoType = AuthenticationType.EMAIL; + break; + case "FACEBOOK": + protoType = AuthenticationType.FACEBOOK; + break; + case "GOOGLEPLUS": + protoType = AuthenticationType.GOOGLEPLUS; + break; + } + return AuthProviderDetails.newBuilder().setAuthenticationProvider(getValue()).setAuthenticationType(protoType) + .build(); + } +} diff --git a/src/main/java/biz/nynja/account/grpc/models/CountryInfo.java b/src/main/java/biz/nynja/account/grpc/models/CountryInfo.java new file mode 100644 index 0000000000000000000000000000000000000000..0aaa9e3fdb72ce5ccd7143e2cfd10bd4d468a2dc --- /dev/null +++ b/src/main/java/biz/nynja/account/grpc/models/CountryInfo.java @@ -0,0 +1,88 @@ +package biz.nynja.account.grpc.models; + +public class CountryInfo { + + private String countryPhoneCode; + private String countryCode; + private String countryName; + private String phoneFormat; + + public CountryInfo() { + } + + public String getCountryPhoneCode() { + return countryPhoneCode; + } + + public void setCountryPhoneCode(String countryPhoneCode) { + this.countryPhoneCode = countryPhoneCode; + } + + public String getCountryCode() { + return countryCode; + } + + public void setCountryCode(String countryCode) { + this.countryCode = countryCode; + } + + public String getCountryName() { + return countryName; + } + + public void setCountryName(String countryName) { + this.countryName = countryName; + } + + public String getPhoneFormat() { + return phoneFormat; + } + + public void setPhoneFormat(String phoneFormat) { + this.phoneFormat = phoneFormat; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((countryCode == null) ? 0 : countryCode.hashCode()); + result = prime * result + ((countryName == null) ? 0 : countryName.hashCode()); + result = prime * result + ((countryPhoneCode == null) ? 0 : countryPhoneCode.hashCode()); + result = prime * result + ((phoneFormat == null) ? 0 : phoneFormat.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + CountryInfo other = (CountryInfo) obj; + if (countryCode == null) { + if (other.countryCode != null) + return false; + } else if (!countryCode.equals(other.countryCode)) + return false; + if (countryName == null) { + if (other.countryName != null) + return false; + } else if (!countryName.equals(other.countryName)) + return false; + if (countryPhoneCode == null) { + if (other.countryPhoneCode != null) + return false; + } else if (!countryPhoneCode.equals(other.countryPhoneCode)) + return false; + if (phoneFormat == null) { + if (other.phoneFormat != null) + return false; + } else if (!phoneFormat.equals(other.phoneFormat)) + return false; + return true; + } + +} diff --git a/src/main/java/biz/nynja/account/grpc/models/PendingAccount.java b/src/main/java/biz/nynja/account/grpc/models/PendingAccount.java new file mode 100644 index 0000000000000000000000000000000000000000..a0bb463de10ea787be146f08c9edaed5065dbf23 --- /dev/null +++ b/src/main/java/biz/nynja/account/grpc/models/PendingAccount.java @@ -0,0 +1,137 @@ +/** + * Copyright (C) 2018 Nynja Inc. All rights reserved. + */ +package biz.nynja.account.grpc.models; + +import java.util.Date; +import java.util.UUID; + +import org.springframework.data.cassandra.core.mapping.Column; +import org.springframework.data.cassandra.core.mapping.PrimaryKey; +import org.springframework.data.cassandra.core.mapping.Table; + +import biz.nynja.account.grpc.CreatePendingAccountRequest; + +@Table("pending_account") +public class PendingAccount { + @PrimaryKey("account_id") + private UUID accountId; + @Column("profile_id") + private UUID profileId; + @Column("authentication_provider") + private String authenticationProvider; + @Column("authentication_provider_type") + private String authenticationProviderType; + @Column("creation_timestamp") + private Long creationTimestamp; + + public UUID getAccountId() { + return accountId; + } + + public void setAccountId(UUID accountId) { + this.accountId = accountId; + } + + public UUID getProfileId() { + return profileId; + } + + public void setProfileId(UUID profileId) { + this.profileId = profileId; + } + + public String getAuthenticationProvider() { + return authenticationProvider; + } + + public void setAuthenticationProvider(String authenticationProvider) { + this.authenticationProvider = authenticationProvider; + } + + public String getAuthenticationProviderType() { + return authenticationProviderType; + } + + public void setAuthenticationProviderType(String authenticationProviderType) { + this.authenticationProviderType = authenticationProviderType; + } + + public Long getCreationTimestamp() { + return creationTimestamp; + } + + public void setCreationTimestamp(Long creationTimestamp) { + this.creationTimestamp = creationTimestamp; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((accountId == null) ? 0 : accountId.hashCode()); + result = prime * result + ((authenticationProvider == null) ? 0 : authenticationProvider.hashCode()); + result = prime * result + ((authenticationProviderType == null) ? 0 : authenticationProviderType.hashCode()); + result = prime * result + ((creationTimestamp == null) ? 0 : creationTimestamp.hashCode()); + result = prime * result + ((profileId == null) ? 0 : profileId.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + PendingAccount other = (PendingAccount) obj; + if (accountId == null) { + if (other.accountId != null) + return false; + } else if (!accountId.equals(other.accountId)) + return false; + if (authenticationProvider == null) { + if (other.authenticationProvider != null) + return false; + } else if (!authenticationProvider.equals(other.authenticationProvider)) + return false; + if (authenticationProviderType == null) { + if (other.authenticationProviderType != null) + return false; + } else if (!authenticationProviderType.equals(other.authenticationProviderType)) + return false; + if (creationTimestamp == null) { + if (other.creationTimestamp != null) + return false; + } else if (!creationTimestamp.equals(other.creationTimestamp)) + return false; + if (profileId == null) { + if (other.profileId != null) + return false; + } else if (!profileId.equals(other.profileId)) + return false; + return true; + } + + @Override + public String toString() { + return new StringBuilder("PendingAccounts [accountId=").append(accountId).append(", profileId=") + .append(profileId).append(", authenticationProvider=").append(authenticationProvider) + .append(", authenticationProviderType=").append(authenticationProviderType) + .append(", creationTimestamp=").append(creationTimestamp).append("]").toString(); + } + + public static PendingAccount fromProto(CreatePendingAccountRequest proto) { + PendingAccount pendingAccount = new PendingAccount(); + pendingAccount.setAuthenticationProviderType(proto.getAuthenticationType().toString()); + pendingAccount.setAuthenticationProvider(proto.getAuthenticationProvider()); + return pendingAccount; + } + + public biz.nynja.account.grpc.PendingAccountDetails toProto() { + return biz.nynja.account.grpc.PendingAccountDetails.newBuilder().setAccountId(getAccountId().toString()) + .build(); + } + +} diff --git a/src/main/java/biz/nynja/account/grpc/models/Profile.java b/src/main/java/biz/nynja/account/grpc/models/Profile.java new file mode 100644 index 0000000000000000000000000000000000000000..2ef9957d1193cae870d7fab14f20b4321e0817b5 --- /dev/null +++ b/src/main/java/biz/nynja/account/grpc/models/Profile.java @@ -0,0 +1,151 @@ +/** + * Copyright (C) 2018 Nynja Inc. All rights reserved. + */ +package biz.nynja.account.grpc.models; + +import java.util.Set; +import java.util.UUID; + +import org.springframework.data.cassandra.core.mapping.PrimaryKey; +import org.springframework.data.cassandra.core.mapping.Table; + +@Table +public class Profile { + + @PrimaryKey + private UUID profileId; + private Set authenticationProviders; + private AuthenticationProvider backupAuthenticationProvider; + private String passcode; + private UUID defaultAccount; + private Long creationTimestamp; + private Long lastUpdateTimestamp; + + public UUID getProfileId() { + return profileId; + } + + public void setProfileId(UUID profileId) { + this.profileId = profileId; + } + + public Set getAuthenticationProviders() { + return authenticationProviders; + } + + public void setAuthenticationProviders(Set authenticationProviders) { + this.authenticationProviders = authenticationProviders; + } + + public Long getCreationTimestamp() { + return creationTimestamp; + } + + public void setCreationTimestamp(Long creationTimestamp) { + this.creationTimestamp = creationTimestamp; + } + + public Long getLastUpdateTimestamp() { + return lastUpdateTimestamp; + } + + public void setLastUpdateTimestamp(Long lastUpdateTimestamp) { + this.lastUpdateTimestamp = lastUpdateTimestamp; + } + + public String getPasscode() { + return passcode; + } + + public void setPasscode(String passcode) { + this.passcode = passcode; + } + + public UUID getDefaultAccount() { + return defaultAccount; + } + + public void setDefaultAccount(UUID defaultAccount) { + this.defaultAccount = defaultAccount; + } + + public AuthenticationProvider getBackupAuthenticationProvider() { + return backupAuthenticationProvider; + } + + public void setBackupAuthenticationProvider(AuthenticationProvider backupAuthenticationProvider) { + this.backupAuthenticationProvider = backupAuthenticationProvider; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((authenticationProviders == null) ? 0 : authenticationProviders.hashCode()); + result = prime * result + + ((backupAuthenticationProvider == null) ? 0 : backupAuthenticationProvider.hashCode()); + result = prime * result + ((creationTimestamp == null) ? 0 : creationTimestamp.hashCode()); + result = prime * result + ((defaultAccount == null) ? 0 : defaultAccount.hashCode()); + result = prime * result + ((lastUpdateTimestamp == null) ? 0 : lastUpdateTimestamp.hashCode()); + result = prime * result + ((passcode == null) ? 0 : passcode.hashCode()); + result = prime * result + ((profileId == null) ? 0 : profileId.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Profile other = (Profile) obj; + if (authenticationProviders == null) { + if (other.authenticationProviders != null) + return false; + } else if (!authenticationProviders.equals(other.authenticationProviders)) + return false; + if (backupAuthenticationProvider == null) { + if (other.backupAuthenticationProvider != null) + return false; + } else if (!backupAuthenticationProvider.equals(other.backupAuthenticationProvider)) + return false; + if (creationTimestamp == null) { + if (other.creationTimestamp != null) + return false; + } else if (!creationTimestamp.equals(other.creationTimestamp)) + return false; + if (defaultAccount == null) { + if (other.defaultAccount != null) + return false; + } else if (!defaultAccount.equals(other.defaultAccount)) + return false; + if (lastUpdateTimestamp == null) { + if (other.lastUpdateTimestamp != null) + return false; + } else if (!lastUpdateTimestamp.equals(other.lastUpdateTimestamp)) + return false; + if (passcode == null) { + if (other.passcode != null) + return false; + } else if (!passcode.equals(other.passcode)) + return false; + if (profileId == null) { + if (other.profileId != null) + return false; + } else if (!profileId.equals(other.profileId)) + return false; + return true; + } + + @Override + public String toString() { + return new StringBuilder("Profile [profileId=").append(profileId).append(", authenticationProviders=") + .append(authenticationProviders).append(", creationTimestamp=").append(creationTimestamp) + .append(", lastUpdateTimestamp=").append(lastUpdateTimestamp).append(", passcode=******") + .append(", defaultAccount=").append(defaultAccount).append(", backupAuthenticationProvider=") + .append(backupAuthenticationProvider).append("]").toString(); + } + +} diff --git a/src/main/java/biz/nynja/account/grpc/models/ProfileByAuthenticationProvider.java b/src/main/java/biz/nynja/account/grpc/models/ProfileByAuthenticationProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..0558a4ab463948580549330294f59ced2c0718da --- /dev/null +++ b/src/main/java/biz/nynja/account/grpc/models/ProfileByAuthenticationProvider.java @@ -0,0 +1,91 @@ +/** + * Copyright (C) 2018 Nynja Inc. All rights reserved. + */ +package biz.nynja.account.grpc.models; + +import java.util.UUID; + +import org.springframework.data.cassandra.core.cql.PrimaryKeyType; +import org.springframework.data.cassandra.core.mapping.Column; +import org.springframework.data.cassandra.core.mapping.PrimaryKeyColumn; +import org.springframework.data.cassandra.core.mapping.Table; + +@Table("profile_by_authentication_provider") +public class ProfileByAuthenticationProvider { + + @PrimaryKeyColumn(name = "authentication_provider", ordinal = 0, type = PrimaryKeyType.PARTITIONED) + private String authenticationProvider; + @PrimaryKeyColumn(name = "authentication_provider_type", ordinal = 1, type = PrimaryKeyType.PARTITIONED) + private String authenticationProviderType; + @Column("profile_id") + private UUID profileId; + + public String getAuthenticationProvider() { + return authenticationProvider; + } + + public void setAuthenticationProvider(String authenticationProvider) { + this.authenticationProvider = authenticationProvider; + } + + public String getAuthenticationProviderType() { + return authenticationProviderType; + } + + public void setAuthenticationProviderType(String authenticationProviderType) { + this.authenticationProviderType = authenticationProviderType; + } + + public UUID getProfileId() { + return profileId; + } + + public void setProfileId(UUID profileId) { + this.profileId = profileId; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((authenticationProvider == null) ? 0 : authenticationProvider.hashCode()); + result = prime * result + ((authenticationProviderType == null) ? 0 : authenticationProviderType.hashCode()); + result = prime * result + ((profileId == null) ? 0 : profileId.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ProfileByAuthenticationProvider other = (ProfileByAuthenticationProvider) obj; + if (authenticationProvider == null) { + if (other.authenticationProvider != null) + return false; + } else if (!authenticationProvider.equals(other.authenticationProvider)) + return false; + if (authenticationProviderType == null) { + if (other.authenticationProviderType != null) + return false; + } else if (!authenticationProviderType.equals(other.authenticationProviderType)) + return false; + if (profileId == null) { + if (other.profileId != null) + return false; + } else if (!profileId.equals(other.profileId)) + return false; + return true; + } + + @Override + public String toString() { + return new StringBuilder("ProfileByAuthenticationProvider [authenticationProvider=") + .append(authenticationProvider).append(", authenticationProviderType=") + .append(authenticationProviderType).append(", profileId=").append(profileId).append("]").toString(); + } + +} diff --git a/src/main/java/biz/nynja/account/grpc/models/UserInfo.java b/src/main/java/biz/nynja/account/grpc/models/UserInfo.java new file mode 100644 index 0000000000000000000000000000000000000000..027a6522a269bbc764b076edb2ea784be78f6b5f --- /dev/null +++ b/src/main/java/biz/nynja/account/grpc/models/UserInfo.java @@ -0,0 +1,268 @@ +/** + * Copyright (C) 2018 Nynja Inc. All rights reserved. + */ +package biz.nynja.account.grpc.models; + +import java.util.UUID; + +import org.springframework.data.cassandra.core.cql.PrimaryKeyType; +import org.springframework.data.cassandra.core.mapping.PrimaryKeyColumn; +import org.springframework.data.cassandra.core.mapping.Table; + +import biz.nynja.account.grpc.AuthenticationType; +import biz.nynja.account.grpc.CreateAccountRequest; +import biz.nynja.account.grpc.Status; + +@Table +public class UserInfo { + + @PrimaryKeyColumn(name = "profile_id", ordinal = 0, type = PrimaryKeyType.PARTITIONED) + private UUID profileId; + @PrimaryKeyColumn(name = "account_id", ordinal = 1, type = PrimaryKeyType.CLUSTERED) + private UUID accountId; + private String firstName; + private String lastName; + private String middleName; + @PrimaryKeyColumn(name = "username", ordinal = 2, type = PrimaryKeyType.CLUSTERED) + private String username; + private String phoneNumber; + private String emailAddress; + private String password; + private Status status; + @PrimaryKeyColumn(name = "authentication_type", ordinal = 3, type = PrimaryKeyType.CLUSTERED) + private AuthenticationType authenticationType; + @PrimaryKeyColumn(name = "authnetication_provider_id", ordinal = 4, type = PrimaryKeyType.CLUSTERED) + private String authenticationProviderId; + private String communicationProcviderId; + + public UserInfo() { + } + + public UUID getProfileId() { + return profileId; + } + + public void setProfileId(UUID profileId) { + this.profileId = profileId; + } + + public UUID getAccountId() { + return accountId; + } + + public void setAccountId(UUID accountId) { + this.accountId = accountId; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getMiddleName() { + return middleName; + } + + public void setMiddleName(String middleName) { + this.middleName = middleName; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPhoneNumber() { + return phoneNumber; + } + + public void setPhoneNumber(String phoneNumber) { + this.phoneNumber = phoneNumber; + } + + public String getEmailAddress() { + return emailAddress; + } + + public void setEmailAddress(String emailAddress) { + this.emailAddress = emailAddress; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public Status getStatus() { + return status; + } + + public void setStatus(Status status) { + this.status = status; + } + + public AuthenticationType getAuthenticationType() { + return authenticationType; + } + + public void setAuthenticationType(AuthenticationType authenticationType) { + this.authenticationType = authenticationType; + } + + public String getAuthenticationProviderId() { + return authenticationProviderId; + } + + public void setAuthenticationProviderId(String authenticationProviderId) { + this.authenticationProviderId = authenticationProviderId; + } + + public String getCommunicationProcviderId() { + return communicationProcviderId; + } + + public void setCommunicationProcviderId(String communicationProcviderId) { + this.communicationProcviderId = communicationProcviderId; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((accountId == null) ? 0 : accountId.hashCode()); + result = prime * result + ((authenticationProviderId == null) ? 0 : authenticationProviderId.hashCode()); + result = prime * result + ((authenticationType == null) ? 0 : authenticationType.hashCode()); + result = prime * result + ((communicationProcviderId == null) ? 0 : communicationProcviderId.hashCode()); + result = prime * result + ((emailAddress == null) ? 0 : emailAddress.hashCode()); + result = prime * result + ((firstName == null) ? 0 : firstName.hashCode()); + result = prime * result + ((lastName == null) ? 0 : lastName.hashCode()); + result = prime * result + ((middleName == null) ? 0 : middleName.hashCode()); + result = prime * result + ((phoneNumber == null) ? 0 : phoneNumber.hashCode()); + result = prime * result + ((profileId == null) ? 0 : profileId.hashCode()); + result = prime * result + ((status == null) ? 0 : status.hashCode()); + result = prime * result + ((username == null) ? 0 : username.hashCode()); + result = prime * result + ((password == null) ? 0 : password.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + UserInfo other = (UserInfo) obj; + if (accountId == null) { + if (other.accountId != null) + return false; + } else if (!accountId.equals(other.accountId)) + return false; + if (authenticationProviderId == null) { + if (other.authenticationProviderId != null) + return false; + } else if (!authenticationProviderId.equals(other.authenticationProviderId)) + return false; + if (authenticationType != other.authenticationType) + return false; + if (communicationProcviderId == null) { + if (other.communicationProcviderId != null) + return false; + } else if (!communicationProcviderId.equals(other.communicationProcviderId)) + return false; + if (emailAddress == null) { + if (other.emailAddress != null) + return false; + } else if (!emailAddress.equals(other.emailAddress)) + return false; + if (firstName == null) { + if (other.firstName != null) + return false; + } else if (!firstName.equals(other.firstName)) + return false; + if (lastName == null) { + if (other.lastName != null) + return false; + } else if (!lastName.equals(other.lastName)) + return false; + if (middleName == null) { + if (other.middleName != null) + return false; + } else if (!middleName.equals(other.middleName)) + return false; + if (phoneNumber == null) { + if (other.phoneNumber != null) + return false; + } else if (!phoneNumber.equals(other.phoneNumber)) + return false; + if (profileId == null) { + if (other.profileId != null) + return false; + } else if (!profileId.equals(other.profileId)) + return false; + if (status != other.status) + return false; + if (username == null) { + if (other.username != null) + return false; + } else if (!username.equals(other.username)) + return false; + if (password == null) { + if (other.password != null) + return false; + } else if (!password.equals(other.password)) + return false; + return true; + } + + @Override + public String toString() { + return new StringBuilder("UserInfo [profileId=").append(profileId).append(", accountId=").append(accountId) + .append(", firstName=").append(firstName).append(", lastName=").append(lastName).append(", middleName=") + .append(middleName).append(", username=").append(username).append(", password=").append(password) + .append(", phoneNumber=").append(phoneNumber).append(", emailAddress=").append(emailAddress) + .append(", status=").append(status).append(", authenticationType=").append(authenticationType) + .append(", authenticationProviderId=").append(authenticationProviderId).append(", avatar=[]") + .append(", communicationProcviderId=").append(communicationProcviderId).append("]").toString(); + } + + public static UserInfo fromProto(CreateAccountRequest proto) { + UserInfo userInfo = new UserInfo(); + userInfo.setUsername(proto.getUsername()); + userInfo.setEmailAddress(proto.getEmailAddress()); + userInfo.setFirstName(proto.getFirstName()); + userInfo.setLastName(proto.getLastName()); + userInfo.setMiddleName(proto.getMiddleName()); + userInfo.setPhoneNumber(proto.getPhoneNumber()); + userInfo.setAuthenticationType(proto.getAuthenticationType()); + userInfo.setStatus(proto.getStatus()); + userInfo.setPassword(proto.getPassword()); + return userInfo; + } + + public biz.nynja.account.grpc.AccountDetails toProto() { + return biz.nynja.account.grpc.AccountDetails.newBuilder().setAccountId(getAccountId().toString()) + .setProfileId(getProfileId().toString()).setUsername(getUsername()) + .setAuthenticationType(getAuthenticationType()).setEmailAddress(getEmailAddress()) + .setFirstName(getFirstName()).setLastName(getLastName()).setMiddleName(getMiddleName()) + .setPhoneNumber(getPhoneNumber()).setStatus(getStatus()).build(); + } +} diff --git a/src/main/java/biz/nynja/account/grpc/models/UserInfoByEmail.java b/src/main/java/biz/nynja/account/grpc/models/UserInfoByEmail.java new file mode 100644 index 0000000000000000000000000000000000000000..bbdf0000b2ed66f56075ff091e16c45b4c2eb323 --- /dev/null +++ b/src/main/java/biz/nynja/account/grpc/models/UserInfoByEmail.java @@ -0,0 +1,250 @@ +/** + * Copyright (C) 2018 Nynja Inc. All rights reserved. + */ +package biz.nynja.account.grpc.models; + +import java.util.UUID; + +import org.springframework.data.cassandra.core.cql.PrimaryKeyType; +import org.springframework.data.cassandra.core.mapping.PrimaryKeyColumn; +import org.springframework.data.cassandra.core.mapping.Table; + +import biz.nynja.account.grpc.AuthenticationType; +import biz.nynja.account.grpc.CreateAccountRequest; +import biz.nynja.account.grpc.Status; + +@Table("userinfo_by_email") +public class UserInfoByEmail { + + @PrimaryKeyColumn(name = "emailaddress", ordinal = 0, type = PrimaryKeyType.PARTITIONED) + private String emailAddress; + @PrimaryKeyColumn(name = "profile_id", ordinal = 1, type = PrimaryKeyType.CLUSTERED) + private UUID profileId; + @PrimaryKeyColumn(name = "account_id", ordinal = 2, type = PrimaryKeyType.CLUSTERED) + private UUID accountId; + @PrimaryKeyColumn(name = "username", ordinal = 3, type = PrimaryKeyType.CLUSTERED) + private String username; + @PrimaryKeyColumn(name = "authentication_type", ordinal = 4, type = PrimaryKeyType.CLUSTERED) + private AuthenticationType authenticationType; + @PrimaryKeyColumn(name = "authnetication_provider_id", ordinal = 5, type = PrimaryKeyType.CLUSTERED) + private String authenticationProviderId; + private String firstName; + private String lastName; + private String middleName; + private String phoneNumber; + private Status status; + private String communicationProcviderId; + + public String getEmailAddress() { + return emailAddress; + } + + public void setEmailAddress(String emailAddress) { + this.emailAddress = emailAddress; + } + + public UUID getProfileId() { + return profileId; + } + + public void setProfileId(UUID profileId) { + this.profileId = profileId; + } + + public UUID getAccountId() { + return accountId; + } + + public void setAccountId(UUID accountId) { + this.accountId = accountId; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public AuthenticationType getAuthenticationType() { + return authenticationType; + } + + public void setAuthenticationType(AuthenticationType authenticationType) { + this.authenticationType = authenticationType; + } + + public String getAuthenticationProviderId() { + return authenticationProviderId; + } + + public void setAuthenticationProviderId(String authenticationProviderId) { + this.authenticationProviderId = authenticationProviderId; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getMiddleName() { + return middleName; + } + + public void setMiddleName(String middleName) { + this.middleName = middleName; + } + + public String getPhoneNumber() { + return phoneNumber; + } + + public void setPhoneNumber(String phoneNumber) { + this.phoneNumber = phoneNumber; + } + + public Status getStatus() { + return status; + } + + public void setStatus(Status status) { + this.status = status; + } + + public String getCommunicationProcviderId() { + return communicationProcviderId; + } + + public void setCommunicationProcviderId(String communicationProcviderId) { + this.communicationProcviderId = communicationProcviderId; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((accountId == null) ? 0 : accountId.hashCode()); + result = prime * result + ((authenticationProviderId == null) ? 0 : authenticationProviderId.hashCode()); + result = prime * result + ((authenticationType == null) ? 0 : authenticationType.hashCode()); + result = prime * result + ((communicationProcviderId == null) ? 0 : communicationProcviderId.hashCode()); + result = prime * result + ((emailAddress == null) ? 0 : emailAddress.hashCode()); + result = prime * result + ((firstName == null) ? 0 : firstName.hashCode()); + result = prime * result + ((lastName == null) ? 0 : lastName.hashCode()); + result = prime * result + ((middleName == null) ? 0 : middleName.hashCode()); + result = prime * result + ((phoneNumber == null) ? 0 : phoneNumber.hashCode()); + result = prime * result + ((profileId == null) ? 0 : profileId.hashCode()); + result = prime * result + ((status == null) ? 0 : status.hashCode()); + result = prime * result + ((username == null) ? 0 : username.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + UserInfoByEmail other = (UserInfoByEmail) obj; + if (accountId == null) { + if (other.accountId != null) + return false; + } else if (!accountId.equals(other.accountId)) + return false; + if (authenticationProviderId == null) { + if (other.authenticationProviderId != null) + return false; + } else if (!authenticationProviderId.equals(other.authenticationProviderId)) + return false; + if (authenticationType != other.authenticationType) + return false; + if (communicationProcviderId == null) { + if (other.communicationProcviderId != null) + return false; + } else if (!communicationProcviderId.equals(other.communicationProcviderId)) + return false; + if (emailAddress == null) { + if (other.emailAddress != null) + return false; + } else if (!emailAddress.equals(other.emailAddress)) + return false; + if (firstName == null) { + if (other.firstName != null) + return false; + } else if (!firstName.equals(other.firstName)) + return false; + if (lastName == null) { + if (other.lastName != null) + return false; + } else if (!lastName.equals(other.lastName)) + return false; + if (middleName == null) { + if (other.middleName != null) + return false; + } else if (!middleName.equals(other.middleName)) + return false; + if (phoneNumber == null) { + if (other.phoneNumber != null) + return false; + } else if (!phoneNumber.equals(other.phoneNumber)) + return false; + if (profileId == null) { + if (other.profileId != null) + return false; + } else if (!profileId.equals(other.profileId)) + return false; + if (status != other.status) + return false; + if (username == null) { + if (other.username != null) + return false; + } else if (!username.equals(other.username)) + return false; + return true; + } + + @Override + public String toString() { + return new StringBuilder("UserInfoByEmail [emailAddress=").append(emailAddress).append(", profileId=") + .append(profileId).append(", accountId=").append(accountId).append(", username=").append(username) + .append(", authenticationType=").append(authenticationType).append(", authenticationProviderId=") + .append(authenticationProviderId).append(", firstName=").append(firstName).append(", lastName=") + .append(lastName).append(", middleName=").append(middleName).append(", phoneNumber=") + .append(phoneNumber).append(", status=").append(status).append(", communicationProcviderId=") + .append(communicationProcviderId).append("]").toString(); + } + + public static UserInfoByEmail fromProto(CreateAccountRequest proto) { + UserInfoByEmail userInfo = new UserInfoByEmail(); + userInfo.setUsername(proto.getUsername()); + userInfo.setEmailAddress(proto.getEmailAddress()); + userInfo.setFirstName(proto.getFirstName()); + userInfo.setLastName(proto.getLastName()); + userInfo.setMiddleName(proto.getMiddleName()); + userInfo.setPhoneNumber(proto.getPhoneNumber()); + userInfo.setAuthenticationType(proto.getAuthenticationType()); + userInfo.setStatus(proto.getStatus()); + return userInfo; + } + + public biz.nynja.account.grpc.AccountDetails toProto() { + return biz.nynja.account.grpc.AccountDetails.newBuilder().setAccountId(getAccountId().toString()) + .setProfileId(getProfileId().toString()).setUsername(getUsername()) + .setAuthenticationType(getAuthenticationType()).setEmailAddress(getEmailAddress()) + .setFirstName(getFirstName()).setLastName(getLastName()).setMiddleName(getMiddleName()) + .setPhoneNumber(getPhoneNumber()).setStatus(getStatus()).build(); + } +} diff --git a/src/main/java/biz/nynja/account/grpc/models/UserInfoByPhone.java b/src/main/java/biz/nynja/account/grpc/models/UserInfoByPhone.java new file mode 100644 index 0000000000000000000000000000000000000000..5b80bd4f3dd2e893148c01b3b23abf3984683224 --- /dev/null +++ b/src/main/java/biz/nynja/account/grpc/models/UserInfoByPhone.java @@ -0,0 +1,247 @@ +package biz.nynja.account.grpc.models; + +import java.util.UUID; + +import org.springframework.data.cassandra.core.cql.PrimaryKeyType; +import org.springframework.data.cassandra.core.mapping.PrimaryKeyColumn; +import org.springframework.data.cassandra.core.mapping.Table; + +import biz.nynja.account.grpc.AuthenticationType; +import biz.nynja.account.grpc.CreateAccountRequest; +import biz.nynja.account.grpc.Status; + +@Table("userinfo_by_phone") +public class UserInfoByPhone { + + @PrimaryKeyColumn(name = "phonenumber", ordinal = 0, type = PrimaryKeyType.PARTITIONED) + private String phoneNumber; + @PrimaryKeyColumn(name = "profile_id", ordinal = 1, type = PrimaryKeyType.CLUSTERED) + private UUID profileId; + @PrimaryKeyColumn(name = "account_id", ordinal = 2, type = PrimaryKeyType.CLUSTERED) + private UUID accountId; + @PrimaryKeyColumn(name = "username", ordinal = 3, type = PrimaryKeyType.CLUSTERED) + private String username; + @PrimaryKeyColumn(name = "authentication_type", ordinal = 4, type = PrimaryKeyType.CLUSTERED) + private AuthenticationType authenticationType; + @PrimaryKeyColumn(name = "authnetication_provider_id", ordinal = 5, type = PrimaryKeyType.CLUSTERED) + private String authenticationProviderId; + private String firstName; + private String lastName; + private String middleName; + private String emailAddress; + private Status status; + private String communicationProcviderId; + + public String getPhoneNumber() { + return phoneNumber; + } + + public void setPhoneNumber(String phoneNumber) { + this.phoneNumber = phoneNumber; + } + + public UUID getProfileId() { + return profileId; + } + + public void setProfileId(UUID profileId) { + this.profileId = profileId; + } + + public UUID getAccountId() { + return accountId; + } + + public void setAccountId(UUID accountId) { + this.accountId = accountId; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public AuthenticationType getAuthenticationType() { + return authenticationType; + } + + public void setAuthenticationType(AuthenticationType authenticationType) { + this.authenticationType = authenticationType; + } + + public String getAuthenticationProviderId() { + return authenticationProviderId; + } + + public void setAuthenticationProviderId(String authenticationProviderId) { + this.authenticationProviderId = authenticationProviderId; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getMiddleName() { + return middleName; + } + + public void setMiddleName(String middleName) { + this.middleName = middleName; + } + + public String getEmailAddress() { + return emailAddress; + } + + public void setEmailAddress(String emailAddress) { + this.emailAddress = emailAddress; + } + + public Status getStatus() { + return status; + } + + public void setStatus(Status status) { + this.status = status; + } + + public String getCommunicationProcviderId() { + return communicationProcviderId; + } + + public void setCommunicationProcviderId(String communicationProcviderId) { + this.communicationProcviderId = communicationProcviderId; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((accountId == null) ? 0 : accountId.hashCode()); + result = prime * result + ((authenticationProviderId == null) ? 0 : authenticationProviderId.hashCode()); + result = prime * result + ((authenticationType == null) ? 0 : authenticationType.hashCode()); + result = prime * result + ((communicationProcviderId == null) ? 0 : communicationProcviderId.hashCode()); + result = prime * result + ((emailAddress == null) ? 0 : emailAddress.hashCode()); + result = prime * result + ((firstName == null) ? 0 : firstName.hashCode()); + result = prime * result + ((lastName == null) ? 0 : lastName.hashCode()); + result = prime * result + ((middleName == null) ? 0 : middleName.hashCode()); + result = prime * result + ((phoneNumber == null) ? 0 : phoneNumber.hashCode()); + result = prime * result + ((profileId == null) ? 0 : profileId.hashCode()); + result = prime * result + ((status == null) ? 0 : status.hashCode()); + result = prime * result + ((username == null) ? 0 : username.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + UserInfoByPhone other = (UserInfoByPhone) obj; + if (accountId == null) { + if (other.accountId != null) + return false; + } else if (!accountId.equals(other.accountId)) + return false; + if (authenticationProviderId == null) { + if (other.authenticationProviderId != null) + return false; + } else if (!authenticationProviderId.equals(other.authenticationProviderId)) + return false; + if (authenticationType != other.authenticationType) + return false; + if (communicationProcviderId == null) { + if (other.communicationProcviderId != null) + return false; + } else if (!communicationProcviderId.equals(other.communicationProcviderId)) + return false; + if (emailAddress == null) { + if (other.emailAddress != null) + return false; + } else if (!emailAddress.equals(other.emailAddress)) + return false; + if (firstName == null) { + if (other.firstName != null) + return false; + } else if (!firstName.equals(other.firstName)) + return false; + if (lastName == null) { + if (other.lastName != null) + return false; + } else if (!lastName.equals(other.lastName)) + return false; + if (middleName == null) { + if (other.middleName != null) + return false; + } else if (!middleName.equals(other.middleName)) + return false; + if (phoneNumber == null) { + if (other.phoneNumber != null) + return false; + } else if (!phoneNumber.equals(other.phoneNumber)) + return false; + if (profileId == null) { + if (other.profileId != null) + return false; + } else if (!profileId.equals(other.profileId)) + return false; + if (status != other.status) + return false; + if (username == null) { + if (other.username != null) + return false; + } else if (!username.equals(other.username)) + return false; + return true; + } + + @Override + public String toString() { + return new StringBuilder("UserInfoByEmail [emailAddress=").append(emailAddress).append(", profileId=") + .append(profileId).append(", accountId=").append(accountId).append(", username=").append(username) + .append(", authenticationType=").append(authenticationType).append(", authenticationProviderId=") + .append(authenticationProviderId).append(", firstName=").append(firstName).append(", lastName=") + .append(lastName).append(", middleName=").append(middleName).append(", phoneNumber=") + .append(phoneNumber).append(", status=").append(status).append(", communicationProcviderId=") + .append(communicationProcviderId).append("]").toString(); + } + + public static UserInfoByPhone fromProto(CreateAccountRequest proto) { + UserInfoByPhone userInfo = new UserInfoByPhone(); + userInfo.setUsername(proto.getUsername()); + userInfo.setEmailAddress(proto.getEmailAddress()); + userInfo.setFirstName(proto.getFirstName()); + userInfo.setLastName(proto.getLastName()); + userInfo.setMiddleName(proto.getMiddleName()); + userInfo.setPhoneNumber(proto.getPhoneNumber()); + userInfo.setAuthenticationType(proto.getAuthenticationType()); + userInfo.setStatus(proto.getStatus()); + return userInfo; + } + + public biz.nynja.account.grpc.AccountDetails toProto() { + return biz.nynja.account.grpc.AccountDetails.newBuilder().setAccountId(getAccountId().toString()) + .setProfileId(getProfileId().toString()).setUsername(getUsername()) + .setAuthenticationType(getAuthenticationType()).setEmailAddress(getEmailAddress()) + .setFirstName(getFirstName()).setLastName(getLastName()).setMiddleName(getMiddleName()) + .setPhoneNumber(getPhoneNumber()).setStatus(getStatus()).build(); + } +} diff --git a/src/main/java/biz/nynja/account/grpc/models/UserInfoByUsername.java b/src/main/java/biz/nynja/account/grpc/models/UserInfoByUsername.java new file mode 100644 index 0000000000000000000000000000000000000000..2b22a752a76ff60399384858a6345b58086ba5d5 --- /dev/null +++ b/src/main/java/biz/nynja/account/grpc/models/UserInfoByUsername.java @@ -0,0 +1,226 @@ +package biz.nynja.account.grpc.models; + +import java.util.UUID; + +import org.springframework.data.cassandra.core.cql.PrimaryKeyType; +import org.springframework.data.cassandra.core.mapping.PrimaryKeyColumn; +import org.springframework.data.cassandra.core.mapping.Table; + +import biz.nynja.account.grpc.AuthenticationType; +import biz.nynja.account.grpc.Status; + +@Table("userinfo_by_username") +public class UserInfoByUsername { + + @PrimaryKeyColumn(name = "username", ordinal = 0, type = PrimaryKeyType.PARTITIONED) + private String username; + @PrimaryKeyColumn(name = "profile_id", ordinal = 1, type = PrimaryKeyType.CLUSTERED) + private UUID profileId; + @PrimaryKeyColumn(name = "account_id", ordinal = 2, type = PrimaryKeyType.CLUSTERED) + private UUID accountId; + @PrimaryKeyColumn(name = "phonenumber", ordinal = 3, type = PrimaryKeyType.CLUSTERED) + private String phoneNumber; + @PrimaryKeyColumn(name = "authentication_type", ordinal = 4, type = PrimaryKeyType.CLUSTERED) + private AuthenticationType authenticationType; + @PrimaryKeyColumn(name = "authnetication_provider_id", ordinal = 5, type = PrimaryKeyType.CLUSTERED) + private String authenticationProviderId; + private String firstName; + private String lastName; + private String middleName; + private String emailAddress; + private Status status; + private String communicationProcviderId; + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public UUID getProfileId() { + return profileId; + } + + public void setProfileId(UUID profileId) { + this.profileId = profileId; + } + + public UUID getAccountId() { + return accountId; + } + + public void setAccountId(UUID accountId) { + this.accountId = accountId; + } + + public String getPhoneNumber() { + return phoneNumber; + } + + public void setPhoneNumber(String phoneNumber) { + this.phoneNumber = phoneNumber; + } + + public AuthenticationType getAuthenticationType() { + return authenticationType; + } + + public void setAuthenticationType(AuthenticationType authenticationType) { + this.authenticationType = authenticationType; + } + + public String getAuthenticationProviderId() { + return authenticationProviderId; + } + + public void setAuthenticationProviderId(String authenticationProviderId) { + this.authenticationProviderId = authenticationProviderId; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getMiddleName() { + return middleName; + } + + public void setMiddleName(String middleName) { + this.middleName = middleName; + } + + public String getEmailAddress() { + return emailAddress; + } + + public void setEmailAddress(String emailAddress) { + this.emailAddress = emailAddress; + } + + public Status getStatus() { + return status; + } + + public void setStatus(Status status) { + this.status = status; + } + + public String getCommunicationProcviderId() { + return communicationProcviderId; + } + + public void setCommunicationProcviderId(String communicationProcviderId) { + this.communicationProcviderId = communicationProcviderId; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((accountId == null) ? 0 : accountId.hashCode()); + result = prime * result + ((authenticationProviderId == null) ? 0 : authenticationProviderId.hashCode()); + result = prime * result + ((authenticationType == null) ? 0 : authenticationType.hashCode()); + result = prime * result + ((communicationProcviderId == null) ? 0 : communicationProcviderId.hashCode()); + result = prime * result + ((emailAddress == null) ? 0 : emailAddress.hashCode()); + result = prime * result + ((firstName == null) ? 0 : firstName.hashCode()); + result = prime * result + ((lastName == null) ? 0 : lastName.hashCode()); + result = prime * result + ((middleName == null) ? 0 : middleName.hashCode()); + result = prime * result + ((phoneNumber == null) ? 0 : phoneNumber.hashCode()); + result = prime * result + ((profileId == null) ? 0 : profileId.hashCode()); + result = prime * result + ((status == null) ? 0 : status.hashCode()); + result = prime * result + ((username == null) ? 0 : username.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + UserInfoByUsername other = (UserInfoByUsername) obj; + if (accountId == null) { + if (other.accountId != null) + return false; + } else if (!accountId.equals(other.accountId)) + return false; + if (authenticationProviderId == null) { + if (other.authenticationProviderId != null) + return false; + } else if (!authenticationProviderId.equals(other.authenticationProviderId)) + return false; + if (authenticationType != other.authenticationType) + return false; + if (communicationProcviderId == null) { + if (other.communicationProcviderId != null) + return false; + } else if (!communicationProcviderId.equals(other.communicationProcviderId)) + return false; + if (emailAddress == null) { + if (other.emailAddress != null) + return false; + } else if (!emailAddress.equals(other.emailAddress)) + return false; + if (firstName == null) { + if (other.firstName != null) + return false; + } else if (!firstName.equals(other.firstName)) + return false; + if (lastName == null) { + if (other.lastName != null) + return false; + } else if (!lastName.equals(other.lastName)) + return false; + if (middleName == null) { + if (other.middleName != null) + return false; + } else if (!middleName.equals(other.middleName)) + return false; + if (phoneNumber == null) { + if (other.phoneNumber != null) + return false; + } else if (!phoneNumber.equals(other.phoneNumber)) + return false; + if (profileId == null) { + if (other.profileId != null) + return false; + } else if (!profileId.equals(other.profileId)) + return false; + if (status != other.status) + return false; + if (username == null) { + if (other.username != null) + return false; + } else if (!username.equals(other.username)) + return false; + return true; + } + + @Override + public String toString() { + return new StringBuilder("UserInfoByEmail [emailAddress=").append(emailAddress).append(", profileId=") + .append(profileId).append(", accountId=").append(accountId).append(", username=").append(username) + .append(", authenticationType=").append(authenticationType).append(", authenticationProviderId=") + .append(authenticationProviderId).append(", firstName=").append(firstName).append(", lastName=") + .append(lastName).append(", middleName=").append(middleName).append(", phoneNumber=") + .append(phoneNumber).append(", status=").append(status).append(", communicationProcviderId=") + .append(communicationProcviderId).append("]").toString(); + } + +} \ No newline at end of file diff --git a/src/main/java/biz/nynja/account/grpc/repositories/AccountByCommunicationProviderRepository.java b/src/main/java/biz/nynja/account/grpc/repositories/AccountByCommunicationProviderRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..2b2ae6ca830e18af0eb533d322b22d870c370325 --- /dev/null +++ b/src/main/java/biz/nynja/account/grpc/repositories/AccountByCommunicationProviderRepository.java @@ -0,0 +1,16 @@ +/** + * Copyright (C) 2018 Nynja Inc. All rights reserved. + */ +package biz.nynja.account.grpc.repositories; + +import java.util.UUID; + +import org.springframework.data.cassandra.repository.CassandraRepository; +import org.springframework.stereotype.Repository; + +import biz.nynja.account.grpc.models.AccountByCommunicationProvider; + +@Repository +public interface AccountByCommunicationProviderRepository extends CassandraRepository { + +} diff --git a/src/main/java/biz/nynja/account/grpc/repositories/AccountByProfileIdRepository.java b/src/main/java/biz/nynja/account/grpc/repositories/AccountByProfileIdRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..638ba37220655d92c61ff3c57d90f0c5a0ec64de --- /dev/null +++ b/src/main/java/biz/nynja/account/grpc/repositories/AccountByProfileIdRepository.java @@ -0,0 +1,19 @@ +/** + * Copyright (C) 2018 Nynja Inc. All rights reserved. + */ +package biz.nynja.account.grpc.repositories; + +import java.util.List; +import java.util.UUID; + +import org.springframework.data.cassandra.repository.CassandraRepository; +import org.springframework.stereotype.Repository; + +import biz.nynja.account.grpc.models.AccountByProfileId; + +@Repository +public interface AccountByProfileIdRepository extends CassandraRepository { + + List findAllByProfileId(UUID profileId); + +} diff --git a/src/main/java/biz/nynja/account/grpc/repositories/AccountInfoRepository.java b/src/main/java/biz/nynja/account/grpc/repositories/AccountInfoRepository.java deleted file mode 100644 index 5fc95377067b40da2f5b36e7c93fe725fbf5b326..0000000000000000000000000000000000000000 --- a/src/main/java/biz/nynja/account/grpc/repositories/AccountInfoRepository.java +++ /dev/null @@ -1,18 +0,0 @@ -/** - * Copyright (C) 2018 Nynja Inc. All rights reserved. - */ -package biz.nynja.account.grpc.repositories; - -import org.springframework.data.cassandra.repository.Query; -import org.springframework.data.repository.CrudRepository; - -import biz.nynja.account.grpc.models.AccountInfo; - -/** - * Account repository for Cassandra operations/queries. - */ -public interface AccountInfoRepository extends CrudRepository { - - @Query(value = "SELECT * FROM AccountInfo WHERE email=?0 ALLOW FILTERING") - public AccountInfo findByEmail(String email); -} diff --git a/src/main/java/biz/nynja/account/grpc/repositories/AccountRepository.java b/src/main/java/biz/nynja/account/grpc/repositories/AccountRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..058aaddda6896547b46dd82e66067f7666d00630 --- /dev/null +++ b/src/main/java/biz/nynja/account/grpc/repositories/AccountRepository.java @@ -0,0 +1,18 @@ +/** + * Copyright (C) 2018 Nynja Inc. All rights reserved. + */ +package biz.nynja.account.grpc.repositories; + +import java.util.UUID; + +import org.springframework.data.cassandra.repository.CassandraRepository; +import org.springframework.stereotype.Repository; + +import biz.nynja.account.grpc.models.Account; + +@Repository +public interface AccountRepository extends CassandraRepository { + + public Account findByAccountId(UUID accountId); + +} diff --git a/src/main/java/biz/nynja/account/grpc/repositories/AccountRepositoryAdditional.java b/src/main/java/biz/nynja/account/grpc/repositories/AccountRepositoryAdditional.java new file mode 100644 index 0000000000000000000000000000000000000000..6fe0e52c1905a1de95b04b979671ae0db2a6c2e0 --- /dev/null +++ b/src/main/java/biz/nynja/account/grpc/repositories/AccountRepositoryAdditional.java @@ -0,0 +1,19 @@ +/** + * Copyright (C) 2018 Nynja Inc. All rights reserved. + */ +package biz.nynja.account.grpc.repositories; + +import org.springframework.stereotype.Repository; + +import biz.nynja.account.grpc.CompletePendingAccountCreationRequest; +import biz.nynja.account.grpc.CreateAccountRequest; +import biz.nynja.account.grpc.CreatePendingAccountRequest; +import biz.nynja.account.grpc.models.Account; +import biz.nynja.account.grpc.models.PendingAccount; + +@Repository +public interface AccountRepositoryAdditional { + + public Account completePendingAccountCreation(CompletePendingAccountCreationRequest request); + +} diff --git a/src/main/java/biz/nynja/account/grpc/repositories/AccountRepositoryAdditionalImpl.java b/src/main/java/biz/nynja/account/grpc/repositories/AccountRepositoryAdditionalImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..191e9268b6178eb6504681191aa5d713eb21ebb4 --- /dev/null +++ b/src/main/java/biz/nynja/account/grpc/repositories/AccountRepositoryAdditionalImpl.java @@ -0,0 +1,131 @@ +/** + * Copyright (C) 2018 Nynja Inc. All rights reserved. + */ +package biz.nynja.account.grpc.repositories; + +import java.util.Date; +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.cassandra.core.CassandraBatchOperations; +import org.springframework.data.cassandra.core.CassandraTemplate; +import org.springframework.data.cassandra.core.WriteResult; +import org.springframework.stereotype.Service; + +import biz.nynja.account.grpc.CompletePendingAccountCreationRequest; +import biz.nynja.account.grpc.models.Account; +import biz.nynja.account.grpc.models.AuthenticationProvider; +import biz.nynja.account.grpc.models.PendingAccount; +import biz.nynja.account.grpc.models.Profile; +import biz.nynja.account.grpc.models.ProfileByAuthenticationProvider; + +@Service +public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditional { + + private static final Logger logger = LoggerFactory.getLogger(AccountRepositoryAdditionalImpl.class); + + @Autowired + private CassandraTemplate cassandraTemplate; + + @Autowired + private AccountRepository accountRepository; + + @Autowired + private PendingAccountRepository pendingAccountRepository; + + @Override + public Account completePendingAccountCreation(CompletePendingAccountCreationRequest request) { + CassandraBatchOperations batchOperations = cassandraTemplate.batchOps(); + PendingAccount pendingAccount = pendingAccountRepository + .findByAccountId(UUID.fromString(request.getAccountId())); + if (pendingAccount == null) { + logger.info("Existing pending account with the provided id was not found."); + logger.debug("Existing pending account with the provided id {} was not found.", request.getAccountId()); + return null; + } else { + Long timeCreated = new Date().getTime(); + Long checkMinutes = timeCreated - pendingAccount.getCreationTimestamp(); + if (checkMinutes > 30 * 60 * 1000) { + logger.info("Account creation timeout expired."); + return null; + } else { + WriteResult wr = null; + try { + newAccountInsert(batchOperations, request, pendingAccount, timeCreated); + newProfileInsert(batchOperations, request, pendingAccount, timeCreated); + newProfileByAuthenticationProviderInsert(batchOperations, pendingAccount); + wr = batchOperations.execute(); + } catch (IllegalArgumentException | IllegalStateException e) { + logger.info("Exception while completing pending account creation."); + logger.debug("Exception while completing pending account creation: {} ...", e.getMessage()); + return null; + } + if (wr != null) { + boolean applied = wr.wasApplied(); + if (applied) { + pendingAccountRepository.deleteById(UUID.fromString(request.getAccountId())); + Account createdAccount = accountRepository + .findByAccountId(UUID.fromString(request.getAccountId())); + return createdAccount; + } + } + return null; + } + } + } + + private void newAccountInsert(CassandraBatchOperations batchOps, CompletePendingAccountCreationRequest request, + PendingAccount pendingAccount, Long creationTimestamp) { + Account newAccount = new Account(); + newAccount.setAccountId(pendingAccount.getAccountId()); + newAccount.setProfileId(pendingAccount.getProfileId()); + newAccount.setAccountMark(request.getAccountMark()); + newAccount.setAuthenticationProvider(pendingAccount.getAuthenticationProvider()); + newAccount.setAuthenticationProviderType(pendingAccount.getAuthenticationProviderType()); + newAccount.setFirstName(request.getFirstName()); + newAccount.setLastName(request.getLastName()); + newAccount.setAvatar(request.getAvatar().asReadOnlyByteBuffer()); + newAccount.setAccountName(request.getAccountName()); + newAccount.setAccountStatus(request.getAccountStatus()); + newAccount.setUsername(request.getUsername()); + newAccount.setCreationTimestamp(creationTimestamp); + Set communicationProvidersSet = new HashSet(); + newAccount.setCommunicationProviders(communicationProvidersSet); + if (request.getCommunicationProvidersList() != null) { + for (int i = 0; i < request.getCommunicationProvidersList().size(); i++) { + communicationProvidersSet.add(AuthenticationProvider + .createAuthenticationProviderFromProto(request.getCommunicationProviders(i))); + } + newAccount.setCommunicationProviders(communicationProvidersSet); + } + newAccount.setCommunicationProviders(communicationProvidersSet); + newAccount.setQrCode(request.getQrCode()); + batchOps.insert(newAccount); + } + + private void newProfileInsert(CassandraBatchOperations batchOps, CompletePendingAccountCreationRequest request, + PendingAccount pendingAccount, Long creationTimestamp) { + Profile newProfile = new Profile(); + newProfile.setProfileId(pendingAccount.getProfileId()); + Set authenticationProvidersSet = new HashSet(); + authenticationProvidersSet.add(AuthenticationProvider.createAuthenticationProviderFromStrings( + pendingAccount.getAuthenticationProviderType(), pendingAccount.getAuthenticationProvider())); + newProfile.setAuthenticationProviders(authenticationProvidersSet); + newProfile.setCreationTimestamp(creationTimestamp); + batchOps.insert(newProfile); + } + + private void newProfileByAuthenticationProviderInsert(CassandraBatchOperations batchOps, + PendingAccount pendingAccount) { + ProfileByAuthenticationProvider newProfileByAuthenticationProvider = new ProfileByAuthenticationProvider(); + newProfileByAuthenticationProvider.setAuthenticationProvider(pendingAccount.getAuthenticationProvider()); + newProfileByAuthenticationProvider.setAuthenticationProviderType(pendingAccount.getAuthenticationProviderType()); + newProfileByAuthenticationProvider.setProfileId(pendingAccount.getProfileId()); + batchOps.insert(newProfileByAuthenticationProvider); + } + +} diff --git a/src/main/java/biz/nynja/account/grpc/repositories/PendingAccountRepository.java b/src/main/java/biz/nynja/account/grpc/repositories/PendingAccountRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..ac63c8ae305967fa029871457d9f304feacf1746 --- /dev/null +++ b/src/main/java/biz/nynja/account/grpc/repositories/PendingAccountRepository.java @@ -0,0 +1,19 @@ +/** + * Copyright (C) 2018 Nynja Inc. All rights reserved. + */ +package biz.nynja.account.grpc.repositories; + +import java.util.UUID; + +import org.springframework.data.cassandra.repository.CassandraRepository; +import org.springframework.stereotype.Repository; + +import biz.nynja.account.grpc.models.Account; +import biz.nynja.account.grpc.models.PendingAccount; + +@Repository +public interface PendingAccountRepository extends CassandraRepository { + + public PendingAccount findByAccountId(UUID accountId); + +} diff --git a/src/main/java/biz/nynja/account/grpc/repositories/ProfileByAuthenticationProviderRepository.java b/src/main/java/biz/nynja/account/grpc/repositories/ProfileByAuthenticationProviderRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..45df8984a9ff62cf977ecc35a7437576e115b2bf --- /dev/null +++ b/src/main/java/biz/nynja/account/grpc/repositories/ProfileByAuthenticationProviderRepository.java @@ -0,0 +1,14 @@ +/** + * Copyright (C) 2018 Nynja Inc. All rights reserved. + */ +package biz.nynja.account.grpc.repositories; + +import org.springframework.data.cassandra.repository.CassandraRepository; +import org.springframework.stereotype.Repository; + +import biz.nynja.account.grpc.models.ProfileByAuthenticationProvider; + +@Repository +public interface ProfileByAuthenticationProviderRepository extends CassandraRepository{ + +} diff --git a/src/main/java/biz/nynja/account/grpc/repositories/ProfileRepository.java b/src/main/java/biz/nynja/account/grpc/repositories/ProfileRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..88f4336b0c19af5c1c5c7061b4014da9c6e89582 --- /dev/null +++ b/src/main/java/biz/nynja/account/grpc/repositories/ProfileRepository.java @@ -0,0 +1,18 @@ +/** + * Copyright (C) 2018 Nynja Inc. All rights reserved. + */ +package biz.nynja.account.grpc.repositories; + +import java.util.UUID; + +import org.springframework.data.cassandra.repository.CassandraRepository; +import org.springframework.stereotype.Repository; + +import biz.nynja.account.grpc.models.Profile; + +@Repository +public interface ProfileRepository extends CassandraRepository { + + public Profile findByProfileId(UUID profileId); + +} diff --git a/src/main/java/biz/nynja/account/grpc/repositories/UserInfoByEmailRepository.java b/src/main/java/biz/nynja/account/grpc/repositories/UserInfoByEmailRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..56acce7a002651cf0b628546f2a0ae1794ed7824 --- /dev/null +++ b/src/main/java/biz/nynja/account/grpc/repositories/UserInfoByEmailRepository.java @@ -0,0 +1,17 @@ +/** + * Copyright (C) 2018 Nynja Inc. All rights reserved. + */ +package biz.nynja.account.grpc.repositories; + +import java.util.List; + +import org.springframework.data.cassandra.repository.CassandraRepository; +import org.springframework.stereotype.Repository; + +import biz.nynja.account.grpc.models.UserInfoByEmail; + +@Repository +public interface UserInfoByEmailRepository extends CassandraRepository { + + List findByEmailAddress(String email); +} diff --git a/src/main/java/biz/nynja/account/grpc/repositories/UserInfoByPhoneRepository.java b/src/main/java/biz/nynja/account/grpc/repositories/UserInfoByPhoneRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..a05e46efd53f6216bc673083c2bc2029a532ac83 --- /dev/null +++ b/src/main/java/biz/nynja/account/grpc/repositories/UserInfoByPhoneRepository.java @@ -0,0 +1,15 @@ +package biz.nynja.account.grpc.repositories; + +import java.util.List; + +import org.springframework.data.cassandra.repository.CassandraRepository; +import org.springframework.stereotype.Repository; + +import biz.nynja.account.grpc.models.UserInfoByPhone; + +@Repository +public interface UserInfoByPhoneRepository extends CassandraRepository{ + + List findByPhoneNumber(String phoneNumber); + +} diff --git a/src/main/java/biz/nynja/account/grpc/repositories/UserInfoByUsernameRepository.java b/src/main/java/biz/nynja/account/grpc/repositories/UserInfoByUsernameRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..32f381e8620b1a9c5d1f4ea38a4f8649f2b37b10 --- /dev/null +++ b/src/main/java/biz/nynja/account/grpc/repositories/UserInfoByUsernameRepository.java @@ -0,0 +1,15 @@ +package biz.nynja.account.grpc.repositories; + +import java.util.List; + +import org.springframework.data.cassandra.repository.CassandraRepository; +import org.springframework.stereotype.Repository; + +import biz.nynja.account.grpc.models.UserInfoByUsername; + +@Repository +public interface UserInfoByUsernameRepository extends CassandraRepository { + + List findByUsername(String username); + +} diff --git a/src/main/java/biz/nynja/account/grpc/repositories/UserInfoRepository.java b/src/main/java/biz/nynja/account/grpc/repositories/UserInfoRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..550cac25f335eb902b07de4d214bd61a4a8b4343 --- /dev/null +++ b/src/main/java/biz/nynja/account/grpc/repositories/UserInfoRepository.java @@ -0,0 +1,17 @@ +/** + * Copyright (C) 2018 Nynja Inc. All rights reserved. + */ +package biz.nynja.account.grpc.repositories; + +import java.util.List; +import java.util.UUID; + +import org.springframework.data.cassandra.repository.CassandraRepository; + +import biz.nynja.account.grpc.models.UserInfo; + +public interface UserInfoRepository extends CassandraRepository { + + public List findAllByProfileId(UUID profileId); + +} diff --git a/src/main/java/biz/nynja/account/grpc/services/AccountServiceImpl.java b/src/main/java/biz/nynja/account/grpc/services/AccountServiceImpl.java index 27414ef60ccecaea8654b3ed57b94fa52242bf8d..46588004555743a791132736612d5014e4b0d8e2 100644 --- a/src/main/java/biz/nynja/account/grpc/services/AccountServiceImpl.java +++ b/src/main/java/biz/nynja/account/grpc/services/AccountServiceImpl.java @@ -3,18 +3,46 @@ */ package biz.nynja.account.grpc.services; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.UUID; + import org.lognet.springboot.grpc.GRpcService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import biz.nynja.account.grpc.models.AccountInfo; -import biz.nynja.account.grpc.repositories.AccountInfoRepository; -import biz.nynja.blueprint.grpc.AccountServiceGrpc; -import biz.nynja.blueprint.grpc.RegisterError; -import biz.nynja.blueprint.grpc.RegisterError.Cause; -import biz.nynja.blueprint.grpc.RegisterRequest; -import biz.nynja.blueprint.grpc.RegisterResponse; +import biz.nynja.account.grpc.AccountDetails; +import biz.nynja.account.grpc.AccountServiceGrpc; +import biz.nynja.account.grpc.AccountsByAuthenticationProviderRequest; +import biz.nynja.account.grpc.AccountsByProfileIdRequest; +import biz.nynja.account.grpc.AccountsResponse; +import biz.nynja.account.grpc.CompletePendingAccountCreationRequest; +import biz.nynja.account.grpc.CompletePendingAccountCreationResponse; +import biz.nynja.account.grpc.CreateAccountRequest; +import biz.nynja.account.grpc.CreateAccountResponse; +import biz.nynja.account.grpc.CreatePendingAccountRequest; +import biz.nynja.account.grpc.CreatePendingAccountResponse; +import biz.nynja.account.grpc.ErrorResponse; +import biz.nynja.account.grpc.ErrorResponse.Cause; +import biz.nynja.account.grpc.GetAccountsResponse; +import biz.nynja.account.grpc.components.Validator; +import biz.nynja.account.grpc.models.Account; +import biz.nynja.account.grpc.models.PendingAccount; +import biz.nynja.account.grpc.models.UserInfo; +import biz.nynja.account.grpc.models.UserInfoByEmail; +import biz.nynja.account.grpc.models.UserInfoByPhone; +import biz.nynja.account.grpc.repositories.AccountRepositoryAdditional; +import biz.nynja.account.grpc.repositories.PendingAccountRepository; +import biz.nynja.account.grpc.models.AccountByProfileId; +import biz.nynja.account.grpc.models.AuthenticationProvider; +import biz.nynja.account.grpc.models.UserInfoByPhone; +import biz.nynja.account.grpc.repositories.AccountByProfileIdRepository; +import biz.nynja.account.grpc.repositories.AccountRepository; +import biz.nynja.account.grpc.repositories.UserInfoByEmailRepository; +import biz.nynja.account.grpc.repositories.UserInfoByPhoneRepository; +import biz.nynja.account.grpc.repositories.UserInfoRepository; import io.grpc.stub.StreamObserver; /** @@ -25,32 +53,226 @@ import io.grpc.stub.StreamObserver; @GRpcService public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBase { - private static final Logger LOGGER = LoggerFactory.getLogger(AccountServiceImpl.class); + private static final Logger logger = LoggerFactory.getLogger(AccountServiceImpl.class); + + @Autowired + private UserInfoRepository userInfoRepository; + + @Autowired + private AccountRepository accountRepository; + + @Autowired + private AccountByProfileIdRepository accountByProfileIdRepository; + + @Autowired + private UserInfoByEmailRepository userInfoByEmailRepository; + + @Autowired + private PendingAccountRepository pendingAccountRepository; + + @Autowired + private AccountRepositoryAdditional accountRepositoryAdditional; + + @Autowired + private UserInfoByPhoneRepository userInfoByPhoneRepository; @Autowired - private AccountInfoRepository accountInfoRepository; + private Validator validator; @Override - public void register(RegisterRequest request, StreamObserver responseObserver) { + public void createAccount(CreateAccountRequest request, StreamObserver responseObserver) { - LOGGER.info("Got a gRPC service request: {}", request); + logger.info("Creating account..."); + logger.debug("Creating account: {} ...", request); - AccountInfo accountInfo = AccountInfo.fromProto(request); + Cause validationCause = validator.validateCreateAccountRequest(request); + if (validationCause != null) { + responseObserver.onNext(CreateAccountResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(validationCause)).build()); + responseObserver.onCompleted(); + return; + } - if (accountInfoRepository.findByEmail(accountInfo.getEmail()) != null) { - responseObserver.onNext(RegisterResponse.newBuilder() - .setError(RegisterError.newBuilder().setCause(Cause.EMAIL_ALREADY_USED)).build()); - responseObserver.onCompleted(); - return; - } + UserInfo userInfo = UserInfo.fromProto(request); + if (request.getProfileId() == null || request.getProfileId().isEmpty()) { + userInfo.setProfileId(UUID.randomUUID()); + } else { + userInfo.setProfileId(UUID.fromString(request.getProfileId())); + } + userInfo.setAccountId(UUID.randomUUID()); + // TODO set authentication provider + userInfo.setAuthenticationProviderId("id"); - AccountInfo savedAccount = accountInfoRepository.save(accountInfo); - LOGGER.info("Account \"{}\" saved into the DB", savedAccount.toString()); + UserInfo savedAccount = userInfoRepository.save(userInfo); + logger.debug("Account \"{}\" saved into the DB", savedAccount.toString()); - RegisterResponse response = RegisterResponse.newBuilder().setAccount(savedAccount.toProto()).build(); - LOGGER.info("Response from gRPC service: \"{}\"", response); + CreateAccountResponse response = CreateAccountResponse.newBuilder().setAccountDetails(savedAccount.toProto()) + .build(); + logger.info("Account created successfully."); + logger.debug("Account: \"{}\" created successfully.", response); responseObserver.onNext(response); responseObserver.onCompleted(); + + return; + } + + @Override + public void getAllAccountsByAuthenticationProvider(AccountsByAuthenticationProviderRequest request, + StreamObserver responseObserver) { + + logger.info("New get all accounts by authentication provider request recieved."); + logger.debug("New get all accounts by authentication provider request recieved: {}", request); + if (request.getAuthenticationType() == null) { + responseObserver.onNext(GetAccountsResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.MISSING_AUTH_PROVIDER_TYPE)).build()); + responseObserver.onCompleted(); + return; + } + if (request.getAuthenticationIdentifier() == null) { + responseObserver.onNext(GetAccountsResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.MISSING_AUTH_PROVIDER_IDENTIFIER)).build()); + responseObserver.onCompleted(); + return; + } + + List accountDetails = new ArrayList(); + + switch (request.getAuthenticationType()) { + case PHONE: { + + List relatedAccounts = userInfoByPhoneRepository + .findByPhoneNumber(request.getAuthenticationIdentifier()); + if (relatedAccounts.isEmpty()) { + responseObserver.onNext(GetAccountsResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.ACCOUNT_NOT_FOUND)).build()); + responseObserver.onCompleted(); + return; + } + + for (UserInfoByPhone account : relatedAccounts) { + accountDetails.add(account.toProto()); + } + GetAccountsResponse response = GetAccountsResponse.newBuilder() + .setAccountsResponse(AccountsResponse.newBuilder().addAllAccountDetails(accountDetails)).build(); + responseObserver.onNext(response); + responseObserver.onCompleted(); + } + case EMAIL: { + List relatedAccounts = userInfoByEmailRepository + .findByEmailAddress(request.getAuthenticationIdentifier()); + if (relatedAccounts.isEmpty()) { + responseObserver.onNext(GetAccountsResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.ACCOUNT_NOT_FOUND)).build()); + responseObserver.onCompleted(); + return; + } + for (UserInfoByEmail account : relatedAccounts) { + accountDetails.add(account.toProto()); + } + } + case FACEBOOK: + break; + case GOOGLEPLUS: + break; + case UNRECOGNIZED: + break; + default: + break; + + } + GetAccountsResponse response = GetAccountsResponse.newBuilder() + .setAccountsResponse(AccountsResponse.newBuilder().addAllAccountDetails(accountDetails)).build(); + + responseObserver.onNext(response); + responseObserver.onCompleted(); + } + + @Override + public void getAllAccountsByProfileId(AccountsByProfileIdRequest request, + StreamObserver responseObserver) { + logger.info("Getting accounts by profile ID..."); + + if ((request.getProfileId() == null) || (request.getProfileId().isEmpty())) { + responseObserver.onNext(GetAccountsResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.MISSING_PROFILE_ID)).build()); + responseObserver.onCompleted(); + return; + } + + List listAccountsByProfileId = accountByProfileIdRepository + .findAllByProfileId(UUID.fromString(request.getProfileId())); + + List responseList = new ArrayList(); + + if (listAccountsByProfileId.size() == 0) { + responseObserver.onNext(GetAccountsResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.ACCOUNT_NOT_FOUND)).build()); + responseObserver.onCompleted(); + return; + } + + for (AccountByProfileId account : listAccountsByProfileId) { + responseList.add(account.toProto()); + } + + GetAccountsResponse response = GetAccountsResponse.newBuilder() + .setAccountsResponse(AccountsResponse.newBuilder().addAllAccountDetails(responseList)).build(); + + logger.debug("Returned response: \"{}\".", response); + + responseObserver.onNext(response); + responseObserver.onCompleted(); + return; + } + + @Override + public void createPendingAccount(CreatePendingAccountRequest request, + StreamObserver responseObserver) { + + logger.info("Creating pending account..."); + logger.debug("Creating pending account: {} ...", request); + + PendingAccount pendingAccount = PendingAccount.fromProto(request); + pendingAccount.setAccountId(UUID.randomUUID()); + pendingAccount.setProfileId(UUID.randomUUID()); + pendingAccount.setCreationTimestamp(new Date().getTime()); + + PendingAccount savedPendingAccount = pendingAccountRepository.save(pendingAccount); + logger.debug("Pending account \"{}\" saved into the DB", savedPendingAccount.toString()); + CreatePendingAccountResponse response = CreatePendingAccountResponse.newBuilder() + .setPendingAccountDetails(savedPendingAccount.toProto()).build(); + logger.info("Pending account created successfully."); + logger.debug("Pending account: \"{}\" created successfully.", response); + + responseObserver.onNext(response); + responseObserver.onCompleted(); + + return; + } + + @Override + public void completePendingAccountCreation(CompletePendingAccountCreationRequest request, + StreamObserver responseObserver) { + logger.info("Complete pending account creation..."); + logger.debug("Complete pending account creation...: {} ...", request); + + Account createdAccount = accountRepositoryAdditional.completePendingAccountCreation(request); + + if (createdAccount == null) { + responseObserver.onNext(CompletePendingAccountCreationResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.ERROR_CREATING_ACCOUNT)).build()); + responseObserver.onCompleted(); + return; + } else { + logger.debug("Account \"{}\" saved into the DB", createdAccount.toString()); + CompletePendingAccountCreationResponse response = CompletePendingAccountCreationResponse.newBuilder() + .setAccountDetails(createdAccount.toCompletePendingAccountProto()).build(); + logger.debug("Account: \"{}\" created successfully.", response); + + responseObserver.onNext(response); + responseObserver.onCompleted(); + return; + } } -} +} \ No newline at end of file diff --git a/src/main/resources/countries.txt b/src/main/resources/countries.txt new file mode 100644 index 0000000000000000000000000000000000000000..60d177a7e180abf4ee8ccd0bb19268187e2f0cf7 --- /dev/null +++ b/src/main/resources/countries.txt @@ -0,0 +1,236 @@ +1876;JM;Jamaica;XXX XXXX +1869;KN;Saint Kitts & Nevis;XXX XXXX +1868;TT;Trinidad & Tobago;XXX XXXX +1784;VC;Saint Vincent & the Grenadines;XXX XXXX +1767;DM;Dominica;XXX XXXX +1758;LC;Saint Lucia;XXX XXXX +1721;SX;Sint Maarten;XXX XXXX +1684;AS;American Samoa;XXX XXXX +1671;GU;Guam;XXX XXXX +1670;MP;Northern Mariana Islands;XXX XXXX +1664;MS;Montserrat;XXX XXXX +1649;TC;Turks & Caicos Islands;XXX XXXX +1473;GD;Grenada;XXX XXXX +1441;BM;Bermuda;XXX XXXX +1345;KY;Cayman Islands;XXX XXXX +1340;VI;US Virgin Islands;XXX XXXX +1284;VG;British Virgin Islands;XXX XXXX +1268;AG;Antigua & Barbuda;XXX XXXX +1264;AI;Anguilla;XXX XXXX +1246;BB;Barbados;XXX XXXX +1242;BS;Bahamas;XXX XXXX +998;UZ;Uzbekistan;XX XXXXXXX +996;KG;Kyrgyzstan;XXX XXXXXX +995;GE;Georgia;XXX XXX XXX +994;AZ;Azerbaijan;XX XXX XXXX +993;TM;Turkmenistan;XX XXXXXX +992;TJ;Tajikistan;XX XXX XXXX +977;NP;Nepal;XX XXXX XXXX +976;MN;Mongolia;XX XX XXXX +975;BT;Bhutan;XX XXX XXX +974;QA;Qatar;XX XXX XXX +973;BH;Bahrain;XXXX XXXX +972;IL;Israel;XX XXX XXXX +971;AE;United Arab Emirates;XX XXX XXXX +970;PS;Palestine;XXX XX XXXX +968;OM;Oman;XXXX XXXX +967;YE;Yemen;XXX XXX XXX +966;SA;Saudi Arabia;XX XXX XXXX +965;KW;Kuwait;XXXX XXXX +964;IQ;Iraq;XXX XXX XXXX +963;SY;Syria;XXX XXX XXX +962;JO;Jordan;X XXXX XXXX +961;LB;Lebanon +960;MV;Maldives;XXX XXXX +886;TW;Taiwan;XXX XXX XXX +883;GO;International Networks +882;GO;International Networks +881;GO;Global Mobile Satellite +880;BD;Bangladesh +856;LA;Laos;XX XX XXX XXX +855;KH;Cambodia +853;MO;Macau;XXXX XXXX +852;HK;Hong Kong;X XXX XXXX +850;KP;North Korea +692;MH;Marshall Islands +691;FM;Micronesia +690;TK;Tokelau +689;PF;French Polynesia +688;TV;Tuvalu +687;NC;New Caledonia +686;KI;Kiribati +685;WS;Samoa +683;NU;Niue +682;CK;Cook Islands +681;WF;Wallis & Futuna +680;PW;Palau +679;FJ;Fiji +678;VU;Vanuatu +677;SB;Solomon Islands +676;TO;Tonga +675;PG;Papua New Guinea +674;NR;Nauru +673;BN;Brunei Darussalam;XXX XXXX +672;NF;Norfolk Island +670;TL;Timor-Leste +599;BQ;Bonaire, Sint Eustatius & Saba +599;CW;Curaçao +598;UY;Uruguay;X XXX XXXX +597;SR;Suriname;XXX XXXX +596;MQ;Martinique +595;PY;Paraguay;XXX XXX XXX +594;GF;French Guiana +593;EC;Ecuador;XX XXX XXXX +592;GY;Guyana +591;BO;Bolivia;X XXX XXXX +590;GP;Guadeloupe;XXX XX XX XX +509;HT;Haiti +508;PM;Saint Pierre & Miquelon +507;PA;Panama;XXXX XXXX +506;CR;Costa Rica;XXXX XXXX +505;NI;Nicaragua;XXXX XXXX +504;HN;Honduras;XXXX XXXX +503;SV;El Salvador;XXXX XXXX +502;GT;Guatemala;X XXX XXXX +501;BZ;Belize +500;FK;Falkland Islands +423;LI;Liechtenstein +421;SK;Slovakia;XXX XXX XXX +420;CZ;Czech Republic;XXX XXX XXX +389;MK;Macedonia;XX XXX XXX +387;BA;Bosnia & Herzegovina;XX XXX XXX +386;SI;Slovenia;XX XXX XXX +385;HR;Croatia +383;XK;Kosovo;XXXX XXXX +382;ME;Montenegro +381;RS;Serbia;XX XXX XXXX +380;UA;Ukraine;XX XXX XX XX +378;SM;San Marino;XXX XXX XXXX +377;MC;Monaco;XXXX XXXX +376;AD;Andorra;XX XX XX +375;BY;Belarus;XX XXX XXXX +374;AM;Armenia;XX XXX XXX +373;MD;Moldova;XX XXX XXX +372;EE;Estonia +371;LV;Latvia;XXX XXXXX +370;LT;Lithuania;XXX XXXXX +359;BG;Bulgaria +358;FI;Finland +357;CY;Cyprus;XXXX XXXX +356;MT;Malta;XX XX XX XX +355;AL;Albania;XX XXX XXXX +354;IS;Iceland;XXX XXXX +353;IE;Ireland;XX XXX XXXX +352;LU;Luxembourg +351;PT;Portugal;X XXXX XXXX +350;GI;Gibraltar;XXXX XXXX +299;GL;Greenland;XXX XXX +298;FO;Faroe Islands;XXX XXX +297;AW;Aruba;XXX XXXX +291;ER;Eritrea;X XXX XXX +290;SH;Saint Helena;XX XXX +269;KM;Comoros;XXX XXXX +268;SZ;Swaziland;XXXX XXXX +267;BW;Botswana;XX XXX XXX +266;LS;Lesotho;XX XXX XXX +265;MW;Malawi;77 XXX XXXX +264;NA;Namibia;XX XXX XXXX +263;ZW;Zimbabwe;XX XXX XXXX +262;RE;Réunion;XXX XXX XXX +261;MG;Madagascar;XX XX XXX XX +260;ZM;Zambia;XX XXX XXXX +258;MZ;Mozambique;XX XXX XXXX +257;BI;Burundi;XX XX XXXX +256;UG;Uganda;XX XXX XXXX +255;TZ;Tanzania;XX XXX XXXX +254;KE;Kenya;XXX XXX XXX +253;DJ;Djibouti;XX XX XX XX +252;SO;Somalia;XX XXX XXX +251;ET;Ethiopia;XX XXX XXXX +250;RW;Rwanda;XXX XXX XXX +249;SD;Sudan;XX XXX XXXX +248;SC;Seychelles;X XX XX XX +247;SH;Saint Helena;XXXX +246;IO;Diego Garcia;XXX XXXX +245;GW;Guinea-Bissau;XXX XXXX +244;AO;Angola;XXX XXX XXX +243;CD;Congo (Dem. Rep.);XX XXX XXXX +242;CG;Congo (Rep.);XX XXX XXXX +241;GA;Gabon;X XX XX XX +240;GQ;Equatorial Guinea;XXX XXX XXX +239;ST;São Tomé & Príncipe;XX XXXXX +238;CV;Cape Verde;XXX XXXX +237;CM;Cameroon;XXXX XXXX +236;CF;Central African Rep.;XX XX XX XX +235;TD;Chad;XX XX XX XX +234;NG;Nigeria +233;GH;Ghana +232;SL;Sierra Leone;XX XXX XXX +231;LR;Liberia +230;MU;Mauritius +229;BJ;Benin;XX XXX XXX +228;TG;Togo;XX XXX XXX +227;NE;Niger;XX XX XX XX +226;BF;Burkina Faso;XX XX XX XX +225;CI;Côte d`Ivoire;XX XXX XXX +224;GN;Guinea;XXX XXX XXX +223;ML;Mali;XXXX XXXX +222;MR;Mauritania;XXXX XXXX +221;SN;Senegal;XX XXX XXXX +220;GM;Gambia;XXX XXXX +218;LY;Libya;XX XXX XXXX +216;TN;Tunisia;XX XXX XXX +213;DZ;Algeria;XXX XX XX XX +212;MA;Morocco;XX XXX XXXX +211;SS;South Sudan;XX XXX XXXX +98;IR;Iran;XXX XXX XXXX +95;MM;Myanmar +94;LK;Sri Lanka;XX XXX XXXX +93;AF;Afghanistan;XXX XXX XXX +92;PK;Pakistan;XXX XXX XXXX +91;IN;India;XXXXX XXXXX +90;TR;Turkey;XXX XXX XXXX +86;CN;China;XXX XXXX XXXX +84;VN;Vietnam +82;KR;South Korea +81;JP;Japan;XX XXXX XXXX +66;TH;Thailand;X XXXX XXXX +65;SG;Singapore;XXXX XXXX +64;NZ;New Zealand +63;PH;Philippines;XXX XXX XXXX +62;ID;Indonesia +61;AU;Australia;XXX XXX XXX +60;MY;Malaysia +58;VE;Venezuela;XXX XXX XXXX +57;CO;Colombia;XXX XXX XXXX +56;CL;Chile;X XXXX XXXX +55;BR;Brazil;XX XXXXX XXXX +54;AR;Argentina +53;CU;Cuba;XXXX XXXX +52;MX;Mexico +51;PE;Peru;XXX XXX XXX +49;DE;Germany +48;PL;Poland;XX XXX XXXX +47;NO;Norway;XXXX XXXX +46;SE;Sweden;XX XXX XXXX +45;DK;Denmark;XXXX XXXX +44;GB;United Kingdom;XXXX XXXXXX +43;AT;Austria +42;YL;Y-land +41;CH;Switzerland;XX XXX XXXX +40;RO;Romania;XXX XXX XXX +39;IT;Italy +36;HU;Hungary;XXX XXX XXX +34;ES;Spain;XXX XXX XXX +33;FR;France;X XX XX XX XX +32;BE;Belgium;XXX XX XX XX +31;NL;Netherlands;X XX XX XX XX +30;GR;Greece;XXX XXX XXXX +27;ZA;South Africa;XX XXX XXXX +20;EG;Egypt;XX XXXX XXXX +7;KZ;Kazakhstan;XXX XXX XX XX +7;RU;Russian Federation;XXX XXX XXXX +1;PR;Puerto Rico;XXX XXX XXXX +1;DO;Dominican Rep.;XXX XXX XXXX +1;CA;Canada;XXX XXX XXXX +1;US;USA;XXX XXX XXXX \ No newline at end of file diff --git a/src/main/resources/logback-spring.groovy b/src/main/resources/logback-spring.groovy new file mode 100644 index 0000000000000000000000000000000000000000..84642ac1546a3b4c28f398b35e72694a355a8391 --- /dev/null +++ b/src/main/resources/logback-spring.groovy @@ -0,0 +1,28 @@ +/** + * Copyright (C) 2018 Nynja Inc. All rights reserved. + */ + +import ch.qos.logback.classic.encoder.PatternLayoutEncoder +import ch.qos.logback.core.rolling.RollingFileAppender +import ch.qos.logback.core.rolling.TimeBasedRollingPolicy +import ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP +import ch.qos.logback.core.status.OnConsoleStatusListener +import ch.qos.logback.classic.Level + +statusListener(OnConsoleStatusListener) + +def file = "${System.getProperty('log.dir', '')}account-service-%d.%i.log" + +appender("FILE", RollingFileAppender) { + // add a status message regarding the file property + addInfo("Starting logging to $file") + append = true + encoder(PatternLayoutEncoder) { pattern = "%d{HH:mm:ss.SSS} %level %logger - %msg%n" } + rollingPolicy(TimeBasedRollingPolicy) { + fileNamePattern = "$file" + timeBasedFileNamingAndTriggeringPolicy(SizeAndTimeBasedFNATP) { maxFileSize = "10mb" }} +} + +logger("org.springframework.cloud.config.client.ConfigServicePropertySourceLocator", Level.WARN) + +root(Level.toLevel("${System.getProperty('log.level', 'INFO')}"), ["FILE"]) \ No newline at end of file diff --git a/src/test/java/biz/nynja/account/grpc/ApplicationTests.java b/src/test/java/biz/nynja/account/grpc/ApplicationTests.java index c0ea2a8f27aac7219c5b209a0bf3d296b84b2287..0c31adf5206036bac4a97a981f495bf4ed59a640 100644 --- a/src/test/java/biz/nynja/account/grpc/ApplicationTests.java +++ b/src/test/java/biz/nynja/account/grpc/ApplicationTests.java @@ -1,88 +1,24 @@ /** - * Copyright (C) 2018 Nynja Inc. All rights reserved. + * Copyright (C) 2018 Nynja Inc. All rights reserved. */ -package biz.nynja.account.grpc; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.BDDMockito.given; -import java.util.Optional; -import java.util.concurrent.ExecutionException; +package biz.nynja.account.grpc; import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; -import biz.nynja.account.grpc.models.AccountInfo; -import biz.nynja.account.grpc.repositories.AccountInfoRepository; -import biz.nynja.blueprint.grpc.AccountServiceGrpc; -import biz.nynja.blueprint.grpc.RegisterError; -import biz.nynja.blueprint.grpc.RegisterRequest; -import biz.nynja.blueprint.grpc.RegisterResponse; +/** + * Main unit test. + */ @RunWith(SpringRunner.class) -@SpringBootTest(classes = Util.class, - properties = { - "spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration", - "spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration" }) -@ActiveProfiles("dev") -public class ApplicationTests extends GrpcServerTestBase { - - @MockBean - private AccountInfoRepository accountInfoRepository; - - @Autowired - @Qualifier("newAccount") - private AccountInfo accountInfo; - - @Autowired - @Qualifier("savedAccount") - private AccountInfo savedAccount; +@ContextConfiguration(classes = { Application.class }) +public class ApplicationTests { @Test - public void testRegister() throws ExecutionException, InterruptedException { - - String testEmail = "email@test.com"; - final RegisterRequest request = RegisterRequest.newBuilder().setId(1).setEmail(testEmail).setPassword("abc") - .build(); - - given(accountInfoRepository.findByEmail(testEmail)).willReturn(null); - given(accountInfoRepository.save(any(AccountInfo.class))).willReturn(savedAccount); - - final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc - .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); - - final RegisterResponse reply = accountServiceBlockingStub.register(request); - - assertNotNull("Reply should not be null", reply); - assertTrue(String.format("Reply should contain email '%s'", testEmail), - reply.getAccount().getEmail().equals(testEmail)); - } - - @Test - public void testRegisterExistEmail() throws ExecutionException, InterruptedException { - - String testEmail = "email@test.com"; - final RegisterRequest request = RegisterRequest.newBuilder().setId(1).setEmail(testEmail).setPassword("abc") - .build(); - - given(accountInfoRepository.findByEmail(testEmail)).willReturn(accountInfo); - - final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc - .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); - - final RegisterResponse reply = accountServiceBlockingStub.register(request); - - assertNotNull("Reply should not be null", reply); - assertTrue(String.format("Reply should contain cause '%s'", testEmail), - reply.getError().getCause().equals(RegisterError.Cause.EMAIL_ALREADY_USED)); + public void testContext() { } } diff --git a/src/test/java/biz/nynja/account/grpc/Util.java b/src/test/java/biz/nynja/account/grpc/Util.java deleted file mode 100644 index 8a9b1d945cd25b4518ecc9eadbb4e1c9e8072348..0000000000000000000000000000000000000000 --- a/src/test/java/biz/nynja/account/grpc/Util.java +++ /dev/null @@ -1,32 +0,0 @@ -package biz.nynja.account.grpc; - -import org.springframework.boot.test.context.TestConfiguration; -import org.springframework.context.annotation.Bean; - -import biz.nynja.account.grpc.models.AccountInfo;; - -@TestConfiguration -public class Util { - - public static final Long ID = 1L; - public static final String EMAIL = "email@test.com"; - public static final String PASSWORD = "abc"; - - @Bean - public AccountInfo newAccount() { - AccountInfo accountInfo = new AccountInfo(); - accountInfo.setId(ID); - accountInfo.setEmail(EMAIL); - accountInfo.setPassword(PASSWORD); - return accountInfo; - } - - @Bean - public AccountInfo savedAccount() { - AccountInfo accountInfo = new AccountInfo(); - accountInfo.setId(ID); - accountInfo.setEmail(EMAIL); - accountInfo.setPassword(PASSWORD); - return accountInfo; - } -} diff --git a/src/test/java/biz/nynja/account/grpc/components/ValidatorTests.java b/src/test/java/biz/nynja/account/grpc/components/ValidatorTests.java new file mode 100644 index 0000000000000000000000000000000000000000..480021008521c9dff64f2fe651b3729db4cd4679 --- /dev/null +++ b/src/test/java/biz/nynja/account/grpc/components/ValidatorTests.java @@ -0,0 +1,138 @@ +/** + * Copyright (C) 2018 Nynja Inc. All rights reserved. + */ + +package biz.nynja.account.grpc.components; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +import biz.nynja.account.grpc.repositories.UserInfoByEmailRepository; +import biz.nynja.account.grpc.repositories.UserInfoByPhoneRepository; +import biz.nynja.account.grpc.repositories.UserInfoByUsernameRepository; + +/** + * Components unit tests. + */ + +@RunWith(SpringRunner.class) +@ContextConfiguration(classes = { Validator.class }) +public class ValidatorTests { + + @Autowired + private Validator validator; + + @MockBean + private UserInfoByEmailRepository userInfoByEmailRepository; + + @MockBean + private UserInfoByPhoneRepository userInfoByPhoneRepository; + + @MockBean + private UserInfoByUsernameRepository userInfoByUsernameRepository; + + @Test + public void validPhoneNumberTest() { + + String phoneNumber = "+359887434646"; + String countryCode = "BG"; + boolean isValid = validator.isPhoneNumberValid(phoneNumber, countryCode); + assertTrue(String.format("Phone number: '%s' should be valid for country '%s'", phoneNumber, countryCode), + isValid == true); + + } + + @Test + public void invalidPhoneNumberTest() { + + String phoneNumber = "+357887434646"; + String countryCode = "BG"; + boolean isValid = validator.isPhoneNumberValid(phoneNumber, countryCode); + assertFalse(String.format("Phone number: '%s' should be invalid for country '%s'", phoneNumber, countryCode), + isValid == true); + + } + + @Test + public void validUsernameTest() { + + String username = "VALID_username1"; + boolean isValid = validator.isUsernameValid(username); + assertTrue(String.format("Username: '%s' should be valid.", username), isValid == true); + + } + + @Test + public void invalidUsernameTest() { + + String username = "INVALID-username1"; + boolean isValid = validator.isUsernameValid(username); + assertFalse(String.format("Username: '%s' should be invalid.", username), isValid == true); + + } + + @Test + public void validEmailTest() { + + String email = "valid.E-mail1@domain-sub.test.com"; + boolean isValid = validator.isEmailValid(email); + assertTrue(String.format("Email: '%s' should be valid.", email), isValid == true); + + } + + @Test + public void invalidEmailTest() { + + String email = "invalid.E-mail1.@domain_test.com1"; + boolean isValid = validator.isEmailValid(email); + assertFalse(String.format("Email: '%s' should be invalid.", email), isValid == true); + + } + + @Test + public void validFistNameTest() { + + String fistName = "Validfirstname"; + boolean isValid = validator.isFirstNameValid(fistName); + assertTrue(String.format("First name: '%s' should be valid.", fistName), isValid == true); + + } + + @Test + public void invalidFirstNameTest() { + + String fistName = "VeryINVALIDFirstNameThisIsForReal"; + boolean isValid = validator.isFirstNameValid(fistName); + assertFalse(String.format("First name: '%s' should be invalid.", fistName), isValid == true); + + } + + @Test + public void validLastNameTest() { + + String lastName = "Validlastname"; + boolean isValid = validator.isLastNameValid(lastName); + assertTrue(String.format("Username: '%s' should be valid.", lastName), isValid == true); + + lastName = ""; + isValid = validator.isLastNameValid(lastName); + assertTrue(String.format("Last name: '%s' should be valid.", lastName), isValid == true); + + } + + @Test + public void invalidlastNameTest() { + + String lastName = "VeryINVALIDFirstNameThisIsForReal"; + boolean isValid = validator.isLastNameValid(lastName); + assertFalse(String.format("Last name: '%s' should be invalid.", lastName), isValid == true); + + } +} diff --git a/src/test/java/biz/nynja/account/grpc/services/AccountServiceTests.java b/src/test/java/biz/nynja/account/grpc/services/AccountServiceTests.java new file mode 100644 index 0000000000000000000000000000000000000000..a7a6820ae5b7aa55b259e779d7dab434ee34d678 --- /dev/null +++ b/src/test/java/biz/nynja/account/grpc/services/AccountServiceTests.java @@ -0,0 +1,527 @@ +/** + * Copyright (C) 2018 Nynja Inc. All rights reserved. + */ +package biz.nynja.account.grpc.services; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.UUID; +import java.util.concurrent.ExecutionException; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + +import com.datastax.driver.core.Session; + +import biz.nynja.account.grpc.AccountServiceGrpc; +import biz.nynja.account.grpc.AccountsByAuthenticationProviderRequest; +import biz.nynja.account.grpc.AccountsByProfileIdRequest; +import biz.nynja.account.grpc.AuthenticationType; +import biz.nynja.account.grpc.CreateAccountRequest; +import biz.nynja.account.grpc.CreateAccountResponse; +import biz.nynja.account.grpc.ErrorResponse.Cause; +import biz.nynja.account.grpc.GetAccountsResponse; +import biz.nynja.account.grpc.Status; +import biz.nynja.account.grpc.models.UserInfo; +import biz.nynja.account.grpc.models.UserInfoByEmail; +import biz.nynja.account.grpc.models.UserInfoByPhone; +import biz.nynja.account.grpc.models.UserInfoByUsername; +import biz.nynja.account.grpc.repositories.UserInfoByEmailRepository; +import biz.nynja.account.grpc.repositories.UserInfoByPhoneRepository; +import biz.nynja.account.grpc.repositories.UserInfoByUsernameRepository; +import biz.nynja.account.grpc.repositories.UserInfoRepository; +import biz.nynja.account.grpc.utils.GrpcServerTestBase; +import biz.nynja.account.grpc.utils.Util; + +/** + * AccountService unit tests. + */ + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = Util.class, + webEnvironment = WebEnvironment.RANDOM_PORT, + properties = { + "spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration", + "spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration" }) +@ActiveProfiles("dev") +public class AccountServiceTests extends GrpcServerTestBase { + + @MockBean + private UserInfoRepository userInfoRepository; + + @MockBean + private UserInfoByEmailRepository userInfoByEmailRepository; + + @MockBean + private UserInfoByPhoneRepository userInfoByPhoneRepository; + + @MockBean + private Session session; + + @MockBean + private UserInfoByUsernameRepository userInfoByUsernameRepository; + + @Autowired + @Qualifier("newAccount") + private UserInfo newAccount; + + @Autowired + @Qualifier("savedAccount") + private UserInfo savedAccount; + + @Autowired + private UserInfoByEmail userInfoByEmail; + + @Autowired + private UserInfoByPhone userInfoByPhone; + + @Test + public void testCreateAccountByEmail() throws ExecutionException, InterruptedException { + final CreateAccountRequest request = CreateAccountRequest.newBuilder().setFirstName(Util.FIRST_NAME) + .setLastName(Util.LAST_NAME).setMiddleName(Util.MIDDLE_NAME) + .setAuthenticationType(AuthenticationType.EMAIL).setUsername(Util.USERNAME).setPassword(Util.PASSWORD) + .setEmailAddress(Util.EMAIL).setStatus(Status.SUSPENDED).build(); + + List usersByPhone = new ArrayList<>(); + List usersByEmail = new ArrayList<>(); + List usersByUsername = new ArrayList<>(); + given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); + given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); + given(userInfoByUsernameRepository.findByUsername(Util.USERNAME)).willReturn(usersByUsername); + given(userInfoRepository.save(any(UserInfo.class))).willReturn(savedAccount); + + final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final CreateAccountResponse reply = accountServiceBlockingStub.createAccount(request); + + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain email '%s'", Util.EMAIL), + reply.getAccountDetails().getEmailAddress().equals(Util.EMAIL)); + } + + @Test + public void testCreateAccountExistEmail() throws ExecutionException, InterruptedException { + final CreateAccountRequest request = CreateAccountRequest.newBuilder().setFirstName(Util.FIRST_NAME) + .setLastName(Util.LAST_NAME).setMiddleName(Util.MIDDLE_NAME) + .setAuthenticationType(AuthenticationType.EMAIL).setUsername(Util.USERNAME).setPassword(Util.PASSWORD) + .setEmailAddress(Util.EMAIL).setPhoneNumber(Util.PHONE_NUMBER).setCountryCode("BG") + .setStatus(Status.SUSPENDED).build(); + + List usersByPhone = new ArrayList<>(); + List usersByEmail = new ArrayList<>(); + usersByEmail.add(new UserInfoByEmail()); + List usersByUsername = new ArrayList<>(); + given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); + given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); + given(userInfoByUsernameRepository.findByUsername(Util.USERNAME)).willReturn(usersByUsername); + given(userInfoRepository.save(any(UserInfo.class))).willReturn(savedAccount); + + final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final CreateAccountResponse reply = accountServiceBlockingStub.createAccount(request); + + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain cause '%s'", Cause.EMAIL_ALREADY_USED), + reply.getError().getCause().equals(Cause.EMAIL_ALREADY_USED)); + } + + @Test + public void testCreateAccountByPhone() throws ExecutionException, InterruptedException { + final CreateAccountRequest request = CreateAccountRequest.newBuilder().setFirstName(Util.FIRST_NAME) + .setLastName(Util.LAST_NAME).setMiddleName(Util.MIDDLE_NAME) + .setAuthenticationType(AuthenticationType.PHONE).setUsername(Util.USERNAME).setPassword(Util.PASSWORD) + .setPhoneNumber(Util.PHONE_NUMBER).setCountryCode("BG").setStatus(Status.SUSPENDED).build(); + + List usersByPhone = new ArrayList<>(); + List usersByEmail = new ArrayList<>(); + List usersByUsername = new ArrayList<>(); + given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); + given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); + given(userInfoByUsernameRepository.findByUsername(Util.USERNAME)).willReturn(usersByUsername); + given(userInfoRepository.save(any(UserInfo.class))).willReturn(savedAccount); + + final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final CreateAccountResponse reply = accountServiceBlockingStub.createAccount(request); + + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain phone '%s'", Util.PHONE_NUMBER), + reply.getAccountDetails().getPhoneNumber().equals(Util.PHONE_NUMBER)); + } + + @Test + public void testCreateAccountExistPhone() throws ExecutionException, InterruptedException { + final CreateAccountRequest request = CreateAccountRequest.newBuilder().setFirstName(Util.FIRST_NAME) + .setLastName(Util.LAST_NAME).setMiddleName(Util.MIDDLE_NAME) + .setAuthenticationType(AuthenticationType.PHONE).setUsername(Util.USERNAME).setPassword(Util.PASSWORD) + .setPhoneNumber(Util.PHONE_NUMBER).setCountryCode("BG").setStatus(Status.SUSPENDED).build(); + + List usersByPhone = new ArrayList<>(); + usersByPhone.add(new UserInfoByPhone()); + List usersByEmail = new ArrayList<>(); + List usersByUsername = new ArrayList<>(); + given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); + given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); + given(userInfoByUsernameRepository.findByUsername(Util.USERNAME)).willReturn(usersByUsername); + given(userInfoRepository.save(any(UserInfo.class))).willReturn(savedAccount); + + final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final CreateAccountResponse reply = accountServiceBlockingStub.createAccount(request); + + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain cause '%s'", Cause.PHONE_NUMBER_ALREADY_USED), + reply.getError().getCause().equals(Cause.PHONE_NUMBER_ALREADY_USED)); + } + + @Test + public void testCreateAccountExistUsername() throws ExecutionException, InterruptedException { + final CreateAccountRequest request = CreateAccountRequest.newBuilder().setFirstName(Util.FIRST_NAME) + .setLastName(Util.LAST_NAME).setMiddleName(Util.MIDDLE_NAME) + .setAuthenticationType(AuthenticationType.PHONE).setUsername(Util.USERNAME).setPassword(Util.PASSWORD) + .setPhoneNumber(Util.PHONE_NUMBER).setCountryCode("BG").setStatus(Status.SUSPENDED).build(); + + List usersByPhone = new ArrayList<>(); + List usersByEmail = new ArrayList<>(); + List usersByUsername = new ArrayList<>(); + usersByUsername.add(new UserInfoByUsername()); + given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); + given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); + given(userInfoByUsernameRepository.findByUsername(Util.USERNAME)).willReturn(usersByUsername); + given(userInfoRepository.save(any(UserInfo.class))).willReturn(savedAccount); + + final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final CreateAccountResponse reply = accountServiceBlockingStub.createAccount(request); + + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain cause '%s'", Cause.USERNAME_ALREADY_USED), + reply.getError().getCause().equals(Cause.USERNAME_ALREADY_USED)); + } + + @Test + public void testCreateAccountInvalidUsername() throws ExecutionException, InterruptedException { + final CreateAccountRequest request = CreateAccountRequest.newBuilder().setFirstName(Util.FIRST_NAME) + .setLastName(Util.LAST_NAME).setMiddleName(Util.MIDDLE_NAME) + .setAuthenticationType(AuthenticationType.PHONE).setUsername(".Invalid-Username.") + .setPassword(Util.PASSWORD).setPhoneNumber(Util.PHONE_NUMBER).setCountryCode("BG") + .setStatus(Status.SUSPENDED).build(); + + List usersByPhone = new ArrayList<>(); + List usersByEmail = new ArrayList<>(); + List usersByUsername = new ArrayList<>(); + given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); + given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); + given(userInfoByUsernameRepository.findByUsername(Util.USERNAME)).willReturn(usersByUsername); + given(userInfoRepository.save(any(UserInfo.class))).willReturn(savedAccount); + + final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final CreateAccountResponse reply = accountServiceBlockingStub.createAccount(request); + + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain cause '%s'", Cause.USERNAME_INVALID), + reply.getError().getCause().equals(Cause.USERNAME_INVALID)); + } + + @Test + public void testCreateAccountMissingFirstName() throws ExecutionException, InterruptedException { + final CreateAccountRequest request = CreateAccountRequest.newBuilder().setLastName(Util.LAST_NAME) + .setMiddleName(Util.MIDDLE_NAME).setAuthenticationType(AuthenticationType.PHONE) + .setUsername(Util.USERNAME).setPassword(Util.PASSWORD).setPhoneNumber(Util.PHONE_NUMBER) + .setCountryCode("BG").setStatus(Status.SUSPENDED).build(); + + List usersByPhone = new ArrayList<>(); + List usersByEmail = new ArrayList<>(); + List usersByUsername = new ArrayList<>(); + given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); + given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); + given(userInfoByUsernameRepository.findByUsername(Util.USERNAME)).willReturn(usersByUsername); + given(userInfoRepository.save(any(UserInfo.class))).willReturn(savedAccount); + + final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final CreateAccountResponse reply = accountServiceBlockingStub.createAccount(request); + + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain cause '%s'", Cause.MISSING_FIRST_NAME), + reply.getError().getCause().equals(Cause.MISSING_FIRST_NAME)); + } + + @Test + public void testCreateAccountInvalidFirstName() throws ExecutionException, InterruptedException { + final CreateAccountRequest request = CreateAccountRequest.newBuilder().setFirstName("n") + .setLastName(Util.LAST_NAME).setMiddleName(Util.MIDDLE_NAME) + .setAuthenticationType(AuthenticationType.PHONE).setUsername(Util.USERNAME).setPassword(Util.PASSWORD) + .setPhoneNumber(Util.PHONE_NUMBER).setCountryCode("BG").setStatus(Status.SUSPENDED).build(); + + List usersByPhone = new ArrayList<>(); + List usersByEmail = new ArrayList<>(); + List usersByUsername = new ArrayList<>(); + given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); + given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); + given(userInfoByUsernameRepository.findByUsername(Util.USERNAME)).willReturn(usersByUsername); + given(userInfoRepository.save(any(UserInfo.class))).willReturn(savedAccount); + + final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final CreateAccountResponse reply = accountServiceBlockingStub.createAccount(request); + + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain cause '%s'", Cause.INVALID_FIRST_NAME), + reply.getError().getCause().equals(Cause.INVALID_FIRST_NAME)); + } + + @Test + public void testCreateAccountInvalidLastName() throws ExecutionException, InterruptedException { + final CreateAccountRequest request = CreateAccountRequest.newBuilder().setFirstName(Util.FIRST_NAME) + .setLastName("ThisIsNotaValidLastNameIndeedAndItIsNotReal").setMiddleName(Util.MIDDLE_NAME) + .setAuthenticationType(AuthenticationType.PHONE).setUsername(Util.USERNAME).setPassword(Util.PASSWORD) + .setPhoneNumber(Util.PHONE_NUMBER).setCountryCode("BG").setStatus(Status.SUSPENDED).build(); + + List usersByPhone = new ArrayList<>(); + List usersByEmail = new ArrayList<>(); + List usersByUsername = new ArrayList<>(); + given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); + given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); + given(userInfoByUsernameRepository.findByUsername(Util.USERNAME)).willReturn(usersByUsername); + given(userInfoRepository.save(any(UserInfo.class))).willReturn(savedAccount); + + final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final CreateAccountResponse reply = accountServiceBlockingStub.createAccount(request); + + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain cause '%s'", Cause.INVALID_LAST_NAME), + reply.getError().getCause().equals(Cause.INVALID_LAST_NAME)); + } + + @Test + public void testCreateAccountInvalidEmail() throws ExecutionException, InterruptedException { + final CreateAccountRequest request = CreateAccountRequest.newBuilder().setFirstName(Util.FIRST_NAME) + .setLastName(Util.LAST_NAME).setMiddleName(Util.MIDDLE_NAME) + .setAuthenticationType(AuthenticationType.EMAIL).setUsername(Util.USERNAME).setPassword(Util.PASSWORD) + .setEmailAddress(".invalid@email-.com").setStatus(Status.SUSPENDED).build(); + + List usersByPhone = new ArrayList<>(); + List usersByEmail = new ArrayList<>(); + List usersByUsername = new ArrayList<>(); + given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); + given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); + given(userInfoByUsernameRepository.findByUsername(Util.USERNAME)).willReturn(usersByUsername); + given(userInfoRepository.save(any(UserInfo.class))).willReturn(savedAccount); + + final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final CreateAccountResponse reply = accountServiceBlockingStub.createAccount(request); + + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain cause '%s'", Cause.EMAIL_INVALID), + reply.getError().getCause().equals(Cause.EMAIL_INVALID)); + } + + @Test + public void testCreateAccountInvalidPhone() throws ExecutionException, InterruptedException { + final CreateAccountRequest request = CreateAccountRequest.newBuilder().setFirstName(Util.FIRST_NAME) + .setLastName(Util.LAST_NAME).setMiddleName(Util.MIDDLE_NAME) + .setAuthenticationType(AuthenticationType.PHONE).setUsername(Util.USERNAME).setPassword(Util.PASSWORD) + .setPhoneNumber("+45955588833648946512957").setCountryCode("BG").setStatus(Status.SUSPENDED).build(); + + List usersByPhone = new ArrayList<>(); + List usersByEmail = new ArrayList<>(); + List usersByUsername = new ArrayList<>(); + given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); + given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); + given(userInfoByUsernameRepository.findByUsername(Util.USERNAME)).willReturn(usersByUsername); + given(userInfoRepository.save(any(UserInfo.class))).willReturn(savedAccount); + + final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final CreateAccountResponse reply = accountServiceBlockingStub.createAccount(request); + + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain cause '%s'", Cause.PHONE_NUMBER_INVALID), + reply.getError().getCause().equals(Cause.PHONE_NUMBER_INVALID)); + } + + @Test + public void testGetAccountsByEmail() throws ExecutionException, InterruptedException { + final AccountsByAuthenticationProviderRequest request = AccountsByAuthenticationProviderRequest.newBuilder() + .setAuthenticationType(AuthenticationType.EMAIL).setAuthenticationIdentifier(Util.EMAIL).build(); + + List usersByEmail = new ArrayList<>(); + usersByEmail.add(userInfoByEmail); + given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); + + final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final GetAccountsResponse reply = accountServiceBlockingStub.getAllAccountsByAuthenticationProvider(request); + + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain email '%s'", Util.EMAIL), + reply.getAccountsResponse().getAccountDetails(0).getEmailAddress().equals(Util.EMAIL)); + } + + @Test + public void testGetAccountsByEmailNotFound() throws ExecutionException, InterruptedException { + final AccountsByAuthenticationProviderRequest request = AccountsByAuthenticationProviderRequest.newBuilder() + .setAuthenticationType(AuthenticationType.EMAIL).setAuthenticationIdentifier(Util.EMAIL).build(); + + List usersByEmail = new ArrayList<>(); + given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); + + final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final GetAccountsResponse reply = accountServiceBlockingStub.getAllAccountsByAuthenticationProvider(request); + + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain cause '%s'", Cause.ACCOUNT_NOT_FOUND), + reply.getError().getCause().equals(Cause.ACCOUNT_NOT_FOUND)); + } + + @Test + public void testGetAccountsByEmailBadRequest() throws ExecutionException, InterruptedException { + final AccountsByAuthenticationProviderRequest request = AccountsByAuthenticationProviderRequest.newBuilder() + .setAuthenticationType(AuthenticationType.EMAIL).build(); + + final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final GetAccountsResponse reply = accountServiceBlockingStub.getAllAccountsByAuthenticationProvider(request); + + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain cause '%s'", Cause.ACCOUNT_NOT_FOUND), + reply.getError().getCause().equals(Cause.ACCOUNT_NOT_FOUND)); + } + + @Test + public void testGetAccountsByPhone() throws ExecutionException, InterruptedException { + final AccountsByAuthenticationProviderRequest request = AccountsByAuthenticationProviderRequest.newBuilder() + .setAuthenticationType(AuthenticationType.PHONE).setAuthenticationIdentifier(Util.PHONE_NUMBER).build(); + + List usersByPhone = new ArrayList<>(); + usersByPhone.add(userInfoByPhone); + given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); + + final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final GetAccountsResponse reply = accountServiceBlockingStub.getAllAccountsByAuthenticationProvider(request); + + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain phone '%s'", Util.PHONE_NUMBER), + reply.getAccountsResponse().getAccountDetails(0).getPhoneNumber().equals(Util.PHONE_NUMBER)); + } + + @Test + public void testGetAccountsByPhoneNotFound() throws ExecutionException, InterruptedException { + final AccountsByAuthenticationProviderRequest request = AccountsByAuthenticationProviderRequest.newBuilder() + .setAuthenticationType(AuthenticationType.PHONE).setAuthenticationIdentifier(Util.PHONE_NUMBER).build(); + + List usersByPhone = new ArrayList<>(); + given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); + + final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final GetAccountsResponse reply = accountServiceBlockingStub.getAllAccountsByAuthenticationProvider(request); + + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain cause '%s'", Cause.ACCOUNT_NOT_FOUND), + reply.getError().getCause().equals(Cause.ACCOUNT_NOT_FOUND)); + } + + @Test + public void testGetAccountsByPhoneBadRequest() throws ExecutionException, InterruptedException { + final AccountsByAuthenticationProviderRequest request = AccountsByAuthenticationProviderRequest.newBuilder() + .setAuthenticationType(AuthenticationType.PHONE).build(); + + final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final GetAccountsResponse reply = accountServiceBlockingStub.getAllAccountsByAuthenticationProvider(request); + + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain cause '%s'", Cause.ACCOUNT_NOT_FOUND), + reply.getError().getCause().equals(Cause.ACCOUNT_NOT_FOUND)); + } + + @Test + public void testGetAccountsByProfileId() throws ExecutionException, InterruptedException { + final AccountsByProfileIdRequest request = AccountsByProfileIdRequest.newBuilder() + .setProfileId(Util.PROFILE_ID.toString()).build(); + + List usersInfo = new ArrayList<>(); + usersInfo.add(savedAccount); + given(userInfoRepository.findAllByProfileId(UUID.fromString(request.getProfileId()))).willReturn(usersInfo); + + final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final GetAccountsResponse reply = accountServiceBlockingStub.getAllAccountsByProfileId(request); + + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain profile ID '%s'", Util.PROFILE_ID.toString()), + reply.getAccountsResponse().getAccountDetails(0).getProfileId().equals(Util.PROFILE_ID.toString())); + } + + @Test + public void testGetAccountsByProfileIdNotFound() throws ExecutionException, InterruptedException { + final AccountsByProfileIdRequest request = AccountsByProfileIdRequest.newBuilder() + .setProfileId(Util.PROFILE_ID.toString()).build(); + + List usersInfo = new ArrayList<>(); + + given(userInfoRepository.findAllByProfileId(Util.PROFILE_ID)).willReturn(usersInfo); + + final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final GetAccountsResponse reply = accountServiceBlockingStub.getAllAccountsByProfileId(request); + + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain cause '%s'", Cause.ACCOUNT_NOT_FOUND), + reply.getError().getCause().equals(Cause.ACCOUNT_NOT_FOUND)); + } + + @Test + public void testGetAccountsByProfileIdBadRequest() throws ExecutionException, InterruptedException { + final AccountsByProfileIdRequest request = AccountsByProfileIdRequest.newBuilder().build(); + + final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final GetAccountsResponse reply = accountServiceBlockingStub.getAllAccountsByProfileId(request); + + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain cause '%s'", Cause.MISSING_PROFILE_ID), + reply.getError().getCause().equals(Cause.MISSING_PROFILE_ID)); + } + +} diff --git a/src/test/java/biz/nynja/account/grpc/GrpcServerTestBase.java b/src/test/java/biz/nynja/account/grpc/utils/GrpcServerTestBase.java similarity index 93% rename from src/test/java/biz/nynja/account/grpc/GrpcServerTestBase.java rename to src/test/java/biz/nynja/account/grpc/utils/GrpcServerTestBase.java index d4b3507ab29b4838ea1b6c1bd09a0a6950aac871..2db24e8e84fc0e00ba779640319daf3972bfb0e4 100644 --- a/src/test/java/biz/nynja/account/grpc/GrpcServerTestBase.java +++ b/src/test/java/biz/nynja/account/grpc/utils/GrpcServerTestBase.java @@ -1,4 +1,8 @@ -package biz.nynja.account.grpc; +/** + * Copyright (C) 2018 Nynja Inc. All rights reserved. + */ + +package biz.nynja.account.grpc.utils; import java.util.Optional; @@ -15,6 +19,10 @@ import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import io.grpc.inprocess.InProcessChannelBuilder; +/** + * gRPC test configurations. + */ + public abstract class GrpcServerTestBase { @Autowired(required = false) @@ -64,4 +72,4 @@ public abstract class GrpcServerTestBase { Optional.ofNullable(channel).ifPresent(ManagedChannel::shutdownNow); Optional.ofNullable(inProcChannel).ifPresent(ManagedChannel::shutdownNow); } -} +} \ No newline at end of file diff --git a/src/test/java/biz/nynja/account/grpc/utils/Util.java b/src/test/java/biz/nynja/account/grpc/utils/Util.java new file mode 100644 index 0000000000000000000000000000000000000000..8d87038d7907638ed83d9fe8f440a78532d37276 --- /dev/null +++ b/src/test/java/biz/nynja/account/grpc/utils/Util.java @@ -0,0 +1,99 @@ +/** + * Copyright (C) 2018 Nynja Inc. All rights reserved. + */ + +package biz.nynja.account.grpc.utils; + +import java.util.UUID; + +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.Bean; + +import biz.nynja.account.grpc.AuthenticationType; +import biz.nynja.account.grpc.Status; +import biz.nynja.account.grpc.models.UserInfo; +import biz.nynja.account.grpc.models.UserInfoByEmail; +import biz.nynja.account.grpc.models.UserInfoByPhone;; + +/** + * Unit tests variables, beans and help methods. + */ + +@TestConfiguration +public class Util { + + public static final UUID PROFILE_ID = UUID.fromString("12352345-e89b-43d3-d156-456732452200"); + public static final UUID ACCOUNT_ID = UUID.fromString("44532732-12b3-132d-e156-223732152200"); + public static final String EMAIL = "email@test.com"; + public static final String USERNAME = "jdoe"; + public static final String PASSWORD = "abc123"; + public static final String FIRST_NAME = "John"; + public static final String LAST_NAME = "Doe"; + public static final String MIDDLE_NAME = "Kass"; + public static final String PHONE_NUMBER = "+359887434646"; + + @Bean + public UserInfo newAccount() { + UserInfo userInfo = new UserInfo(); + userInfo.setUsername(USERNAME); + userInfo.setPassword(PASSWORD); + userInfo.setEmailAddress(EMAIL); + userInfo.setFirstName(FIRST_NAME); + userInfo.setLastName(LAST_NAME); + userInfo.setMiddleName(MIDDLE_NAME); + userInfo.setPhoneNumber(PHONE_NUMBER); + userInfo.setAuthenticationType(AuthenticationType.EMAIL); + userInfo.setStatus(Status.SUSPENDED); + return userInfo; + } + + @Bean + public UserInfo savedAccount() { + UserInfo userInfo = new UserInfo(); + userInfo.setAccountId(ACCOUNT_ID); + userInfo.setProfileId(PROFILE_ID); + userInfo.setEmailAddress(EMAIL); + userInfo.setUsername(USERNAME); + userInfo.setPassword(PASSWORD); + userInfo.setFirstName(FIRST_NAME); + userInfo.setLastName(LAST_NAME); + userInfo.setMiddleName(MIDDLE_NAME); + userInfo.setPhoneNumber(PHONE_NUMBER); + userInfo.setAuthenticationType(AuthenticationType.EMAIL); + userInfo.setStatus(Status.SUSPENDED); + return userInfo; + } + + @Bean + public UserInfoByEmail accountByEmail() { + UserInfoByEmail userInfoByEmail = new UserInfoByEmail(); + userInfoByEmail.setEmailAddress(EMAIL); + userInfoByEmail.setAccountId(ACCOUNT_ID); + userInfoByEmail.setProfileId(PROFILE_ID); + userInfoByEmail.setUsername(USERNAME); + userInfoByEmail.setFirstName(FIRST_NAME); + userInfoByEmail.setLastName(LAST_NAME); + userInfoByEmail.setMiddleName(MIDDLE_NAME); + userInfoByEmail.setPhoneNumber(PHONE_NUMBER); + userInfoByEmail.setAuthenticationType(AuthenticationType.EMAIL); + userInfoByEmail.setStatus(Status.SUSPENDED); + return userInfoByEmail; + } + + @Bean + public UserInfoByPhone accountByPhone() { + UserInfoByPhone userInfoByPhone = new UserInfoByPhone(); + userInfoByPhone.setPhoneNumber(PHONE_NUMBER); + userInfoByPhone.setEmailAddress(EMAIL); + userInfoByPhone.setAccountId(ACCOUNT_ID); + userInfoByPhone.setProfileId(PROFILE_ID); + userInfoByPhone.setUsername(USERNAME); + userInfoByPhone.setFirstName(FIRST_NAME); + userInfoByPhone.setLastName(LAST_NAME); + userInfoByPhone.setMiddleName(MIDDLE_NAME); + userInfoByPhone.setAuthenticationType(AuthenticationType.EMAIL); + userInfoByPhone.setStatus(Status.SUSPENDED); + return userInfoByPhone; + } + +}