Search in sources :

Example 31 with Interpretation

use of org.hisp.dhis.interpretation.Interpretation in project dhis2-core by dhis2.

the class InterpretationController method updateComment.

@PutMapping("/{uid}/comments/{cuid}")
@ResponseStatus(HttpStatus.NO_CONTENT)
@ResponseBody
public WebMessage updateComment(@PathVariable("uid") String uid, @PathVariable("cuid") String cuid, @RequestBody String content) {
    Interpretation interpretation = interpretationService.getInterpretation(uid);
    if (interpretation == null) {
        return conflict("Interpretation does not exist: " + uid);
    }
    for (InterpretationComment comment : interpretation.getComments()) {
        if (comment.getUid().equals(cuid)) {
            if (!currentUserService.getCurrentUser().equals(comment.getCreatedBy()) && !currentUserService.currentUserIsSuper()) {
                throw new AccessDeniedException("You are not allowed to update this comment.");
            }
            comment.setText(content);
            interpretationService.updateComment(interpretation, comment);
        }
    }
    return null;
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) InterpretationComment(org.hisp.dhis.interpretation.InterpretationComment) Interpretation(org.hisp.dhis.interpretation.Interpretation) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PutMapping(org.springframework.web.bind.annotation.PutMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 32 with Interpretation

use of org.hisp.dhis.interpretation.Interpretation in project dhis2-core by dhis2.

the class InterpretationController method deleteObject.

@Override
@ResponseStatus(HttpStatus.NO_CONTENT)
public WebMessage deleteObject(@PathVariable String uid, @CurrentUser User currentUser, HttpServletRequest request, HttpServletResponse response) {
    Interpretation interpretation = interpretationService.getInterpretation(uid);
    if (interpretation == null) {
        return notFound("Interpretation does not exist: " + uid);
    }
    if (!currentUserService.getCurrentUser().equals(interpretation.getCreatedBy()) && !currentUserService.currentUserIsSuper()) {
        throw new AccessDeniedException("You are not allowed to delete this interpretation.");
    }
    interpretationService.deleteInterpretation(interpretation);
    return null;
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) Interpretation(org.hisp.dhis.interpretation.Interpretation) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Example 33 with Interpretation

use of org.hisp.dhis.interpretation.Interpretation in project dhis2-core by dhis2.

the class InterpretationController method writeEventReportInterpretation.

@PostMapping(value = "/eventReport/{uid}", consumes = { "text/html", "text/plain" })
@ResponseBody
@Deprecated
public WebMessage writeEventReportInterpretation(@PathVariable("uid") String uid, @RequestParam(value = "ou", required = false) String orgUnitUid, @CurrentUser User currentUser, @RequestBody String text) throws WebMessageException {
    EventReport eventReport = idObjectManager.get(EventReport.class, uid);
    if (eventReport == null) {
        return conflict("Event report does not exist or is not accessible: " + uid);
    }
    final EventVisualization eventVisualization = idObjectManager.get(EventVisualization.class, eventReport.getUid());
    OrganisationUnit orgUnit = getUserOrganisationUnit(orgUnitUid, eventReport, currentUser);
    return createInterpretation(new Interpretation(eventVisualization, eventReport, orgUnit, text));
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Interpretation(org.hisp.dhis.interpretation.Interpretation) EventReport(org.hisp.dhis.eventreport.EventReport) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

Interpretation (org.hisp.dhis.interpretation.Interpretation)33 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)12 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)11 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)9 AccessDeniedException (org.springframework.security.access.AccessDeniedException)7 InterpretationComment (org.hisp.dhis.interpretation.InterpretationComment)6 PostMapping (org.springframework.web.bind.annotation.PostMapping)6 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)6 User (org.hisp.dhis.user.User)5 EventChart (org.hisp.dhis.eventchart.EventChart)4 EventVisualization (org.hisp.dhis.eventvisualization.EventVisualization)4 EventReport (org.hisp.dhis.eventreport.EventReport)3 Period (org.hisp.dhis.period.Period)3 ArrayList (java.util.ArrayList)2 Chart (org.hisp.dhis.chart.Chart)2 DataSet (org.hisp.dhis.dataset.DataSet)2 Visualization (org.hisp.dhis.visualization.Visualization)2 NotAuthenticatedException (org.hisp.dhis.webapi.controller.exception.NotAuthenticatedException)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2