Search in sources :

Example 1 with Interpretation

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

the class InterpretationController method postComment.

// -------------------------------------------------------------------------
// Comment
// -------------------------------------------------------------------------
@RequestMapping(value = "/{uid}/comments", method = RequestMethod.POST, consumes = { "text/html", "text/plain" })
public void postComment(@PathVariable("uid") String uid, @RequestBody String text, HttpServletResponse response, HttpServletRequest request) throws WebMessageException {
    Interpretation interpretation = interpretationService.getInterpretation(uid);
    if (interpretation == null) {
        throw new WebMessageException(WebMessageUtils.conflict("Interpretation does not exist: " + uid));
    }
    InterpretationComment comment = interpretationService.addInterpretationComment(uid, text);
    String builder = InterpretationSchemaDescriptor.API_ENDPOINT + "/" + uid + "/comments/" + comment.getUid();
    response.addHeader("Location", builder);
    webMessageService.send(WebMessageUtils.created("Commented created"), response, request);
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) InterpretationComment(org.hisp.dhis.interpretation.InterpretationComment) Interpretation(org.hisp.dhis.interpretation.Interpretation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with Interpretation

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

the class InterpretationController method deleteObject.

@Override
public void deleteObject(@PathVariable String uid, HttpServletRequest request, HttpServletResponse response) throws Exception {
    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 delete this interpretation.");
    }
    interpretationService.deleteInterpretation(interpretation);
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Interpretation(org.hisp.dhis.interpretation.Interpretation)

Example 3 with Interpretation

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

the class InterpretationController method unlike.

@RequestMapping(value = "/{uid}/like", method = RequestMethod.DELETE)
public void unlike(@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.unlikeInterpretation(interpretation.getId());
    if (like) {
        webMessageService.send(WebMessageUtils.created("Like removed from interpretation"), response, request);
    } else {
        webMessageService.send(WebMessageUtils.conflict("Could not remove like, user had not previously 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 4 with Interpretation

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

the class InterpretationController method writeDataSetReportInterpretation.

@RequestMapping(value = "/dataSetReport/{uid}", method = RequestMethod.POST, consumes = { "text/html", "text/plain" })
public void writeDataSetReportInterpretation(@PathVariable("uid") String dataSetUid, @RequestParam("pe") String isoPeriod, @RequestParam("ou") String orgUnitUid, @RequestBody String text, HttpServletResponse response, HttpServletRequest request) throws WebMessageException {
    DataSet dataSet = idObjectManager.get(DataSet.class, dataSetUid);
    if (dataSet == null) {
        throw new WebMessageException(WebMessageUtils.conflict("Data set does not exist or is not accessible: " + dataSetUid));
    }
    Period period = PeriodType.getPeriodFromIsoString(isoPeriod);
    if (period == null) {
        throw new WebMessageException(WebMessageUtils.conflict("Period identifier not valid: " + isoPeriod));
    }
    OrganisationUnit orgUnit = idObjectManager.get(OrganisationUnit.class, orgUnitUid);
    if (orgUnit == null) {
        throw new WebMessageException(WebMessageUtils.conflict("Organisation unit does not exist or is not accessible: " + orgUnitUid));
    }
    createIntepretation(new Interpretation(dataSet, period, orgUnit, text), request, response);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Period(org.hisp.dhis.period.Period) Interpretation(org.hisp.dhis.interpretation.Interpretation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with Interpretation

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

the class InterpretationController method writeReportTableInterpretation.

// -------------------------------------------------------------------------
// Intepretation create
// -------------------------------------------------------------------------
@RequestMapping(value = "/reportTable/{uid}", method = RequestMethod.POST, consumes = { "text/html", "text/plain" })
public void writeReportTableInterpretation(@PathVariable("uid") String reportTableUid, @RequestParam(value = "pe", required = false) String isoPeriod, @RequestParam(value = "ou", required = false) String orgUnitUid, @RequestBody String text, HttpServletResponse response, HttpServletRequest request) throws WebMessageException {
    ReportTable reportTable = idObjectManager.get(ReportTable.class, reportTableUid);
    if (reportTable == null) {
        throw new WebMessageException(WebMessageUtils.conflict("Report table does not exist or is not accessible: " + reportTableUid));
    }
    Period period = PeriodType.getPeriodFromIsoString(isoPeriod);
    OrganisationUnit orgUnit = getUserOrganisationUnit(orgUnitUid, reportTable, currentUserService.getCurrentUser());
    createIntepretation(new Interpretation(reportTable, period, orgUnit, text), request, response);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) ReportTable(org.hisp.dhis.reporttable.ReportTable) Period(org.hisp.dhis.period.Period) Interpretation(org.hisp.dhis.interpretation.Interpretation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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