use of io.jmix.rest.exception.RestAPIException in project jmix by jmix-framework.
the class FileDownloadController method downloadFile.
@GetMapping
public void downloadFile(@RequestParam String fileRef, @RequestParam(required = false) Boolean attachment, HttpServletResponse response) {
checkFileDownloadPermission();
try {
FileRef fileReference;
fileReference = FileRef.fromString(fileRef);
fileTransferService.downloadAndWriteResponse(fileReference, fileReference.getStorageName(), attachment, response);
} catch (IllegalArgumentException e) {
throw new RestAPIException("Invalid file reference", String.format("Cannot convert '%s' into valid file reference", fileRef), HttpStatus.BAD_REQUEST, e);
}
}
use of io.jmix.rest.exception.RestAPIException in project jmix by jmix-framework.
the class CubaFileDownloadController method checkFileDownloadPermission.
protected void checkFileDownloadPermission() {
RestFileDownloadContext downloadContext = new RestFileDownloadContext();
accessManager.applyRegisteredConstraints(downloadContext);
if (!downloadContext.isPermitted()) {
throw new RestAPIException("File download failed", "File download is not permitted", HttpStatus.FORBIDDEN);
}
if (!security.isEntityOpPermitted(FileDescriptor.class, EntityOp.READ)) {
throw new RestAPIException("Reading forbidden", "Reading of the sys$FileDescriptor is forbidden", HttpStatus.FORBIDDEN);
}
}
use of io.jmix.rest.exception.RestAPIException in project jmix by jmix-framework.
the class CubaFileUploadController method checkFileUploadPermission.
protected void checkFileUploadPermission() {
RestFileUploadContext uploadContext = new RestFileUploadContext();
accessManager.applyRegisteredConstraints(uploadContext);
if (!uploadContext.isPermitted()) {
throw new RestAPIException("File upload failed", "File upload is not permitted", HttpStatus.FORBIDDEN);
}
if (!security.isEntityOpPermitted(FileDescriptor.class, EntityOp.CREATE)) {
throw new RestAPIException("Creating forbidden", "Creating of the sys$FileDescriptor is forbidden", HttpStatus.FORBIDDEN);
}
}
use of io.jmix.rest.exception.RestAPIException in project jmix by jmix-framework.
the class CubaFileUploadController method checkFileExists.
protected void checkFileExists(@Nullable String id) {
if (Strings.isNullOrEmpty(id)) {
return;
}
LoadContext<FileDescriptor> ctx = new LoadContext<>(FileDescriptor.class).setId(UUID.fromString(id));
FileDescriptor fileDescriptor = dataManager.load(ctx);
if (fileDescriptor != null) {
log.error("File with id = {} already exists", id);
throw new RestAPIException("File already exists", String.format("File with id = %s already exists", id), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
use of io.jmix.rest.exception.RestAPIException in project jmix by jmix-framework.
the class DatatypesControllerManager method getDatatypesJson.
public String getDatatypesJson() {
JsonArray jsonArray = new JsonArray();
try {
for (String id : datatypes.getIds()) {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("id", id);
// for backward compatibility
jsonObject.addProperty("name", id);
Datatype datatype = datatypes.get(id);
if (datatype instanceof ParameterizedDatatype) {
Map<String, Object> parameters = ((ParameterizedDatatype) datatype).getParameters();
for (Map.Entry<String, Object> entry : parameters.entrySet()) {
jsonObject.addProperty(entry.getKey(), entry.getValue().toString());
}
}
jsonArray.add(jsonObject);
}
} catch (Exception e) {
log.error("Fail to get datatype settings", e);
throw new RestAPIException("Fail to get datatype settings", e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR, e);
}
return jsonArray.toString();
}
Aggregations