Search in sources :

Example 1 with SyncOperation

use of com.owncloud.android.operations.common.SyncOperation in project android by nextcloud.

the class UploadFileOperation method grantFolderExistence.

/**
 * Checks the existence of the folder where the current file will be uploaded both
 * in the remote server and in the local database.
 * <p/>
 * If the upload is set to enforce the creation of the folder, the method tries to
 * create it both remote and locally.
 *
 * @param pathToGrant Full remote path whose existence will be granted.
 * @return An {@link OCFile} instance corresponding to the folder where the file
 * will be uploaded.
 */
private RemoteOperationResult grantFolderExistence(String pathToGrant, OwnCloudClient client) {
    RemoteOperation operation = new ExistenceCheckRemoteOperation(pathToGrant, mContext, false);
    RemoteOperationResult result = operation.execute(client, true);
    if (!result.isSuccess() && result.getCode() == ResultCode.FILE_NOT_FOUND && mRemoteFolderToBeCreated) {
        SyncOperation syncOp = new CreateFolderOperation(pathToGrant, true);
        result = syncOp.execute(client, getStorageManager());
    }
    if (result.isSuccess()) {
        OCFile parentDir = getStorageManager().getFileByPath(pathToGrant);
        if (parentDir == null) {
            parentDir = createLocalFolder(pathToGrant);
        }
        if (parentDir != null) {
            result = new RemoteOperationResult(ResultCode.OK);
        } else {
            result = new RemoteOperationResult(ResultCode.UNKNOWN_ERROR);
        }
    }
    return result;
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) ExistenceCheckRemoteOperation(com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation) RemoteOperation(com.owncloud.android.lib.common.operations.RemoteOperation) ExistenceCheckRemoteOperation(com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) SyncOperation(com.owncloud.android.operations.common.SyncOperation)

Example 2 with SyncOperation

use of com.owncloud.android.operations.common.SyncOperation in project android by owncloud.

the class SynchronizeFolderOperation method syncContents.

/**
 * Performs a list of synchronization operations, determining if a download or upload is needed
 * or if exists conflict due to changes both in local and remote contents of the each file.
 * <p>
 * If download or upload is needed, request the operation to the corresponding service and goes
 * on.
 */
private void syncContents() throws OperationCancelledException {
    Timber.v("Starting content synchronization... ");
    RemoteOperationResult contentsResult;
    for (SyncOperation op : mFilesToSyncContents) {
        if (mCancellationRequested.get()) {
            throw new OperationCancelledException();
        }
        contentsResult = op.execute(getStorageManager(), mContext);
        if (!contentsResult.isSuccess()) {
            if (contentsResult.getCode() == ResultCode.SYNC_CONFLICT) {
                mConflictsFound++;
            } else {
                mFailsInFileSyncsFound++;
                if (contentsResult.getException() != null) {
                    Timber.e(contentsResult.getException(), "Error while synchronizing file : %s", contentsResult.getLogMessage());
                } else {
                    Timber.e("Error while synchronizing file : %s", contentsResult.getLogMessage());
                }
            }
        }
    // won't let these fails break the synchronization process
    }
    for (Intent intent : mFoldersToSyncContents) {
        if (mCancellationRequested.get()) {
            throw new OperationCancelledException();
        }
        mContext.startService(intent);
    }
}
Also used : RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) SyncOperation(com.owncloud.android.operations.common.SyncOperation) OperationCancelledException(com.owncloud.android.lib.common.operations.OperationCancelledException) Intent(android.content.Intent)

Example 3 with SyncOperation

use of com.owncloud.android.operations.common.SyncOperation in project android by owncloud.

the class UploadFileOperation method grantFolderExistence.

/**
 * Checks the existence of the folder where the current file will be uploaded both
 * in the remote server and in the local database.
 * <p>
 * If the upload is set to enforce the creation of the folder, the method tries to
 * create it both remote and locally.
 *
 * @param pathToGrant Full remote path whose existence will be granted.
 * @return An {@link OCFile} instance corresponding to the folder where the file
 * will be uploaded.
 */
private RemoteOperationResult grantFolderExistence(String pathToGrant, OwnCloudClient client) {
    RemoteOperation checkPathExistenceOperation = new CheckPathExistenceRemoteOperation(pathToGrant, false);
    RemoteOperationResult result = checkPathExistenceOperation.execute(client);
    if (!result.isSuccess() && result.getCode() == ResultCode.FILE_NOT_FOUND && mRemoteFolderToBeCreated) {
        SyncOperation syncOp = new CreateFolderOperation(pathToGrant, true);
        result = syncOp.execute(client, getStorageManager());
    }
    if (result.isSuccess()) {
        OCFile parentDir = getStorageManager().getFileByPath(pathToGrant);
        if (parentDir == null) {
            parentDir = createLocalFolder(pathToGrant);
        }
        if (parentDir != null) {
            result = new RemoteOperationResult(ResultCode.OK);
        } else {
            result = new RemoteOperationResult(ResultCode.UNKNOWN_ERROR);
        }
    }
    return result;
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) CheckPathExistenceRemoteOperation(com.owncloud.android.lib.resources.files.CheckPathExistenceRemoteOperation) RemoteOperation(com.owncloud.android.lib.common.operations.RemoteOperation) CheckPathExistenceRemoteOperation(com.owncloud.android.lib.resources.files.CheckPathExistenceRemoteOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) SyncOperation(com.owncloud.android.operations.common.SyncOperation)

Example 4 with SyncOperation

use of com.owncloud.android.operations.common.SyncOperation in project android by owncloud.

the class FolderPickerActivity method startSyncFolderOperation.

public void startSyncFolderOperation(OCFile folder, boolean ignoreETag) {
    mSyncInProgress = true;
    // perform folder synchronization
    SyncOperation synchFolderOp = new RefreshFolderOperation(folder, ignoreETag, getAccount(), getApplicationContext());
    synchFolderOp.execute(getStorageManager(), this, null, null);
    OCFileListFragment fileListFragment = getListOfFilesFragment();
    if (fileListFragment != null) {
        fileListFragment.setProgressBarAsIndeterminate(true);
    }
    setBackgroundText();
}
Also used : SyncOperation(com.owncloud.android.operations.common.SyncOperation) RefreshFolderOperation(com.owncloud.android.operations.RefreshFolderOperation) OCFileListFragment(com.owncloud.android.ui.fragment.OCFileListFragment)

Example 5 with SyncOperation

use of com.owncloud.android.operations.common.SyncOperation in project android by nextcloud.

the class SynchronizeFolderOperation method startContentSynchronizations.

/**
 * Performs a list of synchronization operations, determining if a download or upload is needed
 * or if exists conflict due to changes both in local and remote contents of the each file.
 *
 * If download or upload is needed, request the operation to the corresponding service and goes on.
 *
 * @param filesToSyncContents       Synchronization operations to execute.
 */
private void startContentSynchronizations(List<SyncOperation> filesToSyncContents) throws OperationCancelledException {
    Log_OC.v(TAG, "Starting content synchronization... ");
    RemoteOperationResult contentsResult;
    for (SyncOperation op : filesToSyncContents) {
        if (mCancellationRequested.get()) {
            throw new OperationCancelledException();
        }
        contentsResult = op.execute(getStorageManager(), mContext);
        if (!contentsResult.isSuccess()) {
            if (contentsResult.getCode() == ResultCode.SYNC_CONFLICT) {
                mConflictsFound++;
            } else {
                mFailsInFileSyncsFound++;
                if (contentsResult.getException() != null) {
                    Log_OC.e(TAG, "Error while synchronizing file : " + contentsResult.getLogMessage(), contentsResult.getException());
                } else {
                    Log_OC.e(TAG, "Error while synchronizing file : " + contentsResult.getLogMessage());
                }
            }
        // TODO - use the errors count in notifications
        }
    // won't let these fails break the synchronization process
    }
}
Also used : RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) SyncOperation(com.owncloud.android.operations.common.SyncOperation) OperationCancelledException(com.owncloud.android.lib.common.operations.OperationCancelledException)

Aggregations

SyncOperation (com.owncloud.android.operations.common.SyncOperation)6 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)4 OCFile (com.owncloud.android.datamodel.OCFile)2 OperationCancelledException (com.owncloud.android.lib.common.operations.OperationCancelledException)2 RemoteOperation (com.owncloud.android.lib.common.operations.RemoteOperation)2 RefreshFolderOperation (com.owncloud.android.operations.RefreshFolderOperation)2 Intent (android.content.Intent)1 CheckPathExistenceRemoteOperation (com.owncloud.android.lib.resources.files.CheckPathExistenceRemoteOperation)1 ExistenceCheckRemoteOperation (com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation)1 OCFileListFragment (com.owncloud.android.ui.fragment.OCFileListFragment)1