Search in sources :

Example 81 with PreAuthorize

use of org.springframework.security.access.prepost.PreAuthorize in project dhis2-core by dhis2.

the class TrackedEntityInstanceController method getTrackedEntityInstanceById.

@RequestMapping(value = "/{id}", method = RequestMethod.GET)
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_INSTANCE_SEARCH')")
@ResponseBody
public RootNode getTrackedEntityInstanceById(@PathVariable("id") String pvId) throws NotFoundException {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    if (fields.isEmpty()) {
        fields.add(":all");
    }
    CollectionNode collectionNode = fieldFilterService.filter(TrackedEntityInstance.class, Lists.newArrayList(getTrackedEntityInstance(pvId, fields)), fields);
    RootNode rootNode = new RootNode(collectionNode.getChildren().get(0));
    rootNode.setDefaultNamespace(DxfNamespaces.DXF_2_0);
    rootNode.setNamespace(DxfNamespaces.DXF_2_0);
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) CollectionNode(org.hisp.dhis.node.types.CollectionNode) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 82 with PreAuthorize

use of org.springframework.security.access.prepost.PreAuthorize in project dhis2-core by dhis2.

the class EnrollmentController method updateEnrollmentJson.

@RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasRole('ALL') or hasRole('F_PROGRAM_ENROLLMENT')")
public void updateEnrollmentJson(@PathVariable String id, ImportOptions importOptions, HttpServletRequest request, HttpServletResponse response) throws IOException {
    InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
    ImportSummary importSummary = enrollmentService.updateEnrollmentJson(id, inputStream, importOptions);
    importSummary.setImportOptions(importOptions);
    webMessageService.send(WebMessageUtils.importSummary(importSummary), response, request);
}
Also used : InputStream(java.io.InputStream) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 83 with PreAuthorize

use of org.springframework.security.access.prepost.PreAuthorize in project dhis2-core by dhis2.

the class EnrollmentController method updateEnrollmentXml.

@RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_XML_VALUE, produces = MediaType.APPLICATION_XML_VALUE)
@PreAuthorize("hasRole('ALL') or hasRole('F_PROGRAM_ENROLLMENT')")
public void updateEnrollmentXml(@PathVariable String id, ImportOptions importOptions, HttpServletRequest request, HttpServletResponse response) throws IOException {
    InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
    ImportSummary importSummary = enrollmentService.updateEnrollmentXml(id, inputStream, importOptions);
    importSummary.setImportOptions(importOptions);
    webMessageService.send(WebMessageUtils.importSummary(importSummary), response, request);
}
Also used : InputStream(java.io.InputStream) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 84 with PreAuthorize

use of org.springframework.security.access.prepost.PreAuthorize in project dhis2-core by dhis2.

the class EnrollmentController method deleteEnrollment.

// -------------------------------------------------------------------------
// DELETE
// -------------------------------------------------------------------------
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
@PreAuthorize("hasRole('ALL') or hasRole('F_PROGRAM_UNENROLLMENT')")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void deleteEnrollment(@PathVariable String id, HttpServletRequest request, HttpServletResponse response) throws WebMessageException {
    if (!programInstanceService.programInstanceExists(id)) {
        throw new WebMessageException(WebMessageUtils.notFound("Enrollment not found for ID " + id));
    }
    response.setStatus(HttpServletResponse.SC_OK);
    ImportSummary importSummary = enrollmentService.deleteEnrollment(id);
    webMessageService.send(WebMessageUtils.importSummary(importSummary), response, request);
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 85 with PreAuthorize

use of org.springframework.security.access.prepost.PreAuthorize in project dhis2-core by dhis2.

the class EventController method postCsvEvents.

@RequestMapping(method = RequestMethod.POST, consumes = { "application/csv", "text/csv" })
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD')")
public void postCsvEvents(@RequestParam(required = false, defaultValue = "false") boolean skipFirst, HttpServletResponse response, HttpServletRequest request, ImportOptions importOptions) throws IOException {
    InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
    Events events = csvEventService.readEvents(inputStream, skipFirst);
    if (!importOptions.isAsync()) {
        ImportSummaries importSummaries = eventService.addEvents(events.getEvents(), importOptions, null);
        importSummaries.setImportOptions(importOptions);
        webMessageService.send(WebMessageUtils.importSummaries(importSummaries), response, request);
    } else {
        TaskId taskId = new TaskId(TaskCategory.EVENT_IMPORT, currentUserService.getCurrentUser());
        scheduler.executeTask(new ImportEventsTask(events.getEvents(), eventService, importOptions, taskId));
        response.setHeader("Location", ContextUtils.getRootPath(request) + "/system/tasks/" + TaskCategory.EVENT_IMPORT);
        response.setStatus(HttpServletResponse.SC_NO_CONTENT);
    }
}
Also used : ImportEventsTask(org.hisp.dhis.dxf2.events.event.ImportEventsTask) TaskId(org.hisp.dhis.scheduling.TaskId) Events(org.hisp.dhis.dxf2.events.event.Events) InputStream(java.io.InputStream) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)289 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)234 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)88 ApiOperation (io.swagger.annotations.ApiOperation)70 ModelAndView (org.springframework.web.servlet.ModelAndView)51 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)44 ResponseEntity (org.springframework.http.ResponseEntity)41 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)40 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)36 IOException (java.io.IOException)35 ServiceException (org.nhindirect.common.rest.exceptions.ServiceException)34 InputStream (java.io.InputStream)26 Date (java.util.Date)26 ArrayList (java.util.ArrayList)25 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)23 ConfigurationServiceException (org.nhindirect.config.service.ConfigurationServiceException)21 List (java.util.List)17 HttpHeaders (org.springframework.http.HttpHeaders)16 Grid (org.hisp.dhis.common.Grid)14 SearchDomainForm (org.nhindirect.config.ui.form.SearchDomainForm)14