use of com.owncloud.android.operations.RemoteOperationFailedException in project android by nextcloud.
the class FileDataStorageManager method saveFileWithParent.
/**
* traverses a files parent tree to be able to store a file with its parents.
* Throws a RemoteOperationFailedException in case the parent can't be retrieved.
*
* @param file the file
* @param context the app context
* @return the parent file
*/
public OCFile saveFileWithParent(OCFile file, Context context) {
if (file.getParentId() == 0 && !file.getRemotePath().equals("/")) {
String remotePath = file.getRemotePath();
String parentPath = remotePath.substring(0, remotePath.lastIndexOf(file.getFileName()));
OCFile parentFile = getFileByPath(parentPath);
OCFile returnFile;
if (parentFile == null) {
// remote request
ReadRemoteFileOperation operation = new ReadRemoteFileOperation(parentPath);
RemoteOperationResult result = operation.execute(getAccount(), context);
if (result.isSuccess()) {
OCFile remoteFolder = FileStorageUtils.fillOCFile((RemoteFile) result.getData().get(0));
returnFile = saveFileWithParent(remoteFolder, context);
} else {
Exception exception = result.getException();
String message = "Error during saving file with parents: " + file.getRemotePath() + " / " + result.getLogMessage();
if (exception != null) {
throw new RemoteOperationFailedException(message, exception);
} else {
throw new RemoteOperationFailedException(message);
}
}
} else {
returnFile = saveFileWithParent(parentFile, context);
}
file.setParentId(returnFile.getFileId());
saveFile(file);
}
return file;
}
use of com.owncloud.android.operations.RemoteOperationFailedException in project android by nextcloud.
the class OCFileListAdapter method parseVirtuals.
private void parseVirtuals(ArrayList<Object> objects, ExtendedListFragment.SearchType searchType) {
VirtualFolderType type;
boolean onlyImages = false;
switch(searchType) {
case FAVORITE_SEARCH:
type = VirtualFolderType.FAVORITE;
break;
case PHOTO_SEARCH:
type = VirtualFolderType.PHOTOS;
onlyImages = true;
break;
default:
type = VirtualFolderType.NONE;
break;
}
mStorageManager.deleteVirtuals(type);
List<ContentValues> contentValues = new ArrayList<>();
for (int i = 0; i < objects.size(); i++) {
OCFile ocFile = FileStorageUtils.fillOCFile((RemoteFile) objects.get(i));
searchForLocalFileInDefaultPath(ocFile);
try {
ocFile = mStorageManager.saveFileWithParent(ocFile, mContext);
if (!onlyImages || MimeTypeUtil.isImage(ocFile)) {
mFiles.add(ocFile);
}
ContentValues cv = new ContentValues();
cv.put(ProviderMeta.ProviderTableMeta.VIRTUAL_TYPE, type.toString());
cv.put(ProviderMeta.ProviderTableMeta.VIRTUAL_OCFILE_ID, ocFile.getFileId());
contentValues.add(cv);
} catch (RemoteOperationFailedException e) {
Log_OC.e(TAG, "Error saving file with parent" + e.getMessage(), e);
}
}
mStorageManager.saveVirtuals(type, contentValues);
}
Aggregations