use of com.bluenimble.platform.storage.StorageException in project serverless by bluenimble.
the class FileSystemStorageObject method copy.
@Override
public void copy(Folder folder, boolean move) throws StorageException {
if (isRoot) {
throw new StorageException("can't copy root root folder");
}
if (move) {
source.renameTo(new File(((FileSystemFolder) folder).getSource(), name()));
} else {
File newParent = ((FileSystemFolder) folder).getSource();
try {
FileUtils.copy(source, ((FileSystemFolder) folder).getSource(), true);
} catch (IOException e) {
throw new StorageException(e.getMessage(), e);
}
setSource(new File(newParent, name()));
}
}
use of com.bluenimble.platform.storage.StorageException in project serverless by bluenimble.
the class FileSystemStorageObject method rename.
@Override
public void rename(String name) throws StorageException {
if (isRoot) {
throw new StorageException("can't rename root folder");
}
validateName(name);
source.renameTo(new File(source.getParentFile(), name));
if (!name.equals(name())) {
throw new StorageException("unable rename object '" + name() + "' to '" + name + "'. Maybe the object is open by another device.");
}
}
use of com.bluenimble.platform.storage.StorageException in project serverless by bluenimble.
the class DeleteObjectSpi 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);
Boolean force = (Boolean) request.get(Spec.Force);
if (force == null) {
force = false;
}
StorageObject so = null;
try {
so = storage.root().get(path);
} catch (StorageException e) {
throw new ApiServiceExecutionException("storage object '" + path + "' not found", e).status(ApiResponse.NOT_FOUND);
}
long count = so.count();
if (so.isFolder() && count > 0 && !force) {
throw new ApiServiceExecutionException("folder " + path + " isn't empty! It can't be deleted").status(ApiResponse.BAD_REQUEST);
}
boolean deleted = false;
try {
deleted = so.delete();
} catch (StorageException e) {
throw new ApiServiceExecutionException(e.getMessage(), e).status(ApiResponse.NOT_FOUND);
}
return new JsonApiOutput((JsonObject) new JsonObject().set(CommonOutput.Deleted, deleted));
}
use of com.bluenimble.platform.storage.StorageException in project serverless by bluenimble.
the class RenameObjectSpi 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);
String path = (String) request.get(Spec.Object);
String name = (String) request.get(StorageObject.Fields.Name);
Storage storage = space.feature(Storage.class, provider, request);
StorageObject so = null;
try {
so = storage.root().get(path);
} catch (StorageException e) {
throw new ApiServiceExecutionException("storage object '" + path + "' not found", e).status(ApiResponse.NOT_FOUND);
}
try {
so.rename(name);
} catch (StorageException e) {
throw new ApiServiceExecutionException(e.getMessage(), e);
}
return new JsonApiOutput((JsonObject) new JsonObject().set(CommonOutput.Renamed, true));
}
use of com.bluenimble.platform.storage.StorageException in project serverless by bluenimble.
the class UpdateObjectSpi 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);
String path = (String) request.get(Spec.Object);
Boolean append = (Boolean) request.get(Spec.Append);
if (append == null) {
append = false;
}
ApiStreamSource ss = (ApiStreamSource) request.get(ApiRequest.Payload, Scope.Stream);
Storage storage = space.feature(Storage.class, provider, request);
StorageObject so = null;
try {
so = storage.root().get(path);
} catch (StorageException e) {
throw new ApiServiceExecutionException("storage object '" + path + "' not found", e).status(ApiResponse.NOT_FOUND);
}
if (so.isFolder() && ss != null) {
throw new ApiServiceExecutionException("object '" + path + "' isn't a valid content aware storage object").status(ApiResponse.BAD_REQUEST);
}
InputStream stream = ss.stream();
try {
so.update(stream, append);
} catch (StorageException e) {
throw new ApiServiceExecutionException(e.getMessage(), e);
} finally {
IOUtils.closeQuietly(stream);
}
return new JsonApiOutput((JsonObject) new JsonObject().set(CommonOutput.Updated, true));
}
Aggregations