Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/be(FSADT1-1182): Updated submission list with required fields #789

Merged
merged 3 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ public Flux<ClientListSubmissionDto> listSubmissions(
@RequestParam(required = false, defaultValue = "10")
int size,
@RequestParam(required = false)
String[] requestType,
@RequestParam(required = false)
SubmissionStatusEnum[] requestStatus,
@RequestParam(required = false)
String[] clientType,
Expand All @@ -65,23 +63,22 @@ public Flux<ClientListSubmissionDto> 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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public record ClientListSubmissionDto(
String name,
String clientType,
String district,
String updated,
String submittedAt,
String user,
String status,
Long count
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ 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
.of(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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -81,28 +79,26 @@ public class ClientSubmissionService {
public Flux<ClientListSubmissionDto> 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 ->
Expand All @@ -118,7 +114,7 @@ public Flux<ClientListSubmissionDto> 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()),
Expand Down Expand Up @@ -450,14 +446,15 @@ private Mono<SubmissionDetailEntity> loadSubmissionDetail(String[] clientType,
);
}

private Flux<Pair<Long, SubmissionEntity>> loadSubmissions(int page, int size,
String[] requestType,
SubmissionStatusEnum[] requestStatus, String[] updatedAt) {
private Flux<Pair<Long, SubmissionEntity>> 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()) {
Expand Down Expand Up @@ -494,7 +491,7 @@ private Flux<Pair<Long, SubmissionEntity>> 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))
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
);
}
Expand Down Expand Up @@ -70,7 +70,7 @@ void shouldCheckIsBefore(LocalDateTime value, Criteria expected) {
assertTrue(
areCriteriaEqual(
expected,
QueryPredicates.isBefore(value, "updatedAt")
QueryPredicates.isBefore(value, "submittedAt")
)
);
}
Expand All @@ -82,7 +82,7 @@ void shouldCheckIsAfter(LocalDateTime value, Criteria expected) {
assertTrue(
areCriteriaEqual(
expected,
QueryPredicates.isAfter(value, "updatedAt")
QueryPredicates.isAfter(value, "submittedAt")
)
);
}
Expand All @@ -105,7 +105,7 @@ private static Stream<Arguments> orStatus() {
);
}

private static Stream<Arguments> orUpdatedAt() {
private static Stream<Arguments> orSubmittedAt() {
return Stream.of(
Arguments.of(
null, Criteria.empty()
Expand All @@ -118,7 +118,7 @@ private static Stream<Arguments> orUpdatedAt() {
),
Arguments.of(
new String[]{"2020-01-01"},
Criteria.where("updatedAt")
Criteria.where("submittedAt")
.lessThanOrEquals(LocalDateTime.of(2020, 1, 2, 0, 0))
)

Expand Down Expand Up @@ -170,7 +170,7 @@ private static Stream<Arguments> isAfter() {
),
Arguments.of(
LocalDateTime.of(2020, 1, 1, 0, 0),
Criteria.where("updatedAt")
Criteria.where("submittedAt")
.greaterThanOrEquals(LocalDateTime.of(2020, 1, 1, 0, 0))
)

Expand All @@ -184,7 +184,7 @@ private static Stream<Arguments> isBefore() {
),
Arguments.of(
LocalDateTime.of(2020, 1, 1, 0, 0),
Criteria.where("updatedAt")
Criteria.where("submittedAt")
.lessThanOrEquals(LocalDateTime.of(2020, 1, 1, 0, 0))
)

Expand Down
Loading