Search in sources :

Example 61 with WebMessageException

use of org.hisp.dhis.dxf2.webmessage.WebMessageException in project dhis2-core by dhis2.

the class ReportController method updateReportDesign.

// -------------------------------------------------------------------------
// CRUD
// -------------------------------------------------------------------------
@RequestMapping(value = "/{uid}/design", method = RequestMethod.PUT)
@PreAuthorize("hasRole('ALL')")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void updateReportDesign(@PathVariable("uid") String uid, @RequestBody String designContent, HttpServletResponse response) throws Exception {
    Report report = reportService.getReport(uid);
    if (report == null) {
        throw new WebMessageException(WebMessageUtils.notFound("Report not found for identifier: " + uid));
    }
    report.setDesignContent(designContent);
    reportService.saveReport(report);
}
Also used : Report(org.hisp.dhis.report.Report) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 62 with WebMessageException

use of org.hisp.dhis.dxf2.webmessage.WebMessageException in project dhis2-core by dhis2.

the class ReportController method getReport.

// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
private void getReport(HttpServletRequest request, HttpServletResponse response, String uid, String organisationUnitUid, String isoPeriod, Date date, String type, String contentType, boolean attachment) throws Exception {
    Report report = reportService.getReport(uid);
    if (report == null) {
        throw new WebMessageException(WebMessageUtils.notFound("Report not found for identifier: " + uid));
    }
    if (organisationUnitUid == null && report.hasReportTable() && report.getReportTable().hasReportParams() && report.getReportTable().getReportParams().isOrganisationUnitSet()) {
        organisationUnitUid = organisationUnitService.getRootOrganisationUnits().iterator().next().getUid();
    }
    if (report.isTypeHtml()) {
        contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_HTML, report.getCacheStrategy());
        reportService.renderHtmlReport(response.getWriter(), uid, date, organisationUnitUid);
    } else {
        date = date != null ? date : new DateTime().minusMonths(1).toDate();
        Period period = isoPeriod != null ? PeriodType.getPeriodFromIsoString(isoPeriod) : new MonthlyPeriodType().createPeriod(date);
        String filename = CodecUtils.filenameEncode(report.getName()) + "." + type;
        contextUtils.configureResponse(response, contentType, report.getCacheStrategy(), filename, attachment);
        JasperPrint print = reportService.renderReport(response.getOutputStream(), uid, period, organisationUnitUid, type);
        if ("html".equals(type)) {
            request.getSession().setAttribute(BaseHttpServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, print);
        }
    }
}
Also used : Report(org.hisp.dhis.report.Report) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) JasperPrint(net.sf.jasperreports.engine.JasperPrint) Period(org.hisp.dhis.period.Period) DateTime(org.joda.time.DateTime)

Example 63 with WebMessageException

use of org.hisp.dhis.dxf2.webmessage.WebMessageException in project dhis2-core by dhis2.

the class KeyJsonValueController method addKeyJsonValue.

/**
     * Creates a new KeyJsonValue Object on the given namespace with the key and value supplied.
     */
@RequestMapping(value = "/{namespace}/{key}", method = RequestMethod.POST, produces = "application/json", consumes = "application/json")
public void addKeyJsonValue(@PathVariable String namespace, @PathVariable String key, @RequestBody String body, @RequestParam(defaultValue = "false") boolean encrypt, HttpServletResponse response) throws IOException, WebMessageException {
    if (!hasAccess(namespace)) {
        throw new WebMessageException(WebMessageUtils.forbidden("The namespace '" + namespace + "' is protected, and you don't have the right authority to access it."));
    }
    if (keyJsonValueService.getKeyJsonValue(namespace, key) != null) {
        throw new WebMessageException(WebMessageUtils.conflict("The key '" + key + "' already exists on the namespace '" + namespace + "'."));
    }
    if (!renderService.isValidJson(body)) {
        throw new WebMessageException(WebMessageUtils.badRequest("The data is not valid JSON."));
    }
    KeyJsonValue keyJsonValue = new KeyJsonValue();
    keyJsonValue.setKey(key);
    keyJsonValue.setNamespace(namespace);
    keyJsonValue.setValue(body);
    keyJsonValue.setEncrypted(encrypt);
    keyJsonValueService.addKeyJsonValue(keyJsonValue);
    response.setStatus(HttpServletResponse.SC_CREATED);
    messageService.sendJson(WebMessageUtils.created("Key '" + key + "' created."), response);
}
Also used : KeyJsonValue(org.hisp.dhis.keyjsonvalue.KeyJsonValue) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 64 with WebMessageException

use of org.hisp.dhis.dxf2.webmessage.WebMessageException in project dhis2-core by dhis2.

the class LegendSetController method putJsonObject.

@Override
@RequestMapping(value = "/{uid}", method = RequestMethod.PUT, consumes = "application/json")
@PreAuthorize("hasRole('F_GIS_ADMIN') or hasRole('F_LEGEND_SET_PUBLIC_ADD') or hasRole('F_LEGEND_SET_PRIVATE_ADD')  or hasRole('ALL')")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void putJsonObject(@PathVariable String uid, HttpServletRequest request, HttpServletResponse response) throws Exception {
    LegendSet legendSet = legendSetService.getLegendSet(uid);
    if (legendSet == null) {
        throw new WebMessageException(WebMessageUtils.notFound("Legend set does not exist: " + uid));
    }
    MetadataImportParams params = importService.getParamsFromMap(contextService.getParameterValuesMap());
    LegendSet newLegendSet = renderService.fromJson(request.getInputStream(), LegendSet.class);
    newLegendSet.setUser(currentUserService.getCurrentUser());
    newLegendSet.setUid(legendSet.getUid());
    mergeService.merge(new MergeParams<>(newLegendSet, legendSet).setMergeMode(params.getMergeMode()));
    legendSetService.updateLegendSet(legendSet);
}
Also used : MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) MergeParams(org.hisp.dhis.schema.MergeParams) LegendSet(org.hisp.dhis.legend.LegendSet) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 65 with WebMessageException

use of org.hisp.dhis.dxf2.webmessage.WebMessageException in project dhis2-core by dhis2.

the class LegendSetController method deleteObject.

@Override
@RequestMapping(value = "/{uid}", method = RequestMethod.DELETE)
@PreAuthorize("hasRole('F_GIS_ADMIN') or hasRole('F_LEGEND_SET_DELETE') or hasRole('ALL')")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void deleteObject(@PathVariable String uid, HttpServletRequest request, HttpServletResponse response) throws Exception {
    LegendSet legendSet = legendSetService.getLegendSet(uid);
    if (legendSet == null) {
        throw new WebMessageException(WebMessageUtils.notFound("Legend set does not exist: " + uid));
    }
    legendSet.getLegends().clear();
    legendSetService.deleteLegendSet(legendSet);
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) LegendSet(org.hisp.dhis.legend.LegendSet) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)134 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)118 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)31 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)28 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)27 DataSet (org.hisp.dhis.dataset.DataSet)21 Period (org.hisp.dhis.period.Period)21 User (org.hisp.dhis.user.User)20 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)18 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)15 ArrayList (java.util.ArrayList)14 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)14 Interpretation (org.hisp.dhis.interpretation.Interpretation)13 Date (java.util.Date)9 WebOptions (org.hisp.dhis.webapi.webdomain.WebOptions)9 InputStream (java.io.InputStream)8 Grid (org.hisp.dhis.common.Grid)8 Event (org.hisp.dhis.dxf2.events.event.Event)8 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)8 WebMessage (org.hisp.dhis.dxf2.webmessage.WebMessage)8