From 69623c5a537d5e4204184cdb5f8d0d47457de304 Mon Sep 17 00:00:00 2001 From: Stoyan Tzenkov Date: Mon, 12 Nov 2018 16:24:49 +0200 Subject: [PATCH 1/2] NY-4832: updateProfile() removed Signed-off-by: Stoyan Tzenkov --- .../account/services/AccountServiceImpl.java | 36 ------------------- 1 file changed, 36 deletions(-) diff --git a/src/main/java/biz/nynja/account/services/AccountServiceImpl.java b/src/main/java/biz/nynja/account/services/AccountServiceImpl.java index b9fdf4a..0021795 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..."); -- GitLab From 28b049f4c8844630ce64afef5fa8ea6f93014109 Mon Sep 17 00:00:00 2001 From: Stoyan Tzenkov Date: Tue, 13 Nov 2018 11:17:22 +0200 Subject: [PATCH 2/2] NY-4832: Removed the rest of updateProfile from account-service Signed-off-by: Stoyan Tzenkov --- .../nynja/account/components/Validator.java | 8 ---- .../AccountRepositoryAdditional.java | 3 -- .../AccountRepositoryAdditionalImpl.java | 43 ------------------- .../account/services/AccountServiceTests.java | 12 ------ 4 files changed, 66 deletions(-) diff --git a/src/main/java/biz/nynja/account/components/Validator.java b/src/main/java/biz/nynja/account/components/Validator.java index c48ff7d..baf7eb2 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 3503b42..770c59d 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 38f4bff..1b5eea4 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/test/java/biz/nynja/account/services/AccountServiceTests.java b/src/test/java/biz/nynja/account/services/AccountServiceTests.java index 8f02eed..82d3977 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() -- GitLab