Search in sources :

Example 26 with ResponseStatus

use of org.springframework.web.bind.annotation.ResponseStatus in project dhis2-core by dhis2.

the class DataSetController method updateCustomDataEntryFormJson.

@RequestMapping(value = "/{uid}/form", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
@ApiVersion(value = DhisApiVersion.ALL, exclude = DhisApiVersion.V23)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void updateCustomDataEntryFormJson(@PathVariable("uid") String uid, HttpServletRequest request) throws WebMessageException {
    DataSet dataSet = dataSetService.getDataSet(uid);
    if (dataSet == null) {
        throw new WebMessageException(WebMessageUtils.notFound("DataSet not found for uid: " + uid));
    }
    DataEntryForm form = dataSet.getDataEntryForm();
    DataEntryForm newForm;
    try {
        newForm = renderService.fromJson(request.getInputStream(), DataEntryForm.class);
    } catch (IOException e) {
        throw new WebMessageException(WebMessageUtils.badRequest("Failed to parse request", e.getMessage()));
    }
    if (form == null) {
        if (!newForm.hasForm()) {
            throw new WebMessageException(WebMessageUtils.badRequest("Missing required parameter 'htmlCode'"));
        }
        newForm.setName(dataSet.getName());
        dataEntryFormService.addDataEntryForm(newForm);
        dataSet.setDataEntryForm(newForm);
    } else {
        if (newForm.getHtmlCode() != null) {
            form.setHtmlCode(dataEntryFormService.prepareDataEntryFormForSave(newForm.getHtmlCode()));
        }
        if (newForm.getStyle() != null) {
            form.setStyle(newForm.getStyle());
        }
        dataEntryFormService.updateDataEntryForm(form);
    }
    dataSet.increaseVersion();
    dataSetService.updateDataSet(dataSet);
}
Also used : DataSet(org.hisp.dhis.dataset.DataSet) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) DataEntryForm(org.hisp.dhis.dataentryform.DataEntryForm) IOException(java.io.IOException) DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) ApiVersion(org.hisp.dhis.webapi.mvc.annotation.ApiVersion) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 27 with ResponseStatus

use of org.springframework.web.bind.annotation.ResponseStatus in project dhis2-core by dhis2.

the class DataSetController method updateCustomDataEntryFormHtml.

@RequestMapping(value = { "/{uid}/customDataEntryForm", "/{uid}/form" }, method = { RequestMethod.PUT, RequestMethod.POST }, consumes = "text/html")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void updateCustomDataEntryFormHtml(@PathVariable("uid") String uid, @RequestBody String formContent, HttpServletResponse response) throws Exception {
    DataSet dataSet = dataSetService.getDataSet(uid);
    if (dataSet == null) {
        throw new WebMessageException(WebMessageUtils.notFound("DataSet not found for uid: " + uid));
    }
    DataEntryForm form = dataSet.getDataEntryForm();
    if (form == null) {
        form = new DataEntryForm(dataSet.getName(), DisplayDensity.NORMAL, formContent);
        dataEntryFormService.addDataEntryForm(form);
        dataSet.setDataEntryForm(form);
    } else {
        form.setHtmlCode(formContent);
        dataEntryFormService.updateDataEntryForm(form);
    }
    dataSet.increaseVersion();
    dataSetService.updateDataSet(dataSet);
}
Also used : DataSet(org.hisp.dhis.dataset.DataSet) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) DataEntryForm(org.hisp.dhis.dataentryform.DataEntryForm) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 28 with ResponseStatus

use of org.springframework.web.bind.annotation.ResponseStatus in project dhis2-core by dhis2.

the class ConfigurationController method removeSelfRegistrationRole.

@PreAuthorize("hasRole('ALL') or hasRole('F_SYSTEM_SETTING')")
@RequestMapping(value = "/selfRegistrationRole", method = RequestMethod.DELETE)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void removeSelfRegistrationRole() {
    Configuration config = configurationService.getConfiguration();
    config.setSelfRegistrationRole(null);
    configurationService.setConfiguration(config);
}
Also used : Configuration(org.hisp.dhis.configuration.Configuration) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 29 with ResponseStatus

use of org.springframework.web.bind.annotation.ResponseStatus in project dhis2-core by dhis2.

the class ConfigurationController method setFeedbackRecipients.

@PreAuthorize("hasRole('ALL') or hasRole('F_SYSTEM_SETTING')")
@RequestMapping(value = "/feedbackRecipients", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void setFeedbackRecipients(@RequestBody String uid) throws NotFoundException {
    UserGroup group = identifiableObjectManager.get(UserGroup.class, uid);
    if (group == null) {
        throw new NotFoundException("User group", uid);
    }
    Configuration config = configurationService.getConfiguration();
    config.setFeedbackRecipients(group);
    configurationService.setConfiguration(config);
}
Also used : Configuration(org.hisp.dhis.configuration.Configuration) NotFoundException(org.hisp.dhis.webapi.controller.exception.NotFoundException) UserGroup(org.hisp.dhis.user.UserGroup) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 30 with ResponseStatus

use of org.springframework.web.bind.annotation.ResponseStatus in project dhis2-core by dhis2.

the class ConfigurationController method setCorsWhitelist.

@SuppressWarnings("unchecked")
@PreAuthorize("hasRole('ALL') or hasRole('F_SYSTEM_SETTING')")
@RequestMapping(value = "/corsWhitelist", method = RequestMethod.POST, consumes = "application/json")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void setCorsWhitelist(@RequestBody String input) throws IOException {
    Set<String> corsWhitelist = renderService.fromJson(input, Set.class);
    Configuration config = configurationService.getConfiguration();
    config.setCorsWhitelist(corsWhitelist);
    configurationService.setConfiguration(config);
}
Also used : Configuration(org.hisp.dhis.configuration.Configuration) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)93 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)69 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)35 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)26 GetMapping (org.springframework.web.bind.annotation.GetMapping)17 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)16 User (org.hisp.dhis.user.User)14 Date (java.util.Date)13 Configuration (org.hisp.dhis.configuration.Configuration)12 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)12 Period (org.hisp.dhis.period.Period)11 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)9 Calendar (java.util.Calendar)9 DataSet (org.hisp.dhis.dataset.DataSet)7 ISymmetricEngine (org.jumpmind.symmetric.ISymmetricEngine)7 ArrayList (java.util.ArrayList)6 DataApproval (org.hisp.dhis.dataapproval.DataApproval)6 DataApprovalLevel (org.hisp.dhis.dataapproval.DataApprovalLevel)6 NotFoundException (org.hisp.dhis.webapi.controller.exception.NotFoundException)6 Proveedor (sic.modelo.Proveedor)6