Skip to content

Commit

Permalink
fix: add predicate to EndDateFrom case if endDate is null
Browse files Browse the repository at this point in the history
  • Loading branch information
jsteenke committed Jul 23, 2024
1 parent 28afbad commit 2b3c117
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public PageResult<Announcement> loadAnnouncementByCriteria(AnnouncementSearchCri
predicates.add(cb.equal(root.get(Announcement_.WORKSPACE_NAME), criteria.getWorkspaceName()));
}
if (criteria.getStartDateFrom() != null) {

predicates.add(cb.greaterThanOrEqualTo(root.get(Announcement_.START_DATE),
criteria.getStartDateFrom().toLocalDateTime()));
}
Expand All @@ -64,8 +65,15 @@ public PageResult<Announcement> loadAnnouncementByCriteria(AnnouncementSearchCri
criteria.getStartDateTo().toLocalDateTime()));
}
if (criteria.getEndDateFrom() != null) {
predicates.add(cb.greaterThanOrEqualTo(root.get(Announcement_.END_DATE),
criteria.getEndDateFrom().toLocalDateTime()));

Predicate endDatePredicate = cb.greaterThanOrEqualTo(root.get(Announcement_.END_DATE),
criteria.getEndDateFrom().toLocalDateTime());
// Also include cases where END_DATE is null
Predicate endDateIsNullPredicate = cb.isNull(root.get(Announcement_.END_DATE));

// Combine the predicates using OR
predicates.add(cb.or(endDatePredicate, endDateIsNullPredicate));

}
if (criteria.getEndDateTo() != null) {
predicates.add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,34 @@ void getAnnouncementsByCriteriaAllTest() {
.as(AnnouncementPageResultDTO.class);

Assertions.assertThat(data).isNotNull();
Assertions.assertThat(data.getTotalElements()).isEqualTo(5);
Assertions.assertThat(data.getStream()).isNotNull().hasSize(5);
Assertions.assertThat(data.getTotalElements()).isEqualTo(6);
Assertions.assertThat(data.getStream()).isNotNull().hasSize(6);
}

@Test
void getActiveAnnouncementsByCriteriaAllTest() {
AnnouncementSearchCriteriaDTO criteria = new AnnouncementSearchCriteriaDTO();

criteria.status(AnnouncementStatusDTO.ACTIVE);
criteria.workspaceName("workspace6");
criteria.setStartDateTo(OffsetDateTime.parse("2023-03-10T12:15:50-04:00"));
criteria.setEndDateFrom(OffsetDateTime.parse("2023-03-10T12:15:50-04:00"));

var data = given()
.auth().oauth2(getKeycloakClientToken("testClient"))
.contentType(APPLICATION_JSON)
.body(criteria)
.post("search")
.then()
.statusCode(OK.getStatusCode())
.contentType(APPLICATION_JSON)
.extract()
.as(AnnouncementPageResultDTO.class);

Assertions.assertThat(data).isNotNull();
Assertions.assertThat(data.getTotalElements()).isEqualTo(1);
Assertions.assertThat(data.getStream()).isNotNull().hasSize(1);
Assertions.assertThat(data.getStream().get(0).getWorkspaceName()).isEqualTo("workspace6");
}

@Test
Expand Down
3 changes: 3 additions & 0 deletions src/test/resources/data/test-internal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
<ANNOUNCEMENT guid="a5" optlock="0" enddate="2022-02-05 06:01:00" startdate="2009-12-30 14:55:00" status="ACTIVE"
product_name="product2" content="some-content" priority="NORMAL" title="title5" type="INFO" tenant_id="default" workspaceName="workspace2"/>

<ANNOUNCEMENT guid="a6" optlock="0" startdate="2009-12-30 14:55:00" status="ACTIVE"
product_name="product2" content="some-content" priority="NORMAL" title="title6" type="INFO" tenant_id="default" workspaceName="workspace6"/>

<ANNOUNCEMENT guid="a3-100" optlock="0" enddate="2022-02-05 06:01:00" startdate="2009-12-30 14:55:00" status="ACTIVE"
product_name="product2" content="some-content" priority="NORMAL" title="title2" type="EVENT" tenant_id="tenant-100" workspaceName="workspace2"/>
<ANNOUNCEMENT guid="a4-100" optlock="0" enddate="2022-02-05 06:01:00" startdate="2009-12-30 14:55:00" status="INACTIVE"
Expand Down

0 comments on commit 2b3c117

Please sign in to comment.