From ba0baf6800c7f692003aa49b90a3c5234f06db4b Mon Sep 17 00:00:00 2001 From: Maria Martinez Date: Thu, 8 Feb 2024 13:00:26 -0800 Subject: [PATCH] feat/be(FSADT1-1182): Updated submission list with required fields --- .../client/ClientSubmissionController.java | 11 +++---- .../dto/client/ClientListSubmissionDto.java | 2 +- .../app/predicates/SubmissionPredicates.java | 8 ++--- .../client/ClientSubmissionService.java | 29 +++++++++---------- ...ientDistrictControllerIntegrationTest.java | 7 ----- .../CognitoControllerIntegrationTest.java | 1 - .../predicates/SubmissionPredicatesTest.java | 18 ++++++------ 7 files changed, 31 insertions(+), 45 deletions(-) diff --git a/backend/src/main/java/ca/bc/gov/app/controller/client/ClientSubmissionController.java b/backend/src/main/java/ca/bc/gov/app/controller/client/ClientSubmissionController.java index a97ee8c07d..f04632d16f 100644 --- a/backend/src/main/java/ca/bc/gov/app/controller/client/ClientSubmissionController.java +++ b/backend/src/main/java/ca/bc/gov/app/controller/client/ClientSubmissionController.java @@ -55,8 +55,6 @@ public Flux listSubmissions( @RequestParam(required = false, defaultValue = "10") int size, @RequestParam(required = false) - String[] requestType, - @RequestParam(required = false) SubmissionStatusEnum[] requestStatus, @RequestParam(required = false) String[] clientType, @@ -65,23 +63,22 @@ public Flux listSubmissions( @RequestParam(required = false) String[] name, @RequestParam(required = false) - String[] updatedAt, + String[] submittedAt, ServerHttpResponse serverResponse ) { log.info( - "Listing submissions: page={}, size={}, requestType={}, requestStatus={}, clientType={}, name={}, updatedAt={}", - page, size, requestType, requestStatus, clientType, district, name, updatedAt); + "Listing submissions: page={}, size={}, requestType={}, requestStatus={}, clientType={}, name={}, submittedAt={}", + page, size, requestStatus, clientType, district, name, submittedAt); return clientService .listSubmissions( page, size, - requestType, requestStatus, clientType, district, name, - updatedAt + submittedAt ) .doOnNext(dto -> serverResponse .getHeaders() diff --git a/backend/src/main/java/ca/bc/gov/app/dto/client/ClientListSubmissionDto.java b/backend/src/main/java/ca/bc/gov/app/dto/client/ClientListSubmissionDto.java index 2d8edceeb3..f12c09fc81 100644 --- a/backend/src/main/java/ca/bc/gov/app/dto/client/ClientListSubmissionDto.java +++ b/backend/src/main/java/ca/bc/gov/app/dto/client/ClientListSubmissionDto.java @@ -6,7 +6,7 @@ public record ClientListSubmissionDto( String name, String clientType, String district, - String updated, + String submittedAt, String user, String status, Long count diff --git a/backend/src/main/java/ca/bc/gov/app/predicates/SubmissionPredicates.java b/backend/src/main/java/ca/bc/gov/app/predicates/SubmissionPredicates.java index 864bf588b6..f28d0aeb1c 100644 --- a/backend/src/main/java/ca/bc/gov/app/predicates/SubmissionPredicates.java +++ b/backend/src/main/java/ca/bc/gov/app/predicates/SubmissionPredicates.java @@ -30,8 +30,8 @@ public static Criteria orStatus(SubmissionStatusEnum[] values) { } return Criteria.empty(); } - - public static Criteria orUpdatedAt(String[] values) { + + public static Criteria orSubmittedAt(String[] values) { if (values != null) { return Stream @@ -39,11 +39,11 @@ public static Criteria orUpdatedAt(String[] values) { .filter(StringUtils::isNotBlank) .map(value -> LocalDate.parse(value,DateTimeFormatter.ISO_DATE)) .map(value -> value.plusDays(1)) - .map(value -> QueryPredicates.isBefore(value.atStartOfDay(),"updatedAt")) + .map(value -> QueryPredicates.isBefore(value.atStartOfDay(),"submittedAt")) .reduce(Criteria::or) .orElse(Criteria.empty()); } return Criteria.empty(); } - + } diff --git a/backend/src/main/java/ca/bc/gov/app/service/client/ClientSubmissionService.java b/backend/src/main/java/ca/bc/gov/app/service/client/ClientSubmissionService.java index c2f681b2da..cd80aa049b 100644 --- a/backend/src/main/java/ca/bc/gov/app/service/client/ClientSubmissionService.java +++ b/backend/src/main/java/ca/bc/gov/app/service/client/ClientSubmissionService.java @@ -17,7 +17,6 @@ import ca.bc.gov.app.dto.submissions.SubmissionContactDto; import ca.bc.gov.app.dto.submissions.SubmissionDetailsDto; import ca.bc.gov.app.entity.client.ClientTypeCodeEntity; -import ca.bc.gov.app.entity.client.DistrictCodeEntity; import ca.bc.gov.app.entity.client.SubmissionDetailEntity; import ca.bc.gov.app.entity.client.SubmissionEntity; import ca.bc.gov.app.entity.client.SubmissionLocationContactEntity; @@ -47,7 +46,6 @@ import java.util.Optional; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; -import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; @@ -81,28 +79,26 @@ public class ClientSubmissionService { public Flux listSubmissions( int page, int size, - String[] requestType, SubmissionStatusEnum[] requestStatus, String[] clientType, String[] district, String[] name, - String[] updatedAt + String[] submittedAt ) { - log.info("Searching for Page {} Size {} Type {} Status {} Client {} District {} Name {} Updated {}", + log.info("Searching for Page {} Size {} Type {} Status {} Client {} District {} Name {} submittedAt {}", page, size, - requestType, requestStatus, clientType, district, name, - updatedAt + submittedAt ); return getClientTypes() .flatMapMany(clientTypes -> - loadSubmissions(page, size, requestType, requestStatus, updatedAt) + loadSubmissions(page, size, requestStatus, submittedAt) .flatMap(submissionPair -> loadSubmissionDetail(clientType, name, submissionPair.getRight()) .flatMap(submissionDetail -> @@ -118,7 +114,7 @@ public Flux listSubmissions( ), districtFullDesc, Optional - .ofNullable(submissionPair.getRight().getUpdatedAt()) + .ofNullable(submissionPair.getRight().getSubmissionDate()) .map(date -> date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))) .orElse(StringUtils.EMPTY), StringUtils.defaultString(submissionPair.getRight().getUpdatedBy()), @@ -450,14 +446,15 @@ private Mono loadSubmissionDetail(String[] clientType, ); } - private Flux> loadSubmissions(int page, int size, - String[] requestType, - SubmissionStatusEnum[] requestStatus, String[] updatedAt) { + private Flux> loadSubmissions( + int page, + int size, + SubmissionStatusEnum[] requestStatus, + String[] submittedAt) { Criteria userQuery = SubmissionPredicates - .orUpdatedAt(updatedAt) - .and(SubmissionPredicates.orStatus(requestStatus)) - .and(QueryPredicates.orEqualTo(requestType, ApplicationConstant.SUBMISSION_TYPE)); + .orSubmittedAt(submittedAt) + .and(SubmissionPredicates.orStatus(requestStatus)); //If no user provided query found, then use the default one if (userQuery.isEmpty()) { @@ -494,7 +491,7 @@ private Flux> loadSubmissions(int page, int size, .select( query(finalUserQuery) .with(PageRequest.of(page, size)) - .sort(Sort.by("updatedAt").descending()), + .sort(Sort.by("submissionDate").descending()), SubmissionEntity.class ) .map(submission -> Pair.of(count, submission)) diff --git a/backend/src/test/java/ca/bc/gov/app/controller/client/ClientDistrictControllerIntegrationTest.java b/backend/src/test/java/ca/bc/gov/app/controller/client/ClientDistrictControllerIntegrationTest.java index 0396dc9c2d..a3ba757b9b 100644 --- a/backend/src/test/java/ca/bc/gov/app/controller/client/ClientDistrictControllerIntegrationTest.java +++ b/backend/src/test/java/ca/bc/gov/app/controller/client/ClientDistrictControllerIntegrationTest.java @@ -1,21 +1,14 @@ package ca.bc.gov.app.controller.client; -import ca.bc.gov.app.dto.client.CodeNameDto; import ca.bc.gov.app.dto.client.DistrictDto; import ca.bc.gov.app.extensions.AbstractTestContainerIntegrationTest; -import java.net.URI; import java.time.Duration; -import java.util.HashMap; import java.util.Map; -import java.util.function.Function; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.web.reactive.server.WebTestClient; -import org.springframework.web.util.UriBuilder; @DisplayName("Integrated Test | FSA Client District Controller") class ClientDistrictControllerIntegrationTest extends AbstractTestContainerIntegrationTest { diff --git a/backend/src/test/java/ca/bc/gov/app/controller/cognito/CognitoControllerIntegrationTest.java b/backend/src/test/java/ca/bc/gov/app/controller/cognito/CognitoControllerIntegrationTest.java index fab6074ae6..fd5b6cce39 100644 --- a/backend/src/test/java/ca/bc/gov/app/controller/cognito/CognitoControllerIntegrationTest.java +++ b/backend/src/test/java/ca/bc/gov/app/controller/cognito/CognitoControllerIntegrationTest.java @@ -4,7 +4,6 @@ import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; import static com.github.tomakehurst.wiremock.client.WireMock.okJson; import static com.github.tomakehurst.wiremock.client.WireMock.post; -import static com.github.tomakehurst.wiremock.client.WireMock.get; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; import ca.bc.gov.app.TestConstants; diff --git a/backend/src/test/java/ca/bc/gov/app/predicates/SubmissionPredicatesTest.java b/backend/src/test/java/ca/bc/gov/app/predicates/SubmissionPredicatesTest.java index 80e2c412d6..66912d16e9 100644 --- a/backend/src/test/java/ca/bc/gov/app/predicates/SubmissionPredicatesTest.java +++ b/backend/src/test/java/ca/bc/gov/app/predicates/SubmissionPredicatesTest.java @@ -28,13 +28,13 @@ void shouldCheckOrStatus(SubmissionStatusEnum[] values, Criteria expected) { } @ParameterizedTest - @MethodSource("orUpdatedAt") - @DisplayName("CASE 2: Should check orUpdateAt") + @MethodSource("orSubmittedAt") + @DisplayName("CASE 2: Should check orSubmittedAt") void shouldCheckOrUpdateAt(String[] values, Criteria expected) { assertTrue( areCriteriaEqual( expected, - SubmissionPredicates.orUpdatedAt(values) + SubmissionPredicates.orSubmittedAt(values) ) ); } @@ -70,7 +70,7 @@ void shouldCheckIsBefore(LocalDateTime value, Criteria expected) { assertTrue( areCriteriaEqual( expected, - QueryPredicates.isBefore(value, "updatedAt") + QueryPredicates.isBefore(value, "submittedAt") ) ); } @@ -82,7 +82,7 @@ void shouldCheckIsAfter(LocalDateTime value, Criteria expected) { assertTrue( areCriteriaEqual( expected, - QueryPredicates.isAfter(value, "updatedAt") + QueryPredicates.isAfter(value, "submittedAt") ) ); } @@ -105,7 +105,7 @@ private static Stream orStatus() { ); } - private static Stream orUpdatedAt() { + private static Stream orSubmittedAt() { return Stream.of( Arguments.of( null, Criteria.empty() @@ -118,7 +118,7 @@ private static Stream orUpdatedAt() { ), Arguments.of( new String[]{"2020-01-01"}, - Criteria.where("updatedAt") + Criteria.where("submittedAt") .lessThanOrEquals(LocalDateTime.of(2020, 1, 2, 0, 0)) ) @@ -170,7 +170,7 @@ private static Stream isAfter() { ), Arguments.of( LocalDateTime.of(2020, 1, 1, 0, 0), - Criteria.where("updatedAt") + Criteria.where("submittedAt") .greaterThanOrEquals(LocalDateTime.of(2020, 1, 1, 0, 0)) ) @@ -184,7 +184,7 @@ private static Stream isBefore() { ), Arguments.of( LocalDateTime.of(2020, 1, 1, 0, 0), - Criteria.where("updatedAt") + Criteria.where("submittedAt") .lessThanOrEquals(LocalDateTime.of(2020, 1, 1, 0, 0)) )