From 9a50a6d704e5b78e86b013ab3973c8541d277344 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Mon, 11 Dec 2023 14:47:03 +0000 Subject: [PATCH 01/21] Upgrading perftest branch to V16 and adding subnet_suffix --- src/integrationTest/resources/application.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/integrationTest/resources/application.yml b/src/integrationTest/resources/application.yml index 38370e63d4..670257b215 100644 --- a/src/integrationTest/resources/application.yml +++ b/src/integrationTest/resources/application.yml @@ -1,6 +1,6 @@ spring: flyway: - schemas: DBREFDATA + schemas: dbrefdata locations: classpath:db/migration jpa: From d82e8584858309c5fc59c037f1b40a399e5e3d28 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Mon, 12 Feb 2024 21:17:27 +0000 Subject: [PATCH 02/21] End point to update Idam id for a professional user --- .../OrganisationInternalController.java | 73 +++++++++++++++++++ .../ProfessionalUserIdentifierRequest.java | 31 ++++++++ .../domain/UserProfileUpdatedData.java | 8 +- .../service/OrganisationService.java | 2 + .../service/impl/OrganisationServiceImpl.java | 50 +++++++++++++ ...rofessionalExternalUserControllerTest.java | 2 +- ...rofessionalUserInternalControllerTest.java | 2 +- ...ProfileUpdateRequestValidatorImplTest.java | 13 ++-- .../domain/UserProfileUpdatedDataTest.java | 3 +- 9 files changed, 174 insertions(+), 10 deletions(-) create mode 100644 src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/ProfessionalUserIdentifierRequest.java diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalController.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalController.java index ec1b05682e..ecfca2e187 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalController.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalController.java @@ -32,6 +32,7 @@ import uk.gov.hmcts.reform.professionalapi.controller.request.NewUserCreationRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.OrganisationCreationRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.PbaRequest; +import uk.gov.hmcts.reform.professionalapi.controller.request.ProfessionalUserIdentifierRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.UpdatePbaRequest; import uk.gov.hmcts.reform.professionalapi.controller.response.DeleteOrganisationResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.NewUserResponse; @@ -50,8 +51,11 @@ import javax.validation.constraints.NotNull; import javax.validation.constraints.Pattern; +import static org.apache.commons.lang.StringUtils.isBlank; import static org.apache.commons.lang3.BooleanUtils.isNotTrue; import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; +import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ERROR_MESSAGE_EMPTY_CONTACT_INFORMATION; +import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ERROR_MSG_REQUEST_IS_EMPTY; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ORGANISATION_IDENTIFIER_FORMAT_REGEX; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ORG_ID_VALIDATION_ERROR_MESSAGE; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ORG_NOT_ACTIVE; @@ -680,4 +684,73 @@ public ResponseEntity retrieveOrganisationByUserId( @PathVariable("userId") String userId) { return organisationService.retrieveOrganisationByUserId(userId); } + + + @Operation( + summary = "Updates idam id for a user in an organisation", + description = "**IDAM Roles to access API** :
pui-organisation-manager", + security = { + @SecurityRequirement(name = "ServiceAuthorization"), + @SecurityRequirement(name = "Authorization") + } + + ) + + @ApiResponse( + responseCode = "200", + description = "Updated idam id for a user in the organisation", + content = @Content + ) + @ApiResponse( + responseCode = "400", + description = "An invalid request has been provided", + content = @Content + ) + @ApiResponse( + responseCode = "401", + description = "Unauthorized Error : " + + "The requested resource is restricted and requires authentication", + content = @Content + ) + + @ApiResponse( + responseCode = "403", + description = "Forbidden Error: Access denied", + content = @Content + ) + @ApiResponse( + responseCode = "500", + description = "Internal Server Error", + content = @Content + ) + + + @PutMapping( + path = "/userIdam/{orgId}", + consumes = APPLICATION_JSON_VALUE, + produces = APPLICATION_JSON_VALUE + ) + @ResponseStatus(value = HttpStatus.CREATED) + @ResponseBody + @Secured({"prd-admin"}) + public ResponseEntity updateUserIdamForOrganisation( + @io.swagger.v3.oas.annotations.parameters.RequestBody(description = "contactInformationCreationRequests") + @Valid @NotNull @RequestBody ProfessionalUserIdentifierRequest professionalUserIdentifierRequest, + @PathVariable("orgId") @NotBlank String organisationIdentifier) { + + log.info("{}:: Received request to update idam id for an user in an " + + "organisation ::", loggingComponentName); + + if (!Optional.ofNullable(professionalUserIdentifierRequest).isPresent()) { + throw new InvalidRequest(ERROR_MSG_REQUEST_IS_EMPTY); + } else if (isBlank(professionalUserIdentifierRequest.getExistingIdamId()) + || isBlank(professionalUserIdentifierRequest.getNewIdamId()) + ) { + throw new InvalidRequest("Please enter existing and New Idam ids / User identifiers"); + } + return organisationService.updateIdamId(professionalUserIdentifierRequest.getExistingIdamId() + ,professionalUserIdentifierRequest.getNewIdamId()); + } + + } diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/ProfessionalUserIdentifierRequest.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/ProfessionalUserIdentifierRequest.java new file mode 100644 index 0000000000..a5fb190cfc --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/ProfessionalUserIdentifierRequest.java @@ -0,0 +1,31 @@ +package uk.gov.hmcts.reform.professionalapi.controller.request; + +import javax.validation.constraints.NotNull; + +import com.fasterxml.jackson.annotation.JsonCreator; +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; + + +@Getter +@Setter +@Builder(builderMethodName = "aUserIdentifierRequest") +public class ProfessionalUserIdentifierRequest { + + @NotNull + private final String existingIdamId; + + @NotNull + private final String newIdamId; + + + @JsonCreator + public ProfessionalUserIdentifierRequest(String existingIdamId, String newIdamId) { + this.existingIdamId = existingIdamId; + this.newIdamId = newIdamId; + } + + +} + diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/domain/UserProfileUpdatedData.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/domain/UserProfileUpdatedData.java index e8fdcbd6fa..d7f3a41761 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/domain/UserProfileUpdatedData.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/domain/UserProfileUpdatedData.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -11,8 +12,11 @@ @NoArgsConstructor @Getter @Setter +@Builder public class UserProfileUpdatedData { + private String idamId; + private String email; private String firstName; @@ -28,7 +32,8 @@ public class UserProfileUpdatedData { private Set userAccessTypes; @JsonCreator - public UserProfileUpdatedData(@JsonProperty(value = "email") String email, + public UserProfileUpdatedData(@JsonProperty(value = "idamId") String idamId, + @JsonProperty(value = "email") String email, @JsonProperty(value = "firstName") String firstName, @JsonProperty(value = "lastName") String lastName, @JsonProperty(value = "idamStatus") String idamStatus, @@ -36,6 +41,7 @@ public UserProfileUpdatedData(@JsonProperty(value = "email") String email, @JsonProperty(value = "rolesDelete") Set rolesDelete, @JsonProperty(value = "userAccessTypes") Set userAccessTypes ) { + this.idamId = idamId; this.email = email; this.firstName = firstName; this.lastName = lastName; diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/OrganisationService.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/OrganisationService.java index a0213a4bb0..aea58ac462 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/OrganisationService.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/OrganisationService.java @@ -73,4 +73,6 @@ void addContactInformationsToOrganisation( ResponseEntity retrieveOrganisationByUserId(String userId); + ResponseEntity updateIdamId(String existingUserIdentifier, String newUserIdentifier); + } diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java index 0f316cc666..bf914e849a 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java @@ -1,5 +1,7 @@ package uk.gov.hmcts.reform.professionalapi.service.impl; +import feign.FeignException; +import feign.Response; import lombok.Setter; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -16,6 +18,8 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; +import uk.gov.hmcts.reform.professionalapi.controller.advice.ErrorResponse; +import uk.gov.hmcts.reform.professionalapi.controller.advice.ExternalApiException; import uk.gov.hmcts.reform.professionalapi.controller.advice.ResourceNotFoundException; import uk.gov.hmcts.reform.professionalapi.controller.constants.IdamStatus; import uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants; @@ -34,6 +38,7 @@ import uk.gov.hmcts.reform.professionalapi.controller.response.BulkCustomerOrganisationsDetailResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.DeleteOrganisationResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.FetchPbaByStatusResponse; +import uk.gov.hmcts.reform.professionalapi.controller.response.GetUserProfileResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationEntityResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationEntityResponseV2; import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationResponse; @@ -46,6 +51,7 @@ import uk.gov.hmcts.reform.professionalapi.domain.ContactInformation; import uk.gov.hmcts.reform.professionalapi.domain.DxAddress; import uk.gov.hmcts.reform.professionalapi.domain.FailedPbaReason; +import uk.gov.hmcts.reform.professionalapi.domain.ModifyUserRolesResponse; import uk.gov.hmcts.reform.professionalapi.domain.OrgAttribute; import uk.gov.hmcts.reform.professionalapi.domain.Organisation; import uk.gov.hmcts.reform.professionalapi.domain.OrganisationMfaStatus; @@ -54,6 +60,7 @@ import uk.gov.hmcts.reform.professionalapi.domain.PbaStatus; import uk.gov.hmcts.reform.professionalapi.domain.ProfessionalUser; import uk.gov.hmcts.reform.professionalapi.domain.UserAttribute; +import uk.gov.hmcts.reform.professionalapi.domain.UserProfileUpdatedData; import uk.gov.hmcts.reform.professionalapi.repository.BulkCustomerDetailsRepository; import uk.gov.hmcts.reform.professionalapi.repository.ContactInformationRepository; import uk.gov.hmcts.reform.professionalapi.repository.DxAddressRepository; @@ -85,8 +92,11 @@ import java.util.stream.Stream; import static java.lang.Boolean.TRUE; +import static java.util.Objects.nonNull; +import static java.util.Objects.requireNonNull; import static org.apache.commons.lang3.ObjectUtils.isNotEmpty; import static org.springframework.util.CollectionUtils.isEmpty; +import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ERROR_MESSAGE_UP_FAILED; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ERROR_MSG_PARTIAL_SUCCESS; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.FALSE; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.LENGTH_OF_ORGANISATION_IDENTIFIER; @@ -103,6 +113,7 @@ import static uk.gov.hmcts.reform.professionalapi.domain.OrganisationStatus.PENDING; import static uk.gov.hmcts.reform.professionalapi.domain.PbaStatus.ACCEPTED; import static uk.gov.hmcts.reform.professionalapi.generator.ProfessionalApiGenerator.generateUniqueAlphanumericId; +import static uk.gov.hmcts.reform.professionalapi.util.JsonFeignResponseUtil.toResponseEntity; @Service @Slf4j @@ -946,5 +957,44 @@ public void deleteMultipleAddressOfGivenOrganisation(Set idsSet) { contactInformationRepository.deleteByIdIn(idsSet); } + @Transactional + public ResponseEntity updateIdamId(String existingUserIdentifier, String newUserIdentifier){ + + try (Response response = userProfileFeignClient.getUserProfileById(existingUserIdentifier)) { + + Object clazz = response.status() > 300 ? ErrorResponse.class : GetUserProfileResponse.class; + ResponseEntity responseResponseEntity = toResponseEntity(response, clazz); + + if (response.status() > 300) { + String errorMessage = nonNull(responseResponseEntity.getBody()) + ? ((ErrorResponse)responseResponseEntity.getBody()).getErrorMessage() : ERROR_MESSAGE_UP_FAILED; + throw new ExternalApiException(responseResponseEntity.getStatusCode(), errorMessage); + + } + GetUserProfileResponse existingUserProfile = + (GetUserProfileResponse) requireNonNull(responseResponseEntity.getBody()); + + UserProfileUpdatedData userProfileUpdatedData = UserProfileUpdatedData.builder() + .idamId(newUserIdentifier) + .idamStatus(existingUserProfile.getIdamStatus().name()) + .build(); + + Response userResponse = userProfileFeignClient.modifyUserRoles(userProfileUpdatedData, existingUserIdentifier, + " "); + + Optional professionalUser = Optional.ofNullable(professionalUserService.findProfessionalUserByUserIdentifier(existingUserIdentifier)); + if(professionalUser.isPresent()){ + professionalUser.get().setUserIdentifier(newUserIdentifier); + professionalUserRepository.save(professionalUser.get()); + }else{ + throw new EmptyResultDataAccessException(PROFESSIONAL_USER_404_MESSAGE, 1); + } + return toResponseEntity( + userResponse, userResponse.status() > 300 ? ErrorResponse.class : ModifyUserRolesResponse.class); + } catch (FeignException ex) { + throw new ExternalApiException(HttpStatus.valueOf(ex.status()), ERROR_MESSAGE_UP_FAILED); + } + } + } diff --git a/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/external/ProfessionalExternalUserControllerTest.java b/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/external/ProfessionalExternalUserControllerTest.java index c40b438c7d..024d6d222a 100644 --- a/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/external/ProfessionalExternalUserControllerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/external/ProfessionalExternalUserControllerTest.java @@ -371,7 +371,7 @@ void test_FindUserStatusByEmailFromHeaderThrows400WhenEmailIsInvalid() { @Test void test_modifyRolesForExistingUserOfExternalOrganisation() { ResponseEntity newResponse = ResponseEntity.status(200).body(""); - UserProfileUpdatedData userProfileUpdatedData = new UserProfileUpdatedData("test@email.com", "firstName", + UserProfileUpdatedData userProfileUpdatedData = new UserProfileUpdatedData(UUID.randomUUID().toString(),"test@email.com", "firstName", "lastName", IdamStatus.ACTIVE.name(), null, null, null); String orgId = "org123"; String userId = "1234567890"; diff --git a/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/internal/ProfessionalUserInternalControllerTest.java b/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/internal/ProfessionalUserInternalControllerTest.java index 1d8b6e113c..7a9cc51966 100644 --- a/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/internal/ProfessionalUserInternalControllerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/internal/ProfessionalUserInternalControllerTest.java @@ -69,7 +69,7 @@ class ProfessionalUserInternalControllerTest { void setUp() { organisation = new Organisation("Org-Name", OrganisationStatus.PENDING, "sra-id", "companyN", false, "www.org.com"); - userProfileUpdatedData = new UserProfileUpdatedData("test@email.com", "firstName", + userProfileUpdatedData = new UserProfileUpdatedData(UUID.randomUUID().toString(),"test@email.com", "firstName", "lastName", IdamStatus.ACTIVE.name(), null, null, null); organisationServiceMock = mock(OrganisationService.class); diff --git a/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/request/validator/impl/UserProfileUpdateRequestValidatorImplTest.java b/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/request/validator/impl/UserProfileUpdateRequestValidatorImplTest.java index 6a4ea8b3f5..a8aa63ca4e 100644 --- a/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/request/validator/impl/UserProfileUpdateRequestValidatorImplTest.java +++ b/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/request/validator/impl/UserProfileUpdateRequestValidatorImplTest.java @@ -13,6 +13,7 @@ import java.util.HashSet; import java.util.Set; +import java.util.UUID; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -51,7 +52,7 @@ void setUp() { @Test void test_ValidateRequestIfBothStatusAndRoleArePresent() { - UserProfileUpdatedData userProfileUpdatedData = new UserProfileUpdatedData(email, firstName, lastName, + UserProfileUpdatedData userProfileUpdatedData = new UserProfileUpdatedData(UUID.randomUUID().toString(),email, firstName, lastName, IdamStatus.ACTIVE.name(), rolesData, rolesToDeleteData, null); UserProfileUpdateRequestValidator sut = new UserProfileUpdateRequestValidatorImpl(); @@ -66,7 +67,7 @@ void test_ValidateRequestIfBothStatusAndRoleArePresent() { @Test void test_ValidateRequestForStatus() { - UserProfileUpdatedData userProfileUpdatedData = new UserProfileUpdatedData(email, firstName, lastName, + UserProfileUpdatedData userProfileUpdatedData = new UserProfileUpdatedData(UUID.randomUUID().toString(),email, firstName, lastName, IdamStatus.ACTIVE.name(), null, null, null); UserProfileUpdateRequestValidator sut = new UserProfileUpdateRequestValidatorImpl(); @@ -80,7 +81,7 @@ void test_ValidateRequestForStatus() { @Test void test_ValidateRequestForRoles() { - UserProfileUpdatedData userProfileUpdatedData = new UserProfileUpdatedData(email, firstName, lastName, + UserProfileUpdatedData userProfileUpdatedData = new UserProfileUpdatedData(UUID.randomUUID().toString(),email, firstName, lastName, null, rolesData, rolesToDeleteData, null); UserProfileUpdateRequestValidator sut = new UserProfileUpdateRequestValidatorImpl(); @@ -94,7 +95,7 @@ void test_ValidateRequestForRoles() { @Test void test_ValidateRequestForAccessTypes() { - UserProfileUpdatedData userProfileUpdatedData = new UserProfileUpdatedData(email, firstName, lastName, + UserProfileUpdatedData userProfileUpdatedData = new UserProfileUpdatedData(UUID.randomUUID().toString(),email, firstName, lastName, IdamStatus.ACTIVE.name(), null, null, userAccessTypes); UserProfileUpdateRequestValidator sut = new UserProfileUpdateRequestValidatorImpl(); @@ -109,7 +110,7 @@ void test_ValidateRequestForAccessTypes() { @Test void test_ValidateRequestForAccessTypesEmpty() { - UserProfileUpdatedData userProfileUpdatedData = new UserProfileUpdatedData(email, firstName, lastName, + UserProfileUpdatedData userProfileUpdatedData = new UserProfileUpdatedData(UUID.randomUUID().toString(),email, firstName, lastName, IdamStatus.ACTIVE.name(), null, null, new HashSet<>()); UserProfileUpdateRequestValidator sut = new UserProfileUpdateRequestValidatorImpl(); @@ -124,7 +125,7 @@ void test_ValidateRequestForAccessTypesEmpty() { @Test void test_ThrowErrorIfValidateRequestIsEmpty() { - UserProfileUpdatedData userProfileUpdatedData = new UserProfileUpdatedData(email, firstName, lastName, + UserProfileUpdatedData userProfileUpdatedData = new UserProfileUpdatedData(UUID.randomUUID().toString(),email, firstName, lastName, null, null, null, null); UserProfileUpdateRequestValidator sut = new UserProfileUpdateRequestValidatorImpl(); diff --git a/src/test/java/uk/gov/hmcts/reform/professionalapi/domain/UserProfileUpdatedDataTest.java b/src/test/java/uk/gov/hmcts/reform/professionalapi/domain/UserProfileUpdatedDataTest.java index b68c1c1551..e7e0759488 100644 --- a/src/test/java/uk/gov/hmcts/reform/professionalapi/domain/UserProfileUpdatedDataTest.java +++ b/src/test/java/uk/gov/hmcts/reform/professionalapi/domain/UserProfileUpdatedDataTest.java @@ -6,6 +6,7 @@ import java.util.HashSet; import java.util.Set; +import java.util.UUID; import static org.assertj.core.api.Assertions.assertThat; @@ -29,7 +30,7 @@ void test_should_add_roles_add_when_modified() { Set userAccessTypes = new HashSet<>(); userAccessTypes.add(userAccessType1); - UserProfileUpdatedData userProfileUpdatedData = new UserProfileUpdatedData("test@test.com", "fname", "lname", + UserProfileUpdatedData userProfileUpdatedData = new UserProfileUpdatedData(UUID.randomUUID().toString(),"test@test.com", "fname", "lname", "ACTIVE", rolesAdd, rolesDelete, userAccessTypes); userProfileUpdatedData.setRolesAdd(rolesAdd); userProfileUpdatedData.setRolesDelete(rolesDelete); From 9b93b8dd5c29f5644ffc92ccc6b7e02e3d1db1cb Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Tue, 30 Apr 2024 20:32:23 +0100 Subject: [PATCH 03/21] Delete User and User Profile --- .../service/impl/OrganisationServiceImpl.java | 11 +- .../impl/OrganisationServiceImplTest.java | 116 +++++++++++++++++- 2 files changed, 123 insertions(+), 4 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java index d88277d27c..a04db0d4e2 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java @@ -1074,7 +1074,7 @@ private boolean getMoreAvailable(Page pageableOrganisations) { public ResponseEntity updateIdamId(String existingUserIdentifier, String newUserIdentifier){ try (Response response = userProfileFeignClient.getUserProfileById(existingUserIdentifier)) { - + ResponseEntity modifiedUserResponse; Object clazz = response.status() > 300 ? ErrorResponse.class : GetUserProfileResponse.class; ResponseEntity responseResponseEntity = toResponseEntity(response, clazz); @@ -1102,8 +1102,13 @@ public ResponseEntity updateIdamId(String existingUserIdentifier, Strin }else{ throw new EmptyResultDataAccessException(PROFESSIONAL_USER_404_MESSAGE, 1); } - return toResponseEntity( - userResponse, userResponse.status() > 300 ? ErrorResponse.class : ModifyUserRolesResponse.class); + + if(userResponse != null && userResponse.status() > 300){ + modifiedUserResponse = toResponseEntity(userResponse, ModifyUserRolesResponse.class); + }else { + modifiedUserResponse = toResponseEntity(userResponse, ErrorResponse.class); + } + return modifiedUserResponse; } catch (FeignException ex) { throw new ExternalApiException(HttpStatus.valueOf(ex.status()), ERROR_MESSAGE_UP_FAILED); } diff --git a/src/test/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImplTest.java b/src/test/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImplTest.java index 4d0a951e6a..1de77db1b3 100644 --- a/src/test/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImplTest.java +++ b/src/test/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImplTest.java @@ -81,6 +81,7 @@ import uk.gov.hmcts.reform.professionalapi.service.ProfessionalUserService; import uk.gov.hmcts.reform.professionalapi.service.UserAccountMapService; import uk.gov.hmcts.reform.professionalapi.service.UserAttributeService; +import uk.gov.hmcts.reform.professionalapi.util.JsonFeignResponseUtil; import uk.gov.hmcts.reform.professionalapi.util.OrganisationProfileIdConstants; import uk.gov.hmcts.reform.professionalapi.util.RefDataUtil; @@ -198,6 +199,8 @@ class OrganisationServiceImplTest { private DeleteOrganisationResponse deleteOrganisationResponse; private List emptypaymentAccounts; + + Set emptypaymentAccountList; @InjectMocks @@ -290,7 +293,6 @@ void setUp() { when(organisationRepositoryImplNullReturnedMock.findByOrganisationIdentifier(any())).thenReturn(null); when(organisationMfaStatusRepositoryMock.save(any(OrganisationMfaStatus.class))) .thenReturn(organisationMfaStatus); - when(bulkCustomerDetailsRepositoryMock.save(any(BulkCustomerDetails.class))).thenReturn(bulkCustomerDetails); } @@ -2635,6 +2637,7 @@ void testGetOrganisationByStatus2() { List result = sut.getOrganisationByStatus(OrganisationStatus.ACTIVE, null); assertThat(result).isNotEmpty(); + } @Test @@ -2718,4 +2721,115 @@ void shouldRetrieveOrganisationsWithEmptyProfileIdList() { assertThat(result).isNotNull(); assertThat(result.getOrganisationInfo()).isNullOrEmpty(); } + + @Test + void test_modifyOrganisationSetNewIdamIdForUser() throws JsonProcessingException { + String existUserId = UUID.randomUUID().toString(); + String newUserId = UUID.randomUUID().toString(); + NewUserResponse newUserResponse = new NewUserResponse(); + newUserResponse.setUserIdentifier(newUserId); + newUserResponse.setIdamStatus("ACTIVE"); + + ObjectMapper mapper = new ObjectMapper(); + String body = mapper.writeValueAsString(newUserResponse); + + Response userResponse = Response.builder() + .request(mock(Request.class)).body(body, Charset.defaultCharset()).status(200).build(); + + when(userProfileFeignClient.getUserProfileById(existUserId)).thenReturn(userResponse); + + Response response = mock(Response.class); + when(response.status()).thenReturn(200); + when(userProfileFeignClient.modifyUserRoles(any(), any(), any())).thenReturn(response); + + ProfessionalUser professionalUserMock = mock(ProfessionalUser.class); + + when(professionalUserServiceMock.findProfessionalUserByUserIdentifier(any())) + .thenReturn(professionalUserMock); + + assertThat(userResponse).isNotNull(); + ResponseEntity result = sut.updateIdamId(existUserId, newUserId); + + assertThat(result).isNotNull(); + assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK); + + verify(professionalUserRepositoryMock, times(1)).save(any()); + verify(userProfileFeignClient, times(1)).modifyUserRoles(any(),any(),any()); + } + + + @Test + void test_modifyOrganisationSetNewIdamIdForNonExistingUserProfileGivesError() throws JsonProcessingException { + String existUserId = UUID.randomUUID().toString(); + String newUserId = UUID.randomUUID().toString(); + NewUserResponse newUserResponse = new NewUserResponse(); + newUserResponse.setUserIdentifier(newUserId); + newUserResponse.setIdamStatus("ACTIVE"); + + ObjectMapper mapper = new ObjectMapper(); + String body = mapper.writeValueAsString(newUserResponse); + + Response userResponse = Response.builder() + .request(mock(Request.class)).body(body, Charset.defaultCharset()).status(400).build(); + + when(userProfileFeignClient.getUserProfileById(existUserId)).thenReturn(userResponse); + + assertThrows(ExternalApiException.class, () -> sut.updateIdamId(existUserId, newUserId)); + + } + + @Test + void test_modifyOrganisationSetNewIdamIdForNonExistingProfessionalUserGivesError() throws JsonProcessingException { + String existUserId = UUID.randomUUID().toString(); + String newUserId = UUID.randomUUID().toString(); + NewUserResponse newUserResponse = new NewUserResponse(); + newUserResponse.setUserIdentifier(newUserId); + newUserResponse.setIdamStatus("ACTIVE"); + + ObjectMapper mapper = new ObjectMapper(); + String body = mapper.writeValueAsString(newUserResponse); + + Response userResponse = Response.builder() + .request(mock(Request.class)).body(body, Charset.defaultCharset()).status(200).build(); + + when(userProfileFeignClient.getUserProfileById(existUserId)).thenReturn(userResponse); + Response response = mock(Response.class); + when(userProfileFeignClient.modifyUserRoles(any(), any(), any())).thenReturn(response); + when(professionalUserServiceMock.findProfessionalUserByUserIdentifier(any())) + .thenReturn(null); + assertThrows(EmptyResultDataAccessException.class, () -> sut.updateIdamId(existUserId, newUserId)); + } + + @Test + void test_modifyOrganisationSetNewIdamIdForUserGivesError() throws JsonProcessingException { + String existUserId = UUID.randomUUID().toString(); + String newUserId = UUID.randomUUID().toString(); + NewUserResponse newUserResponse = new NewUserResponse(); + newUserResponse.setUserIdentifier(newUserId); + newUserResponse.setIdamStatus("ACTIVE"); + + ObjectMapper mapper = new ObjectMapper(); + String body = mapper.writeValueAsString(newUserResponse); + + Response userResponse = Response.builder() + .request(mock(Request.class)).body(body, Charset.defaultCharset()).status(200).build(); + + when(userProfileFeignClient.getUserProfileById(existUserId)).thenReturn(userResponse); + assertThat(userResponse).isNotNull(); + + Response response = mock(Response.class); + when(response.status()).thenReturn(400); + when(userProfileFeignClient.modifyUserRoles(any(), any(), any())).thenReturn(response); + + ProfessionalUser professionalUserMock = mock(ProfessionalUser.class); + + when(professionalUserServiceMock.findProfessionalUserByUserIdentifier(any())) + .thenReturn(professionalUserMock); + + ResponseEntity result = sut.updateIdamId(existUserId, newUserId); + + assertThat(result).isNotNull(); + assertThat(result.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST); + + } } From afa9069fc52760de92f40ab1cc1dca8fe96df411 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Tue, 30 Apr 2024 22:11:34 +0100 Subject: [PATCH 04/21] Delete User and User Profile --- .../ModifyUserIdamIdIntegrationTest.java | 113 ++++++++++++++++++ .../util/ProfessionalReferenceDataClient.java | 21 ++++ .../OrganisationInternalController.java | 5 +- 3 files changed, 136 insertions(+), 3 deletions(-) create mode 100644 src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/ModifyUserIdamIdIntegrationTest.java diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/ModifyUserIdamIdIntegrationTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/ModifyUserIdamIdIntegrationTest.java new file mode 100644 index 0000000000..b494219f77 --- /dev/null +++ b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/ModifyUserIdamIdIntegrationTest.java @@ -0,0 +1,113 @@ +package uk.gov.hmcts.reform.professionalapi; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + +import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; +import static org.assertj.core.api.Assertions.assertThat; + +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.Test; +import org.springframework.http.HttpStatus; +import uk.gov.hmcts.reform.lib.util.serenity5.SerenityTest; +import uk.gov.hmcts.reform.professionalapi.controller.request.ProfessionalUserIdentifierRequest; +import uk.gov.hmcts.reform.professionalapi.domain.RoleName; +import uk.gov.hmcts.reform.professionalapi.domain.UserProfileUpdatedData; +import uk.gov.hmcts.reform.professionalapi.util.AuthorizationEnabledIntegrationTest; + +@SerenityTest +@Slf4j +class ModifyUserIdamIdIntegrationTest extends AuthorizationEnabledIntegrationTest { + + @Test + void ac1_modify_idamId_of_active_user_for_an_active_organisation_should_return_200() { + //create and update organisation + String organisationIdentifier = createOrganisationRequest(); + updateOrganisation(organisationIdentifier, hmctsAdmin, ACTIVE); + + //create new user + List userRoles = new ArrayList<>(); + userProfileCreateUserWireMock(HttpStatus.CREATED); + userRoles.add(puiCaseManager); + + Map newUserResponse = + professionalReferenceDataClient.addUserToOrganisation(organisationIdentifier, + inviteUserCreationRequest(randomAlphabetic(5) + "@email.com", + userRoles), hmctsAdmin); + String existingUserIdentifier = (String) newUserResponse.get(USER_IDENTIFIER); + + ProfessionalUserIdentifierRequest professionalUserIdentifierRequest = ProfessionalUserIdentifierRequest + .aUserIdentifierRequest().existingIdamId(existingUserIdentifier).newIdamId(UUID.randomUUID().toString()) + .build(); + + //modify Idam details in user Profile + userProfileCreateUserWireMock(HttpStatus.CREATED); + + updateUserProfileRolesMock(HttpStatus.OK); + + Map modifiedUserResponse = + professionalReferenceDataClient.updateUserIdamForOrganisation(professionalUserIdentifierRequest,hmctsAdmin); + + + //validate overall response should be 200 always + assertThat(modifiedUserResponse.get("http_status")).isNotNull(); + assertThat(modifiedUserResponse.get("http_status")).isEqualTo("200 OK"); + + } + + + @Test + void ac2_modify_idam_newId_null_should_return_400() { + + //create and update organisation + String organisationIdentifier = createOrganisationRequest(); + updateOrganisation(organisationIdentifier, hmctsAdmin, ACTIVE); + + //create new user + List userRoles = new ArrayList<>(); + userProfileCreateUserWireMock(HttpStatus.CREATED); + userRoles.add(puiCaseManager); + + Map newUserResponse = + professionalReferenceDataClient.addUserToOrganisation(organisationIdentifier, + inviteUserCreationRequest(randomAlphabetic(5) + "@email.com", + userRoles), hmctsAdmin); + String existingUserIdentifier = (String) newUserResponse.get(USER_IDENTIFIER); + + ProfessionalUserIdentifierRequest professionalUserIdentifierRequest = ProfessionalUserIdentifierRequest + .aUserIdentifierRequest().existingIdamId(existingUserIdentifier).newIdamId(null) + .build(); + + userProfileCreateUserWireMock(HttpStatus.CREATED); + updateUserProfileRolesMock(HttpStatus.BAD_REQUEST); + + Map modifiedUserResponse = + professionalReferenceDataClient.updateUserIdamForOrganisation(professionalUserIdentifierRequest,hmctsAdmin); + + assertThat(modifiedUserResponse.get("http_status")).isNotNull(); + assertThat(modifiedUserResponse).containsEntry("http_status","400"); + + } + + + @Test + void ac2_modify_idam_existingId_null_should_return_400() { + + ProfessionalUserIdentifierRequest professionalUserIdentifierRequest = ProfessionalUserIdentifierRequest + .aUserIdentifierRequest().existingIdamId(null).newIdamId(UUID.randomUUID().toString()) + .build(); + + userProfileCreateUserWireMock(HttpStatus.CREATED); + updateUserProfileRolesMock(HttpStatus.BAD_REQUEST); + + Map modifiedUserResponse = + professionalReferenceDataClient.updateUserIdamForOrganisation(professionalUserIdentifierRequest,hmctsAdmin); + + assertThat(modifiedUserResponse.get("http_status")).isNotNull(); + assertThat(modifiedUserResponse).containsEntry("http_status","400"); + } +} \ No newline at end of file diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/util/ProfessionalReferenceDataClient.java b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/util/ProfessionalReferenceDataClient.java index 9f05b9c5e1..2cffe96fc3 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/util/ProfessionalReferenceDataClient.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/util/ProfessionalReferenceDataClient.java @@ -27,6 +27,7 @@ import uk.gov.hmcts.reform.professionalapi.controller.request.OrganisationCreationRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.OrganisationOtherOrgsCreationRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.PbaRequest; +import uk.gov.hmcts.reform.professionalapi.controller.request.ProfessionalUserIdentifierRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.UpdatePbaRequest; import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationMinimalInfoResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationResponse; @@ -663,6 +664,26 @@ public Map modifyUserRolesOfOrganisation(UserProfileUpdatedData return getResponse(responseEntity); } + public Map updateUserIdamForOrganisation( + ProfessionalUserIdentifierRequest professionalUserIdentifierRequest , String hmctsAdmin) { + ResponseEntity responseEntity = null; + String urlPath = "http://localhost:" + prdApiPort + APP_INT_BASE_PATH + "/userIdam/"; + + try { + HttpEntity requestEntity = new HttpEntity<>(professionalUserIdentifierRequest, + getMultipleAuthHeaders(hmctsAdmin)); + responseEntity = restTemplate.exchange(urlPath, HttpMethod.PUT, requestEntity, Map.class); + } catch (RestClientResponseException ex) { + HashMap statusAndBody = new HashMap<>(2); + statusAndBody.put("http_status", String.valueOf(ex.getRawStatusCode())); + statusAndBody.put("response_body", ex.getResponseBodyAsString()); + return statusAndBody; + } + + + return getResponse(responseEntity); + } + public Map modifyUserRolesOfOrganisationExternal(UserProfileUpdatedData userProfileUpdatedData, String userIdentifier, String externalRole) { ResponseEntity responseEntity = null; diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalController.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalController.java index db9a95ba6b..191771cc35 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalController.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalController.java @@ -741,7 +741,7 @@ public ResponseEntity retrieveOrganisationByUserId( @PutMapping( - path = "/userIdam/{orgId}", + path = "/userIdam", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE ) @@ -750,8 +750,7 @@ public ResponseEntity retrieveOrganisationByUserId( @Secured({"prd-admin"}) public ResponseEntity updateUserIdamForOrganisation( @io.swagger.v3.oas.annotations.parameters.RequestBody(description = "contactInformationCreationRequests") - @Valid @NotNull @RequestBody ProfessionalUserIdentifierRequest professionalUserIdentifierRequest, - @PathVariable("orgId") @NotBlank String organisationIdentifier) { + @Valid @NotNull @RequestBody ProfessionalUserIdentifierRequest professionalUserIdentifierRequest) { log.info("{}:: Received request to update idam id for an user in an " + "organisation ::", loggingComponentName); From 3e9c773c65fd3c71c907ddf7130268f509d8a7e7 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Tue, 30 Apr 2024 22:23:02 +0100 Subject: [PATCH 05/21] Delete User and User Profile --- .../ModifyUserIdamIdIntegrationTest.java | 18 +++++++--------- .../util/ProfessionalReferenceDataClient.java | 5 +++-- .../OrganisationInternalController.java | 9 ++++---- .../ProfessionalUserIdentifierRequest.java | 4 ++-- .../service/impl/OrganisationServiceImpl.java | 21 ++++++++----------- ...rofessionalExternalUserControllerTest.java | 3 ++- ...ProfileUpdateRequestValidatorImplTest.java | 18 ++++++++++------ .../domain/UserProfileUpdatedDataTest.java | 3 ++- .../impl/OrganisationServiceImplTest.java | 5 ++--- 9 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/ModifyUserIdamIdIntegrationTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/ModifyUserIdamIdIntegrationTest.java index b494219f77..6213e14938 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/ModifyUserIdamIdIntegrationTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/ModifyUserIdamIdIntegrationTest.java @@ -1,24 +1,20 @@ package uk.gov.hmcts.reform.professionalapi; +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.Test; +import org.springframework.http.HttpStatus; +import uk.gov.hmcts.reform.lib.util.serenity5.SerenityTest; +import uk.gov.hmcts.reform.professionalapi.controller.request.ProfessionalUserIdentifierRequest; +import uk.gov.hmcts.reform.professionalapi.util.AuthorizationEnabledIntegrationTest; + import java.util.ArrayList; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.UUID; import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; import static org.assertj.core.api.Assertions.assertThat; -import lombok.extern.slf4j.Slf4j; -import org.junit.jupiter.api.Test; -import org.springframework.http.HttpStatus; -import uk.gov.hmcts.reform.lib.util.serenity5.SerenityTest; -import uk.gov.hmcts.reform.professionalapi.controller.request.ProfessionalUserIdentifierRequest; -import uk.gov.hmcts.reform.professionalapi.domain.RoleName; -import uk.gov.hmcts.reform.professionalapi.domain.UserProfileUpdatedData; -import uk.gov.hmcts.reform.professionalapi.util.AuthorizationEnabledIntegrationTest; - @SerenityTest @Slf4j class ModifyUserIdamIdIntegrationTest extends AuthorizationEnabledIntegrationTest { diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/util/ProfessionalReferenceDataClient.java b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/util/ProfessionalReferenceDataClient.java index 2cffe96fc3..a438c1b42f 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/util/ProfessionalReferenceDataClient.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/util/ProfessionalReferenceDataClient.java @@ -665,12 +665,13 @@ public Map modifyUserRolesOfOrganisation(UserProfileUpdatedData } public Map updateUserIdamForOrganisation( - ProfessionalUserIdentifierRequest professionalUserIdentifierRequest , String hmctsAdmin) { + ProfessionalUserIdentifierRequest professionalUserIdentifierRequest, String hmctsAdmin) { ResponseEntity responseEntity = null; String urlPath = "http://localhost:" + prdApiPort + APP_INT_BASE_PATH + "/userIdam/"; try { - HttpEntity requestEntity = new HttpEntity<>(professionalUserIdentifierRequest, + HttpEntity requestEntity = + new HttpEntity<>(professionalUserIdentifierRequest, getMultipleAuthHeaders(hmctsAdmin)); responseEntity = restTemplate.exchange(urlPath, HttpMethod.PUT, requestEntity, Map.class); } catch (RestClientResponseException ex) { diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalController.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalController.java index 191771cc35..63d09f300b 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalController.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalController.java @@ -60,7 +60,6 @@ import static org.apache.commons.lang.StringUtils.isBlank; import static org.apache.commons.lang3.BooleanUtils.isNotTrue; import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; -import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ERROR_MESSAGE_EMPTY_CONTACT_INFORMATION; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ERROR_MSG_REQUEST_IS_EMPTY; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ORGANISATION_IDENTIFIER_FORMAT_REGEX; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ORG_ID_VALIDATION_ERROR_MESSAGE; @@ -752,8 +751,8 @@ public ResponseEntity updateUserIdamForOrganisation( @io.swagger.v3.oas.annotations.parameters.RequestBody(description = "contactInformationCreationRequests") @Valid @NotNull @RequestBody ProfessionalUserIdentifierRequest professionalUserIdentifierRequest) { - log.info("{}:: Received request to update idam id for an user in an " + - "organisation ::", loggingComponentName); + log.info("{}:: Received request to update idam id for an user in an " + + "organisation ::", loggingComponentName); if (!Optional.ofNullable(professionalUserIdentifierRequest).isPresent()) { throw new InvalidRequest(ERROR_MSG_REQUEST_IS_EMPTY); @@ -762,8 +761,8 @@ public ResponseEntity updateUserIdamForOrganisation( ) { throw new InvalidRequest("Please enter existing and New Idam ids / User identifiers"); } - return organisationService.updateIdamId(professionalUserIdentifierRequest.getExistingIdamId() - ,professionalUserIdentifierRequest.getNewIdamId()); + return organisationService.updateIdamId(professionalUserIdentifierRequest.getExistingIdamId(), + professionalUserIdentifierRequest.getNewIdamId()); } diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/ProfessionalUserIdentifierRequest.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/ProfessionalUserIdentifierRequest.java index a5fb190cfc..e26fc26225 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/ProfessionalUserIdentifierRequest.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/ProfessionalUserIdentifierRequest.java @@ -1,12 +1,12 @@ package uk.gov.hmcts.reform.professionalapi.controller.request; -import javax.validation.constraints.NotNull; - import com.fasterxml.jackson.annotation.JsonCreator; import lombok.Builder; import lombok.Getter; import lombok.Setter; +import javax.validation.constraints.NotNull; + @Getter @Setter diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java index a04db0d4e2..2fd24a7c76 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java @@ -38,11 +38,8 @@ import uk.gov.hmcts.reform.professionalapi.controller.response.BulkCustomerOrganisationsDetailResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.DeleteOrganisationResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.FetchPbaByStatusResponse; - import uk.gov.hmcts.reform.professionalapi.controller.response.GetUserProfileResponse; - import uk.gov.hmcts.reform.professionalapi.controller.response.MultipleOrganisationsResponse; - import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationEntityResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationEntityResponseV2; import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationResponse; @@ -1071,8 +1068,7 @@ private boolean getMoreAvailable(Page pageableOrganisations) { } @Transactional - public ResponseEntity updateIdamId(String existingUserIdentifier, String newUserIdentifier){ - + public ResponseEntity updateIdamId(String existingUserIdentifier, String newUserIdentifier) { try (Response response = userProfileFeignClient.getUserProfileById(existingUserIdentifier)) { ResponseEntity modifiedUserResponse; Object clazz = response.status() > 300 ? ErrorResponse.class : GetUserProfileResponse.class; @@ -1092,20 +1088,21 @@ public ResponseEntity updateIdamId(String existingUserIdentifier, Strin .idamStatus(existingUserProfile.getIdamStatus().name()) .build(); - Response userResponse = userProfileFeignClient.modifyUserRoles(userProfileUpdatedData, existingUserIdentifier, - " "); + Response userResponse = userProfileFeignClient + .modifyUserRoles(userProfileUpdatedData, existingUserIdentifier," "); - Optional professionalUser = Optional.ofNullable(professionalUserService.findProfessionalUserByUserIdentifier(existingUserIdentifier)); - if(professionalUser.isPresent()){ + Optional professionalUser = Optional + .ofNullable(professionalUserService.findProfessionalUserByUserIdentifier(existingUserIdentifier)); + if (professionalUser.isPresent()) { professionalUser.get().setUserIdentifier(newUserIdentifier); professionalUserRepository.save(professionalUser.get()); - }else{ + } else { throw new EmptyResultDataAccessException(PROFESSIONAL_USER_404_MESSAGE, 1); } - if(userResponse != null && userResponse.status() > 300){ + if (userResponse != null && userResponse.status() > 300) { modifiedUserResponse = toResponseEntity(userResponse, ModifyUserRolesResponse.class); - }else { + } else { modifiedUserResponse = toResponseEntity(userResponse, ErrorResponse.class); } return modifiedUserResponse; diff --git a/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/external/ProfessionalExternalUserControllerTest.java b/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/external/ProfessionalExternalUserControllerTest.java index 024d6d222a..8533eb4475 100644 --- a/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/external/ProfessionalExternalUserControllerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/external/ProfessionalExternalUserControllerTest.java @@ -371,7 +371,8 @@ void test_FindUserStatusByEmailFromHeaderThrows400WhenEmailIsInvalid() { @Test void test_modifyRolesForExistingUserOfExternalOrganisation() { ResponseEntity newResponse = ResponseEntity.status(200).body(""); - UserProfileUpdatedData userProfileUpdatedData = new UserProfileUpdatedData(UUID.randomUUID().toString(),"test@email.com", "firstName", + UserProfileUpdatedData userProfileUpdatedData = + new UserProfileUpdatedData(UUID.randomUUID().toString(),"test@email.com", "firstName", "lastName", IdamStatus.ACTIVE.name(), null, null, null); String orgId = "org123"; String userId = "1234567890"; diff --git a/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/request/validator/impl/UserProfileUpdateRequestValidatorImplTest.java b/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/request/validator/impl/UserProfileUpdateRequestValidatorImplTest.java index a8aa63ca4e..3da9fd43c7 100644 --- a/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/request/validator/impl/UserProfileUpdateRequestValidatorImplTest.java +++ b/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/request/validator/impl/UserProfileUpdateRequestValidatorImplTest.java @@ -52,7 +52,8 @@ void setUp() { @Test void test_ValidateRequestIfBothStatusAndRoleArePresent() { - UserProfileUpdatedData userProfileUpdatedData = new UserProfileUpdatedData(UUID.randomUUID().toString(),email, firstName, lastName, + UserProfileUpdatedData userProfileUpdatedData = + new UserProfileUpdatedData(UUID.randomUUID().toString(),email, firstName, lastName, IdamStatus.ACTIVE.name(), rolesData, rolesToDeleteData, null); UserProfileUpdateRequestValidator sut = new UserProfileUpdateRequestValidatorImpl(); @@ -67,7 +68,8 @@ void test_ValidateRequestIfBothStatusAndRoleArePresent() { @Test void test_ValidateRequestForStatus() { - UserProfileUpdatedData userProfileUpdatedData = new UserProfileUpdatedData(UUID.randomUUID().toString(),email, firstName, lastName, + UserProfileUpdatedData userProfileUpdatedData = + new UserProfileUpdatedData(UUID.randomUUID().toString(),email, firstName, lastName, IdamStatus.ACTIVE.name(), null, null, null); UserProfileUpdateRequestValidator sut = new UserProfileUpdateRequestValidatorImpl(); @@ -81,7 +83,8 @@ void test_ValidateRequestForStatus() { @Test void test_ValidateRequestForRoles() { - UserProfileUpdatedData userProfileUpdatedData = new UserProfileUpdatedData(UUID.randomUUID().toString(),email, firstName, lastName, + UserProfileUpdatedData userProfileUpdatedData = + new UserProfileUpdatedData(UUID.randomUUID().toString(),email, firstName, lastName, null, rolesData, rolesToDeleteData, null); UserProfileUpdateRequestValidator sut = new UserProfileUpdateRequestValidatorImpl(); @@ -95,7 +98,8 @@ void test_ValidateRequestForRoles() { @Test void test_ValidateRequestForAccessTypes() { - UserProfileUpdatedData userProfileUpdatedData = new UserProfileUpdatedData(UUID.randomUUID().toString(),email, firstName, lastName, + UserProfileUpdatedData userProfileUpdatedData = + new UserProfileUpdatedData(UUID.randomUUID().toString(),email, firstName, lastName, IdamStatus.ACTIVE.name(), null, null, userAccessTypes); UserProfileUpdateRequestValidator sut = new UserProfileUpdateRequestValidatorImpl(); @@ -110,7 +114,8 @@ void test_ValidateRequestForAccessTypes() { @Test void test_ValidateRequestForAccessTypesEmpty() { - UserProfileUpdatedData userProfileUpdatedData = new UserProfileUpdatedData(UUID.randomUUID().toString(),email, firstName, lastName, + UserProfileUpdatedData userProfileUpdatedData = + new UserProfileUpdatedData(UUID.randomUUID().toString(),email, firstName, lastName, IdamStatus.ACTIVE.name(), null, null, new HashSet<>()); UserProfileUpdateRequestValidator sut = new UserProfileUpdateRequestValidatorImpl(); @@ -125,7 +130,8 @@ void test_ValidateRequestForAccessTypesEmpty() { @Test void test_ThrowErrorIfValidateRequestIsEmpty() { - UserProfileUpdatedData userProfileUpdatedData = new UserProfileUpdatedData(UUID.randomUUID().toString(),email, firstName, lastName, + UserProfileUpdatedData userProfileUpdatedData = + new UserProfileUpdatedData(UUID.randomUUID().toString(),email, firstName, lastName, null, null, null, null); UserProfileUpdateRequestValidator sut = new UserProfileUpdateRequestValidatorImpl(); diff --git a/src/test/java/uk/gov/hmcts/reform/professionalapi/domain/UserProfileUpdatedDataTest.java b/src/test/java/uk/gov/hmcts/reform/professionalapi/domain/UserProfileUpdatedDataTest.java index e7e0759488..656a6a2ac2 100644 --- a/src/test/java/uk/gov/hmcts/reform/professionalapi/domain/UserProfileUpdatedDataTest.java +++ b/src/test/java/uk/gov/hmcts/reform/professionalapi/domain/UserProfileUpdatedDataTest.java @@ -30,7 +30,8 @@ void test_should_add_roles_add_when_modified() { Set userAccessTypes = new HashSet<>(); userAccessTypes.add(userAccessType1); - UserProfileUpdatedData userProfileUpdatedData = new UserProfileUpdatedData(UUID.randomUUID().toString(),"test@test.com", "fname", "lname", + UserProfileUpdatedData userProfileUpdatedData = + new UserProfileUpdatedData(UUID.randomUUID().toString(),"test@test.com", "fname", "lname", "ACTIVE", rolesAdd, rolesDelete, userAccessTypes); userProfileUpdatedData.setRolesAdd(rolesAdd); userProfileUpdatedData.setRolesDelete(rolesDelete); diff --git a/src/test/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImplTest.java b/src/test/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImplTest.java index 1de77db1b3..536776c522 100644 --- a/src/test/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImplTest.java +++ b/src/test/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImplTest.java @@ -81,7 +81,6 @@ import uk.gov.hmcts.reform.professionalapi.service.ProfessionalUserService; import uk.gov.hmcts.reform.professionalapi.service.UserAccountMapService; import uk.gov.hmcts.reform.professionalapi.service.UserAttributeService; -import uk.gov.hmcts.reform.professionalapi.util.JsonFeignResponseUtil; import uk.gov.hmcts.reform.professionalapi.util.OrganisationProfileIdConstants; import uk.gov.hmcts.reform.professionalapi.util.RefDataUtil; @@ -2748,7 +2747,7 @@ void test_modifyOrganisationSetNewIdamIdForUser() throws JsonProcessingException .thenReturn(professionalUserMock); assertThat(userResponse).isNotNull(); - ResponseEntity result = sut.updateIdamId(existUserId, newUserId); + ResponseEntity result = sut.updateIdamId(existUserId, newUserId); assertThat(result).isNotNull(); assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK); @@ -2826,7 +2825,7 @@ void test_modifyOrganisationSetNewIdamIdForUserGivesError() throws JsonProcessin when(professionalUserServiceMock.findProfessionalUserByUserIdentifier(any())) .thenReturn(professionalUserMock); - ResponseEntity result = sut.updateIdamId(existUserId, newUserId); + ResponseEntity result = sut.updateIdamId(existUserId, newUserId); assertThat(result).isNotNull(); assertThat(result.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST); From 97d98d51c9ff7d811bc39eaad19276222b396ced Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Wed, 1 May 2024 20:57:52 +0100 Subject: [PATCH 06/21] Delete User and User Profile --- ...rofessionalInternalUserFunctionalTest.java | 42 +++++++++++++++++++ .../client/ProfessionalApiClient.java | 20 ++++++++- 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java index 3844286592..f5140ea896 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java @@ -18,6 +18,7 @@ import uk.gov.hmcts.reform.professionalapi.controller.request.OrganisationCreationRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.PbaRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.PbaUpdateRequest; +import uk.gov.hmcts.reform.professionalapi.controller.request.ProfessionalUserIdentifierRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.UpdatePbaRequest; import uk.gov.hmcts.reform.professionalapi.controller.response.FetchPbaByStatusResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationsWithPbaStatusResponse; @@ -38,6 +39,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.UUID; import java.util.stream.Collectors; import static java.util.Objects.nonNull; @@ -689,6 +691,46 @@ void findOrganisationByPbaStatusShouldReturn403WhenToggledOff() { } + @Test + @DisplayName("Update Organisation's Idam id should return 200 when toggled off") + void updateUserIdamForOrganisationShouldReturnSuccess() { + log.info("updateUserIdamForOrganisationShouldReturnSuccess :: STARTED"); + OrganisationCreationRequest orgReq = createOrganisationRequest().build(); + Map response = professionalApiClient.createOrganisation(orgReq); + String orgIdentifier = (String) response.get("organisationIdentifier"); + orgReq.setStatus("ACTIVE"); + professionalApiClient.updateOrganisation(orgReq, hmctsAdmin, + orgIdentifier, OK); + + NewUserCreationRequest newUserCreationRequest = + professionalApiClient.createNewUserRequest("testEmail@hmcts.com"); + Map newUserResponse = professionalApiClient.addNewUserToAnOrganisation(orgIdentifier, + hmctsAdmin, newUserCreationRequest, HttpStatus.CREATED); + assertThat(newUserResponse).isNotNull(); + assertThat(newUserResponse.get("userIdentifier")).isNotNull(); + String existingUserId = (String) newUserResponse.get("userIdentifier"); + + ProfessionalUserIdentifierRequest professionalUserIdentifierRequest = ProfessionalUserIdentifierRequest + .aUserIdentifierRequest().existingIdamId(existingUserId).newIdamId(UUID.randomUUID().toString()) + .build(); + + Map updatedIdamResponse = professionalApiClient.updateUserIdamForOrganisation( + professionalUserIdentifierRequest, OK); + + Map searchResponse = professionalApiClient + .searchOrganisationUsersByStatusInternal(orgIdentifier, hmctsAdmin, OK); + + List> professionalUsersResponses = (List>) searchResponse.get("users"); + Map professionalUsersResponse = getUserById(professionalUsersResponses, existingUserId); + + professionalApiClient.deleteOrganisation(orgIdentifier, hmctsAdmin, NO_CONTENT); + + assertThat(updatedIdamResponse).isNotNull(); + assertThat(professionalUsersResponse).isNotNull(); + + log.info("updateUserIdamForOrganisationShouldReturnSuccess :: END"); + } + @Test @ToggleEnable(mapKey = "OrganisationInternalController.updateAnOrganisationsRegisteredPbas", withFeature = true) @ExtendWith(FeatureToggleConditionExtension.class) diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/client/ProfessionalApiClient.java b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/client/ProfessionalApiClient.java index c2afa21ad1..a3ad1bdad3 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/client/ProfessionalApiClient.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/client/ProfessionalApiClient.java @@ -22,6 +22,7 @@ import uk.gov.hmcts.reform.professionalapi.controller.request.OrganisationCreationRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.OrganisationOtherOrgsCreationRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.PbaRequest; +import uk.gov.hmcts.reform.professionalapi.controller.request.ProfessionalUserIdentifierRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.UpdatePbaRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.UserCreationRequest; import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationMinimalInfoResponse; @@ -773,6 +774,21 @@ public Map retrievePaymentAccountsByEmail(String email, String r return response.body().as(Map.class); } + public Map updateUserIdamForOrganisation( + ProfessionalUserIdentifierRequest professionalUserIdentifierRequest, HttpStatus status) { + Response response = getMultipleAuthHeadersInternal() + .body(professionalUserIdentifierRequest) + .put("/refdata/internal/v1/organisations/userIdam") + .andReturn(); + + response.then() + .assertThat() + .statusCode(OK.value()); + + return response.body().as(Map.class); + } + + public Map retrievePaymentAccountsByEmailV2(String email, String role) { Response response = getUserEmailAsHeaderWithExisting(idamOpenIdClient .getcwdAdminOpenIdToken("prd-admin"), email) @@ -1196,8 +1212,8 @@ public void updateOrganisationV2(OrganisationOtherOrgsCreationRequest organisati public void updateOrganisation(String organisationIdentifier, String role) { - OrganisationCreationRequest organisationCreationRequest = createOrganisationRequest().status("ACTIVE").build(); - + OrganisationCreationRequest organisationCreationRequest = createOrganisationRequest().status("ACTIVE") + .statusMessage("Activate organisation").build(); updateOrganisation(organisationCreationRequest, role, organisationIdentifier); } From 681846a73764b79d7f0b66340aee46e98cfe5544 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Thu, 2 May 2024 09:05:57 +0100 Subject: [PATCH 07/21] Delete User and User Profile --- src/integrationTest/resources/application.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/integrationTest/resources/application.yml b/src/integrationTest/resources/application.yml index 670257b215..38370e63d4 100644 --- a/src/integrationTest/resources/application.yml +++ b/src/integrationTest/resources/application.yml @@ -1,6 +1,6 @@ spring: flyway: - schemas: dbrefdata + schemas: DBREFDATA locations: classpath:db/migration jpa: From f3bae92cd10929b3e6012faf6b169ed443af83d2 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Tue, 7 May 2024 21:48:07 +0100 Subject: [PATCH 08/21] updateUserIdamForOrganisation --- .../professionalapi/ProfessionalInternalUserFunctionalTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java index f05b254f7e..441388df23 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java @@ -692,7 +692,9 @@ void findOrganisationByPbaStatusShouldReturn403WhenToggledOff() { } @Test + @ExtendWith(FeatureToggleConditionExtension.class) @DisplayName("Update Organisation's Idam id should return 200 when toggled off") + @ToggleEnable(mapKey = "OrganisationInternalController.retrieveOrgByPbaStatus", withFeature = false) void updateUserIdamForOrganisationShouldReturnSuccess() { log.info("updateUserIdamForOrganisationShouldReturnSuccess :: STARTED"); OrganisationCreationRequest orgReq = createOrganisationRequest().build(); From d0f711673074e813039356a65146c7848378f582 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Tue, 11 Jun 2024 22:05:28 +0100 Subject: [PATCH 09/21] update admin unit tests --- .../professionalapi/service/impl/OrganisationServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java index 2fd24a7c76..f4c4599d91 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java @@ -1074,7 +1074,7 @@ public ResponseEntity updateIdamId(String existingUserIdentifier, Strin Object clazz = response.status() > 300 ? ErrorResponse.class : GetUserProfileResponse.class; ResponseEntity responseResponseEntity = toResponseEntity(response, clazz); - if (response.status() > 300) { + if (response.status() > 300 && responseResponseEntity.getBody() != null) { String errorMessage = nonNull(responseResponseEntity.getBody()) ? ((ErrorResponse)responseResponseEntity.getBody()).getErrorMessage() : ERROR_MESSAGE_UP_FAILED; throw new ExternalApiException(responseResponseEntity.getStatusCode(), errorMessage); From df2a5238abd3549d31b8a97bcc0cac5f6602fe8e Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Tue, 11 Jun 2024 22:07:06 +0100 Subject: [PATCH 10/21] update admin unit tests --- .../professionalapi/service/impl/OrganisationServiceImpl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java index f4c4599d91..fdda8e56ec 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java @@ -1080,6 +1080,7 @@ public ResponseEntity updateIdamId(String existingUserIdentifier, Strin throw new ExternalApiException(responseResponseEntity.getStatusCode(), errorMessage); } + GetUserProfileResponse existingUserProfile = (GetUserProfileResponse) requireNonNull(responseResponseEntity.getBody()); From 70abbd7cc2a857a6505723ddb7609d4c4cc5abbf Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Tue, 11 Jun 2024 22:35:11 +0100 Subject: [PATCH 11/21] update admin unit tests --- .../service/impl/OrganisationServiceImpl.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java index fdda8e56ec..2cf65cad06 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java @@ -1073,12 +1073,14 @@ public ResponseEntity updateIdamId(String existingUserIdentifier, Strin ResponseEntity modifiedUserResponse; Object clazz = response.status() > 300 ? ErrorResponse.class : GetUserProfileResponse.class; ResponseEntity responseResponseEntity = toResponseEntity(response, clazz); - - if (response.status() > 300 && responseResponseEntity.getBody() != null) { - String errorMessage = nonNull(responseResponseEntity.getBody()) - ? ((ErrorResponse)responseResponseEntity.getBody()).getErrorMessage() : ERROR_MESSAGE_UP_FAILED; + String errorMessage ; + if (response.status() > 300) { + if(responseResponseEntity != null && responseResponseEntity.getBody() != null){ + errorMessage = ((ErrorResponse)responseResponseEntity.getBody()).getErrorMessage(); + } else{ + errorMessage = ERROR_MESSAGE_UP_FAILED; + } throw new ExternalApiException(responseResponseEntity.getStatusCode(), errorMessage); - } GetUserProfileResponse existingUserProfile = From 548a071dfd5b8cada3fb4f0e15c673f89624e108 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Wed, 12 Jun 2024 07:17:03 +0100 Subject: [PATCH 12/21] update admin unit tests --- .../service/impl/OrganisationServiceImpl.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java index 2cf65cad06..1b90ab50f8 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java @@ -98,7 +98,6 @@ import java.util.stream.Stream; import static java.lang.Boolean.TRUE; -import static java.util.Objects.nonNull; import static java.util.Objects.requireNonNull; import static org.apache.commons.lang3.ObjectUtils.isNotEmpty; import static org.springframework.util.CollectionUtils.isEmpty; @@ -1073,11 +1072,11 @@ public ResponseEntity updateIdamId(String existingUserIdentifier, Strin ResponseEntity modifiedUserResponse; Object clazz = response.status() > 300 ? ErrorResponse.class : GetUserProfileResponse.class; ResponseEntity responseResponseEntity = toResponseEntity(response, clazz); - String errorMessage ; + String errorMessage; if (response.status() > 300) { - if(responseResponseEntity != null && responseResponseEntity.getBody() != null){ + if (responseResponseEntity != null && responseResponseEntity.getBody() != null) { errorMessage = ((ErrorResponse)responseResponseEntity.getBody()).getErrorMessage(); - } else{ + } else { errorMessage = ERROR_MESSAGE_UP_FAILED; } throw new ExternalApiException(responseResponseEntity.getStatusCode(), errorMessage); From 71c907cac4d00dc1144c8fc8402a9f8c6bc55f45 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Wed, 12 Jun 2024 09:30:04 +0100 Subject: [PATCH 13/21] update admin unit tests --- .../service/impl/OrganisationServiceImpl.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java index 1b90ab50f8..56e1507c9e 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java @@ -40,6 +40,7 @@ import uk.gov.hmcts.reform.professionalapi.controller.response.FetchPbaByStatusResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.GetUserProfileResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.MultipleOrganisationsResponse; +import uk.gov.hmcts.reform.professionalapi.controller.response.NewUserResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationEntityResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationEntityResponseV2; import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationResponse; @@ -76,6 +77,7 @@ import uk.gov.hmcts.reform.professionalapi.service.ProfessionalUserService; import uk.gov.hmcts.reform.professionalapi.service.UserAccountMapService; import uk.gov.hmcts.reform.professionalapi.service.UserAttributeService; +import uk.gov.hmcts.reform.professionalapi.util.JsonFeignResponseUtil; import uk.gov.hmcts.reform.professionalapi.util.OrganisationProfileIdConstants; import uk.gov.hmcts.reform.professionalapi.util.OrganisationTypeConstants; import uk.gov.hmcts.reform.professionalapi.util.RefDataUtil; @@ -98,6 +100,7 @@ import java.util.stream.Stream; import static java.lang.Boolean.TRUE; +import static java.util.Objects.nonNull; import static java.util.Objects.requireNonNull; import static org.apache.commons.lang3.ObjectUtils.isNotEmpty; import static org.springframework.util.CollectionUtils.isEmpty; @@ -1069,16 +1072,13 @@ private boolean getMoreAvailable(Page pageableOrganisations) { @Transactional public ResponseEntity updateIdamId(String existingUserIdentifier, String newUserIdentifier) { try (Response response = userProfileFeignClient.getUserProfileById(existingUserIdentifier)) { + ResponseEntity modifiedUserResponse; Object clazz = response.status() > 300 ? ErrorResponse.class : GetUserProfileResponse.class; ResponseEntity responseResponseEntity = toResponseEntity(response, clazz); - String errorMessage; if (response.status() > 300) { - if (responseResponseEntity != null && responseResponseEntity.getBody() != null) { - errorMessage = ((ErrorResponse)responseResponseEntity.getBody()).getErrorMessage(); - } else { - errorMessage = ERROR_MESSAGE_UP_FAILED; - } + String errorMessage = nonNull(responseResponseEntity.getBody()) + ? ((ErrorResponse)requireNonNull(responseResponseEntity.getBody())).getErrorMessage() : ERROR_MESSAGE_UP_FAILED; throw new ExternalApiException(responseResponseEntity.getStatusCode(), errorMessage); } From bae5f689e8e93e0a6230837c894b83004c5a9436 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Wed, 12 Jun 2024 09:48:45 +0100 Subject: [PATCH 14/21] update admin unit tests --- .../service/impl/OrganisationServiceImpl.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java index 56e1507c9e..f6970953e9 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java @@ -40,7 +40,6 @@ import uk.gov.hmcts.reform.professionalapi.controller.response.FetchPbaByStatusResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.GetUserProfileResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.MultipleOrganisationsResponse; -import uk.gov.hmcts.reform.professionalapi.controller.response.NewUserResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationEntityResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationEntityResponseV2; import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationResponse; @@ -77,7 +76,6 @@ import uk.gov.hmcts.reform.professionalapi.service.ProfessionalUserService; import uk.gov.hmcts.reform.professionalapi.service.UserAccountMapService; import uk.gov.hmcts.reform.professionalapi.service.UserAttributeService; -import uk.gov.hmcts.reform.professionalapi.util.JsonFeignResponseUtil; import uk.gov.hmcts.reform.professionalapi.util.OrganisationProfileIdConstants; import uk.gov.hmcts.reform.professionalapi.util.OrganisationTypeConstants; import uk.gov.hmcts.reform.professionalapi.util.RefDataUtil; @@ -1078,7 +1076,8 @@ public ResponseEntity updateIdamId(String existingUserIdentifier, Strin ResponseEntity responseResponseEntity = toResponseEntity(response, clazz); if (response.status() > 300) { String errorMessage = nonNull(responseResponseEntity.getBody()) - ? ((ErrorResponse)requireNonNull(responseResponseEntity.getBody())).getErrorMessage() : ERROR_MESSAGE_UP_FAILED; + ? ((ErrorResponse)requireNonNull(responseResponseEntity.getBody())).getErrorMessage() + : ERROR_MESSAGE_UP_FAILED; throw new ExternalApiException(responseResponseEntity.getStatusCode(), errorMessage); } From ed445d54cb547ce98c13b93fb872a12274a7e346 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Tue, 9 Jul 2024 18:07:55 +0100 Subject: [PATCH 15/21] update functional tests --- .../ProfessionalInternalUserFunctionalTest.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java index 441388df23..23c73e143d 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java @@ -711,9 +711,9 @@ void updateUserIdamForOrganisationShouldReturnSuccess() { assertThat(newUserResponse).isNotNull(); assertThat(newUserResponse.get("userIdentifier")).isNotNull(); String existingUserId = (String) newUserResponse.get("userIdentifier"); - + String newId = UUID.randomUUID().toString(); ProfessionalUserIdentifierRequest professionalUserIdentifierRequest = ProfessionalUserIdentifierRequest - .aUserIdentifierRequest().existingIdamId(existingUserId).newIdamId(UUID.randomUUID().toString()) + .aUserIdentifierRequest().existingIdamId(existingUserId).newIdamId(newId) .build(); Map updatedIdamResponse = professionalApiClient.updateUserIdamForOrganisation( @@ -725,10 +725,12 @@ void updateUserIdamForOrganisationShouldReturnSuccess() { List> professionalUsersResponses = (List>) searchResponse.get("users"); Map professionalUsersResponse = getUserById(professionalUsersResponses, existingUserId); - professionalApiClient.deleteOrganisation(orgIdentifier, hmctsAdmin, NO_CONTENT); - assertThat(updatedIdamResponse).isNotNull(); assertThat(professionalUsersResponse).isNotNull(); + assertThat(professionalUsersResponse.get("userIdentifier").toString()) + .contains(newId); + + professionalApiClient.deleteOrganisation(orgIdentifier, hmctsAdmin, NO_CONTENT); log.info("updateUserIdamForOrganisationShouldReturnSuccess :: END"); } From 40acc8e957001da4b45a20cab1faf5d98e0c4693 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Tue, 9 Jul 2024 18:22:28 +0100 Subject: [PATCH 16/21] update functional tests --- .../ModifyUserIdamIdIntegrationTest.java | 16 ++++++++++++++++ .../internal/OrganisationInternalController.java | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/ModifyUserIdamIdIntegrationTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/ModifyUserIdamIdIntegrationTest.java index 6213e14938..a1bc808fae 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/ModifyUserIdamIdIntegrationTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/ModifyUserIdamIdIntegrationTest.java @@ -106,4 +106,20 @@ void ac2_modify_idam_existingId_null_should_return_400() { assertThat(modifiedUserResponse.get("http_status")).isNotNull(); assertThat(modifiedUserResponse).containsEntry("http_status","400"); } + + void ac2_modify_idam_empty_Request_should_return_400() { + + ProfessionalUserIdentifierRequest professionalUserIdentifierRequest = ProfessionalUserIdentifierRequest + .aUserIdentifierRequest().existingIdamId(null).newIdamId(UUID.randomUUID().toString()) + .build(); + + userProfileCreateUserWireMock(HttpStatus.CREATED); + updateUserProfileRolesMock(HttpStatus.BAD_REQUEST); + + Map modifiedUserResponse = + professionalReferenceDataClient.updateUserIdamForOrganisation(null,hmctsAdmin); + + assertThat(modifiedUserResponse.get("http_status")).isNotNull(); + assertThat(modifiedUserResponse).containsEntry("http_status","400"); + } } \ No newline at end of file diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalController.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalController.java index fb2fe78ef7..c80139ae19 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalController.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalController.java @@ -703,7 +703,7 @@ public ResponseEntity retrieveOrganisationByUserId( @Operation( summary = "Updates idam id for a user in an organisation", - description = "**IDAM Roles to access API** :
pui-organisation-manager", + description = "**IDAM Roles to access API** :
prd-admin ", security = { @SecurityRequirement(name = "ServiceAuthorization"), @SecurityRequirement(name = "Authorization") From f8178fd5d7d0a75ff42fea4485e0fdda586a12d8 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Tue, 9 Jul 2024 18:28:56 +0100 Subject: [PATCH 17/21] update functional tests --- .../service/impl/OrganisationServiceImpl.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java index f6970953e9..43b0fefa6c 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java @@ -1092,19 +1092,18 @@ public ResponseEntity updateIdamId(String existingUserIdentifier, Strin Response userResponse = userProfileFeignClient .modifyUserRoles(userProfileUpdatedData, existingUserIdentifier," "); - Optional professionalUser = Optional - .ofNullable(professionalUserService.findProfessionalUserByUserIdentifier(existingUserIdentifier)); - if (professionalUser.isPresent()) { - professionalUser.get().setUserIdentifier(newUserIdentifier); - professionalUserRepository.save(professionalUser.get()); - } else { - throw new EmptyResultDataAccessException(PROFESSIONAL_USER_404_MESSAGE, 1); - } - if (userResponse != null && userResponse.status() > 300) { - modifiedUserResponse = toResponseEntity(userResponse, ModifyUserRolesResponse.class); - } else { modifiedUserResponse = toResponseEntity(userResponse, ErrorResponse.class); + } else { + Optional professionalUser = Optional + .ofNullable(professionalUserService.findProfessionalUserByUserIdentifier(existingUserIdentifier)); + if (professionalUser.isPresent()) { + professionalUser.get().setUserIdentifier(newUserIdentifier); + professionalUserRepository.save(professionalUser.get()); + } else { + throw new EmptyResultDataAccessException(PROFESSIONAL_USER_404_MESSAGE, 1); + } + modifiedUserResponse = toResponseEntity(userResponse, ModifyUserRolesResponse.class); } return modifiedUserResponse; } catch (FeignException ex) { From f87d92b1fd75f0d18df716d37f241c38e0fcf4ab Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Tue, 9 Jul 2024 18:35:37 +0100 Subject: [PATCH 18/21] update functional tests --- .../ModifyUserIdamIdIntegrationTest.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/ModifyUserIdamIdIntegrationTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/ModifyUserIdamIdIntegrationTest.java index a1bc808fae..5ef04ab654 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/ModifyUserIdamIdIntegrationTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/ModifyUserIdamIdIntegrationTest.java @@ -122,4 +122,39 @@ void ac2_modify_idam_empty_Request_should_return_400() { assertThat(modifiedUserResponse.get("http_status")).isNotNull(); assertThat(modifiedUserResponse).containsEntry("http_status","400"); } + + @Test + void ac1_modify_idamId_userProfileFeignClient_getUserProfileById_Bad_Request_error() { + //create and update organisation + String organisationIdentifier = createOrganisationRequest(); + updateOrganisation(organisationIdentifier, hmctsAdmin, ACTIVE); + + //create new user + List userRoles = new ArrayList<>(); + userProfileCreateUserWireMock(HttpStatus.CREATED); + userRoles.add(puiCaseManager); + + Map newUserResponse = + professionalReferenceDataClient.addUserToOrganisation(organisationIdentifier, + inviteUserCreationRequest(randomAlphabetic(5) + "@email.com", + userRoles), hmctsAdmin); + String existingUserIdentifier = (String) newUserResponse.get(USER_IDENTIFIER); + + ProfessionalUserIdentifierRequest professionalUserIdentifierRequest = ProfessionalUserIdentifierRequest + .aUserIdentifierRequest().existingIdamId(existingUserIdentifier).newIdamId(UUID.randomUUID().toString()) + .build(); + + //modify Idam details in user Profile + userProfileCreateUserWireMock(HttpStatus.CREATED); + + updateUserProfileRolesMock(HttpStatus.BAD_REQUEST); + + Map modifiedUserResponse = + professionalReferenceDataClient.updateUserIdamForOrganisation(professionalUserIdentifierRequest,hmctsAdmin); + + //validate overall response should be 200 always + assertThat(modifiedUserResponse.get("http_status")).isNotNull(); + assertThat(modifiedUserResponse).containsEntry("http_status","400"); + + } } \ No newline at end of file From 3eabbed4f19ed61ef297697618721b990ed42597 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Wed, 17 Jul 2024 12:12:01 +0100 Subject: [PATCH 19/21] update pact tests --- .../OrganisationalInternalControllerProviderTest.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalInternalControllerProviderTest.java b/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalInternalControllerProviderTest.java index 2e2f8719be..bb818200e8 100644 --- a/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalInternalControllerProviderTest.java +++ b/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalInternalControllerProviderTest.java @@ -356,6 +356,14 @@ private Organisation getOrganisation() { contactInformation.setCreated(LocalDateTime.now()); contactInformation.setId(UUID.randomUUID()); organisation.setContactInformations(List.of(contactInformation)); + + SuperUser superUser = new SuperUser("firstName", "lastName", + "email", organisation); + superUser.setUserIdentifier(UUID.randomUUID().toString()); + List users = new ArrayList<>(); + users.add(superUser); + organisation.setUsers(users); + return organisation; } From 5f5b2e344768ecbc38582f9da7567aa199044748 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Wed, 17 Jul 2024 12:24:31 +0100 Subject: [PATCH 20/21] update pact tests --- infrastructure/variables.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/infrastructure/variables.tf b/infrastructure/variables.tf index 550b2d859b..53a9edc566 100644 --- a/infrastructure/variables.tf +++ b/infrastructure/variables.tf @@ -33,11 +33,11 @@ variable "team_name" { default = "RD" } -variable "sku_name" { +variable sku_name { default = "GP_Gen5_2" } -variable "sku_capacity" { +variable sku_capacity { default = "2" } From 5c17dec6a364b463eaed0ff910d625ed68b86e00 Mon Sep 17 00:00:00 2001 From: 54687 <61242337+hmcts-jenkins-j-to-z[bot]@users.noreply.github.com> Date: Wed, 17 Jul 2024 11:35:05 +0000 Subject: [PATCH 21/21] Updating Terraform Formatting --- infrastructure/variables.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/infrastructure/variables.tf b/infrastructure/variables.tf index 53a9edc566..550b2d859b 100644 --- a/infrastructure/variables.tf +++ b/infrastructure/variables.tf @@ -33,11 +33,11 @@ variable "team_name" { default = "RD" } -variable sku_name { +variable "sku_name" { default = "GP_Gen5_2" } -variable sku_capacity { +variable "sku_capacity" { default = "2" }