diff --git a/src/main/java/biz/nynja/account/components/Validator.java b/src/main/java/biz/nynja/account/components/Validator.java index c48ff7dbb976c2806d2babd64097421c92f7f06c..baf7eb282b22daa4073a624534a124de1413beca 100644 --- a/src/main/java/biz/nynja/account/components/Validator.java +++ b/src/main/java/biz/nynja/account/components/Validator.java @@ -25,7 +25,6 @@ import biz.nynja.account.grpc.Date; import biz.nynja.account.grpc.DeleteAuthenticationProviderRequest; import biz.nynja.account.grpc.ErrorResponse.Cause; import biz.nynja.account.grpc.UpdateAccountRequest; -import biz.nynja.account.grpc.UpdateProfileRequest; import biz.nynja.account.phone.PhoneNumberValidator; /** @@ -217,13 +216,6 @@ public class Validator { return null; } - public Cause validateUpdateProfileRequest(UpdateProfileRequest request) { - if (!isValidUuid(request.getProfileId())) { - return Cause.INVALID_PROFILE_ID; - } - return null; - } - public Cause validateAddAuthenticationProviderRequest(AddAuthenticationProviderRequest request) { if (!isValidUuid(request.getProfileId())) { return Cause.INVALID_PROFILE_ID; diff --git a/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditional.java b/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditional.java index 3503b4236be83bffa281342e3d73a454e54f8d73..770c59d8109cba2cd9b468b64536ab22f7e7c8b5 100644 --- a/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditional.java +++ b/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditional.java @@ -9,7 +9,6 @@ import org.springframework.stereotype.Repository; import biz.nynja.account.grpc.CompletePendingAccountCreationRequest; import biz.nynja.account.grpc.UpdateAccountRequest; -import biz.nynja.account.grpc.UpdateProfileRequest; import biz.nynja.account.models.Account; import biz.nynja.account.models.AuthenticationProvider; import biz.nynja.account.models.ContactInfo; @@ -23,8 +22,6 @@ public interface AccountRepositoryAdditional { Account updateAccount(UpdateAccountRequest request); - Profile updateProfile(UpdateProfileRequest request); - boolean deleteAccount(UUID accountId); boolean deleteProfile(UUID profileId); diff --git a/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java b/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java index 38f4bff208bfe3027a2be163255b75c1f537ca8c..1b5eea4a4c6fa4fe2869c8f2605d23e4bb243ffd 100644 --- a/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java +++ b/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java @@ -33,7 +33,6 @@ import biz.nynja.account.components.Validator; import biz.nynja.account.grpc.AccessStatus; import biz.nynja.account.grpc.CompletePendingAccountCreationRequest; import biz.nynja.account.grpc.UpdateAccountRequest; -import biz.nynja.account.grpc.UpdateProfileRequest; import biz.nynja.account.models.Account; import biz.nynja.account.models.AccountByAuthenticationProvider; import biz.nynja.account.models.AccountByProfileId; @@ -172,35 +171,6 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio batchOps.insert(newProfileByAuthenticationProvider); } - public Profile updateProfile(UpdateProfileRequest request) { - CassandraBatchOperations batchOperations = cassandraTemplate.batchOps(); - Profile existingProfile = profileRepository.findByProfileId(UUID.fromString(request.getProfileId())); - if (existingProfile == null) { - logger.info("Existing profile with the provided id was not found."); - logger.debug("Existing profile with the provided id {} was not found.", request.getProfileId()); - return null; - } - Long timeUpdated = Instant.now().toEpochMilli(); - WriteResult wr = null; - try { - updateProfileData(batchOperations, request, existingProfile, timeUpdated); - wr = batchOperations.execute(); - } catch (IllegalArgumentException | IllegalStateException e) { - logger.info("Exception while updating profile."); - logger.debug("Exception while updating profile: {} ...", e.getMessage()); - return null; - } - - if (wr != null) { - boolean applied = wr.wasApplied(); - if (applied) { - Profile updatedProfile = profileRepository.findByProfileId(UUID.fromString(request.getProfileId())); - return updatedProfile; - } - } - return null; - } - public Account updateAccount(UpdateAccountRequest request) { CassandraBatchOperations batchOperations = cassandraTemplate.batchOps(); Account existingAccount = accountRepository.findByAccountId(UUID.fromString(request.getAccountId())); @@ -339,19 +309,6 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio batchOps.update(updatedAccount); } - private void updateProfileData(CassandraBatchOperations batchOps, UpdateProfileRequest request, - Profile existingProfile, Long lastUpdateTimestamp) { - Profile updatedProfile = existingProfile; - updatedProfile.setPasscode(request.getPasscode()); - if (!request.getDefaultAccountId().trim().isEmpty()) { - updatedProfile.setDefaultAccount(UUID.fromString(request.getDefaultAccountId())); - } else { - updatedProfile.setDefaultAccount(null); - } - updatedProfile.setLastUpdateTimestamp(lastUpdateTimestamp); - batchOps.update(updatedProfile); - } - private void updateAuthProvidersInProfileWhenDeletingAccount(CassandraBatchOperations batchOps, Profile existingProfile, Set authProvidersToUpdate, Long lastUpdateTimestamp) { Profile updatedProfile = existingProfile; diff --git a/src/main/java/biz/nynja/account/services/AccountServiceImpl.java b/src/main/java/biz/nynja/account/services/AccountServiceImpl.java index b9fdf4aa5d8a7afca9e494565b0b8eb53e570664..00217950cc7be8de78e8151b466b33fd3cc1b9ca 100644 --- a/src/main/java/biz/nynja/account/services/AccountServiceImpl.java +++ b/src/main/java/biz/nynja/account/services/AccountServiceImpl.java @@ -42,7 +42,6 @@ import biz.nynja.account.grpc.SearchResponse; import biz.nynja.account.grpc.SearchResultDetails; import biz.nynja.account.grpc.StatusResponse; import biz.nynja.account.grpc.UpdateAccountRequest; -import biz.nynja.account.grpc.UpdateProfileRequest; import biz.nynja.account.models.Account; import biz.nynja.account.models.AccountByQrCode; import biz.nynja.account.models.AccountByUsername; @@ -398,41 +397,6 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas responseObserver.onCompleted(); } - @Override - public void updateProfile(UpdateProfileRequest request, StreamObserver responseObserver) { - - logger.info("Updating profile..."); - logger.debug("Updating profile...: {}", request); - - if ((request.getProfileId() == null) || (request.getProfileId().isEmpty())) { - logAndBuildGrpcProfileResponse(responseObserver, ProfileResponse.newBuilder(), "Missing profile id", "", - Cause.MISSING_PROFILE_ID); - return; - } - - Cause cause = validator.validateUpdateProfileRequest(request); - if (cause != null) { - logAndBuildGrpcProfileResponse(responseObserver, ProfileResponse.newBuilder(), "Validation failed", "", - cause); - return; - } - - Profile updatedProfile = accountRepositoryAdditional.updateProfile(request); - - if (updatedProfile == null) { - logAndBuildGrpcProfileResponse(responseObserver, ProfileResponse.newBuilder(), "Error updating profile", "", - Cause.ERROR_UPDATING_PROFILE); - return; - } - logger.debug("Profile \"{}\" updated in the DB", updatedProfile.toString()); - logger.debug("Profile: \"{}\" updated successfully.", updatedProfile); - ProfileResponse response = ProfileResponse.newBuilder().setProfileDetails(updatedProfile.toProto()).build(); - responseObserver.onNext(response); - responseObserver.onCompleted(); - logger.info("Profile updated successfully."); - return; - } - @Override public void updateAccount(UpdateAccountRequest request, StreamObserver responseObserver) { logger.info("Updating account..."); diff --git a/src/test/java/biz/nynja/account/services/AccountServiceTests.java b/src/test/java/biz/nynja/account/services/AccountServiceTests.java index 8f02eedbce7a8319e013955a51a27f3f83224579..82d397745c389acc733a34980e3b604f375e23f1 100644 --- a/src/test/java/biz/nynja/account/services/AccountServiceTests.java +++ b/src/test/java/biz/nynja/account/services/AccountServiceTests.java @@ -65,7 +65,6 @@ import biz.nynja.account.grpc.Role; import biz.nynja.account.grpc.SearchResponse; import biz.nynja.account.grpc.StatusResponse; import biz.nynja.account.grpc.UpdateAccountRequest; -import biz.nynja.account.grpc.UpdateProfileRequest; import biz.nynja.account.models.Account; import biz.nynja.account.models.AccountByAuthenticationProvider; import biz.nynja.account.models.AccountByProfileId; @@ -485,17 +484,6 @@ public class AccountServiceTests extends GrpcServerTestBase { reply.getError().getCause().equals(Cause.ACCOUNT_ALREADY_CREATED)); } - @Test - public void testUpdateProfileMissingProfileId() throws ExecutionException, InterruptedException { - final UpdateProfileRequest request = UpdateProfileRequest.newBuilder().build(); - final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc - .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); - final ProfileResponse reply = accountServiceBlockingStub.updateProfile(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)); - } - @Test public void testCreatePendingAccountOK() { final CreatePendingAccountRequest request = CreatePendingAccountRequest.newBuilder()