use of com.bluenimble.platform.storage.Storage in project serverless by bluenimble.
the class GetObjectSpi method execute.
@Override
public ApiOutput execute(Api api, ApiConsumer consumer, ApiRequest request, ApiResponse response) throws ApiServiceExecutionException {
ApiSpace space;
try {
space = MgmUtils.space(consumer, api);
} catch (ApiAccessDeniedException e) {
throw new ApiServiceExecutionException(e.getMessage(), e).status(ApiResponse.FORBIDDEN);
}
String provider = (String) request.get(CommonSpec.Provider);
Storage storage = space.feature(Storage.class, provider, request);
String path = (String) request.get(Spec.Object);
String filter = (String) request.get(Spec.Filter);
Folder root = null;
StorageObject so = null;
try {
root = storage.root();
so = root;
} catch (StorageException e) {
throw new ApiServiceExecutionException(e.getMessage(), e);
}
try {
if (!Lang.isNullOrEmpty(path) && !path.trim().equals(Lang.DOT)) {
so = root.get(path);
}
} catch (StorageException e) {
throw new ApiServiceExecutionException("storage object '" + path + "' not found", e).status(ApiResponse.NOT_FOUND);
}
try {
return so.toOutput(StorageUtils.guessFilter(filter), null, null);
} catch (Exception e) {
throw new ApiServiceExecutionException(e.getMessage(), e);
}
}
use of com.bluenimble.platform.storage.Storage in project serverless by bluenimble.
the class PutStorageObjectApiServiceSpi method execute.
@Override
public ApiOutput execute(Api api, ApiConsumer consumer, ApiRequest request, ApiResponse response) throws ApiServiceExecutionException {
Storage storage = api.space().feature(Storage.class, provider, request);
String path = (String) request.get(objectParameter);
if (Lang.isNullOrEmpty(path)) {
throw new ApiServiceExecutionException("missing object path parameter '" + objectParameter + "'").status(ApiResponse.BAD_REQUEST);
}
String objectName = null;
StorageObject so = null;
long length = -1;
ApiStreamSource stream = null;
try {
stream = (ApiStreamSource) request.get(streamParameter, Scope.Stream);
if (Lang.isNullOrEmpty(stream.name())) {
objectName = Lang.UUID(20);
}
so = findFolder(storage.root(), this.folder).add(stream, objectName, true);
length = so.length();
} catch (StorageException e) {
throw new ApiServiceExecutionException(e.getMessage(), e);
}
return new JsonApiOutput((JsonObject) new JsonObject().set(StorageObject.Fields.Name, so.name()).set(StorageObject.Fields.Timestamp, Lang.toUTC(so.timestamp())).set(StorageObject.Fields.Length, length));
}
use of com.bluenimble.platform.storage.Storage 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;
}
Aggregations