use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.
the class PreCheckExistenceValidationHookTest method verifyEventValidationSuccessWhenEventIsNotPresent.
@Test
void verifyEventValidationSuccessWhenEventIsNotPresent() {
// given
Event event = Event.builder().event(NOT_PRESENT_EVENT_UID).build();
// when
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
validationHook.validateEvent(reporter, event);
// then
assertFalse(reporter.hasErrors());
}
use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.
the class PreCheckUidValidationHookTest method verifyEventValidationSuccess.
@Test
void verifyEventValidationSuccess() {
// given
Note note = Note.builder().note(CodeGenerator.generateUid()).build();
Event event = Event.builder().event(CodeGenerator.generateUid()).notes(Lists.newArrayList(note)).build();
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
validationHook.validateEvent(reporter, event);
// then
assertFalse(reporter.hasErrors());
}
use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.
the class PreCheckUidValidationHookTest method verifyEventWithNoteWithInvalidUidFails.
@Test
void verifyEventWithNoteWithInvalidUidFails() {
// given
Note note = Note.builder().note(INVALID_UID).build();
Event event = Event.builder().event(CodeGenerator.generateUid()).notes(Lists.newArrayList(note)).build();
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
validationHook.validateEvent(reporter, event);
// then
hasTrackerError(reporter, E1048, EVENT, event.getUid());
}
use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.
the class TrackerImportController method asyncPostCsvTracker.
@PostMapping(value = "", consumes = { "application/csv", "text/csv" }, produces = APPLICATION_JSON_VALUE)
@ResponseBody
public WebMessage asyncPostCsvTracker(HttpServletRequest request, @CurrentUser User currentUser, @RequestParam(required = false, defaultValue = "true") boolean skipFirst) throws IOException, ParseException {
String jobId = CodeGenerator.generateUid();
InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
List<Event> events = csvEventService.readEvents(inputStream, skipFirst);
TrackerBundleParams trackerBundleParams = new TrackerBundleParams();
trackerBundleParams.setEvents(events);
TrackerImportReportRequest trackerImportReportRequest = TrackerImportReportRequest.builder().trackerBundleParams(trackerBundleParams).contextService(contextService).userUid(currentUser.getUid()).isAsync(true).uid(jobId).authentication(SecurityContextHolder.getContext().getAuthentication()).build();
trackerImportStrategy.importReport(trackerImportReportRequest);
String location = ContextUtils.getRootPath(request) + "/tracker/jobs/" + jobId;
return ok(TRACKER_JOB_ADDED).setLocation("/tracker/jobs/" + jobId).setResponse(TrackerJobWebMessageResponse.builder().id(jobId).location(location).build());
}
use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.
the class DefaultTrackerObjectsDeletionService method deleteEvents.
@Override
public TrackerTypeReport deleteEvents(TrackerBundle bundle) {
TrackerTypeReport typeReport = new TrackerTypeReport(TrackerType.EVENT);
List<Event> events = bundle.getEvents();
for (int idx = 0; idx < events.size(); idx++) {
String uid = events.get(idx).getEvent();
TrackerObjectReport objectReport = new TrackerObjectReport(TrackerType.EVENT, uid, idx);
ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance(uid);
ProgramInstance programInstance = programStageInstance.getProgramInstance();
programStageInstanceService.deleteProgramStageInstance(programStageInstance);
if (programStageInstance.getProgramStage().getProgram().isRegistration()) {
teiService.updateTrackedEntityInstance(programStageInstance.getProgramInstance().getEntityInstance());
programInstance.getProgramStageInstances().remove(programStageInstance);
programInstanceService.updateProgramInstance(programInstance);
}
typeReport.getStats().incDeleted();
typeReport.addObjectReport(objectReport);
}
return typeReport;
}
Aggregations