use of org.hisp.dhis.tracker.report.TrackerWarningReport in project dhis2-core by dhis2.
the class ProgramRuleIntegrationTest method testImportEventInProgramStageSuccessWithWarningRaised.
@Test
void testImportEventInProgramStageSuccessWithWarningRaised() throws IOException {
InputStream inputStream = new ClassPathResource("tracker/tei_enrollment_event.json").getInputStream();
TrackerImportParams params = renderService.fromJson(inputStream, TrackerImportParams.class);
params.setUserId(userA.getUid());
TrackerImportReport trackerImportReport = trackerImportService.importTracker(params);
assertNotNull(trackerImportReport);
assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
List<TrackerWarningReport> warningReports = trackerImportReport.getValidationReport().getWarnings();
assertEquals(4, warningReports.size());
assertEquals(3, warningReports.stream().filter(w -> w.getTrackerType().equals(TrackerType.EVENT)).count());
assertEquals(1, warningReports.stream().filter(w -> w.getTrackerType().equals(TrackerType.ENROLLMENT)).count());
inputStream = new ClassPathResource("tracker/event_update_no_datavalue.json").getInputStream();
params = renderService.fromJson(inputStream, TrackerImportParams.class);
params.setUserId(userA.getUid());
params.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE);
trackerImportReport = trackerImportService.importTracker(params);
assertNotNull(trackerImportReport);
assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
warningReports = trackerImportReport.getValidationReport().getWarnings();
assertEquals(3, warningReports.size());
assertEquals(TrackerErrorCode.E1308, warningReports.get(0).getWarningCode());
assertEquals("Generated by program rule (`ProgramRule`) - DataElement `DATAEL00001` is being replaced in event `EVENT123456`", warningReports.get(0).getWarningMessage());
inputStream = new ClassPathResource("tracker/event_update_datavalue.json").getInputStream();
params = renderService.fromJson(inputStream, TrackerImportParams.class);
params.setUserId(userA.getUid());
params.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE);
trackerImportReport = trackerImportService.importTracker(params);
assertNotNull(trackerImportReport);
assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
warningReports = trackerImportReport.getValidationReport().getWarnings();
assertEquals(3, warningReports.size());
assertEquals(TrackerErrorCode.E1308, warningReports.get(0).getWarningCode());
assertEquals("Generated by program rule (`ProgramRule`) - DataElement `DATAEL00001` is being replaced in event `EVENT123456`", warningReports.get(0).getWarningMessage());
}
use of org.hisp.dhis.tracker.report.TrackerWarningReport in project dhis2-core by dhis2.
the class ValidationUtils method validateNotes.
protected static List<Note> validateNotes(ValidationErrorReporter reporter, TrackerDto dto, List<Note> notesToCheck) {
TrackerImportValidationContext context = reporter.getValidationContext();
final List<Note> notes = new ArrayList<>();
for (Note note : notesToCheck) {
if (// Ignore notes with no text
isNotEmpty(note.getValue())) {
// warning, ignore the note and continue
if (isNotEmpty(note.getNote()) && context.getNote(note.getNote()).isPresent()) {
TrackerWarningReport warning = TrackerWarningReport.builder().uid(dto.getUid()).trackerType(dto.getTrackerType()).warningCode(TrackerErrorCode.E1119).addArg(note.getNote()).build(reporter.getValidationContext().getBundle());
reporter.addWarning(warning);
} else {
notes.add(note);
}
}
}
return notes;
}
use of org.hisp.dhis.tracker.report.TrackerWarningReport in project dhis2-core by dhis2.
the class ValidationUtils method addIssuesToReporter.
public static void addIssuesToReporter(ValidationErrorReporter reporter, TrackerDto dto, List<ProgramRuleIssue> programRuleIssues) {
programRuleIssues.stream().filter(issue -> issue.getIssueType().equals(ERROR)).forEach(issue -> {
List<String> args = Lists.newArrayList(issue.getRuleUid());
args.addAll(issue.getArgs());
TrackerErrorReport error = TrackerErrorReport.builder().uid(dto.getUid()).trackerType(dto.getTrackerType()).errorCode(issue.getIssueCode()).addArgs(args.toArray()).build(reporter.getValidationContext().getBundle());
reporter.addError(error);
});
programRuleIssues.stream().filter(issue -> issue.getIssueType().equals(WARNING)).forEach(issue -> {
List<String> args = Lists.newArrayList(issue.getRuleUid());
args.addAll(issue.getArgs());
TrackerWarningReport warning = TrackerWarningReport.builder().uid(dto.getUid()).trackerType(dto.getTrackerType()).warningCode(issue.getIssueCode()).addArgs(args.toArray()).build(reporter.getValidationContext().getBundle());
reporter.addWarning(warning);
});
}
Aggregations