use of com.owncloud.android.operations.SynchronizeFolderOperation in project android by nextcloud.
the class SyncFolderHandler method cancel.
/**
* Cancels a pending or current sync' operation.
*
* @param account ownCloud {@link Account} where the remote file is stored.
* @param file A file in the queue of pending synchronizations
*/
public void cancel(Account account, OCFile file) {
if (account == null || file == null) {
Log_OC.e(TAG, "Cannot cancel with NULL parameters");
return;
}
Pair<SynchronizeFolderOperation, String> removeResult = mPendingOperations.remove(account.name, file.getRemotePath());
SynchronizeFolderOperation synchronization = removeResult.first;
if (synchronization != null) {
synchronization.cancel();
} else {
// TODO synchronize?
if (mCurrentSyncOperation != null && mCurrentAccount != null && mCurrentSyncOperation.getRemotePath().startsWith(file.getRemotePath()) && account.name.equals(mCurrentAccount.name)) {
mCurrentSyncOperation.cancel();
}
}
// sendBroadcastFinishedSyncFolder(account, file.getRemotePath());
}
use of com.owncloud.android.operations.SynchronizeFolderOperation in project android by owncloud.
the class OperationsService method newOperation.
/**
* Creates a new operation, as described by operationIntent.
*
* TODO - move to ServiceHandler (probably)
*
* @param operationIntent Intent describing a new operation to queue and execute.
* @return Pair with the new operation object and the information about its
* target server.
*/
private Pair<Target, RemoteOperation> newOperation(Intent operationIntent) {
RemoteOperation operation = null;
Target target = null;
try {
if (!operationIntent.hasExtra(EXTRA_ACCOUNT) && !operationIntent.hasExtra(EXTRA_SERVER_URL)) {
Timber.e("Not enough information provided in intent");
} else {
Account account = operationIntent.getParcelableExtra(EXTRA_ACCOUNT);
String serverUrl = operationIntent.getStringExtra(EXTRA_SERVER_URL);
String cookie = operationIntent.getStringExtra(EXTRA_COOKIE);
target = new Target(account, (serverUrl == null) ? null : Uri.parse(serverUrl), cookie);
String action = operationIntent.getAction();
if (action != null) {
switch(action) {
case ACTION_RENAME:
{
// Rename file or folder
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
String newName = operationIntent.getStringExtra(EXTRA_NEWNAME);
operation = new RenameFileOperation(remotePath, newName);
break;
}
case ACTION_REMOVE:
{
// Remove file or folder
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
boolean onlyLocalCopy = operationIntent.getBooleanExtra(EXTRA_REMOVE_ONLY_LOCAL, false);
operation = new RemoveFileOperation(remotePath, onlyLocalCopy, operationIntent.getBooleanExtra(EXTRA_IS_LAST_FILE_TO_REMOVE, false));
break;
}
case ACTION_CREATE_FOLDER:
{
// Create Folder
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
boolean createFullPath = operationIntent.getBooleanExtra(EXTRA_CREATE_FULL_PATH, true);
operation = new CreateFolderOperation(remotePath, createFullPath);
break;
}
case ACTION_SYNC_FILE:
{
// Sync file
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
operation = new SynchronizeFileOperation(remotePath, account, getApplicationContext());
break;
}
case ACTION_SYNC_FOLDER:
{
// Sync folder (all its descendant files are synced)
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
boolean pushOnly = operationIntent.getBooleanExtra(EXTRA_PUSH_ONLY, false);
boolean syncContentOfRegularFiles = operationIntent.getBooleanExtra(EXTRA_SYNC_REGULAR_FILES, false);
operation = new SynchronizeFolderOperation(// TODO remove this dependency from construction time
this, remotePath, account, // TODO remove this dependency from construction time
System.currentTimeMillis(), pushOnly, false, syncContentOfRegularFiles);
break;
}
case ACTION_MOVE_FILE:
{
// Move file/folder
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
String newParentPath = operationIntent.getStringExtra(EXTRA_NEW_PARENT_PATH);
operation = new MoveFileOperation(remotePath, newParentPath);
break;
}
case ACTION_COPY_FILE:
{
// Copy file/folder
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
String newParentPath = operationIntent.getStringExtra(EXTRA_NEW_PARENT_PATH);
operation = new CopyFileOperation(remotePath, newParentPath);
break;
}
case ACTION_CHECK_CURRENT_CREDENTIALS:
// Check validity of currently stored credentials for a given account
operation = new CheckCurrentCredentialsOperation(account);
break;
}
}
}
} catch (IllegalArgumentException e) {
Timber.e(e, "Bad information provided in intent: %s", e.getMessage());
operation = null;
}
if (operation != null) {
return new Pair<>(target, operation);
} else {
return null;
}
}
use of com.owncloud.android.operations.SynchronizeFolderOperation in project android by owncloud.
the class FileSyncAdapter method synchronizeFolder.
/**
* Synchronizes the list of files contained in a folder identified with its remote path.
* <p>
* Fetches the list and properties of the files contained in the given folder, including their
* properties, and updates the local database with them.
* <p>
* Enters in the child folders to synchronize their contents also, following a recursive
* depth first strategy.
*
* @param folder Folder to synchronize.
* @param pushOnly When 'true', it's assumed that the folder did not change in the
* server, so data will not be fetched. Only local changes of
* available offline files will be pushed.
*/
private void synchronizeFolder(OCFile folder, boolean pushOnly) {
if (mFailedResultsCounter > MAX_FAILED_RESULTS || isFinisher(mLastFailedResult)) {
return;
}
// folder synchronization
SynchronizeFolderOperation synchFolderOp = new SynchronizeFolderOperation(getContext(), folder.getRemotePath(), getAccount(), mCurrentSyncTime, pushOnly, // sync full account
true, // sync regular files in folder
false);
RemoteOperationResult result;
boolean repeat;
do {
repeat = false;
result = synchFolderOp.execute(getClient(), getStorageManager());
} while (repeat);
// synchronized folder -> notice to UI - ALWAYS, although !result.isSuccess
sendLocalBroadcast(EVENT_FULL_SYNC_FOLDER_CONTENTS_SYNCED, folder.getRemotePath(), result);
// check the result of synchronizing the folder
if (result.isSuccess() || result.getCode() == ResultCode.SYNC_CONFLICT) {
if (result.getCode() == ResultCode.SYNC_CONFLICT) {
mConflictsFound += synchFolderOp.getConflictsFound();
mFailsInFavouritesFound += synchFolderOp.getFailsInFileSyncsFound();
}
if (result.isSuccess()) {
// synchronize children folders
List<Pair<OCFile, Boolean>> children = synchFolderOp.getFoldersToVisit();
// beware of the 'hidden' recursion here!
syncSubfolders(children);
}
} else if (result.getCode() != ResultCode.FILE_NOT_FOUND) {
// in failures, the statistics for the global result are updated
if (RemoteOperationResult.ResultCode.UNAUTHORIZED.equals(result.getCode())) {
mSyncResult.stats.numAuthExceptions++;
} else if (result.getException() instanceof DavException) {
mSyncResult.stats.numParseExceptions++;
} else if (result.getException() instanceof IOException) {
mSyncResult.stats.numIoExceptions++;
}
mFailedResultsCounter++;
mLastFailedResult = result;
}
// else, ResultCode.FILE_NOT_FOUND is ignored, remote folder was
// removed from other thread or other client during the synchronization,
// before this thread fetched its contents
}
use of com.owncloud.android.operations.SynchronizeFolderOperation in project android by nextcloud.
the class OperationsService method newOperation.
/**
* Creates a new operation, as described by operationIntent.
* <p>
* TODO - move to ServiceHandler (probably)
*
* @param operationIntent Intent describing a new operation to queue and execute.
* @return Pair with the new operation object and the information about its target server.
*/
private Pair<Target, RemoteOperation> newOperation(Intent operationIntent) {
RemoteOperation operation = null;
Target target = null;
try {
if (!operationIntent.hasExtra(EXTRA_ACCOUNT) && !operationIntent.hasExtra(EXTRA_SERVER_URL)) {
Log_OC.e(TAG, "Not enough information provided in intent");
} else {
Account account = operationIntent.getParcelableExtra(EXTRA_ACCOUNT);
User user = toUser(account);
String serverUrl = operationIntent.getStringExtra(EXTRA_SERVER_URL);
target = new Target(account, (serverUrl == null) ? null : Uri.parse(serverUrl));
String action = operationIntent.getAction();
String remotePath;
String password;
ShareType shareType;
String newParentPath;
long shareId;
FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(user, getContentResolver());
switch(action) {
case ACTION_CREATE_SHARE_VIA_LINK:
remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
password = operationIntent.getStringExtra(EXTRA_SHARE_PASSWORD);
if (!TextUtils.isEmpty(remotePath)) {
operation = new CreateShareViaLinkOperation(remotePath, password, fileDataStorageManager);
}
break;
case ACTION_UPDATE_PUBLIC_SHARE:
shareId = operationIntent.getLongExtra(EXTRA_SHARE_ID, -1);
if (shareId > 0) {
UpdateShareViaLinkOperation updateLinkOperation = new UpdateShareViaLinkOperation(shareId, fileDataStorageManager);
password = operationIntent.getStringExtra(EXTRA_SHARE_PASSWORD);
updateLinkOperation.setPassword(password);
long expirationDate = operationIntent.getLongExtra(EXTRA_SHARE_EXPIRATION_DATE_IN_MILLIS, 0);
updateLinkOperation.setExpirationDateInMillis(expirationDate);
boolean hideFileDownload = operationIntent.getBooleanExtra(EXTRA_SHARE_HIDE_FILE_DOWNLOAD, false);
updateLinkOperation.setHideFileDownload(hideFileDownload);
if (operationIntent.hasExtra(EXTRA_SHARE_PUBLIC_LABEL)) {
updateLinkOperation.setLabel(operationIntent.getStringExtra(EXTRA_SHARE_PUBLIC_LABEL));
}
operation = updateLinkOperation;
}
break;
case ACTION_UPDATE_USER_SHARE:
shareId = operationIntent.getLongExtra(EXTRA_SHARE_ID, -1);
if (shareId > 0) {
UpdateSharePermissionsOperation updateShare = new UpdateSharePermissionsOperation(shareId, fileDataStorageManager);
int permissions = operationIntent.getIntExtra(EXTRA_SHARE_PERMISSIONS, -1);
updateShare.setPermissions(permissions);
long expirationDateInMillis = operationIntent.getLongExtra(EXTRA_SHARE_EXPIRATION_DATE_IN_MILLIS, 0L);
updateShare.setExpirationDateInMillis(expirationDateInMillis);
password = operationIntent.getStringExtra(EXTRA_SHARE_PASSWORD);
updateShare.setPassword(password);
operation = updateShare;
}
break;
case ACTION_UPDATE_SHARE_NOTE:
shareId = operationIntent.getLongExtra(EXTRA_SHARE_ID, -1);
String note = operationIntent.getStringExtra(EXTRA_SHARE_NOTE);
if (shareId > 0) {
operation = new UpdateNoteForShareOperation(shareId, note, fileDataStorageManager);
}
break;
case ACTION_CREATE_SHARE_WITH_SHAREE:
remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
String shareeName = operationIntent.getStringExtra(EXTRA_SHARE_WITH);
shareType = (ShareType) operationIntent.getSerializableExtra(EXTRA_SHARE_TYPE);
int permissions = operationIntent.getIntExtra(EXTRA_SHARE_PERMISSIONS, -1);
String noteMessage = operationIntent.getStringExtra(EXTRA_SHARE_NOTE);
String sharePassword = operationIntent.getStringExtra(EXTRA_SHARE_PASSWORD);
long expirationDateInMillis = operationIntent.getLongExtra(EXTRA_SHARE_EXPIRATION_DATE_IN_MILLIS, 0L);
boolean hideFileDownload = operationIntent.getBooleanExtra(EXTRA_SHARE_HIDE_FILE_DOWNLOAD, false);
if (!TextUtils.isEmpty(remotePath)) {
CreateShareWithShareeOperation createShareWithShareeOperation = new CreateShareWithShareeOperation(remotePath, shareeName, shareType, permissions, noteMessage, sharePassword, expirationDateInMillis, hideFileDownload, fileDataStorageManager);
if (operationIntent.hasExtra(EXTRA_SHARE_PUBLIC_LABEL)) {
createShareWithShareeOperation.setLabel(operationIntent.getStringExtra(EXTRA_SHARE_PUBLIC_LABEL));
}
operation = createShareWithShareeOperation;
}
break;
case ACTION_UPDATE_SHARE_INFO:
shareId = operationIntent.getLongExtra(EXTRA_SHARE_ID, -1);
if (shareId > 0) {
UpdateShareInfoOperation updateShare = new UpdateShareInfoOperation(shareId, fileDataStorageManager);
int permissionsToChange = operationIntent.getIntExtra(EXTRA_SHARE_PERMISSIONS, -1);
updateShare.setPermissions(permissionsToChange);
long expirationDateInMills = operationIntent.getLongExtra(EXTRA_SHARE_EXPIRATION_DATE_IN_MILLIS, 0L);
updateShare.setExpirationDateInMillis(expirationDateInMills);
password = operationIntent.getStringExtra(EXTRA_SHARE_PASSWORD);
updateShare.setPassword(password);
boolean fileDownloadHide = operationIntent.getBooleanExtra(EXTRA_SHARE_HIDE_FILE_DOWNLOAD, false);
updateShare.setHideFileDownload(fileDownloadHide);
if (operationIntent.hasExtra(EXTRA_SHARE_PUBLIC_LABEL)) {
updateShare.setLabel(operationIntent.getStringExtra(EXTRA_SHARE_PUBLIC_LABEL));
}
operation = updateShare;
}
break;
case ACTION_UNSHARE:
remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
shareId = operationIntent.getLongExtra(EXTRA_SHARE_ID, -1);
if (shareId > 0) {
operation = new UnshareOperation(remotePath, shareId, fileDataStorageManager);
}
break;
case ACTION_GET_SERVER_INFO:
operation = new GetServerInfoOperation(serverUrl, this);
break;
case ACTION_GET_USER_NAME:
operation = new GetUserInfoRemoteOperation();
break;
case ACTION_RENAME:
remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
String newName = operationIntent.getStringExtra(EXTRA_NEWNAME);
operation = new RenameFileOperation(remotePath, newName, fileDataStorageManager);
break;
case ACTION_REMOVE:
// Remove file or folder
OCFile file = operationIntent.getParcelableExtra(EXTRA_FILE);
boolean onlyLocalCopy = operationIntent.getBooleanExtra(EXTRA_REMOVE_ONLY_LOCAL, false);
boolean inBackground = operationIntent.getBooleanExtra(EXTRA_IN_BACKGROUND, false);
operation = new RemoveFileOperation(file, onlyLocalCopy, account, inBackground, getApplicationContext(), fileDataStorageManager);
break;
case ACTION_CREATE_FOLDER:
remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
operation = new CreateFolderOperation(remotePath, user, getApplicationContext(), fileDataStorageManager);
break;
case ACTION_SYNC_FILE:
remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
boolean syncFileContents = operationIntent.getBooleanExtra(EXTRA_SYNC_FILE_CONTENTS, true);
operation = new SynchronizeFileOperation(remotePath, user, syncFileContents, getApplicationContext(), fileDataStorageManager);
break;
case ACTION_SYNC_FOLDER:
remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
operation = new SynchronizeFolderOperation(// TODO remove this dependency from construction time
this, remotePath, user, // TODO remove this dependency from construction time
System.currentTimeMillis(), fileDataStorageManager);
break;
case ACTION_MOVE_FILE:
remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
newParentPath = operationIntent.getStringExtra(EXTRA_NEW_PARENT_PATH);
operation = new MoveFileOperation(remotePath, newParentPath, fileDataStorageManager);
break;
case ACTION_COPY_FILE:
remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
newParentPath = operationIntent.getStringExtra(EXTRA_NEW_PARENT_PATH);
operation = new CopyFileOperation(remotePath, newParentPath, fileDataStorageManager);
break;
case ACTION_CHECK_CURRENT_CREDENTIALS:
operation = new CheckCurrentCredentialsOperation(user, fileDataStorageManager);
break;
case ACTION_RESTORE_VERSION:
FileVersion fileVersion = operationIntent.getParcelableExtra(EXTRA_FILE_VERSION);
operation = new RestoreFileVersionRemoteOperation(fileVersion.getRemoteId(), fileVersion.getFileName());
break;
default:
// do nothing
break;
}
}
} catch (IllegalArgumentException e) {
Log_OC.e(TAG, "Bad information provided in intent: " + e.getMessage());
operation = null;
}
if (operation != null) {
return new Pair<>(target, operation);
} else {
return null;
}
}
use of com.owncloud.android.operations.SynchronizeFolderOperation in project android by owncloud.
the class SyncFolderHandler method cancel.
/**
* Cancels a pending or current sync' operation.
*
* @param account ownCloud {@link Account} where the remote file is stored.
* @param file A file in the queue of pending synchronizations
*/
public void cancel(Account account, OCFile file) {
if (account == null || file == null) {
Timber.e("Cannot cancel with NULL parameters");
return;
}
Pair<SynchronizeFolderOperation, String> removeResult = mPendingOperations.remove(account.name, file.getRemotePath());
SynchronizeFolderOperation synchronization = removeResult.first;
if (synchronization != null) {
synchronization.cancel();
} else {
// TODO synchronize?
if (mCurrentSyncOperation != null && mCurrentAccount != null && mCurrentSyncOperation.getRemotePath().startsWith(file.getRemotePath()) && account.name.equals(mCurrentAccount.name)) {
mCurrentSyncOperation.cancel();
}
}
}
Aggregations