use of org.springframework.security.access.prepost.PreAuthorize in project dhis2-core by dhis2.
the class SynchronizationController method importMetaData.
@PreAuthorize("hasRole('ALL')")
@RequestMapping(value = "/metadataPull", method = RequestMethod.POST)
public void importMetaData(@RequestBody String url, HttpServletResponse response) throws IOException {
ImportReport importReport = synchronizationManager.executeMetadataPull(url);
response.setContentType(CONTENT_TYPE_JSON);
renderService.toJson(response.getOutputStream(), importReport);
}
use of org.springframework.security.access.prepost.PreAuthorize in project dhis2-core by dhis2.
the class SynchronizationController method execute.
@PreAuthorize("hasRole('ALL') or hasRole('F_EXPORT_DATA')")
@RequestMapping(value = "/dataPush", method = RequestMethod.POST)
public void execute(HttpServletResponse response) throws IOException {
ImportSummary summary = synchronizationManager.executeDataPush();
response.setContentType(CONTENT_TYPE_JSON);
renderService.toJson(response.getOutputStream(), summary);
}
use of org.springframework.security.access.prepost.PreAuthorize in project dhis2-core by dhis2.
the class EventController method getEvent.
@RequestMapping(value = "/{uid}", method = RequestMethod.GET)
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD') or hasRole('F_TRACKED_ENTITY_DATAVALUE_READ')")
@ResponseBody
public Event getEvent(@PathVariable("uid") String uid, @RequestParam Map<String, String> parameters, Model model, HttpServletRequest request) throws Exception {
Event event = eventService.getEvent(uid);
if (event == null) {
throw new WebMessageException(WebMessageUtils.notFound("Event not found for ID " + uid));
}
event.setHref(ContextUtils.getRootPath(request) + RESOURCE_PATH + "/" + uid);
return event;
}
use of org.springframework.security.access.prepost.PreAuthorize in project dhis2-core by dhis2.
the class EventController method putJsonEventForEventDate.
@RequestMapping(value = "/{uid}/eventDate", method = RequestMethod.PUT, consumes = "application/json")
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD')")
public void putJsonEventForEventDate(HttpServletResponse response, HttpServletRequest request, @PathVariable("uid") String uid, 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 updatedEvent = renderService.fromJson(inputStream, Event.class);
updatedEvent.setEvent(uid);
eventService.updateEventForEventDate(updatedEvent);
webMessageService.send(WebMessageUtils.ok("Event updated " + uid), response, request);
}
use of org.springframework.security.access.prepost.PreAuthorize in project dhis2-core by dhis2.
the class EventController method postJsonEvent.
@RequestMapping(method = RequestMethod.POST, consumes = "application/json")
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD')")
public void postJsonEvent(@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.addEventsJson(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.getEventsJson(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);
}
}
Aggregations