Search in sources :

Example 1 with RemoteOperationFailedException

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;
}
Also used : RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) RemoteOperationFailedException(com.owncloud.android.operations.RemoteOperationFailedException) ReadRemoteFileOperation(com.owncloud.android.lib.resources.files.ReadRemoteFileOperation) RemoteException(android.os.RemoteException) RemoteOperationFailedException(com.owncloud.android.operations.RemoteOperationFailedException) OperationApplicationException(android.content.OperationApplicationException)

Example 2 with RemoteOperationFailedException

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);
}
Also used : ContentValues(android.content.ContentValues) OCFile(com.owncloud.android.datamodel.OCFile) RemoteOperationFailedException(com.owncloud.android.operations.RemoteOperationFailedException) ArrayList(java.util.ArrayList) VirtualFolderType(com.owncloud.android.datamodel.VirtualFolderType)

Aggregations

RemoteOperationFailedException (com.owncloud.android.operations.RemoteOperationFailedException)2 ContentValues (android.content.ContentValues)1 OperationApplicationException (android.content.OperationApplicationException)1 RemoteException (android.os.RemoteException)1 OCFile (com.owncloud.android.datamodel.OCFile)1 VirtualFolderType (com.owncloud.android.datamodel.VirtualFolderType)1 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)1 ReadRemoteFileOperation (com.owncloud.android.lib.resources.files.ReadRemoteFileOperation)1 ArrayList (java.util.ArrayList)1