From 4b70e62296c406732065d91a16f35ea90b1ca067 Mon Sep 17 00:00:00 2001 From: Stoyan Tzenkov Date: Mon, 21 Jan 2019 16:57:50 +0200 Subject: [PATCH 1/2] NY-6574: Got rid of warning message. Signed-off-by: Stoyan Tzenkov --- .../AccountRepositoryAdditionalImpl.java | 38 ++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java b/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java index d7bffb5..3542ea2 100644 --- a/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java +++ b/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java @@ -10,11 +10,15 @@ import java.time.Instant; import java.time.LocalDate; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; +import javax.annotation.PostConstruct; + import org.apache.commons.lang3.SerializationUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -22,10 +26,12 @@ import org.springframework.data.cassandra.core.CassandraBatchOperations; import org.springframework.data.cassandra.core.CassandraTemplate; import org.springframework.data.cassandra.core.UpdateOptions; import org.springframework.data.cassandra.core.WriteResult; +import org.springframework.data.cassandra.core.cql.CqlOperations; import org.springframework.stereotype.Service; import com.datastax.driver.core.BatchStatement; import com.datastax.driver.core.BoundStatement; +import com.datastax.driver.core.PreparedStatement; import com.datastax.driver.core.ResultSet; import com.datastax.driver.core.Session; @@ -56,9 +62,9 @@ import biz.nynja.account.services.decomposition.IncorrectAccountCountException; import biz.nynja.account.services.erlang.ErlangAccountBridge; import io.grpc.StatusRuntimeException; -// TODO: 11/19/2018 refactor this class and adding rolback cassandra data if erlang return fail state @Service public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditional { + private PreparedStatement preparedCql; private static final Logger logger = LoggerFactory.getLogger(AccountRepositoryAdditionalImpl.class); private final PendingAccountConfiguration pendingAccountConfiguration; @@ -106,6 +112,15 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio this.accountDataConfiguration = accountDataConfiguration; } + @PostConstruct + public void initStatements() { + + preparedCql = session.prepare( + "INSERT INTO pendingAccount (accountId, profileId, authenticationProvider, authenticationProviderType, creationTimestamp)" + + " VALUES (?, ?, ? ,?, ?) " + "USING TTL " + pendingAccountConfiguration.getTtl() * 60 + ";"); + + } + public Account completePendingAccountCreation(CompletePendingAccountCreationRequest request) { Transaction sagaTransaction = new SagaTransaction(cassandraTemplate); PendingAccount pendingAccount = pendingAccountRepository @@ -198,8 +213,8 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio public Account updateAccount(UpdateAccountRequest request) { Transaction sagaTransaction = new SagaTransaction(cassandraTemplate); - Account existingAccount = accountRepository.findByAccountId(UUID.fromString(request.getAccountId())); + Account existingAccount = accountRepository.findByAccountId(UUID.fromString(request.getAccountId())); if (existingAccount == null) { logger.error("Existing account with the provided id {} was not found.", request.getAccountId()); logger.debug("Existing account with the provided id {} was not found.", request.getAccountId()); @@ -211,7 +226,6 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio Set roles = existingAccount.getRoles().stream().map(Role::valueOf).collect(Collectors.toSet()); request = UpdateAccountRequest.newBuilder(request).clearRoles().addAllRoles(roles).build(); } - Long timeUpdated = Instant.now().toEpochMilli(); WriteResult wr = null; try { @@ -998,20 +1012,18 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio return false; } - public PendingAccount savePendingAccount(PendingAccount pendingAccount) { + public PendingAccount savePendingAccount(PendingAccount pendingAccount) throws RuntimeException { // for saving back compatibility. need refactoring in the future - if (!createSavePendingAccount(pendingAccount)) { - throw new RuntimeException("Exception for save save pending account id=" + pendingAccount.getAccountId()); - } - return pendingAccount; - } - private boolean createSavePendingAccount(PendingAccount pendingAccount) { - String cql = "INSERT INTO pendingAccount (accountId, profileId, authenticationProvider, authenticationProviderType, creationTimestamp)" - + " VALUES (?, ?, ? ,?, ?) " + "USING TTL " + pendingAccountConfiguration.getTtl() * 60 + ";"; - return cassandraTemplate.getCqlOperations().execute(cql, pendingAccount.getAccountId(), + BoundStatement boundStatement = new BoundStatement(preparedCql).bind(pendingAccount.getAccountId(), pendingAccount.getProfileId(), pendingAccount.getAuthenticationProvider(), pendingAccount.getAuthenticationProviderType(), pendingAccount.getCreationTimestamp()); + try { + ResultSet result = session.execute(boundStatement); + } catch (Exception ex) { + throw new RuntimeException("Exception for save save pending account id=" + pendingAccount.getAccountId()); + } + return pendingAccount; } public void removeNullsForSearchableOption() { -- GitLab From 8dde85a24ad983eafde79802f1ab24a8976f8376 Mon Sep 17 00:00:00 2001 From: Stoyan Tzenkov Date: Wed, 23 Jan 2019 10:21:13 +0200 Subject: [PATCH 2/2] NY-6574: Small message fix. Signed-off-by: Stoyan Tzenkov --- .../account/repositories/AccountRepositoryAdditionalImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java b/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java index 3542ea2..1737eff 100644 --- a/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java +++ b/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java @@ -1021,7 +1021,7 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio try { ResultSet result = session.execute(boundStatement); } catch (Exception ex) { - throw new RuntimeException("Exception for save save pending account id=" + pendingAccount.getAccountId()); + throw new RuntimeException("Exception during save pending account id=" + pendingAccount.getAccountId()); } return pendingAccount; } -- GitLab