Skip to content

Commit

Permalink
fix: Event import using CSV cannot have empty "Due Date"Column [DHIS2…
Browse files Browse the repository at this point in the history
…-12352] [2.40] (#16182)

* fix: due date not mandatory

* fix: import

* fix: test name

* fix: psi
  • Loading branch information
lucaCambi77 authored Jan 16, 2024
1 parent 5d05bf9 commit d75fbe7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.hisp.dhis.dxf2.common.ImportOptions;
import org.hisp.dhis.dxf2.events.importer.Checker;
import org.hisp.dhis.dxf2.events.importer.context.WorkContext;
Expand Down Expand Up @@ -75,7 +76,10 @@ private List<String> validate(ImmutableEvent event, WorkContext ctx) {
}

private void validateDates(ImmutableEvent event, List<String> errors) {
if (event.getDueDate() != null && !dateIsValid(event.getDueDate())) {
if (!StringUtils.isEmpty(
event.getDueDate()) // The due date is not mandatory and can be an empty string in the
// CSV import.
&& !dateIsValid(event.getDueDate())) {
errors.add("Invalid event due date: " + event.getDueDate());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,24 @@ void verifyErrorOnInvalidDueDate() {
assertHasConflict(importSummary, event, "Invalid event due date: " + event.getDueDate());
}

@Test
void shouldReportNoErrorsWhenDueDateIsEmpty() {
when(workContext.getProgramInstanceMap())
.thenReturn(Map.of(event.getUid(), new ProgramInstance()));
event.setDueDate("");
ImportSummary importSummary = rule.check(new ImmutableEvent(event), workContext);
assertNoError(importSummary);
}

@Test
void shouldReportNoErrorsWhenDueDateIsNull() {
when(workContext.getProgramInstanceMap())
.thenReturn(Map.of(event.getUid(), new ProgramInstance()));
event.setDueDate(null);
ImportSummary importSummary = rule.check(new ImmutableEvent(event), workContext);
assertNoError(importSummary);
}

@Test
void verifyErrorOnInvalidEventDate() {
event.setEvent(event.getUid());
Expand Down

0 comments on commit d75fbe7

Please sign in to comment.