Search in sources :

Example 61 with WebMessage

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

the class PdfFormController method sendFormPdfDataSet.

@PostMapping("/dataSet")
@PreAuthorize("hasRole('ALL') or hasRole('F_DATAVALUE_ADD')")
@ResponseBody
public WebMessage sendFormPdfDataSet(HttpServletRequest request) throws Exception {
    JobConfiguration jobId = new JobConfiguration("inMemoryDataValueImport", JobType.DATAVALUE_IMPORT, currentUserService.getCurrentUser().getUid(), true);
    notifier.clear(jobId);
    InputStream in = request.getInputStream();
    in = StreamUtils.wrapAndCheckCompressionFormat(in);
    ImportSummary summary = dataValueSetService.importDataValueSetPdf(in, ImportOptions.getDefaultImportOptions(), jobId);
    return importSummary(summary);
}
Also used : InputStream(java.io.InputStream) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) PostMapping(org.springframework.web.bind.annotation.PostMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 62 with WebMessage

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

the class SystemSettingController method setSystemSettingV29.

@PostMapping(consumes = ContextUtils.CONTENT_TYPE_JSON)
@PreAuthorize("hasRole('ALL') or hasRole('F_SYSTEM_SETTING')")
@ResponseBody
public WebMessage setSystemSettingV29(@RequestBody Map<String, Object> settings) {
    List<String> invalidKeys = settings.keySet().stream().filter((key) -> !SettingKey.getByName(key).isPresent()).collect(Collectors.toList());
    if (!invalidKeys.isEmpty()) {
        return conflict("Key(s) is not supported: " + StringUtils.join(invalidKeys, ", "));
    }
    for (Entry<String, Object> entry : settings.entrySet()) {
        String key = entry.getKey();
        Serializable valueObject = SettingKey.getAsRealClass(key, entry.getValue().toString());
        systemSettingManager.saveSystemSetting(SettingKey.getByName(key).get(), valueObject);
    }
    return ok("System settings imported");
}
Also used : DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) PathVariable(org.springframework.web.bind.annotation.PathVariable) Arrays(java.util.Arrays) RequestParam(org.springframework.web.bind.annotation.RequestParam) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RenderService(org.hisp.dhis.render.RenderService) UserSettingKey(org.hisp.dhis.user.UserSettingKey) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Controller(org.springframework.stereotype.Controller) ApiVersion(org.hisp.dhis.webapi.mvc.annotation.ApiVersion) StringUtils(org.apache.commons.lang3.StringUtils) CacheControl(org.springframework.http.CacheControl) CurrentUser(org.hisp.dhis.user.CurrentUser) HashSet(java.util.HashSet) RequestBody(org.springframework.web.bind.annotation.RequestBody) WebMessageUtils.ok(org.hisp.dhis.dxf2.webmessage.WebMessageUtils.ok) HttpServletRequest(javax.servlet.http.HttpServletRequest) UserSettingService(org.hisp.dhis.user.UserSettingService) Locale(java.util.Locale) Map(java.util.Map) User(org.hisp.dhis.user.User) GetMapping(org.springframework.web.bind.annotation.GetMapping) Collections.singletonMap(java.util.Collections.singletonMap) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) SystemSettingManager(org.hisp.dhis.setting.SystemSettingManager) ContextUtils(org.hisp.dhis.webapi.utils.ContextUtils) PostMapping(org.springframework.web.bind.annotation.PostMapping) HttpServletResponse(javax.servlet.http.HttpServletResponse) Set(java.util.Set) APPLICATION_JSON_VALUE(org.springframework.http.MediaType.APPLICATION_JSON_VALUE) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) ObjectUtils(org.hisp.dhis.util.ObjectUtils) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) WebMessageUtils.conflict(org.hisp.dhis.dxf2.webmessage.WebMessageUtils.conflict) Entry(java.util.Map.Entry) Optional(java.util.Optional) ResponseEntity(org.springframework.http.ResponseEntity) SettingKey(org.hisp.dhis.setting.SettingKey) AllArgsConstructor(lombok.AllArgsConstructor) WebMessage(org.hisp.dhis.dxf2.webmessage.WebMessage) Serializable(java.io.Serializable) PostMapping(org.springframework.web.bind.annotation.PostMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 63 with WebMessage

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

the class UserSettingController method setUserSettingByKey.

@PostMapping(value = "/{key}")
public WebMessage setUserSettingByKey(@PathVariable(value = "key") String key, @RequestParam(value = "user", required = false) String username, @RequestParam(value = "userId", required = false) String userId, @RequestParam(required = false) String value, @RequestBody(required = false) String valuePayload) throws WebMessageException {
    UserSettingKey userSettingKey = getUserSettingKey(key);
    User user = getUser(userId, username);
    String newValue = ObjectUtils.firstNonNull(value, valuePayload);
    if (StringUtils.isEmpty(newValue)) {
        throw new WebMessageException(conflict("You need to specify a new value"));
    }
    userSettingService.saveUserSetting(userSettingKey, UserSettingKey.getAsRealClass(key, newValue), user);
    return ok("User setting saved");
}
Also used : User(org.hisp.dhis.user.User) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) UserSettingKey(org.hisp.dhis.user.UserSettingKey) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 64 with WebMessage

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

the class FileResourceController method saveFileResource.

@PostMapping
public WebMessage saveFileResource(@RequestParam MultipartFile file, @RequestParam(defaultValue = "DATA_VALUE") FileResourceDomain domain) throws WebMessageException, IOException {
    FileResource fileResource = fileResourceUtils.saveFileResource(file, domain);
    WebMessage webMessage = new WebMessage(Status.OK, HttpStatus.ACCEPTED);
    webMessage.setResponse(new FileResourceWebMessageResponse(fileResource));
    return webMessage;
}
Also used : FileResourceWebMessageResponse(org.hisp.dhis.dxf2.webmessage.responses.FileResourceWebMessageResponse) FileResource(org.hisp.dhis.fileresource.FileResource) WebMessage(org.hisp.dhis.dxf2.webmessage.WebMessage) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 65 with WebMessage

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

the class EnrollmentController method updateEnrollmentJson.

@PutMapping(value = "/{id}", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
@ResponseBody
public WebMessage updateEnrollmentJson(@PathVariable String id, ImportOptions importOptions, HttpServletRequest request) throws IOException {
    InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
    ImportSummary importSummary = enrollmentService.updateEnrollmentJson(id, inputStream, importOptions);
    importSummary.setImportOptions(importOptions);
    return importSummary(importSummary);
}
Also used : InputStream(java.io.InputStream) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) PutMapping(org.springframework.web.bind.annotation.PutMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ResponseBody (org.springframework.web.bind.annotation.ResponseBody)49 PostMapping (org.springframework.web.bind.annotation.PostMapping)29 WebMessage (org.hisp.dhis.dxf2.webmessage.WebMessage)28 InputStream (java.io.InputStream)24 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)20 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)17 PutMapping (org.springframework.web.bind.annotation.PutMapping)17 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)17 ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)15 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)14 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)13 JobConfiguration (org.hisp.dhis.scheduling.JobConfiguration)10 User (org.hisp.dhis.user.User)10 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)10 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)9 List (java.util.List)8 Event (org.hisp.dhis.dxf2.events.event.Event)8 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)7 IOException (java.io.IOException)6 FileResourceWebMessageResponse (org.hisp.dhis.dxf2.webmessage.responses.FileResourceWebMessageResponse)6