diff --git a/src/main/java/biz/nynja/account/components/StatementsPool.java b/src/main/java/biz/nynja/account/components/StatementsPool.java index 28dfacaf9a627e231f3dd5ec64f17b7d7228ac9d..2bbc0d4005afd4ea3e27842a2e171dc7c5ede82e 100644 --- a/src/main/java/biz/nynja/account/components/StatementsPool.java +++ b/src/main/java/biz/nynja/account/components/StatementsPool.java @@ -3,6 +3,7 @@ */ package biz.nynja.account.components; +import java.time.Instant; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; @@ -26,10 +27,11 @@ public class StatementsPool { this.preparedStatementsCache = preparedStatementsCache; } - public BoundStatement addAuthenticationProviderToProfile(UUID profileId, AuthenticationProvider authProvider) { - String cql = "UPDATE profile SET authenticationproviders = authenticationproviders + ? WHERE profileid = ? ;"; + public BoundStatement addAuthenticationProviderToProfile(UUID profileId, AuthenticationProvider authProvider, Long updatedTimestamp) { + String cql = "UPDATE profile SET authenticationproviders = authenticationproviders + ?, lastupdatetimestamp = ? WHERE profileid = ? ;"; Set toBeAdded = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(authProvider))); - BoundStatement bound = preparedStatementsCache.getPreparedStatement(cql).bind(toBeAdded, profileId); + BoundStatement bound = preparedStatementsCache.getPreparedStatement(cql).bind(toBeAdded, updatedTimestamp, + profileId); return bound; } @@ -51,11 +53,12 @@ public class StatementsPool { return bound; } - public BoundStatement deleteAuthenicationProviderFromProfile(UUID profileId, AuthenticationProvider authProvider) { - String cql = "UPDATE profile SET authenticationproviders = authenticationproviders - ? WHERE profileid = ? ;"; + public BoundStatement deleteAuthenicationProviderFromProfile(UUID profileId, AuthenticationProvider authProvider, Long updatedTimestamp) { + String cql = "UPDATE profile SET authenticationproviders = authenticationproviders - ?, lastupdatetimestamp = ? WHERE profileid = ? ;"; Set toBeDeleted = Collections .unmodifiableSet(new HashSet<>(Arrays.asList(authProvider))); - BoundStatement bound = preparedStatementsCache.getPreparedStatement(cql).bind(toBeDeleted, profileId); + BoundStatement bound = preparedStatementsCache.getPreparedStatement(cql).bind(toBeDeleted, updatedTimestamp, + profileId); return bound; } diff --git a/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java b/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java index 199cf34146d148703ade1ff9d6ece0aea7d78627..a30e94f24183674a612d2282ae01aee797f923f5 100644 --- a/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java +++ b/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java @@ -536,9 +536,11 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio public boolean addAuthenticationProvider(UUID profileId, AuthenticationProvider authProvider) { BatchStatement batch = new BatchStatement(); ResultSet wr = null; + Long timeUpdated = Instant.now().toEpochMilli(); + try { BoundStatement updateAuthProvidersInProfile = statementsPool.addAuthenticationProviderToProfile(profileId, - authProvider); + authProvider, timeUpdated); batch.add(updateAuthProvidersInProfile); BoundStatement insertInProfileByAuthProvider = statementsPool.insertProfileByAuthenticationProvider( @@ -793,10 +795,11 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio BatchStatement batch = new BatchStatement(); ResultSet rs = null; + Long timeUpdated = Instant.now().toEpochMilli(); // Remove authentication provider form list of authentication providers in profile BoundStatement deleteAuthProviderStatement = statementsPool - .deleteAuthenicationProviderFromProfile(profile.getProfileId(), authProvider); + .deleteAuthenicationProviderFromProfile(profile.getProfileId(), authProvider, timeUpdated); batch.add(deleteAuthProviderStatement); // Remove record for profile by this authentication provider