Search in sources :

Example 11 with Interpretation

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

the class PostInterpretation method execute.

// -------------------------------------------------------------------------
// Action Implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    Chart c = chartService.getChart(id);
    Interpretation i = new Interpretation(c, null, interpretation);
    i.setUser(currentUserService.getCurrentUser());
    interpretationService.saveInterpretation(i);
    return SUCCESS;
}
Also used : Interpretation(org.hisp.dhis.interpretation.Interpretation) Chart(org.hisp.dhis.chart.Chart)

Example 12 with Interpretation

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

the class InterpretationController method writeChartInterpretation.

@RequestMapping(value = "/chart/{uid}", method = RequestMethod.POST, consumes = { "text/html", "text/plain" })
public void writeChartInterpretation(@PathVariable("uid") String uid, @RequestParam(value = "ou", required = false) String orgUnitUid, @RequestBody String text, HttpServletResponse response, HttpServletRequest request) throws WebMessageException {
    Chart chart = idObjectManager.get(Chart.class, uid);
    if (chart == null) {
        throw new WebMessageException(WebMessageUtils.conflict("Chart does not exist or is not accessible: " + uid));
    }
    OrganisationUnit orgUnit = getUserOrganisationUnit(orgUnitUid, chart, currentUserService.getCurrentUser());
    createIntepretation(new Interpretation(chart, orgUnit, text), request, response);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Interpretation(org.hisp.dhis.interpretation.Interpretation) EventChart(org.hisp.dhis.eventchart.EventChart) Chart(org.hisp.dhis.chart.Chart) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with Interpretation

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

the class InterpretationController method updateInterpretation.

// -------------------------------------------------------------------------
// Interpretation update
// -------------------------------------------------------------------------
@RequestMapping(value = "/{uid}", method = RequestMethod.PUT)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void updateInterpretation(@PathVariable("uid") String uid, @RequestBody String text, HttpServletResponse response) throws WebMessageException {
    Interpretation interpretation = interpretationService.getInterpretation(uid);
    if (interpretation == null) {
        throw new WebMessageException(WebMessageUtils.notFound("Interpretation does not exist: " + uid));
    }
    if (!currentUserService.getCurrentUser().equals(interpretation.getUser()) && !currentUserService.currentUserIsSuper()) {
        throw new AccessDeniedException("You are not allowed to update this interpretation.");
    }
    interpretation.setText(text);
    interpretationService.updateInterpretation(interpretation);
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Interpretation(org.hisp.dhis.interpretation.Interpretation) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with Interpretation

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

the class InterpretationController method like.

// -------------------------------------------------------------------------
// Likes
// -------------------------------------------------------------------------
@RequestMapping(value = "/{uid}/like", method = RequestMethod.POST)
public void like(@PathVariable("uid") String uid, HttpServletResponse response, HttpServletRequest request) throws WebMessageException {
    Interpretation interpretation = interpretationService.getInterpretation(uid);
    if (interpretation == null) {
        throw new WebMessageException(WebMessageUtils.conflict("Interpretation does not exist: " + uid));
    }
    boolean like = interpretationService.likeInterpretation(interpretation.getId());
    if (like) {
        webMessageService.send(WebMessageUtils.created("Like added to interpretation"), response, request);
    } else {
        webMessageService.send(WebMessageUtils.conflict("Could not add like, user had already liked interpretation"), response, request);
    }
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Interpretation(org.hisp.dhis.interpretation.Interpretation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with Interpretation

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

the class InterpretationController method updateComment.

@RequestMapping(value = "/{uid}/comments/{cuid}", method = RequestMethod.PUT)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void updateComment(@PathVariable("uid") String uid, @PathVariable("cuid") String cuid, HttpServletResponse response, @RequestBody String content) throws WebMessageException {
    Interpretation interpretation = interpretationService.getInterpretation(uid);
    if (interpretation == null) {
        throw new WebMessageException(WebMessageUtils.conflict("Interpretation does not exist: " + uid));
    }
    for (InterpretationComment comment : interpretation.getComments()) {
        if (comment.getUid().equals(cuid)) {
            if (!currentUserService.getCurrentUser().equals(comment.getUser()) && !currentUserService.currentUserIsSuper()) {
                throw new AccessDeniedException("You are not allowed to update this comment.");
            }
            comment.setText(content);
        }
    }
    interpretationService.updateInterpretation(interpretation);
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) InterpretationComment(org.hisp.dhis.interpretation.InterpretationComment) Interpretation(org.hisp.dhis.interpretation.Interpretation) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Interpretation (org.hisp.dhis.interpretation.Interpretation)21 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)14 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)13 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)5 User (org.hisp.dhis.user.User)5 InterpretationComment (org.hisp.dhis.interpretation.InterpretationComment)4 AccessDeniedException (org.springframework.security.access.AccessDeniedException)4 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)3 ArrayList (java.util.ArrayList)2 Chart (org.hisp.dhis.chart.Chart)2 EventChart (org.hisp.dhis.eventchart.EventChart)2 Period (org.hisp.dhis.period.Period)2 NotAuthenticatedException (org.hisp.dhis.webapi.controller.exception.NotAuthenticatedException)2 Transactional (org.springframework.transaction.annotation.Transactional)2 Date (java.util.Date)1 Query (org.hibernate.Query)1 DataSet (org.hisp.dhis.dataset.DataSet)1 EventReport (org.hisp.dhis.eventreport.EventReport)1 Map (org.hisp.dhis.mapping.Map)1 MessageConversation (org.hisp.dhis.message.MessageConversation)1