Search in sources :

Example 21 with StorageException

use of com.bluenimble.platform.storage.StorageException in project serverless by bluenimble.

the class GetStorageObjectApiServiceSpi method getObject.

private ApiOutput getObject(Api api, ApiRequest request) throws ApiServiceExecutionException {
    Storage storage = api.space().feature(Storage.class, provider, request);
    String path = (String) request.get(objectParameter);
    if (Lang.isNullOrEmpty(path)) {
        throw new ApiServiceExecutionException("object path not found. Missing request parameter '" + objectParameter + "'").status(ApiResponse.BAD_REQUEST);
    }
    ApiOutput output;
    try {
        StorageObject object = findFolder(storage.root(), this.folder).get(path);
        output = object.toOutput(null, (String) request.get(Spec.As), MediaTypeUtils.getMediaForFile((String) request.get(Spec.Type)));
    } catch (StorageException e) {
        throw new ApiServiceExecutionException(e.getMessage(), e);
    }
    if (output == null) {
        throw new ApiServiceExecutionException("object " + this.folder + Lang.SLASH + path + " not found").status(ApiResponse.BAD_REQUEST);
    }
    request.set(Output, output);
    return output;
}
Also used : Storage(com.bluenimble.platform.storage.Storage) ApiOutput(com.bluenimble.platform.api.ApiOutput) StorageObject(com.bluenimble.platform.storage.StorageObject) ApiServiceExecutionException(com.bluenimble.platform.api.ApiServiceExecutionException) StorageException(com.bluenimble.platform.storage.StorageException)

Aggregations

StorageException (com.bluenimble.platform.storage.StorageException)21 StorageObject (com.bluenimble.platform.storage.StorageObject)10 IOException (java.io.IOException)9 ApiServiceExecutionException (com.bluenimble.platform.api.ApiServiceExecutionException)8 Storage (com.bluenimble.platform.storage.Storage)8 JsonObject (com.bluenimble.platform.json.JsonObject)7 ApiAccessDeniedException (com.bluenimble.platform.api.ApiAccessDeniedException)6 ApiSpace (com.bluenimble.platform.api.ApiSpace)6 JsonApiOutput (com.bluenimble.platform.api.impls.JsonApiOutput)6 File (java.io.File)6 Folder (com.bluenimble.platform.storage.Folder)5 ApiStreamSource (com.bluenimble.platform.api.ApiStreamSource)4 FileInputStream (java.io.FileInputStream)4 FileOutputStream (java.io.FileOutputStream)4 FileChannel (java.nio.channels.FileChannel)4 InputStream (java.io.InputStream)3 OutputStream (java.io.OutputStream)3 ApiOutput (com.bluenimble.platform.api.ApiOutput)2 Chunk (com.bluenimble.platform.streams.Chunk)2 ByteBuffer (java.nio.ByteBuffer)2