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;
}
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);
}
}
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;
}
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();
}
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
}
}
Aggregations