use of org.hisp.dhis.dxf2.events.event.Event in project dhis2-core by dhis2.
the class RegistrationSingleEventServiceTest method testSaveWithEnrollmentShouldNotFail.
@Test
public void testSaveWithEnrollmentShouldNotFail() {
Enrollment enrollment = createEnrollment(programA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance());
ImportSummary importSummary = enrollmentService.addEnrollment(enrollment, null);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
Event event = createEvent(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance());
importSummary = eventService.addEvent(event, null);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
}
use of org.hisp.dhis.dxf2.events.event.Event in project dhis2-core by dhis2.
the class ImportEventAction method execute.
// -------------------------------------------------------------------------
// Action Implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
TaskId taskId = new TaskId(TaskCategory.EVENT_IMPORT, currentUserService.getCurrentUser());
notifier.clear(taskId);
InputStream in = new FileInputStream(upload);
in = StreamUtils.wrapAndCheckCompressionFormat(in);
ImportOptions importOptions = new ImportOptions().setDryRun(dryRun).setOrgUnitIdScheme(orgUnitIdScheme.toString()).setEventIdScheme(eventIdScheme.toString()).setFilename(uploadFileName);
if (FORMAT_CSV.equals(payloadFormat)) {
Events events = csvEventService.readEvents(in, skipFirst);
scheduler.executeTask(new ImportEventsTask(events.getEvents(), eventService, importOptions, taskId));
} else {
List<Event> events;
if (FORMAT_JSON.equals(payloadFormat)) {
events = eventService.getEventsJson(in);
} else {
events = eventService.getEventsXml(in);
}
scheduler.executeTask(new ImportEventTask(events, eventService, importOptions, taskId));
}
return SUCCESS;
}
use of org.hisp.dhis.dxf2.events.event.Event in project dhis2-core by dhis2.
the class EventController method postXmlEvent.
// -------------------------------------------------------------------------
// CREATE
// -------------------------------------------------------------------------
@RequestMapping(method = RequestMethod.POST, consumes = "application/xml")
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD')")
public void postXmlEvent(@RequestParam(defaultValue = "CREATE") ImportStrategy strategy, HttpServletResponse response, HttpServletRequest request, ImportOptions importOptions) throws Exception {
importOptions.setImportStrategy(strategy);
InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
importOptions.setIdSchemes(getIdSchemesFromParameters(importOptions.getIdSchemes(), contextService.getParameterValuesMap()));
if (!importOptions.isAsync()) {
ImportSummaries importSummaries = eventService.addEventsXml(inputStream, importOptions);
importSummaries.setImportOptions(importOptions);
importSummaries.getImportSummaries().stream().filter(importSummary -> !importOptions.isDryRun() && !importSummary.getStatus().equals(ImportStatus.ERROR) && !importOptions.getImportStrategy().isDelete()).forEach(importSummary -> importSummary.setHref(ContextUtils.getRootPath(request) + RESOURCE_PATH + "/" + importSummary.getReference()));
if (importSummaries.getImportSummaries().size() == 1) {
ImportSummary importSummary = importSummaries.getImportSummaries().get(0);
importSummary.setImportOptions(importOptions);
if (!importOptions.isDryRun()) {
if (!importSummary.getStatus().equals(ImportStatus.ERROR)) {
response.setHeader("Location", ContextUtils.getRootPath(request) + RESOURCE_PATH + "/" + importSummary.getReference());
}
}
}
webMessageService.send(WebMessageUtils.importSummaries(importSummaries), response, request);
} else {
TaskId taskId = new TaskId(TaskCategory.EVENT_IMPORT, currentUserService.getCurrentUser());
List<Event> events = eventService.getEventsXml(inputStream);
scheduler.executeTask(new ImportEventTask(events, eventService, importOptions, taskId));
response.setHeader("Location", ContextUtils.getRootPath(request) + "/system/tasks/" + TaskCategory.EVENT_IMPORT);
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
}
}
use of org.hisp.dhis.dxf2.events.event.Event in project dhis2-core by dhis2.
the class EventController method getEventsGrid.
// -------------------------------------------------------------------------
// READ
// -------------------------------------------------------------------------
@RequestMapping(value = "/query", method = RequestMethod.GET, produces = { ContextUtils.CONTENT_TYPE_JSON, ContextUtils.CONTENT_TYPE_JAVASCRIPT })
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD') or hasRole('F_TRACKED_ENTITY_DATAVALUE_READ')")
@ResponseBody
public Grid getEventsGrid(@RequestParam(required = false) String program, @RequestParam(required = false) String programStage, @RequestParam(required = false) ProgramStatus programStatus, @RequestParam(required = false) Boolean followUp, @RequestParam(required = false) String trackedEntityInstance, @RequestParam(required = false) String orgUnit, @RequestParam(required = false) OrganisationUnitSelectionMode ouMode, @RequestParam(required = false) Date startDate, @RequestParam(required = false) Date endDate, @RequestParam(required = false) Date dueDateStart, @RequestParam(required = false) Date dueDateEnd, @RequestParam(required = false) Date lastUpdated, @RequestParam(required = false) Date lastUpdatedStartDate, @RequestParam(required = false) Date lastUpdatedEndDate, @RequestParam(required = false) EventStatus status, @RequestParam(required = false) String attributeCc, @RequestParam(required = false) String attributeCos, @RequestParam(required = false) boolean skipMeta, @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer pageSize, @RequestParam(required = false) boolean totalPages, @RequestParam(required = false) boolean skipPaging, @RequestParam(required = false) String order, @RequestParam(required = false) String attachment, @RequestParam(required = false, defaultValue = "false") boolean includeDeleted, @RequestParam(required = false) String event, @RequestParam(required = false) Set<String> filter, @RequestParam(required = false) Set<String> dataElement, @RequestParam Map<String, String> parameters, IdSchemes idSchemes, Model model, HttpServletResponse response, HttpServletRequest request) throws WebMessageException {
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
if (fields.isEmpty()) {
fields.addAll(Preset.ALL.getFields());
}
boolean allowNoAttrOptionCombo = trackedEntityInstance != null && entityInstanceService.getTrackedEntityInstance(trackedEntityInstance) != null;
DataElementCategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(attributeCc, attributeCos, allowNoAttrOptionCombo);
if (attributeOptionCombo == null && !allowNoAttrOptionCombo) {
throw new WebMessageException(WebMessageUtils.conflict("Illegal attribute option combo identifier: " + attributeCc + " " + attributeCos));
}
Set<String> eventIds = TextUtils.splitToArray(event, TextUtils.SEMICOLON);
lastUpdatedStartDate = lastUpdatedStartDate != null ? lastUpdatedStartDate : lastUpdated;
EventSearchParams params = eventService.getFromUrl(program, programStage, programStatus, followUp, orgUnit, ouMode, trackedEntityInstance, startDate, endDate, dueDateStart, dueDateEnd, lastUpdatedStartDate, lastUpdatedEndDate, status, attributeOptionCombo, idSchemes, page, pageSize, totalPages, skipPaging, null, getGridOrderParams(order), false, eventIds, filter, dataElement, includeDeleted);
contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_JSON, CacheStrategy.NO_CACHE);
return eventService.getEventsGrid(params);
}
use of org.hisp.dhis.dxf2.events.event.Event in project dhis2-core by dhis2.
the class EventController method postJsonEventForNote.
@RequestMapping(value = "/{uid}/note", method = RequestMethod.POST, consumes = "application/json")
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD')")
public void postJsonEventForNote(@PathVariable("uid") String uid, HttpServletResponse response, HttpServletRequest request, ImportOptions importOptions) throws IOException, WebMessageException {
if (!programStageInstanceService.programStageInstanceExists(uid)) {
throw new WebMessageException(WebMessageUtils.notFound("Event not found for ID " + uid));
}
InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
Event event = renderService.fromJson(inputStream, Event.class);
event.setEvent(uid);
eventService.updateEventForNote(event);
webMessageService.send(WebMessageUtils.ok("Event updated: " + uid), response, request);
}
Aggregations