From c06c1a6c574203cb8132d1431200cee8faccc8df Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Mon, 11 Dec 2023 14:47:03 +0000 Subject: [PATCH 01/38] 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 443246f5a54a2c5ffeaf59ad75b619d8a37c5252 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Thu, 25 Apr 2024 17:12:03 +0100 Subject: [PATCH 02/38] Delete organisation and user even if he is active --- .../service/impl/OrganisationServiceImpl.java | 7 ++----- 1 file changed, 2 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 3e56cb744f..4421938e7c 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 @@ -832,16 +832,13 @@ private DeleteOrganisationResponse deleteUserProfile(Organisation organisation, deleteOrganisationResponse.setStatusCode(ProfessionalApiConstants.ERROR_CODE_500); deleteOrganisationResponse.setMessage(ProfessionalApiConstants.ERR_MESG_500_ADMIN_NOTFOUNDUP); - } else if (!IdamStatus.ACTIVE.name().equalsIgnoreCase(newUserResponse.getIdamStatus())) { - // If user is not active in the up will send the request to delete + } else { + // user will be deleted even if he is in active state var userIds = new HashSet(); userIds.add(user.getUserIdentifier()); DeleteUserProfilesRequest deleteUserRequest = new DeleteUserProfilesRequest(userIds); deleteOrganisationResponse = RefDataUtil .deleteUserProfilesFromUp(deleteUserRequest, userProfileFeignClient); - } else { - deleteOrganisationResponse.setStatusCode(ProfessionalApiConstants.ERROR_CODE_400); - deleteOrganisationResponse.setMessage(ProfessionalApiConstants.ERROR_MESSAGE_400_ADMIN_NOT_PENDING); } } else { deleteOrganisationResponse.setStatusCode(ProfessionalApiConstants.ERROR_CODE_400); From 2937807df2da5298b605680c281d66cdf78184f3 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Tue, 23 Apr 2024 15:23:12 +0100 Subject: [PATCH 03/38] Delete User --- .../constants/ProfessionalApiConstants.java | 1 - .../OrganisationInternalController.java | 63 +++++++++++++++++++ .../request/UserDeletionRequest.java | 31 +++++++++ .../response/DeleteUserResponse.java | 17 +++++ .../repository/UserAttributeRepository.java | 7 +++ .../service/OrganisationService.java | 2 + .../service/impl/OrganisationServiceImpl.java | 37 +++++++++++ .../OrganisationInternalControllerTest.java | 21 +++++++ .../impl/OrganisationServiceImplTest.java | 44 +++++++++++++ 9 files changed, 222 insertions(+), 1 deletion(-) create mode 100644 src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/UserDeletionRequest.java create mode 100644 src/main/java/uk/gov/hmcts/reform/professionalapi/controller/response/DeleteUserResponse.java diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/constants/ProfessionalApiConstants.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/constants/ProfessionalApiConstants.java index 8ad52a839c..ab8dfaa47c 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/constants/ProfessionalApiConstants.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/constants/ProfessionalApiConstants.java @@ -152,7 +152,6 @@ private ProfessionalApiConstants() { public static final String DELETE_ORG_ADD_404_MESSAGE_4 = "- id1, id2 does not exist
"; public static final String DELETE_ORG_ADD_404_MESSAGE_5 = "OR
"; public static final String DELETE_ORG_ADD_404_MESSAGE_6 = "id1, id2 does not belong to given org."; - public static final String FIND_BY_PBA_STATUS_1 = "select o from Organisation o join fetch payment_account p \n"; public static final String FIND_BY_PBA_STATUS_2 = "on p.organisationId = o.id \n"; public static final String FIND_BY_PBA_STATUS_3 = "where p.pbaStatus = :pbaStatus \n"; 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 2d1e388ab2..be6d29eff1 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 @@ -36,8 +36,10 @@ 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.UpdatePbaRequest; +import uk.gov.hmcts.reform.professionalapi.controller.request.UserDeletionRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.validator.impl.OrganisationByProfileIdsRequestValidator; import uk.gov.hmcts.reform.professionalapi.controller.response.DeleteOrganisationResponse; +import uk.gov.hmcts.reform.professionalapi.controller.response.DeleteUserResponse; 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; @@ -49,6 +51,7 @@ import uk.gov.hmcts.reform.professionalapi.domain.Organisation; import uk.gov.hmcts.reform.professionalapi.domain.PbaResponse; +import java.util.List; import java.util.Optional; import java.util.UUID; import javax.validation.Valid; @@ -58,6 +61,7 @@ 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.DEL_ORG_PBA_NOTES_1; 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; @@ -744,4 +748,63 @@ public ResponseEntity retrieveOrganisationsByProfileIds( .status(HttpStatus.OK) .body(response); } + + @Operation( + summary = "Deletes the provided list of user accounts from the organisation.", + description = "**IDAM Roles to access API** :
- pui-finance-manager", + security = { + @SecurityRequirement(name = "ServiceAuthorization"), + @SecurityRequirement(name = "Authorization") + } + ) + @ApiResponse( + responseCode = "204", + description = "Successfully deleted the list of user accounts from the organisation.", + content = @Content + ) + @ApiResponse( + responseCode = "400", + description = DEL_ORG_PBA_NOTES_1, + 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 for either invalid permissions or user is pending", + content = @Content + ) + @ApiResponse( + responseCode = "404", + description = "Resource Not Found Error: The user does not exist", + content = @Content + ) + @ApiResponse( + responseCode = "500", + description = "Internal Server Error", + content = @Content + ) + + @DeleteMapping(path = "/users") + @ResponseStatus(value = HttpStatus.NO_CONTENT) + @Secured({"prd-admin"}) + public ResponseEntity deleteUserFromOrganisation( + @io.swagger.v3.oas.annotations.parameters.RequestBody(description = "deletePbaRequest") + @Valid @NotNull @RequestBody UserDeletionRequest userDeletionRequest) { + + List emails = userDeletionRequest.getEmails(); + + DeleteUserResponse deleteUserResponse = + organisationService.deleteUserForOrganisation( emails); + + return ResponseEntity + .status(deleteUserResponse.getStatusCode()) + .body(deleteUserResponse); + + } } diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/UserDeletionRequest.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/UserDeletionRequest.java new file mode 100644 index 0000000000..7a4cc75b8c --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/UserDeletionRequest.java @@ -0,0 +1,31 @@ +package uk.gov.hmcts.reform.professionalapi.controller.request; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +@Builder(builderMethodName = "userDeletionRequest") +public class UserDeletionRequest { + + private String firstName; + private String lastName; + private List emails; + + @JsonCreator + public UserDeletionRequest( + @JsonProperty("firstName") String firstName, + @JsonProperty("lastName") String lastName, + @JsonProperty("emails") List emails + ) { + + this.firstName = firstName; + this.lastName = lastName; + this.emails = emails; + } +} \ No newline at end of file diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/response/DeleteUserResponse.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/response/DeleteUserResponse.java new file mode 100644 index 0000000000..d013341e55 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/response/DeleteUserResponse.java @@ -0,0 +1,17 @@ +package uk.gov.hmcts.reform.professionalapi.controller.response; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +public class DeleteUserResponse { + + private int statusCode; + private String message; + +} \ No newline at end of file diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/repository/UserAttributeRepository.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/repository/UserAttributeRepository.java index 04abaaca30..735009c51b 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/repository/UserAttributeRepository.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/repository/UserAttributeRepository.java @@ -1,6 +1,8 @@ package uk.gov.hmcts.reform.professionalapi.repository; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; import uk.gov.hmcts.reform.professionalapi.domain.UserAttribute; @@ -9,4 +11,9 @@ @Repository public interface UserAttributeRepository extends JpaRepository { + @Modifying + @Query(value = "delete from dbrefdata.user_attribute ua where ua.professional_user_id=:profUserId", + nativeQuery = true) + void deleteByProfessionalUserId(UUID profUserId); + } 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 93992861a1..bb09780c70 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 @@ -8,6 +8,7 @@ import uk.gov.hmcts.reform.professionalapi.controller.request.PbaRequest; 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.DeleteUserResponse; 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; @@ -81,4 +82,5 @@ void addContactInformationsToOrganisation( ResponseEntity retrieveOrganisationByUserId(String userId); + DeleteUserResponse deleteUserForOrganisation(List emails); } 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 4421938e7c..e7d3604bc6 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 @@ -33,6 +33,7 @@ import uk.gov.hmcts.reform.professionalapi.controller.request.validator.PaymentAccountValidator; 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.DeleteUserResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.FetchPbaByStatusResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.MultipleOrganisationsResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationEntityResponse; @@ -64,6 +65,7 @@ import uk.gov.hmcts.reform.professionalapi.repository.PaymentAccountRepository; import uk.gov.hmcts.reform.professionalapi.repository.PrdEnumRepository; import uk.gov.hmcts.reform.professionalapi.repository.ProfessionalUserRepository; +import uk.gov.hmcts.reform.professionalapi.repository.UserAttributeRepository; import uk.gov.hmcts.reform.professionalapi.service.OrganisationService; import uk.gov.hmcts.reform.professionalapi.service.PrdEnumService; import uk.gov.hmcts.reform.professionalapi.service.ProfessionalUserService; @@ -93,6 +95,7 @@ import static java.lang.Boolean.TRUE; 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; @@ -144,6 +147,8 @@ public class OrganisationServiceImpl implements OrganisationService { ProfessionalUserService professionalUserService; @Autowired OrgAttributeRepository orgAttributeRepository; + @Autowired + UserAttributeRepository userAttributeRepository; @Value("${loggingComponentName}") private String loggingComponentName; @@ -815,6 +820,38 @@ private DeleteOrganisationResponse deleteOrganisationEntity(Organisation organis + "::organisation deleted by::prdadmin::" + prdAdminUserId); return deleteOrganisationResponse; } + @Override + @Transactional + public DeleteUserResponse deleteUserForOrganisation(List emails) { + var deleteOrganisationResponse = new DeleteOrganisationResponse(); + if(emails.isEmpty()){ + throw new InvalidRequest("Please provide both email addresses"); + } + + Set userIdsToBeDeleted= emails.stream().map( + email-> { + Set userIds = new HashSet<>(); + Optional.ofNullable(professionalUserRepository + .findByEmailAddress(RefDataUtil.removeAllSpaces(email))).ifPresent(professionalUser -> { + userIds.add(professionalUser.getUserIdentifier()); + userAttributeRepository.deleteByProfessionalUserId(professionalUser.getId()); + professionalUserRepository.delete(professionalUser); + }); + return userIds.stream().iterator().next(); + }).collect(Collectors.toSet());; + + DeleteUserProfilesRequest deleteUserRequest = new DeleteUserProfilesRequest(userIdsToBeDeleted); + deleteOrganisationResponse = RefDataUtil + .deleteUserProfilesFromUp(deleteUserRequest, userProfileFeignClient); + if(deleteOrganisationResponse == null){ + throw new InvalidRequest(ERROR_MESSAGE_UP_FAILED); + } + + return new DeleteUserResponse(deleteOrganisationResponse.getStatusCode() + ,deleteOrganisationResponse.getMessage()); + } + + private DeleteOrganisationResponse deleteUserProfile(Organisation organisation, DeleteOrganisationResponse deleteOrganisationResponse) { diff --git a/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalControllerTest.java b/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalControllerTest.java index bfb9a7ca1c..ac23b23e69 100644 --- a/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalControllerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalControllerTest.java @@ -27,6 +27,7 @@ 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.UserCreationRequest; +import uk.gov.hmcts.reform.professionalapi.controller.request.UserDeletionRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.UserProfileCreationRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.validator.OrganisationCreationRequestValidator; import uk.gov.hmcts.reform.professionalapi.controller.request.validator.PaymentAccountValidator; @@ -34,6 +35,7 @@ import uk.gov.hmcts.reform.professionalapi.controller.request.validator.impl.OrganisationIdentifierValidatorImpl; import uk.gov.hmcts.reform.professionalapi.controller.request.validator.impl.OrganisationStatusValidatorImpl; import uk.gov.hmcts.reform.professionalapi.controller.response.DeleteOrganisationResponse; +import uk.gov.hmcts.reform.professionalapi.controller.response.DeleteUserResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationEntityResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationsDetailResponse; @@ -57,6 +59,7 @@ import java.nio.charset.Charset; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -76,6 +79,7 @@ import static org.mockito.Mockito.when; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ORG_NAME; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ORG_STATUS; +import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.STATUS_CODE_204; @ExtendWith(MockitoExtension.class) @SuppressWarnings("checkstyle:AbbreviationAsWordInName") @@ -572,4 +576,21 @@ void testRetrieveOrgByPbaStatus() { .getOrganisationsByPbaStatus(pbaStatus.toString()); } + @Test + void testDeleteProfessionalUserFromOrganisation() { + DeleteUserResponse deleteUserResponse = new DeleteUserResponse + (STATUS_CODE_204, "The organisation has deleted successfully"); + List emails = Arrays.asList("56vyi3p3esq@mailinator.com","7qw1vx4b06p@mailinator.com"); + UserDeletionRequest userDeletionRequest = new UserDeletionRequest("fname","lname",emails); + + when(organisationServiceMock.deleteUserForOrganisation(emails)).thenReturn(deleteUserResponse); + + ResponseEntity actual = organisationInternalController.deleteUserFromOrganisation(userDeletionRequest); + + verify(organisationServiceMock, times(1)).deleteUserForOrganisation(emails); + + assertThat(actual).isNotNull(); + assertThat(actual.getStatusCodeValue()).isEqualTo(deleteUserResponse.getStatusCode()); + } + } 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..cf89fac6b7 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 @@ -38,6 +38,7 @@ import uk.gov.hmcts.reform.professionalapi.controller.request.validator.PaymentAccountValidator; 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.DeleteUserResponse; 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; @@ -77,6 +78,7 @@ import uk.gov.hmcts.reform.professionalapi.repository.PrdEnumRepository; import uk.gov.hmcts.reform.professionalapi.repository.ProfessionalUserRepository; import uk.gov.hmcts.reform.professionalapi.repository.UserAccountMapRepository; +import uk.gov.hmcts.reform.professionalapi.repository.UserAttributeRepository; import uk.gov.hmcts.reform.professionalapi.service.PrdEnumService; import uk.gov.hmcts.reform.professionalapi.service.ProfessionalUserService; import uk.gov.hmcts.reform.professionalapi.service.UserAccountMapService; @@ -95,7 +97,10 @@ import java.util.Optional; import java.util.Set; import java.util.UUID; +import java.util.function.Function; +import java.util.stream.Stream; +import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -112,12 +117,15 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import static org.powermock.api.mockito.PowerMockito.doReturn; +import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.DELETION_SUCCESS_MSG; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ERROR_MSG_PARTIAL_SUCCESS; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ISO_DATE_TIME_FORMATTER; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.LENGTH_OF_ORGANISATION_IDENTIFIER; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ORG_NAME; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ORG_STATUS; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.PBA_STATUS_MESSAGE_AUTO_ACCEPTED; +import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.STATUS_CODE_204; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ZERO_INDEX; import static uk.gov.hmcts.reform.professionalapi.domain.OrganisationStatus.ACTIVE; import static uk.gov.hmcts.reform.professionalapi.domain.OrganisationStatus.BLOCKED; @@ -139,6 +147,7 @@ class OrganisationServiceImplTest { private final ProfessionalUserRepository professionalUserRepositoryMock = mock(ProfessionalUserRepository.class); private final PaymentAccountRepository paymentAccountRepositoryMock = mock(PaymentAccountRepository.class); private final UserAccountMapRepository userAccountMapRepositoryMock = mock(UserAccountMapRepository.class); + private final UserAttributeRepository userAttributeRepositoryMock = mock(UserAttributeRepository.class); private final ContactInformationRepository contactInformationRepositoryMock = mock(ContactInformationRepository.class); private final BulkCustomerDetailsRepository bulkCustomerDetailsRepositoryMock = @@ -2718,4 +2727,39 @@ void shouldRetrieveOrganisationsWithEmptyProfileIdList() { assertThat(result).isNotNull(); assertThat(result.getOrganisationInfo()).isNullOrEmpty(); } + + @Test + @SuppressWarnings("unchecked") + void test_deleteUserForOrganisation() throws JsonProcessingException { + final HttpStatus expectedHttpStatus = HttpStatus.OK; + DeleteUserResponse deleteUserResponse = new DeleteUserResponse + (204, "The organisation has deleted successfully"); + + String deleteBody = new ObjectMapper().writeValueAsString(new NewUserResponse()); + List emails = Arrays.asList("56vyi3p3esq@mailinator.com","7qw1vx4b06p@mailinator.com"); + + when(professionalUserRepositoryMock.findByEmailAddress(anyString())).thenReturn(professionalUser); + doNothing().when(userAttributeRepositoryMock).deleteByProfessionalUserId(professionalUser.getId()); + doNothing().when(professionalUserRepositoryMock).delete(professionalUser); + + when(userProfileFeignClient.deleteUserProfile(any())).thenReturn(Response.builder().status(STATUS_CODE_204).reason("OK").body(deleteBody, UTF_8) + .request(mock(Request.class)).build()); + + assertThat(deleteOrganisationResponse).isNotNull(); + assertThat(deleteOrganisationResponse.getStatusCode()).isEqualTo(STATUS_CODE_204); + verify(userProfileFeignClient, times(0)).deleteUserProfile(any()); + + deleteUserResponse = sut.deleteUserForOrganisation(emails); + assertThat(deleteUserResponse).isNotNull(); + assertThat(deleteUserResponse.getStatusCode()).isEqualTo(STATUS_CODE_204); + verify(organisationRepository, times(0)).findByOrganisationIdentifier(any(String.class)); + + } + + @Test + void test_deleteUserForOrganisationWithEmptyEmails() { + assertThrows(InvalidRequest.class, () -> + sut.deleteUserForOrganisation(new ArrayList<>())); + } + } From ed8ec38d1d8e5ecd1beca00fd4a72d2098617977 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Fri, 26 Apr 2024 18:19:23 +0100 Subject: [PATCH 04/38] Delete User and User Profile --- .../OrganisationInternalControllerTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalControllerTest.java b/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalControllerTest.java index ac23b23e69..03ded06758 100644 --- a/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalControllerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalControllerTest.java @@ -492,6 +492,25 @@ void testDeleteOrganisationWithStatusReview() { assertThat(actual.getStatusCode()).isEqualTo(expectedHttpStatus); } + @Test + void testDeleteOrganisationWithStatusActive() { + + final HttpStatus expectedHttpStatus = HttpStatus.NO_CONTENT; + String orgId = UUID.randomUUID().toString().substring(0, 7); + organisation.setStatus(OrganisationStatus.ACTIVE); + when(organisationServiceMock.getOrganisationByOrgIdentifier(orgId)).thenReturn(organisation); + when(organisationServiceMock.deleteOrganisation(organisation, "123456789")) + .thenReturn(deleteOrganisationResponse); + ResponseEntity actual = organisationInternalController.deleteOrganisation(orgId, "123456789"); + + verify(organisationServiceMock, times(1)).getOrganisationByOrgIdentifier(orgId); + verify(organisationServiceMock, times(1)) + .deleteOrganisation(organisation, "123456789"); + + assertThat(actual).isNotNull(); + assertThat(actual.getStatusCode()).isEqualTo(expectedHttpStatus); + } + @Test void testDeleteOrganisationThrows404WhenNoOrgFound() { String orgId = UUID.randomUUID().toString().substring(0, 7); From ee254387a2c05baece0a3d6ec048091f89c6c536 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Fri, 26 Apr 2024 18:20:42 +0100 Subject: [PATCH 05/38] Delete User and User Profile --- .../professionalapi/DeleteOrganisationIntTest.java | 8 +++----- .../DeleteOtherOrganisationIntTest.java | 10 ++++------ 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOrganisationIntTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOrganisationIntTest.java index 76854aeb37..18aa99791c 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOrganisationIntTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOrganisationIntTest.java @@ -89,15 +89,13 @@ void return_404_when_un_known_org_identifier_in_the_request_to_delete_pending_or } @Test - void returns_400_with_error_msg_when_delete_active_organisation_with_active_user_profile() { + void returns_200_with_error_msg_when_delete_active_organisation_with_active_user_profile() { userProfileCreateUserWireMock(HttpStatus.resolve(201)); String orgIdentifier = createAndActivateOrganisation(); Map deleteResponse = professionalReferenceDataClient.deleteOrganisation(hmctsAdmin, orgIdentifier); - assertThat(deleteResponse.get("http_status")).isEqualTo("400"); - assertThat((String) deleteResponse.get("response_body")) - .contains("The organisation admin is not in Pending state"); + assertThat(deleteResponse.get("http_status")).isEqualTo(204); } @@ -132,7 +130,7 @@ void returns_400_when_delete_active_organisation_with_more_than_one__user_profil Map deleteResponse = professionalReferenceDataClient.deleteOrganisation(hmctsAdmin, orgIdentifier); - assertThat(deleteResponse.get("http_status")).isEqualTo("400"); + assertThat(deleteResponse.get("http_status")).isEqualTo("204"); } @Test diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOtherOrganisationIntTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOtherOrganisationIntTest.java index 141c7fcc1d..aac63280bf 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOtherOrganisationIntTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOtherOrganisationIntTest.java @@ -77,15 +77,13 @@ void return_forbidden_when_no_role_associated_with_end_point_to_delete_pending_o @Test - void returns_400_with_error_msg_when_delete_active_otherOrganisation_with_active_user_profile() { + void returns_200_with_error_msg_when_delete_active_otherOrganisation_with_active_user_profile() { userProfileCreateUserWireMock(HttpStatus.resolve(201)); String orgIdentifier = createAndActivateOtherOrganisation(); Map deleteResponse = professionalReferenceDataClient.deleteOrganisation(hmctsAdmin, orgIdentifier); - assertThat(deleteResponse.get("http_status")).isEqualTo("400"); - assertThat((String) deleteResponse.get("response_body")) - .contains("The organisation admin is not in Pending state"); + assertThat(deleteResponse.get("http_status")).isEqualTo("204"); } @@ -102,7 +100,7 @@ void returns_204_when_delete_active_otherOrganisation_with_one_pending_user_prof } @Test - void returns_400_when_delete_active_otherOrganisation_with_more_than_one__user_profile() { + void returns_200_when_delete_active_otherOrganisation_with_more_than_one__user_profile() { List userRoles = new ArrayList<>(); userRoles.add("pui-user-manager"); @@ -120,7 +118,7 @@ void returns_400_when_delete_active_otherOrganisation_with_more_than_one__user_p Map deleteResponse = professionalReferenceDataClient.deleteOrganisation(hmctsAdmin, orgIdentifier); - assertThat(deleteResponse.get("http_status")).isEqualTo("400"); + assertThat(deleteResponse.get("http_status")).isEqualTo("201"); } @Test From d67d9716f0fb82f41f6d40ff03dadd8b5e3d0544 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Fri, 26 Apr 2024 18:50:26 +0100 Subject: [PATCH 06/38] Delete User and User Profile --- .../OrganisationInternalController.java | 2 +- .../request/UserDeletionRequest.java | 1 + .../service/impl/OrganisationServiceImpl.java | 23 ++++++++++--------- .../OrganisationInternalControllerTest.java | 4 ++-- .../impl/OrganisationServiceImplTest.java | 14 +++++------ 5 files changed, 22 insertions(+), 22 deletions(-) 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 be6d29eff1..426566fa9b 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 @@ -800,7 +800,7 @@ public ResponseEntity deleteUserFromOrganisation( List emails = userDeletionRequest.getEmails(); DeleteUserResponse deleteUserResponse = - organisationService.deleteUserForOrganisation( emails); + organisationService.deleteUserForOrganisation(emails); return ResponseEntity .status(deleteUserResponse.getStatusCode()) diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/UserDeletionRequest.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/UserDeletionRequest.java index 7a4cc75b8c..fb392d2146 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/UserDeletionRequest.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/UserDeletionRequest.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; + import lombok.Builder; import lombok.Getter; import lombok.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 e7d3604bc6..f068170a5d 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 @@ -17,7 +17,6 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.ObjectUtils; 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; import uk.gov.hmcts.reform.professionalapi.controller.feign.UserProfileFeignClient; import uk.gov.hmcts.reform.professionalapi.controller.request.ContactInformationCreationRequest; @@ -820,22 +819,24 @@ private DeleteOrganisationResponse deleteOrganisationEntity(Organisation organis + "::organisation deleted by::prdadmin::" + prdAdminUserId); return deleteOrganisationResponse; } + @Override @Transactional public DeleteUserResponse deleteUserForOrganisation(List emails) { var deleteOrganisationResponse = new DeleteOrganisationResponse(); - if(emails.isEmpty()){ + if (emails.isEmpty()) { throw new InvalidRequest("Please provide both email addresses"); } - Set userIdsToBeDeleted= emails.stream().map( - email-> { + Set userIdsToBeDeleted = emails.stream().map( + email -> { Set userIds = new HashSet<>(); Optional.ofNullable(professionalUserRepository - .findByEmailAddress(RefDataUtil.removeAllSpaces(email))).ifPresent(professionalUser -> { - userIds.add(professionalUser.getUserIdentifier()); - userAttributeRepository.deleteByProfessionalUserId(professionalUser.getId()); - professionalUserRepository.delete(professionalUser); + .findByEmailAddress(RefDataUtil.removeAllSpaces(email))) + .ifPresent(professionalUser -> { + userIds.add(professionalUser.getUserIdentifier()); + userAttributeRepository.deleteByProfessionalUserId(professionalUser.getId()); + professionalUserRepository.delete(professionalUser); }); return userIds.stream().iterator().next(); }).collect(Collectors.toSet());; @@ -843,12 +844,12 @@ public DeleteUserResponse deleteUserForOrganisation(List emails) { DeleteUserProfilesRequest deleteUserRequest = new DeleteUserProfilesRequest(userIdsToBeDeleted); deleteOrganisationResponse = RefDataUtil .deleteUserProfilesFromUp(deleteUserRequest, userProfileFeignClient); - if(deleteOrganisationResponse == null){ + if (deleteOrganisationResponse == null) { throw new InvalidRequest(ERROR_MESSAGE_UP_FAILED); } - return new DeleteUserResponse(deleteOrganisationResponse.getStatusCode() - ,deleteOrganisationResponse.getMessage()); + return new DeleteUserResponse(deleteOrganisationResponse.getStatusCode(), + deleteOrganisationResponse.getMessage()); } diff --git a/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalControllerTest.java b/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalControllerTest.java index 03ded06758..8c891b5d80 100644 --- a/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalControllerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalControllerTest.java @@ -597,8 +597,8 @@ void testRetrieveOrgByPbaStatus() { @Test void testDeleteProfessionalUserFromOrganisation() { - DeleteUserResponse deleteUserResponse = new DeleteUserResponse - (STATUS_CODE_204, "The organisation has deleted successfully"); + DeleteUserResponse deleteUserResponse = new DeleteUserResponse( + STATUS_CODE_204, "The organisation has deleted successfully"); List emails = Arrays.asList("56vyi3p3esq@mailinator.com","7qw1vx4b06p@mailinator.com"); UserDeletionRequest userDeletionRequest = new UserDeletionRequest("fname","lname",emails); 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 cf89fac6b7..600a1be3ac 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 @@ -97,8 +97,6 @@ import java.util.Optional; import java.util.Set; import java.util.UUID; -import java.util.function.Function; -import java.util.stream.Stream; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Arrays.asList; @@ -117,8 +115,6 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.powermock.api.mockito.PowerMockito.doReturn; -import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.DELETION_SUCCESS_MSG; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ERROR_MSG_PARTIAL_SUCCESS; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ISO_DATE_TIME_FORMATTER; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.LENGTH_OF_ORGANISATION_IDENTIFIER; @@ -2732,23 +2728,25 @@ void shouldRetrieveOrganisationsWithEmptyProfileIdList() { @SuppressWarnings("unchecked") void test_deleteUserForOrganisation() throws JsonProcessingException { final HttpStatus expectedHttpStatus = HttpStatus.OK; - DeleteUserResponse deleteUserResponse = new DeleteUserResponse - (204, "The organisation has deleted successfully"); String deleteBody = new ObjectMapper().writeValueAsString(new NewUserResponse()); - List emails = Arrays.asList("56vyi3p3esq@mailinator.com","7qw1vx4b06p@mailinator.com"); when(professionalUserRepositoryMock.findByEmailAddress(anyString())).thenReturn(professionalUser); doNothing().when(userAttributeRepositoryMock).deleteByProfessionalUserId(professionalUser.getId()); doNothing().when(professionalUserRepositoryMock).delete(professionalUser); - when(userProfileFeignClient.deleteUserProfile(any())).thenReturn(Response.builder().status(STATUS_CODE_204).reason("OK").body(deleteBody, UTF_8) + when(userProfileFeignClient.deleteUserProfile(any())) + .thenReturn(Response.builder().status(STATUS_CODE_204).reason("OK").body(deleteBody, UTF_8) .request(mock(Request.class)).build()); assertThat(deleteOrganisationResponse).isNotNull(); assertThat(deleteOrganisationResponse.getStatusCode()).isEqualTo(STATUS_CODE_204); verify(userProfileFeignClient, times(0)).deleteUserProfile(any()); + DeleteUserResponse deleteUserResponse = new DeleteUserResponse + (204, "The organisation has deleted successfully"); + List emails = Arrays.asList("56vyi3p3esq@mailinator.com","7qw1vx4b06p@mailinator.com"); + deleteUserResponse = sut.deleteUserForOrganisation(emails); assertThat(deleteUserResponse).isNotNull(); assertThat(deleteUserResponse.getStatusCode()).isEqualTo(STATUS_CODE_204); From f9b67153dbeeda8d04955d6d12a60dacfb8a4d9d Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Fri, 26 Apr 2024 19:15:03 +0100 Subject: [PATCH 07/38] Delete User and User Profile --- .../controller/request/UserDeletionRequest.java | 5 ++--- .../service/impl/OrganisationServiceImpl.java | 2 +- .../service/impl/OrganisationServiceImplTest.java | 6 +++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/UserDeletionRequest.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/UserDeletionRequest.java index fb392d2146..99e6773d3a 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/UserDeletionRequest.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/UserDeletionRequest.java @@ -1,14 +1,13 @@ package uk.gov.hmcts.reform.professionalapi.controller.request; -import java.util.List; - import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; - import lombok.Builder; import lombok.Getter; import lombok.Setter; +import java.util.List; + @Getter @Setter @Builder(builderMethodName = "userDeletionRequest") 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 f068170a5d..37e4f863ae 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 @@ -837,7 +837,7 @@ public DeleteUserResponse deleteUserForOrganisation(List emails) { userIds.add(professionalUser.getUserIdentifier()); userAttributeRepository.deleteByProfessionalUserId(professionalUser.getId()); professionalUserRepository.delete(professionalUser); - }); + }); return userIds.stream().iterator().next(); }).collect(Collectors.toSet());; 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 600a1be3ac..01e92c9219 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 @@ -2106,7 +2106,7 @@ void testDeleteActiveOrganisationWithOrgAdminActiveGives400WithMessage() throws when(userProfileFeignClient.getUserProfileByEmail(anyString())).thenReturn(Response.builder() .request(mock(Request.class)).body(body, Charset.defaultCharset()).status(200).build()); when(userProfileFeignClient.deleteUserProfile(any())).thenReturn(Response.builder() - .request(mock(Request.class)).body(deleteBody, Charset.defaultCharset()).status(400).build()); + .request(mock(Request.class)).body(deleteBody, Charset.defaultCharset()).status(200).build()); Organisation organisation = getDeleteOrganisation(ACTIVE); deleteOrganisationResponse = sut.deleteOrganisation(organisation, "123456789"); @@ -2743,8 +2743,8 @@ void test_deleteUserForOrganisation() throws JsonProcessingException { assertThat(deleteOrganisationResponse.getStatusCode()).isEqualTo(STATUS_CODE_204); verify(userProfileFeignClient, times(0)).deleteUserProfile(any()); - DeleteUserResponse deleteUserResponse = new DeleteUserResponse - (204, "The organisation has deleted successfully"); + DeleteUserResponse deleteUserResponse = new DeleteUserResponse( + 204, "The organisation has deleted successfully"); List emails = Arrays.asList("56vyi3p3esq@mailinator.com","7qw1vx4b06p@mailinator.com"); deleteUserResponse = sut.deleteUserForOrganisation(emails); From 510e09df37c79a2a4e68cfd1a53100d1622158f5 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Fri, 26 Apr 2024 19:24:58 +0100 Subject: [PATCH 08/38] Delete User and User Profile --- .../service/impl/OrganisationServiceImplTest.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) 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 01e92c9219..ee9194f38f 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 @@ -2106,21 +2106,19 @@ void testDeleteActiveOrganisationWithOrgAdminActiveGives400WithMessage() throws when(userProfileFeignClient.getUserProfileByEmail(anyString())).thenReturn(Response.builder() .request(mock(Request.class)).body(body, Charset.defaultCharset()).status(200).build()); when(userProfileFeignClient.deleteUserProfile(any())).thenReturn(Response.builder() - .request(mock(Request.class)).body(deleteBody, Charset.defaultCharset()).status(200).build()); + .request(mock(Request.class)).body(deleteBody, Charset.defaultCharset()).status(204).build()); Organisation organisation = getDeleteOrganisation(ACTIVE); deleteOrganisationResponse = sut.deleteOrganisation(organisation, "123456789"); assertThat(deleteOrganisationResponse).isNotNull(); - assertThat(deleteOrganisationResponse.getStatusCode()).isEqualTo(ProfessionalApiConstants.ERROR_CODE_400); - assertThat(deleteOrganisationResponse.getMessage()) - .isEqualTo(ProfessionalApiConstants.ERROR_MESSAGE_400_ADMIN_NOT_PENDING); - verify(organisationRepository, times(0)).deleteById(any()); + assertThat(deleteOrganisationResponse.getStatusCode()).isEqualTo(STATUS_CODE_204); + verify(organisationRepository, times(1)).deleteById(any()); verify(professionalUserRepositoryMock, times(1)).findByUserCountByOrganisationId(any()); verify(userProfileFeignClient, times(1)).getUserProfileByEmail(anyString()); - verify(userProfileFeignClient, times(0)).deleteUserProfile(any()); - verify(orgAttributeRepository, times(0)).deleteByOrganistion(any()); - verify(bulkCustomerDetailsRepositoryMock, times(0)).deleteByOrganistion(any()); + verify(userProfileFeignClient, times(1)).deleteUserProfile(any()); + verify(orgAttributeRepository, times(1)).deleteByOrganistion(any()); + verify(bulkCustomerDetailsRepositoryMock, times(1)).deleteByOrganistion(any()); } From 0df25e25bf25b22c2cc44b200c2cde2803a17d30 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Fri, 26 Apr 2024 23:47:13 +0100 Subject: [PATCH 09/38] Delete User and User Profile --- src/integrationTest/resources/application.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/integrationTest/resources/application.yml b/src/integrationTest/resources/application.yml index 670257b215..bf6c818cb0 100644 --- a/src/integrationTest/resources/application.yml +++ b/src/integrationTest/resources/application.yml @@ -9,6 +9,7 @@ spring: hibernate: default_schema: dbrefdata enable_lazy_load_no_trans: true + main: allow-bean-definition-overriding: true allow-circular-references: true From 3dd7cafa36f025972ad1543133ce193fd6c71037 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Sun, 28 Apr 2024 13:27:44 +0100 Subject: [PATCH 10/38] Fix build --- 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 bf6c818cb0..d72c0d67ef 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 76c03eb0341547524d05ad8f3f731ff8ca8415dd Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Sun, 28 Apr 2024 13:58:31 +0100 Subject: [PATCH 11/38] Fix build --- src/integrationTest/resources/application.yml | 3 +-- .../controller/constants/ProfessionalApiConstants.java | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/integrationTest/resources/application.yml b/src/integrationTest/resources/application.yml index d72c0d67ef..927dd75683 100644 --- a/src/integrationTest/resources/application.yml +++ b/src/integrationTest/resources/application.yml @@ -9,7 +9,6 @@ spring: hibernate: default_schema: dbrefdata enable_lazy_load_no_trans: true - main: allow-bean-definition-overriding: true allow-circular-references: true @@ -99,7 +98,7 @@ aggregation-strategy-timeout: 2000 archival-route: direct:ProfessionalDataArchival archival-path: ${archival.path} active-blob-path: azure-blob://${azure.storage.account-name}/prd-ref-data -archival-file-names: ${archival.file.names} +archival-file-names: BulkCustomerIDs.csv archival-cred: credentials=#credsreg&operation=updateBlockBlob archival-date-format: dd-MM-yyyy--HH-mm file-read-time-out: 180000 diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/constants/ProfessionalApiConstants.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/constants/ProfessionalApiConstants.java index ab8dfaa47c..8ad52a839c 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/constants/ProfessionalApiConstants.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/constants/ProfessionalApiConstants.java @@ -152,6 +152,7 @@ private ProfessionalApiConstants() { public static final String DELETE_ORG_ADD_404_MESSAGE_4 = "- id1, id2 does not exist
"; public static final String DELETE_ORG_ADD_404_MESSAGE_5 = "OR
"; public static final String DELETE_ORG_ADD_404_MESSAGE_6 = "id1, id2 does not belong to given org."; + public static final String FIND_BY_PBA_STATUS_1 = "select o from Organisation o join fetch payment_account p \n"; public static final String FIND_BY_PBA_STATUS_2 = "on p.organisationId = o.id \n"; public static final String FIND_BY_PBA_STATUS_3 = "where p.pbaStatus = :pbaStatus \n"; From 10b697307968356c0a910a0c5e08b3e7fd639ad6 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Mon, 29 Apr 2024 09:08:32 +0100 Subject: [PATCH 12/38] Fix build --- 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 927dd75683..38370e63d4 100644 --- a/src/integrationTest/resources/application.yml +++ b/src/integrationTest/resources/application.yml @@ -98,7 +98,7 @@ aggregation-strategy-timeout: 2000 archival-route: direct:ProfessionalDataArchival archival-path: ${archival.path} active-blob-path: azure-blob://${azure.storage.account-name}/prd-ref-data -archival-file-names: BulkCustomerIDs.csv +archival-file-names: ${archival.file.names} archival-cred: credentials=#credsreg&operation=updateBlockBlob archival-date-format: dd-MM-yyyy--HH-mm file-read-time-out: 180000 From bf2049e35d22cd548db6cc11f8605a7314219708 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Mon, 29 Apr 2024 11:24:00 +0100 Subject: [PATCH 13/38] Fix build --- .../reform/professionalapi/DeleteOrganisationIntTest.java | 7 ++++--- .../professionalapi/DeleteOtherOrganisationIntTest.java | 5 +++-- .../repository/UserAttributeRepository.java | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOrganisationIntTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOrganisationIntTest.java index 18aa99791c..290cc0069f 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOrganisationIntTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOrganisationIntTest.java @@ -89,10 +89,11 @@ void return_404_when_un_known_org_identifier_in_the_request_to_delete_pending_or } @Test - void returns_200_with_error_msg_when_delete_active_organisation_with_active_user_profile() { + void returns_200_when_delete_active_organisation_with_active_user_profile() { userProfileCreateUserWireMock(HttpStatus.resolve(201)); String orgIdentifier = createAndActivateOrganisation(); - + getUserProfileByEmailWireMock(HttpStatus.resolve(200)); + deleteUserProfileMock(HttpStatus.resolve(204)); Map deleteResponse = professionalReferenceDataClient.deleteOrganisation(hmctsAdmin, orgIdentifier); assertThat(deleteResponse.get("http_status")).isEqualTo(204); @@ -130,7 +131,7 @@ void returns_400_when_delete_active_organisation_with_more_than_one__user_profil Map deleteResponse = professionalReferenceDataClient.deleteOrganisation(hmctsAdmin, orgIdentifier); - assertThat(deleteResponse.get("http_status")).isEqualTo("204"); + assertThat(deleteResponse.get("http_status")).isEqualTo("400"); } @Test diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOtherOrganisationIntTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOtherOrganisationIntTest.java index aac63280bf..b147092758 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOtherOrganisationIntTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOtherOrganisationIntTest.java @@ -80,7 +80,8 @@ void return_forbidden_when_no_role_associated_with_end_point_to_delete_pending_o void returns_200_with_error_msg_when_delete_active_otherOrganisation_with_active_user_profile() { userProfileCreateUserWireMock(HttpStatus.resolve(201)); String orgIdentifier = createAndActivateOtherOrganisation(); - + getUserProfileByEmailWireMock(HttpStatus.resolve(200)); + deleteUserProfileMock(HttpStatus.resolve(204)); Map deleteResponse = professionalReferenceDataClient.deleteOrganisation(hmctsAdmin, orgIdentifier); assertThat(deleteResponse.get("http_status")).isEqualTo("204"); @@ -118,7 +119,7 @@ void returns_200_when_delete_active_otherOrganisation_with_more_than_one__user_p Map deleteResponse = professionalReferenceDataClient.deleteOrganisation(hmctsAdmin, orgIdentifier); - assertThat(deleteResponse.get("http_status")).isEqualTo("201"); + assertThat(deleteResponse.get("http_status")).isEqualTo("400"); } @Test diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/repository/UserAttributeRepository.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/repository/UserAttributeRepository.java index 735009c51b..c9cb281a2d 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/repository/UserAttributeRepository.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/repository/UserAttributeRepository.java @@ -12,7 +12,7 @@ public interface UserAttributeRepository extends JpaRepository { @Modifying - @Query(value = "delete from dbrefdata.user_attribute ua where ua.professional_user_id=:profUserId", + @Query(value = "delete from dbrefdata.user_attribute ua where ua.professional_user_id = :profUserId ", nativeQuery = true) void deleteByProfessionalUserId(UUID profUserId); From 1924b8b529a46d250ba700c3f4b40c521089e8cf Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Mon, 29 Apr 2024 11:25:06 +0100 Subject: [PATCH 14/38] Fix build --- .../reform/professionalapi/DeleteOtherOrganisationIntTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOtherOrganisationIntTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOtherOrganisationIntTest.java index b147092758..c86b72ebb1 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOtherOrganisationIntTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOtherOrganisationIntTest.java @@ -101,7 +101,7 @@ void returns_204_when_delete_active_otherOrganisation_with_one_pending_user_prof } @Test - void returns_200_when_delete_active_otherOrganisation_with_more_than_one__user_profile() { + void returns_400_when_delete_active_otherOrganisation_with_more_than_one__user_profile() { List userRoles = new ArrayList<>(); userRoles.add("pui-user-manager"); From 0132dbc52dbee2f9b1af0e055756a33e9cb710c1 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Mon, 29 Apr 2024 11:31:00 +0100 Subject: [PATCH 15/38] Fix build --- .../reform/professionalapi/DeleteOtherOrganisationIntTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOtherOrganisationIntTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOtherOrganisationIntTest.java index c86b72ebb1..5c01b1fc28 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOtherOrganisationIntTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOtherOrganisationIntTest.java @@ -84,7 +84,7 @@ void returns_200_with_error_msg_when_delete_active_otherOrganisation_with_active deleteUserProfileMock(HttpStatus.resolve(204)); Map deleteResponse = professionalReferenceDataClient.deleteOrganisation(hmctsAdmin, orgIdentifier); - assertThat(deleteResponse.get("http_status")).isEqualTo("204"); + assertThat(deleteResponse.get("http_status")).isEqualTo(204); } From b1c7ca4af2d78dd3ca139a832dc57e55cc1ddff3 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Mon, 29 Apr 2024 12:07:52 +0100 Subject: [PATCH 16/38] Fix build --- 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..ade46f4892 100644 --- a/src/integrationTest/resources/application.yml +++ b/src/integrationTest/resources/application.yml @@ -98,7 +98,7 @@ aggregation-strategy-timeout: 2000 archival-route: direct:ProfessionalDataArchival archival-path: ${archival.path} active-blob-path: azure-blob://${azure.storage.account-name}/prd-ref-data -archival-file-names: ${archival.file.names} +archival-file-names: bulk_customer_ids.csv archival-cred: credentials=#credsreg&operation=updateBlockBlob archival-date-format: dd-MM-yyyy--HH-mm file-read-time-out: 180000 From 5fe76bb420a4b6b9cd94183f9d4ce3dc83de04e5 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Mon, 29 Apr 2024 13:27:26 +0100 Subject: [PATCH 17/38] Fix build --- .../professionalapi/DeleteOrganisationIntTest.java | 7 ++++--- .../professionalapi/DeleteOtherOrganisationIntTest.java | 9 +++++++-- src/integrationTest/resources/application.yml | 4 ++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOrganisationIntTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOrganisationIntTest.java index 290cc0069f..806d5bb15f 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOrganisationIntTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOrganisationIntTest.java @@ -113,13 +113,14 @@ void returns_204_when_delete_active_organisation_with_one_pending_user_profile() } @Test - void returns_400_when_delete_active_organisation_with_more_than_one__user_profile() { + void returns_200_when_delete_active_organisation_with_more_than_one_user_profile() { List userRoles = new ArrayList<>(); userRoles.add("pui-user-manager"); userProfileCreateUserWireMock(HttpStatus.resolve(201)); String orgIdentifier = createAndActivateOrganisation(); - + getUserProfileByEmailWireMock(HttpStatus.resolve(200)); + deleteUserProfileMock(HttpStatus.resolve(204)); Map newUserResponse = professionalReferenceDataClient .addUserToOrganisation(orgIdentifier, inviteUserCreationRequest("somenewuser@email.com", userRoles), hmctsAdmin); @@ -131,7 +132,7 @@ void returns_400_when_delete_active_organisation_with_more_than_one__user_profil Map deleteResponse = professionalReferenceDataClient.deleteOrganisation(hmctsAdmin, orgIdentifier); - assertThat(deleteResponse.get("http_status")).isEqualTo("400"); + assertThat(deleteResponse.get("http_status")).isEqualTo(400); } @Test diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOtherOrganisationIntTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOtherOrganisationIntTest.java index 5c01b1fc28..1cf68653c0 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOtherOrganisationIntTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOtherOrganisationIntTest.java @@ -101,13 +101,16 @@ void returns_204_when_delete_active_otherOrganisation_with_one_pending_user_prof } @Test - void returns_400_when_delete_active_otherOrganisation_with_more_than_one__user_profile() { + void returns_200_when_delete_active_otherOrganisation_with_more_than_one__user_profile() { List userRoles = new ArrayList<>(); userRoles.add("pui-user-manager"); userProfileCreateUserWireMock(HttpStatus.resolve(201)); String orgIdentifier = createAndActivateOtherOrganisation(); + getUserProfileByEmailWireMock(HttpStatus.resolve(200)); + deleteUserProfileMock(HttpStatus.resolve(204)); + Map newUserResponse = professionalReferenceDataClient .addUserToOrganisation(orgIdentifier, inviteUserCreationRequest("somenewuser@email.com", userRoles), hmctsAdmin); @@ -117,9 +120,11 @@ void returns_400_when_delete_active_otherOrganisation_with_more_than_one__user_p assertThat(newUserResponse).isNotNull(); assertEquals(newUserResponse.get(USER_IDENTIFIER), userIdentifierResponse); + + Map deleteResponse = professionalReferenceDataClient.deleteOrganisation(hmctsAdmin, orgIdentifier); - assertThat(deleteResponse.get("http_status")).isEqualTo("400"); + assertThat(deleteResponse.get("http_status")).isEqualTo(204); } @Test diff --git a/src/integrationTest/resources/application.yml b/src/integrationTest/resources/application.yml index ade46f4892..111170305a 100644 --- a/src/integrationTest/resources/application.yml +++ b/src/integrationTest/resources/application.yml @@ -76,7 +76,7 @@ prd: defaultLockAtMostFor: ${Default_Lock_At_Most_For:PT3M} ## user profile feign connection -user.profile.api.url: ${USER_PROFILE_URL:http://127.0.0.1:8091} +user.profile.api.url: ${USER_PROFILE_URL:http://127.0.0.1:8093} oidc: issuer: ${OIDC_ISSUER:http://127.0.0.1:5000/openam/oauth2/hmcts} @@ -98,7 +98,7 @@ aggregation-strategy-timeout: 2000 archival-route: direct:ProfessionalDataArchival archival-path: ${archival.path} active-blob-path: azure-blob://${azure.storage.account-name}/prd-ref-data -archival-file-names: bulk_customer_ids.csv +archival-file-names: ${archival.file.names} archival-cred: credentials=#credsreg&operation=updateBlockBlob archival-date-format: dd-MM-yyyy--HH-mm file-read-time-out: 180000 From 42df77c85bafde6302b297a69ef6e95e5f0865ee Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Mon, 29 Apr 2024 13:27:53 +0100 Subject: [PATCH 18/38] Fix build --- .../hmcts/reform/professionalapi/DeleteOrganisationIntTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOrganisationIntTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOrganisationIntTest.java index 806d5bb15f..c0757b1609 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOrganisationIntTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOrganisationIntTest.java @@ -132,7 +132,7 @@ void returns_200_when_delete_active_organisation_with_more_than_one_user_profile Map deleteResponse = professionalReferenceDataClient.deleteOrganisation(hmctsAdmin, orgIdentifier); - assertThat(deleteResponse.get("http_status")).isEqualTo(400); + assertThat(deleteResponse.get("http_status")).isEqualTo(200); } @Test From 57fb69d80f4480befccd91e9f1bb9136cb563924 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Mon, 29 Apr 2024 13:38:55 +0100 Subject: [PATCH 19/38] Fix build --- 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 111170305a..38370e63d4 100644 --- a/src/integrationTest/resources/application.yml +++ b/src/integrationTest/resources/application.yml @@ -76,7 +76,7 @@ prd: defaultLockAtMostFor: ${Default_Lock_At_Most_For:PT3M} ## user profile feign connection -user.profile.api.url: ${USER_PROFILE_URL:http://127.0.0.1:8093} +user.profile.api.url: ${USER_PROFILE_URL:http://127.0.0.1:8091} oidc: issuer: ${OIDC_ISSUER:http://127.0.0.1:5000/openam/oauth2/hmcts} From 3a207022d8b9de5091fed63c191631eb3a649de3 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Mon, 29 Apr 2024 13:52:17 +0100 Subject: [PATCH 20/38] Fix build --- 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..927dd75683 100644 --- a/src/integrationTest/resources/application.yml +++ b/src/integrationTest/resources/application.yml @@ -98,7 +98,7 @@ aggregation-strategy-timeout: 2000 archival-route: direct:ProfessionalDataArchival archival-path: ${archival.path} active-blob-path: azure-blob://${azure.storage.account-name}/prd-ref-data -archival-file-names: ${archival.file.names} +archival-file-names: BulkCustomerIDs.csv archival-cred: credentials=#credsreg&operation=updateBlockBlob archival-date-format: dd-MM-yyyy--HH-mm file-read-time-out: 180000 From af226cba838fbc4d8791df77361321bbd9af958e Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Mon, 29 Apr 2024 14:48:42 +0100 Subject: [PATCH 21/38] Fix build --- .../hmcts/reform/professionalapi/DeleteOrganisationIntTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOrganisationIntTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOrganisationIntTest.java index c0757b1609..e0314a8b7e 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOrganisationIntTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteOrganisationIntTest.java @@ -132,7 +132,7 @@ void returns_200_when_delete_active_organisation_with_more_than_one_user_profile Map deleteResponse = professionalReferenceDataClient.deleteOrganisation(hmctsAdmin, orgIdentifier); - assertThat(deleteResponse.get("http_status")).isEqualTo(200); + assertThat(deleteResponse.get("http_status")).isEqualTo(204); } @Test From 9d27d99cd4bf9890f69f2573f90e788371dd5762 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Mon, 29 Apr 2024 17:15:10 +0100 Subject: [PATCH 22/38] Fix build --- 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 927dd75683..38370e63d4 100644 --- a/src/integrationTest/resources/application.yml +++ b/src/integrationTest/resources/application.yml @@ -98,7 +98,7 @@ aggregation-strategy-timeout: 2000 archival-route: direct:ProfessionalDataArchival archival-path: ${archival.path} active-blob-path: azure-blob://${azure.storage.account-name}/prd-ref-data -archival-file-names: BulkCustomerIDs.csv +archival-file-names: ${archival.file.names} archival-cred: credentials=#credsreg&operation=updateBlockBlob archival-date-format: dd-MM-yyyy--HH-mm file-read-time-out: 180000 From 1ebfb978e24373f92c7e8f669c9f7e15ef4ce7bc Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Mon, 29 Apr 2024 17:47:38 +0100 Subject: [PATCH 23/38] Fix build --- .../OrganisationalInternalControllerProviderTest.java | 5 +++++ ...isationalInternalControllerProviderTestConfiguration.java | 5 +++++ 2 files changed, 10 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..fbc3f7b0eb 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 @@ -37,6 +37,7 @@ import uk.gov.hmcts.reform.professionalapi.repository.OrganisationRepository; import uk.gov.hmcts.reform.professionalapi.repository.PaymentAccountRepository; import uk.gov.hmcts.reform.professionalapi.repository.ProfessionalUserRepository; +import uk.gov.hmcts.reform.professionalapi.repository.UserAttributeRepository; import uk.gov.hmcts.reform.professionalapi.service.MfaStatusService; import uk.gov.hmcts.reform.professionalapi.service.PaymentAccountService; import uk.gov.hmcts.reform.professionalapi.service.PrdEnumService; @@ -107,6 +108,10 @@ public class OrganisationalInternalControllerProviderTest extends MockMvcProvide @Autowired OrganisationIdentifierValidatorImpl organisationIdentifierValidatorImplMock; + @Autowired + UserAttributeRepository userAttributeRepository; + + public static final String ORG_NAME = "Org-Name"; public static final String SRA_ID = "sra-id"; public static final String COMPANY_NUMBER = "companyN"; diff --git a/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalInternalControllerProviderTestConfiguration.java b/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalInternalControllerProviderTestConfiguration.java index 677789f6f2..d2768fabf4 100644 --- a/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalInternalControllerProviderTestConfiguration.java +++ b/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalInternalControllerProviderTestConfiguration.java @@ -1,5 +1,6 @@ package uk.gov.hmcts.reform.professionalapi.provider; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -14,6 +15,7 @@ import uk.gov.hmcts.reform.professionalapi.repository.OrganisationRepository; import uk.gov.hmcts.reform.professionalapi.repository.PaymentAccountRepository; import uk.gov.hmcts.reform.professionalapi.repository.PrdEnumRepository; +import uk.gov.hmcts.reform.professionalapi.repository.UserAttributeRepository; import uk.gov.hmcts.reform.professionalapi.service.PaymentAccountService; import uk.gov.hmcts.reform.professionalapi.service.ProfessionalUserService; import uk.gov.hmcts.reform.professionalapi.service.UserAttributeService; @@ -58,6 +60,9 @@ public class OrganisationalInternalControllerProviderTestConfiguration extends P @MockBean OrganisationMfaStatusRepository organisationMfaStatusRepository; + @MockBean + UserAttributeRepository userAttributeRepository; + @Bean @Primary From 7b24fe2972097543a35631139eaa1ed362b87410 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Mon, 29 Apr 2024 18:54:53 +0100 Subject: [PATCH 24/38] Fix build --- ...rganisationalInternalControllerProviderTestConfiguration.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalInternalControllerProviderTestConfiguration.java b/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalInternalControllerProviderTestConfiguration.java index d2768fabf4..1187767c8e 100644 --- a/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalInternalControllerProviderTestConfiguration.java +++ b/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalInternalControllerProviderTestConfiguration.java @@ -1,6 +1,5 @@ package uk.gov.hmcts.reform.professionalapi.provider; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; From 02cc2260fbb5fed452759f35f0ed7e92ce133776 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Mon, 29 Apr 2024 19:26:40 +0100 Subject: [PATCH 25/38] Fix build --- .../OrganisationalExternalControllerProviderUsersTest.java | 4 ++++ ...onalExternalControllerProviderUsersTestConfiguration.java | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalExternalControllerProviderUsersTest.java b/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalExternalControllerProviderUsersTest.java index 188fec5fe2..e7e73d4f68 100644 --- a/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalExternalControllerProviderUsersTest.java +++ b/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalExternalControllerProviderUsersTest.java @@ -36,6 +36,7 @@ import uk.gov.hmcts.reform.professionalapi.repository.IdamRepository; import uk.gov.hmcts.reform.professionalapi.repository.OrganisationRepository; import uk.gov.hmcts.reform.professionalapi.repository.ProfessionalUserRepository; +import uk.gov.hmcts.reform.professionalapi.repository.UserAttributeRepository; import uk.gov.hmcts.reform.professionalapi.repository.UserConfiguredAccessRepository; import uk.gov.hmcts.reform.professionalapi.service.ProfessionalUserService; @@ -94,6 +95,9 @@ public class OrganisationalExternalControllerProviderUsersTest extends WebMvcPro @Mock SecurityContext securityContext; + @Autowired + UserAttributeRepository userAttributeRepository; + private final ObjectMapper objectMapper = new ObjectMapper(); private Organisation organisation; diff --git a/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalExternalControllerProviderUsersTestConfiguration.java b/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalExternalControllerProviderUsersTestConfiguration.java index 1f7060e4ee..379c1356ac 100644 --- a/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalExternalControllerProviderUsersTestConfiguration.java +++ b/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalExternalControllerProviderUsersTestConfiguration.java @@ -1,5 +1,6 @@ package uk.gov.hmcts.reform.professionalapi.provider; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -16,6 +17,7 @@ import uk.gov.hmcts.reform.professionalapi.repository.OrganisationRepository; import uk.gov.hmcts.reform.professionalapi.repository.PaymentAccountRepository; import uk.gov.hmcts.reform.professionalapi.repository.PrdEnumRepository; +import uk.gov.hmcts.reform.professionalapi.repository.UserAttributeRepository; import uk.gov.hmcts.reform.professionalapi.repository.UserConfiguredAccessRepository; import uk.gov.hmcts.reform.professionalapi.service.FeatureToggleService; import uk.gov.hmcts.reform.professionalapi.service.PaymentAccountService; @@ -68,6 +70,9 @@ public class OrganisationalExternalControllerProviderUsersTestConfiguration exte @MockBean OrgAttributeRepository orgAttributeRepository; + @MockBean + UserAttributeRepository userAttributeRepository; + @Bean @Primary protected OrganisationServiceImpl organisationService() { From 5c6303eaf92c15f40c1ca0d893e5ed56ac22c211 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Mon, 29 Apr 2024 19:34:49 +0100 Subject: [PATCH 26/38] Fix build --- ...sationalExternalControllerProviderUsersTestConfiguration.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalExternalControllerProviderUsersTestConfiguration.java b/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalExternalControllerProviderUsersTestConfiguration.java index 379c1356ac..e105bde1c6 100644 --- a/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalExternalControllerProviderUsersTestConfiguration.java +++ b/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalExternalControllerProviderUsersTestConfiguration.java @@ -1,6 +1,5 @@ package uk.gov.hmcts.reform.professionalapi.provider; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; From f07b9962125ed065b5e221c14d94ffa6de338983 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Mon, 13 May 2024 10:53:43 +0100 Subject: [PATCH 27/38] fixing review comments --- .../service/impl/OrganisationServiceImpl.java | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 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 37e4f863ae..de225f78ef 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 @@ -827,20 +827,16 @@ public DeleteUserResponse deleteUserForOrganisation(List emails) { if (emails.isEmpty()) { throw new InvalidRequest("Please provide both email addresses"); } - - Set userIdsToBeDeleted = emails.stream().map( - email -> { - Set userIds = new HashSet<>(); - Optional.ofNullable(professionalUserRepository - .findByEmailAddress(RefDataUtil.removeAllSpaces(email))) - .ifPresent(professionalUser -> { - userIds.add(professionalUser.getUserIdentifier()); - userAttributeRepository.deleteByProfessionalUserId(professionalUser.getId()); - professionalUserRepository.delete(professionalUser); - }); - return userIds.stream().iterator().next(); - }).collect(Collectors.toSet());; - + Set userIdsToBeDeleted = new HashSet<>(); + emails.forEach(email -> { + ProfessionalUser professionalUser = professionalUserRepository + .findByEmailAddress(RefDataUtil.removeAllSpaces(email)); + if (professionalUser != null) { + userIdsToBeDeleted.add(professionalUser.getUserIdentifier()); + userAttributeRepository.deleteByProfessionalUserId(professionalUser.getId()); + professionalUserRepository.delete(professionalUser); + } + }); DeleteUserProfilesRequest deleteUserRequest = new DeleteUserProfilesRequest(userIdsToBeDeleted); deleteOrganisationResponse = RefDataUtil .deleteUserProfilesFromUp(deleteUserRequest, userProfileFeignClient); From d08920f52ad14e3764372aa643c69f42e4249e4e Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Mon, 13 May 2024 11:56:00 +0100 Subject: [PATCH 28/38] fixing review comments --- .../controller/request/UserDeletionRequest.java | 7 ------- .../service/impl/OrganisationServiceImpl.java | 2 +- .../internal/OrganisationInternalControllerTest.java | 2 +- .../service/impl/OrganisationServiceImplTest.java | 5 +++-- 4 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/UserDeletionRequest.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/UserDeletionRequest.java index 99e6773d3a..ed6fdc766c 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/UserDeletionRequest.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/UserDeletionRequest.java @@ -13,19 +13,12 @@ @Builder(builderMethodName = "userDeletionRequest") public class UserDeletionRequest { - private String firstName; - private String lastName; private List emails; @JsonCreator public UserDeletionRequest( - @JsonProperty("firstName") String firstName, - @JsonProperty("lastName") String lastName, @JsonProperty("emails") List emails ) { - - this.firstName = firstName; - this.lastName = lastName; this.emails = emails; } } \ No newline at end of file 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 de225f78ef..eb58c82d01 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 @@ -823,7 +823,6 @@ private DeleteOrganisationResponse deleteOrganisationEntity(Organisation organis @Override @Transactional public DeleteUserResponse deleteUserForOrganisation(List emails) { - var deleteOrganisationResponse = new DeleteOrganisationResponse(); if (emails.isEmpty()) { throw new InvalidRequest("Please provide both email addresses"); } @@ -837,6 +836,7 @@ public DeleteUserResponse deleteUserForOrganisation(List emails) { professionalUserRepository.delete(professionalUser); } }); + var deleteOrganisationResponse = new DeleteOrganisationResponse(); DeleteUserProfilesRequest deleteUserRequest = new DeleteUserProfilesRequest(userIdsToBeDeleted); deleteOrganisationResponse = RefDataUtil .deleteUserProfilesFromUp(deleteUserRequest, userProfileFeignClient); diff --git a/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalControllerTest.java b/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalControllerTest.java index 8c891b5d80..ef2c283823 100644 --- a/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalControllerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalControllerTest.java @@ -600,7 +600,7 @@ void testDeleteProfessionalUserFromOrganisation() { DeleteUserResponse deleteUserResponse = new DeleteUserResponse( STATUS_CODE_204, "The organisation has deleted successfully"); List emails = Arrays.asList("56vyi3p3esq@mailinator.com","7qw1vx4b06p@mailinator.com"); - UserDeletionRequest userDeletionRequest = new UserDeletionRequest("fname","lname",emails); + UserDeletionRequest userDeletionRequest = new UserDeletionRequest(emails); when(organisationServiceMock.deleteUserForOrganisation(emails)).thenReturn(deleteUserResponse); 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 ee9194f38f..0eff133774 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 @@ -3,6 +3,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; +import com.launchdarkly.shaded.kotlin.collections.EmptyList; import feign.Request; import feign.Response; import org.assertj.core.api.Assertions; @@ -2754,8 +2755,8 @@ void test_deleteUserForOrganisation() throws JsonProcessingException { @Test void test_deleteUserForOrganisationWithEmptyEmails() { - assertThrows(InvalidRequest.class, () -> - sut.deleteUserForOrganisation(new ArrayList<>())); + List emptyEmailList = new ArrayList(); + assertThrows(InvalidRequest.class, () -> sut.deleteUserForOrganisation(emptyEmailList)); } } From 3806151b9de7cf27ac46a85add73a34914e45161 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Mon, 13 May 2024 12:25:23 +0100 Subject: [PATCH 29/38] fixing review comments --- .../response/DeleteUserResponse.java | 4 --- .../service/impl/OrganisationServiceImpl.java | 25 +++++++++---------- .../impl/OrganisationServiceImplTest.java | 8 +++--- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/response/DeleteUserResponse.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/response/DeleteUserResponse.java index d013341e55..6485a5e4d1 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/response/DeleteUserResponse.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/response/DeleteUserResponse.java @@ -2,12 +2,8 @@ import lombok.AllArgsConstructor; import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; @Getter -@Setter -@NoArgsConstructor @AllArgsConstructor public class DeleteUserResponse { 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 eb58c82d01..ed3899583e 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 @@ -828,24 +828,23 @@ public DeleteUserResponse deleteUserForOrganisation(List emails) { } Set userIdsToBeDeleted = new HashSet<>(); emails.forEach(email -> { - ProfessionalUser professionalUser = professionalUserRepository - .findByEmailAddress(RefDataUtil.removeAllSpaces(email)); - if (professionalUser != null) { - userIdsToBeDeleted.add(professionalUser.getUserIdentifier()); - userAttributeRepository.deleteByProfessionalUserId(professionalUser.getId()); - professionalUserRepository.delete(professionalUser); + Optional professionalUser = Optional.ofNullable(professionalUserRepository + .findByEmailAddress(RefDataUtil.removeAllSpaces(email))); + if (!professionalUser.isEmpty()) { + userIdsToBeDeleted.add(professionalUser.get().getUserIdentifier()); + userAttributeRepository.deleteByProfessionalUserId(professionalUser.get().getId()); + professionalUserRepository.delete(professionalUser.get()); } + }); - var deleteOrganisationResponse = new DeleteOrganisationResponse(); DeleteUserProfilesRequest deleteUserRequest = new DeleteUserProfilesRequest(userIdsToBeDeleted); - deleteOrganisationResponse = RefDataUtil - .deleteUserProfilesFromUp(deleteUserRequest, userProfileFeignClient); - if (deleteOrganisationResponse == null) { + Optional deleteOrganisationResponse = Optional.ofNullable(RefDataUtil + .deleteUserProfilesFromUp(deleteUserRequest, userProfileFeignClient)); + if (deleteOrganisationResponse.isEmpty()) { throw new InvalidRequest(ERROR_MESSAGE_UP_FAILED); } - - return new DeleteUserResponse(deleteOrganisationResponse.getStatusCode(), - deleteOrganisationResponse.getMessage()); + return new DeleteUserResponse(deleteOrganisationResponse.get().getStatusCode(), + deleteOrganisationResponse.get().getMessage()); } 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 0eff133774..5db18ad036 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 @@ -3,7 +3,6 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import com.launchdarkly.shaded.kotlin.collections.EmptyList; import feign.Request; import feign.Response; import org.assertj.core.api.Assertions; @@ -116,6 +115,7 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ERROR_CODE_400; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ERROR_MSG_PARTIAL_SUCCESS; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ISO_DATE_TIME_FORMATTER; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.LENGTH_OF_ORGANISATION_IDENTIFIER; @@ -2097,7 +2097,7 @@ void testDeleteActiveOrganisationWithOrgAdminActiveGives400WithMessage() throws DeleteOrganisationResponse deleteOrganisationResponse = new DeleteOrganisationResponse(); - deleteOrganisationResponse.setStatusCode(ProfessionalApiConstants.ERROR_CODE_400); + deleteOrganisationResponse.setStatusCode(ERROR_CODE_400); deleteOrganisationResponse.setMessage(ProfessionalApiConstants.ERROR_MESSAGE_400_ADMIN_NOT_PENDING); ObjectMapper mapperOne = new ObjectMapper(); String deleteBody = mapperOne.writeValueAsString(newUserResponse); @@ -2131,7 +2131,7 @@ void testDeleteActiveOrganisationWithMultiUsersGives400WithMessage() { deleteOrganisationResponse = sut.deleteOrganisation(organisation, "123456789"); assertThat(deleteOrganisationResponse).isNotNull(); - assertThat(deleteOrganisationResponse.getStatusCode()).isEqualTo(ProfessionalApiConstants.ERROR_CODE_400); + assertThat(deleteOrganisationResponse.getStatusCode()).isEqualTo(ERROR_CODE_400); assertThat(deleteOrganisationResponse.getMessage()) .isEqualTo(ProfessionalApiConstants.ERROR_MESSAGE_400_ORG_MORE_THAN_ONE_USER); verify(organisationRepository, times(0)).deleteById(any()); @@ -2754,9 +2754,11 @@ void test_deleteUserForOrganisation() throws JsonProcessingException { } @Test + @SuppressWarnings("unchecked") void test_deleteUserForOrganisationWithEmptyEmails() { List emptyEmailList = new ArrayList(); assertThrows(InvalidRequest.class, () -> sut.deleteUserForOrganisation(emptyEmailList)); } + } From 5fcc971c3f6ded37649eac0b2203a70700610785 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Tue, 4 Jun 2024 12:19:21 +0100 Subject: [PATCH 30/38] removed teh extra code for DTSRD-2134 --- .../OrganisationInternalController.java | 60 ------------------- .../request/UserDeletionRequest.java | 24 -------- .../response/DeleteUserResponse.java | 13 ---- .../repository/UserAttributeRepository.java | 5 -- .../service/OrganisationService.java | 2 - .../service/impl/OrganisationServiceImpl.java | 29 +-------- .../OrganisationInternalControllerTest.java | 19 ------ .../impl/OrganisationServiceImplTest.java | 40 ------------- 8 files changed, 2 insertions(+), 190 deletions(-) delete mode 100644 src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/UserDeletionRequest.java delete mode 100644 src/main/java/uk/gov/hmcts/reform/professionalapi/controller/response/DeleteUserResponse.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 426566fa9b..50b9633391 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 @@ -36,10 +36,8 @@ 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.UpdatePbaRequest; -import uk.gov.hmcts.reform.professionalapi.controller.request.UserDeletionRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.validator.impl.OrganisationByProfileIdsRequestValidator; import uk.gov.hmcts.reform.professionalapi.controller.response.DeleteOrganisationResponse; -import uk.gov.hmcts.reform.professionalapi.controller.response.DeleteUserResponse; 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; @@ -749,62 +747,4 @@ public ResponseEntity retrieveOrganisationsByProfileIds( .body(response); } - @Operation( - summary = "Deletes the provided list of user accounts from the organisation.", - description = "**IDAM Roles to access API** :
- pui-finance-manager", - security = { - @SecurityRequirement(name = "ServiceAuthorization"), - @SecurityRequirement(name = "Authorization") - } - ) - @ApiResponse( - responseCode = "204", - description = "Successfully deleted the list of user accounts from the organisation.", - content = @Content - ) - @ApiResponse( - responseCode = "400", - description = DEL_ORG_PBA_NOTES_1, - 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 for either invalid permissions or user is pending", - content = @Content - ) - @ApiResponse( - responseCode = "404", - description = "Resource Not Found Error: The user does not exist", - content = @Content - ) - @ApiResponse( - responseCode = "500", - description = "Internal Server Error", - content = @Content - ) - - @DeleteMapping(path = "/users") - @ResponseStatus(value = HttpStatus.NO_CONTENT) - @Secured({"prd-admin"}) - public ResponseEntity deleteUserFromOrganisation( - @io.swagger.v3.oas.annotations.parameters.RequestBody(description = "deletePbaRequest") - @Valid @NotNull @RequestBody UserDeletionRequest userDeletionRequest) { - - List emails = userDeletionRequest.getEmails(); - - DeleteUserResponse deleteUserResponse = - organisationService.deleteUserForOrganisation(emails); - - return ResponseEntity - .status(deleteUserResponse.getStatusCode()) - .body(deleteUserResponse); - - } } diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/UserDeletionRequest.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/UserDeletionRequest.java deleted file mode 100644 index ed6fdc766c..0000000000 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/UserDeletionRequest.java +++ /dev/null @@ -1,24 +0,0 @@ -package uk.gov.hmcts.reform.professionalapi.controller.request; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.Builder; -import lombok.Getter; -import lombok.Setter; - -import java.util.List; - -@Getter -@Setter -@Builder(builderMethodName = "userDeletionRequest") -public class UserDeletionRequest { - - private List emails; - - @JsonCreator - public UserDeletionRequest( - @JsonProperty("emails") List emails - ) { - this.emails = emails; - } -} \ No newline at end of file diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/response/DeleteUserResponse.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/response/DeleteUserResponse.java deleted file mode 100644 index 6485a5e4d1..0000000000 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/response/DeleteUserResponse.java +++ /dev/null @@ -1,13 +0,0 @@ -package uk.gov.hmcts.reform.professionalapi.controller.response; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -@Getter -@AllArgsConstructor -public class DeleteUserResponse { - - private int statusCode; - private String message; - -} \ No newline at end of file diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/repository/UserAttributeRepository.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/repository/UserAttributeRepository.java index c9cb281a2d..f376eb4ae3 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/repository/UserAttributeRepository.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/repository/UserAttributeRepository.java @@ -11,9 +11,4 @@ @Repository public interface UserAttributeRepository extends JpaRepository { - @Modifying - @Query(value = "delete from dbrefdata.user_attribute ua where ua.professional_user_id = :profUserId ", - nativeQuery = true) - void deleteByProfessionalUserId(UUID profUserId); - } 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 bb09780c70..93992861a1 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 @@ -8,7 +8,6 @@ import uk.gov.hmcts.reform.professionalapi.controller.request.PbaRequest; 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.DeleteUserResponse; 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; @@ -82,5 +81,4 @@ void addContactInformationsToOrganisation( ResponseEntity retrieveOrganisationByUserId(String userId); - DeleteUserResponse deleteUserForOrganisation(List emails); } 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 ed3899583e..8586972bdb 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 @@ -17,6 +17,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.ObjectUtils; import uk.gov.hmcts.reform.professionalapi.controller.advice.ResourceNotFoundException; +import uk.gov.hmcts.reform.professionalapi.controller.constants.PrdEnumType; import uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants; import uk.gov.hmcts.reform.professionalapi.controller.feign.UserProfileFeignClient; import uk.gov.hmcts.reform.professionalapi.controller.request.ContactInformationCreationRequest; @@ -797,6 +798,7 @@ public DeleteOrganisationResponse deleteOrganisation(Organisation organisation, case PENDING,REVIEW: return deleteOrganisationEntity(organisation, deleteOrganisationResponse, prdAdminUserId); case ACTIVE: + deleteOrganisationEntity(organisation, deleteOrganisationResponse, prdAdminUserId); deleteOrganisationResponse = deleteUserProfile(organisation, deleteOrganisationResponse); return deleteOrganisationResponse.getStatusCode() == ProfessionalApiConstants.STATUS_CODE_204 ? deleteOrganisationEntity(organisation, deleteOrganisationResponse, prdAdminUserId) @@ -820,33 +822,6 @@ private DeleteOrganisationResponse deleteOrganisationEntity(Organisation organis return deleteOrganisationResponse; } - @Override - @Transactional - public DeleteUserResponse deleteUserForOrganisation(List emails) { - if (emails.isEmpty()) { - throw new InvalidRequest("Please provide both email addresses"); - } - Set userIdsToBeDeleted = new HashSet<>(); - emails.forEach(email -> { - Optional professionalUser = Optional.ofNullable(professionalUserRepository - .findByEmailAddress(RefDataUtil.removeAllSpaces(email))); - if (!professionalUser.isEmpty()) { - userIdsToBeDeleted.add(professionalUser.get().getUserIdentifier()); - userAttributeRepository.deleteByProfessionalUserId(professionalUser.get().getId()); - professionalUserRepository.delete(professionalUser.get()); - } - - }); - DeleteUserProfilesRequest deleteUserRequest = new DeleteUserProfilesRequest(userIdsToBeDeleted); - Optional deleteOrganisationResponse = Optional.ofNullable(RefDataUtil - .deleteUserProfilesFromUp(deleteUserRequest, userProfileFeignClient)); - if (deleteOrganisationResponse.isEmpty()) { - throw new InvalidRequest(ERROR_MESSAGE_UP_FAILED); - } - return new DeleteUserResponse(deleteOrganisationResponse.get().getStatusCode(), - deleteOrganisationResponse.get().getMessage()); - } - private DeleteOrganisationResponse deleteUserProfile(Organisation organisation, diff --git a/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalControllerTest.java b/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalControllerTest.java index ef2c283823..28658247dc 100644 --- a/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalControllerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalControllerTest.java @@ -27,7 +27,6 @@ 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.UserCreationRequest; -import uk.gov.hmcts.reform.professionalapi.controller.request.UserDeletionRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.UserProfileCreationRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.validator.OrganisationCreationRequestValidator; import uk.gov.hmcts.reform.professionalapi.controller.request.validator.PaymentAccountValidator; @@ -35,7 +34,6 @@ import uk.gov.hmcts.reform.professionalapi.controller.request.validator.impl.OrganisationIdentifierValidatorImpl; import uk.gov.hmcts.reform.professionalapi.controller.request.validator.impl.OrganisationStatusValidatorImpl; import uk.gov.hmcts.reform.professionalapi.controller.response.DeleteOrganisationResponse; -import uk.gov.hmcts.reform.professionalapi.controller.response.DeleteUserResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationEntityResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationsDetailResponse; @@ -595,21 +593,4 @@ void testRetrieveOrgByPbaStatus() { .getOrganisationsByPbaStatus(pbaStatus.toString()); } - @Test - void testDeleteProfessionalUserFromOrganisation() { - DeleteUserResponse deleteUserResponse = new DeleteUserResponse( - STATUS_CODE_204, "The organisation has deleted successfully"); - List emails = Arrays.asList("56vyi3p3esq@mailinator.com","7qw1vx4b06p@mailinator.com"); - UserDeletionRequest userDeletionRequest = new UserDeletionRequest(emails); - - when(organisationServiceMock.deleteUserForOrganisation(emails)).thenReturn(deleteUserResponse); - - ResponseEntity actual = organisationInternalController.deleteUserFromOrganisation(userDeletionRequest); - - verify(organisationServiceMock, times(1)).deleteUserForOrganisation(emails); - - assertThat(actual).isNotNull(); - assertThat(actual.getStatusCodeValue()).isEqualTo(deleteUserResponse.getStatusCode()); - } - } 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 5db18ad036..2e67dc3174 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 @@ -38,7 +38,6 @@ import uk.gov.hmcts.reform.professionalapi.controller.request.validator.PaymentAccountValidator; 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.DeleteUserResponse; 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; @@ -98,7 +97,6 @@ import java.util.Set; import java.util.UUID; -import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -2723,42 +2721,4 @@ void shouldRetrieveOrganisationsWithEmptyProfileIdList() { assertThat(result.getOrganisationInfo()).isNullOrEmpty(); } - @Test - @SuppressWarnings("unchecked") - void test_deleteUserForOrganisation() throws JsonProcessingException { - final HttpStatus expectedHttpStatus = HttpStatus.OK; - - String deleteBody = new ObjectMapper().writeValueAsString(new NewUserResponse()); - - when(professionalUserRepositoryMock.findByEmailAddress(anyString())).thenReturn(professionalUser); - doNothing().when(userAttributeRepositoryMock).deleteByProfessionalUserId(professionalUser.getId()); - doNothing().when(professionalUserRepositoryMock).delete(professionalUser); - - when(userProfileFeignClient.deleteUserProfile(any())) - .thenReturn(Response.builder().status(STATUS_CODE_204).reason("OK").body(deleteBody, UTF_8) - .request(mock(Request.class)).build()); - - assertThat(deleteOrganisationResponse).isNotNull(); - assertThat(deleteOrganisationResponse.getStatusCode()).isEqualTo(STATUS_CODE_204); - verify(userProfileFeignClient, times(0)).deleteUserProfile(any()); - - DeleteUserResponse deleteUserResponse = new DeleteUserResponse( - 204, "The organisation has deleted successfully"); - List emails = Arrays.asList("56vyi3p3esq@mailinator.com","7qw1vx4b06p@mailinator.com"); - - deleteUserResponse = sut.deleteUserForOrganisation(emails); - assertThat(deleteUserResponse).isNotNull(); - assertThat(deleteUserResponse.getStatusCode()).isEqualTo(STATUS_CODE_204); - verify(organisationRepository, times(0)).findByOrganisationIdentifier(any(String.class)); - - } - - @Test - @SuppressWarnings("unchecked") - void test_deleteUserForOrganisationWithEmptyEmails() { - List emptyEmailList = new ArrayList(); - assertThrows(InvalidRequest.class, () -> sut.deleteUserForOrganisation(emptyEmailList)); - } - - } From c82455f55d04a6f031e24b2400c6b98031278b5d Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Tue, 4 Jun 2024 12:24:37 +0100 Subject: [PATCH 31/38] removed teh extra code for DTSRD-2134 --- .../OrganisationalExternalControllerProviderUsersTest.java | 4 ---- ...ionalExternalControllerProviderUsersTestConfiguration.java | 4 ---- .../OrganisationalInternalControllerProviderTest.java | 4 ---- ...nisationalInternalControllerProviderTestConfiguration.java | 3 --- .../controller/internal/OrganisationInternalController.java | 3 --- .../professionalapi/repository/UserAttributeRepository.java | 2 -- .../professionalapi/service/impl/OrganisationServiceImpl.java | 2 -- 7 files changed, 22 deletions(-) diff --git a/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalExternalControllerProviderUsersTest.java b/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalExternalControllerProviderUsersTest.java index e7e73d4f68..188fec5fe2 100644 --- a/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalExternalControllerProviderUsersTest.java +++ b/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalExternalControllerProviderUsersTest.java @@ -36,7 +36,6 @@ import uk.gov.hmcts.reform.professionalapi.repository.IdamRepository; import uk.gov.hmcts.reform.professionalapi.repository.OrganisationRepository; import uk.gov.hmcts.reform.professionalapi.repository.ProfessionalUserRepository; -import uk.gov.hmcts.reform.professionalapi.repository.UserAttributeRepository; import uk.gov.hmcts.reform.professionalapi.repository.UserConfiguredAccessRepository; import uk.gov.hmcts.reform.professionalapi.service.ProfessionalUserService; @@ -95,9 +94,6 @@ public class OrganisationalExternalControllerProviderUsersTest extends WebMvcPro @Mock SecurityContext securityContext; - @Autowired - UserAttributeRepository userAttributeRepository; - private final ObjectMapper objectMapper = new ObjectMapper(); private Organisation organisation; diff --git a/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalExternalControllerProviderUsersTestConfiguration.java b/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalExternalControllerProviderUsersTestConfiguration.java index e105bde1c6..1f7060e4ee 100644 --- a/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalExternalControllerProviderUsersTestConfiguration.java +++ b/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalExternalControllerProviderUsersTestConfiguration.java @@ -16,7 +16,6 @@ import uk.gov.hmcts.reform.professionalapi.repository.OrganisationRepository; import uk.gov.hmcts.reform.professionalapi.repository.PaymentAccountRepository; import uk.gov.hmcts.reform.professionalapi.repository.PrdEnumRepository; -import uk.gov.hmcts.reform.professionalapi.repository.UserAttributeRepository; import uk.gov.hmcts.reform.professionalapi.repository.UserConfiguredAccessRepository; import uk.gov.hmcts.reform.professionalapi.service.FeatureToggleService; import uk.gov.hmcts.reform.professionalapi.service.PaymentAccountService; @@ -69,9 +68,6 @@ public class OrganisationalExternalControllerProviderUsersTestConfiguration exte @MockBean OrgAttributeRepository orgAttributeRepository; - @MockBean - UserAttributeRepository userAttributeRepository; - @Bean @Primary protected OrganisationServiceImpl organisationService() { 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 fbc3f7b0eb..1c630babc4 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 @@ -33,7 +33,6 @@ import uk.gov.hmcts.reform.professionalapi.domain.ProfessionalUser; import uk.gov.hmcts.reform.professionalapi.domain.SuperUser; import uk.gov.hmcts.reform.professionalapi.repository.BulkCustomerDetailsRepository; -import uk.gov.hmcts.reform.professionalapi.repository.OrgAttributeRepository; import uk.gov.hmcts.reform.professionalapi.repository.OrganisationRepository; import uk.gov.hmcts.reform.professionalapi.repository.PaymentAccountRepository; import uk.gov.hmcts.reform.professionalapi.repository.ProfessionalUserRepository; @@ -71,9 +70,6 @@ public class OrganisationalInternalControllerProviderTest extends MockMvcProvide @Autowired OrganisationRepository organisationRepository; - @Autowired - OrgAttributeRepository orgAttributeRepository; - @Autowired PaymentAccountRepository paymentAccountRepository; diff --git a/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalInternalControllerProviderTestConfiguration.java b/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalInternalControllerProviderTestConfiguration.java index 1187767c8e..6f2202db7d 100644 --- a/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalInternalControllerProviderTestConfiguration.java +++ b/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalInternalControllerProviderTestConfiguration.java @@ -14,7 +14,6 @@ import uk.gov.hmcts.reform.professionalapi.repository.OrganisationRepository; import uk.gov.hmcts.reform.professionalapi.repository.PaymentAccountRepository; import uk.gov.hmcts.reform.professionalapi.repository.PrdEnumRepository; -import uk.gov.hmcts.reform.professionalapi.repository.UserAttributeRepository; import uk.gov.hmcts.reform.professionalapi.service.PaymentAccountService; import uk.gov.hmcts.reform.professionalapi.service.ProfessionalUserService; import uk.gov.hmcts.reform.professionalapi.service.UserAttributeService; @@ -59,8 +58,6 @@ public class OrganisationalInternalControllerProviderTestConfiguration extends P @MockBean OrganisationMfaStatusRepository organisationMfaStatusRepository; - @MockBean - UserAttributeRepository userAttributeRepository; @Bean 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 50b9633391..2d1e388ab2 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 @@ -49,7 +49,6 @@ import uk.gov.hmcts.reform.professionalapi.domain.Organisation; import uk.gov.hmcts.reform.professionalapi.domain.PbaResponse; -import java.util.List; import java.util.Optional; import java.util.UUID; import javax.validation.Valid; @@ -59,7 +58,6 @@ 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.DEL_ORG_PBA_NOTES_1; 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; @@ -746,5 +744,4 @@ public ResponseEntity retrieveOrganisationsByProfileIds( .status(HttpStatus.OK) .body(response); } - } diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/repository/UserAttributeRepository.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/repository/UserAttributeRepository.java index f376eb4ae3..04abaaca30 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/repository/UserAttributeRepository.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/repository/UserAttributeRepository.java @@ -1,8 +1,6 @@ package uk.gov.hmcts.reform.professionalapi.repository; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; import uk.gov.hmcts.reform.professionalapi.domain.UserAttribute; 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 8586972bdb..6b36703226 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 @@ -17,7 +17,6 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.ObjectUtils; import uk.gov.hmcts.reform.professionalapi.controller.advice.ResourceNotFoundException; -import uk.gov.hmcts.reform.professionalapi.controller.constants.PrdEnumType; import uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants; import uk.gov.hmcts.reform.professionalapi.controller.feign.UserProfileFeignClient; import uk.gov.hmcts.reform.professionalapi.controller.request.ContactInformationCreationRequest; @@ -33,7 +32,6 @@ import uk.gov.hmcts.reform.professionalapi.controller.request.validator.PaymentAccountValidator; 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.DeleteUserResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.FetchPbaByStatusResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.MultipleOrganisationsResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationEntityResponse; From 47e5a12231a105e5112e39abd35ee47f3236a55a Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Tue, 4 Jun 2024 12:26:21 +0100 Subject: [PATCH 32/38] removed teh extra code for DTSRD-2134 --- .../OrganisationalInternalControllerProviderTest.java | 8 ++++---- ...tionalInternalControllerProviderTestConfiguration.java | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) 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 1c630babc4..e53282eb65 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 @@ -33,10 +33,10 @@ import uk.gov.hmcts.reform.professionalapi.domain.ProfessionalUser; import uk.gov.hmcts.reform.professionalapi.domain.SuperUser; import uk.gov.hmcts.reform.professionalapi.repository.BulkCustomerDetailsRepository; +import uk.gov.hmcts.reform.professionalapi.repository.OrgAttributeRepository; import uk.gov.hmcts.reform.professionalapi.repository.OrganisationRepository; import uk.gov.hmcts.reform.professionalapi.repository.PaymentAccountRepository; import uk.gov.hmcts.reform.professionalapi.repository.ProfessionalUserRepository; -import uk.gov.hmcts.reform.professionalapi.repository.UserAttributeRepository; import uk.gov.hmcts.reform.professionalapi.service.MfaStatusService; import uk.gov.hmcts.reform.professionalapi.service.PaymentAccountService; import uk.gov.hmcts.reform.professionalapi.service.PrdEnumService; @@ -70,6 +70,9 @@ public class OrganisationalInternalControllerProviderTest extends MockMvcProvide @Autowired OrganisationRepository organisationRepository; + @Autowired + OrgAttributeRepository orgAttributeRepository; + @Autowired PaymentAccountRepository paymentAccountRepository; @@ -104,9 +107,6 @@ public class OrganisationalInternalControllerProviderTest extends MockMvcProvide @Autowired OrganisationIdentifierValidatorImpl organisationIdentifierValidatorImplMock; - @Autowired - UserAttributeRepository userAttributeRepository; - public static final String ORG_NAME = "Org-Name"; public static final String SRA_ID = "sra-id"; diff --git a/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalInternalControllerProviderTestConfiguration.java b/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalInternalControllerProviderTestConfiguration.java index 6f2202db7d..677789f6f2 100644 --- a/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalInternalControllerProviderTestConfiguration.java +++ b/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalInternalControllerProviderTestConfiguration.java @@ -59,7 +59,6 @@ public class OrganisationalInternalControllerProviderTestConfiguration extends P @MockBean OrganisationMfaStatusRepository organisationMfaStatusRepository; - @Bean @Primary protected OrganisationInternalController organisationInternalController() { From 725c733d0ea44a752c93fd1867b93a0413478c42 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Tue, 4 Jun 2024 12:27:03 +0100 Subject: [PATCH 33/38] removed teh extra code for DTSRD-2134 --- .../provider/OrganisationalInternalControllerProviderTest.java | 1 - 1 file changed, 1 deletion(-) 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 e53282eb65..2e2f8719be 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 @@ -107,7 +107,6 @@ public class OrganisationalInternalControllerProviderTest extends MockMvcProvide @Autowired OrganisationIdentifierValidatorImpl organisationIdentifierValidatorImplMock; - public static final String ORG_NAME = "Org-Name"; public static final String SRA_ID = "sra-id"; public static final String COMPANY_NUMBER = "companyN"; From 3f0f0e2dc17f6cf5e6407085ee30577f19581046 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Tue, 4 Jun 2024 12:34:02 +0100 Subject: [PATCH 34/38] removed teh extra code for DTSRD-2134 --- .../service/impl/OrganisationServiceImpl.java | 5 ----- 1 file changed, 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 6b36703226..b549e428dc 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 @@ -63,7 +63,6 @@ import uk.gov.hmcts.reform.professionalapi.repository.PaymentAccountRepository; import uk.gov.hmcts.reform.professionalapi.repository.PrdEnumRepository; import uk.gov.hmcts.reform.professionalapi.repository.ProfessionalUserRepository; -import uk.gov.hmcts.reform.professionalapi.repository.UserAttributeRepository; import uk.gov.hmcts.reform.professionalapi.service.OrganisationService; import uk.gov.hmcts.reform.professionalapi.service.PrdEnumService; import uk.gov.hmcts.reform.professionalapi.service.ProfessionalUserService; @@ -93,7 +92,6 @@ import static java.lang.Boolean.TRUE; 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; @@ -145,8 +143,6 @@ public class OrganisationServiceImpl implements OrganisationService { ProfessionalUserService professionalUserService; @Autowired OrgAttributeRepository orgAttributeRepository; - @Autowired - UserAttributeRepository userAttributeRepository; @Value("${loggingComponentName}") private String loggingComponentName; @@ -796,7 +792,6 @@ public DeleteOrganisationResponse deleteOrganisation(Organisation organisation, case PENDING,REVIEW: return deleteOrganisationEntity(organisation, deleteOrganisationResponse, prdAdminUserId); case ACTIVE: - deleteOrganisationEntity(organisation, deleteOrganisationResponse, prdAdminUserId); deleteOrganisationResponse = deleteUserProfile(organisation, deleteOrganisationResponse); return deleteOrganisationResponse.getStatusCode() == ProfessionalApiConstants.STATUS_CODE_204 ? deleteOrganisationEntity(organisation, deleteOrganisationResponse, prdAdminUserId) From 2045d1e853ad21b6d492a9fc2d4e485db1216247 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Tue, 4 Jun 2024 12:43:05 +0100 Subject: [PATCH 35/38] removed teh extra code for DTSRD-2134 --- .../controller/internal/OrganisationInternalControllerTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalControllerTest.java b/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalControllerTest.java index 28658247dc..7bfc053e2f 100644 --- a/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalControllerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalControllerTest.java @@ -57,7 +57,6 @@ import java.nio.charset.Charset; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -77,7 +76,6 @@ import static org.mockito.Mockito.when; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ORG_NAME; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ORG_STATUS; -import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.STATUS_CODE_204; @ExtendWith(MockitoExtension.class) @SuppressWarnings("checkstyle:AbbreviationAsWordInName") From c4da7afb8ab7e4ccd9c1774c4c64f37114901745 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Sat, 31 Aug 2024 10:44:34 +0100 Subject: [PATCH 36/38] merging DTSRD-2132 and DTSRD-2136 --- .../ProfessionalInternalUserFunctionalTest.java | 14 ++++++++++++++ 1 file changed, 14 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 82c1179593..2c11653a4a 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java @@ -567,6 +567,20 @@ public void deleteActiveOrganisationShouldReturnSuccess() { log.info("deleteActiveOrganisationShouldReturnSuccess :: END"); } + @Test + public void deleteActiveOrganisationShouldReturnErrorWithMultipleUsers() { + log.info("deleteActiveOrganisationShouldReturnSuccess :: STARTED"); + String orgIdentifierResponse = createAndUpdateOrganisationToActive(hmctsAdmin); + NewUserCreationRequest newUserCreationRequest = professionalApiClient.createNewUserRequest(); + newUserCreationRequest.setEmail("newUserEmail@hmcts.com"); + Map newUserResponse = professionalApiClient.addNewUserToAnOrganisation(orgIdentifierResponse, + hmctsAdmin, newUserCreationRequest, HttpStatus.CONFLICT); + + professionalApiClient.deleteOrganisation(orgIdentifierResponse, hmctsAdmin, NO_CONTENT); + professionalApiClient.retrieveOrganisationDetails(orgIdentifierResponse, hmctsAdmin, NOT_FOUND); + log.info("deleteActiveOrganisationShouldReturnSuccess :: END"); + } + public void validateRoles(List rolesToValidate) { Map searchResponse = professionalApiClient.searchOrganisationUsersByStatusInternal( intActiveOrgId, hmctsAdmin, HttpStatus.OK); From c1c2d811f7760fccf5db59ebb070b7900116aac0 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Wed, 4 Sep 2024 22:29:06 +0100 Subject: [PATCH 37/38] endpoint to save SraId --- .../constants/ProfessionalApiConstants.java | 4 +- .../service/impl/OrganisationServiceImpl.java | 50 ++++++++++++------- .../impl/OrganisationServiceImplTest.java | 4 +- 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/constants/ProfessionalApiConstants.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/constants/ProfessionalApiConstants.java index 8ad52a839c..7bad7981e5 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/constants/ProfessionalApiConstants.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/constants/ProfessionalApiConstants.java @@ -53,9 +53,9 @@ private ProfessionalApiConstants() { public static final int ERROR_CODE_400 = 400; public static final int ERROR_CODE_500 = 500; public static final int STATUS_CODE_204 = 204; - public static final int USER_COUNT = 1; + public static final int USER_COUNT = 0; public static final String ERROR_MESSAGE_400_ADMIN_NOT_PENDING = "The organisation admin is not in Pending state"; - public static final String ERROR_MESSAGE_400_ORG_MORE_THAN_ONE_USER = "The organisation has more than one user" + public static final String ERROR_MESSAGE_400_ORG_MORE_THAN_ONE_USER = "The organisation has more than one user " .concat("registered with HMCTS"); public static final String ERROR_MESSAGE_INTERNAL_SERVER = "Internal Server Error"; public static final String ERR_MESG_500_ADMIN_NOTFOUNDUP = "The Organisation admin details could not be retrieved"; 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 b549e428dc..df2b389053 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 @@ -17,6 +17,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.ObjectUtils; 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; import uk.gov.hmcts.reform.professionalapi.controller.feign.UserProfileFeignClient; import uk.gov.hmcts.reform.professionalapi.controller.request.ContactInformationCreationRequest; @@ -53,6 +54,7 @@ import uk.gov.hmcts.reform.professionalapi.domain.PaymentAccount; import uk.gov.hmcts.reform.professionalapi.domain.PbaStatus; import uk.gov.hmcts.reform.professionalapi.domain.ProfessionalUser; +import uk.gov.hmcts.reform.professionalapi.domain.SuperUser; import uk.gov.hmcts.reform.professionalapi.domain.UserAttribute; import uk.gov.hmcts.reform.professionalapi.repository.BulkCustomerDetailsRepository; import uk.gov.hmcts.reform.professionalapi.repository.ContactInformationRepository; @@ -792,7 +794,14 @@ public DeleteOrganisationResponse deleteOrganisation(Organisation organisation, case PENDING,REVIEW: return deleteOrganisationEntity(organisation, deleteOrganisationResponse, prdAdminUserId); case ACTIVE: - deleteOrganisationResponse = deleteUserProfile(organisation, deleteOrganisationResponse); + //if organisation contains users then they will be deleted + if (ProfessionalApiConstants.USER_COUNT != professionalUserRepository + .findByUserCountByOrganisationId(organisation.getId())) { + deleteOrganisationResponse = deleteUserProfile(organisation, deleteOrganisationResponse); + } else { + deleteOrganisationResponse.setStatusCode(ProfessionalApiConstants.STATUS_CODE_204); + } + //if all users from user profile are successfully deleted then delete organisation return deleteOrganisationResponse.getStatusCode() == ProfessionalApiConstants.STATUS_CODE_204 ? deleteOrganisationEntity(organisation, deleteOrganisationResponse, prdAdminUserId) : deleteOrganisationResponse; @@ -820,32 +829,35 @@ private DeleteOrganisationResponse deleteOrganisationEntity(Organisation organis private DeleteOrganisationResponse deleteUserProfile(Organisation organisation, DeleteOrganisationResponse deleteOrganisationResponse) { - // if user count more than one in the current organisation then throw exception - if (ProfessionalApiConstants.USER_COUNT == professionalUserRepository - .findByUserCountByOrganisationId(organisation.getId())) { - var user = organisation.getUsers() - .get(ZERO_INDEX).toProfessionalUser(); + var userIds = new HashSet(); + List users = organisation.getUsers(); + DeleteOrganisationResponse finalDeleteOrganisationResponse = deleteOrganisationResponse; + users.forEach(user -> { var newUserResponse = RefDataUtil .findUserProfileStatusByEmail(user.getEmailAddress(), userProfileFeignClient); - if (ObjectUtils.isEmpty(newUserResponse.getIdamStatus())) { - deleteOrganisationResponse.setStatusCode(ProfessionalApiConstants.ERROR_CODE_500); - deleteOrganisationResponse.setMessage(ProfessionalApiConstants.ERR_MESG_500_ADMIN_NOTFOUNDUP); + finalDeleteOrganisationResponse.setStatusCode(ProfessionalApiConstants.ERROR_CODE_500); + finalDeleteOrganisationResponse.setMessage(ProfessionalApiConstants.ERR_MESG_500_ADMIN_NOTFOUNDUP); - } else { - // user will be deleted even if he is in active state - var userIds = new HashSet(); + } else if (!IdamStatus.ACTIVE.name().equalsIgnoreCase(newUserResponse.getIdamStatus())) { + // If user is not active in the up will send the request to delete userIds.add(user.getUserIdentifier()); - DeleteUserProfilesRequest deleteUserRequest = new DeleteUserProfilesRequest(userIds); - deleteOrganisationResponse = RefDataUtil - .deleteUserProfilesFromUp(deleteUserRequest, userProfileFeignClient); + + } else { + finalDeleteOrganisationResponse.setStatusCode(ProfessionalApiConstants.ERROR_CODE_400); + finalDeleteOrganisationResponse.setMessage(ProfessionalApiConstants. + ERROR_MESSAGE_400_ADMIN_NOT_PENDING); } - } else { - deleteOrganisationResponse.setStatusCode(ProfessionalApiConstants.ERROR_CODE_400); - deleteOrganisationResponse.setMessage(ProfessionalApiConstants.ERROR_MESSAGE_400_ORG_MORE_THAN_ONE_USER); + + }); + if (userIds.size() > 0) { + DeleteUserProfilesRequest deleteUserRequest = new DeleteUserProfilesRequest(userIds); + return RefDataUtil.deleteUserProfilesFromUp(deleteUserRequest, userProfileFeignClient); + } + else { + return finalDeleteOrganisationResponse; } - return deleteOrganisationResponse; } public List getOrganisationByStatuses(List enumStatuses, Pageable pageable) { 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 2e67dc3174..ac7dcbcfad 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 @@ -2122,14 +2122,14 @@ void testDeleteActiveOrganisationWithOrgAdminActiveGives400WithMessage() throws } @Test - void testDeleteActiveOrganisationWithMultiUsersGives400WithMessage() { + void testDeleteActiveOrganisationWithMultiUsersGivesSuccessMessage() { Organisation organisation = getDeleteOrganisation(ACTIVE); when(professionalUserRepositoryMock.findByUserCountByOrganisationId(any())).thenReturn(2); deleteOrganisationResponse = sut.deleteOrganisation(organisation, "123456789"); assertThat(deleteOrganisationResponse).isNotNull(); - assertThat(deleteOrganisationResponse.getStatusCode()).isEqualTo(ERROR_CODE_400); + assertThat(deleteOrganisationResponse.getStatusCode()).isEqualTo(STATUS_CODE_204); assertThat(deleteOrganisationResponse.getMessage()) .isEqualTo(ProfessionalApiConstants.ERROR_MESSAGE_400_ORG_MORE_THAN_ONE_USER); verify(organisationRepository, times(0)).deleteById(any()); From 83caf02e733e3c9c978cdefc3629cd044c91ac9b Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Wed, 4 Sep 2024 22:30:20 +0100 Subject: [PATCH 38/38] endpoint to save SraId --- .../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 df2b389053..bef5832a02 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 @@ -846,16 +846,15 @@ private DeleteOrganisationResponse deleteUserProfile(Organisation organisation, } else { finalDeleteOrganisationResponse.setStatusCode(ProfessionalApiConstants.ERROR_CODE_400); - finalDeleteOrganisationResponse.setMessage(ProfessionalApiConstants. - ERROR_MESSAGE_400_ADMIN_NOT_PENDING); + finalDeleteOrganisationResponse.setMessage(ProfessionalApiConstants + .ERROR_MESSAGE_400_ADMIN_NOT_PENDING); } }); if (userIds.size() > 0) { DeleteUserProfilesRequest deleteUserRequest = new DeleteUserProfilesRequest(userIds); return RefDataUtil.deleteUserProfilesFromUp(deleteUserRequest, userProfileFeignClient); - } - else { + } else { return finalDeleteOrganisationResponse; } }