use of com.owncloud.android.lib.common.operations.RemoteOperationResult 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.
*
* If download or upload is needed, request the operation to the corresponding service and goes
* on.
*/
private void syncContents() throws OperationCancelledException {
Log_OC.v(TAG, "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) {
Log_OC.e(TAG, // Vs " av-off file"
"Error while synchronizing file : " + contentsResult.getLogMessage(), contentsResult.getException());
} else {
Log_OC.e(TAG, "Error while synchronizing file : " + 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.lib.common.operations.RemoteOperationResult in project android by owncloud.
the class UpdateSharePermissionsOperation method run.
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
// ShareType.USER | ShareType.GROUP
OCShare share = getStorageManager().getShareById(mShareId);
if (share == null) {
// TODO try to get remote share before failing?
return new RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND);
}
mPath = share.getPath();
// Update remote share with password
UpdateRemoteShareOperation updateOp = new UpdateRemoteShareOperation(share.getRemoteId());
updateOp.setPermissions(mPermissions);
RemoteOperationResult result = updateOp.execute(client);
if (result.isSuccess()) {
RemoteOperation getShareOp = new GetRemoteShareOperation(share.getRemoteId());
result = getShareOp.execute(client);
if (result.isSuccess()) {
share = (OCShare) result.getData().get(0);
// TODO check permissions are being saved
updateData(share);
}
}
return result;
}
use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by owncloud.
the class AuthenticatorActivity method createAccount.
/**
* Creates a new account through the Account Authenticator that started this activity.
*
* This makes the account permanent.
*
* TODO Decide how to name the OAuth accounts
*/
private boolean createAccount(RemoteOperationResult authResult) {
/// create and save new ownCloud account
boolean isOAuth = AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType()).equals(mAuthTokenType);
boolean isSaml = AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).equals(mAuthTokenType);
String lastPermanentLocation = authResult.getLastPermanentLocation();
if (lastPermanentLocation != null) {
mServerInfo.mBaseUrl = AccountUtils.trimWebdavSuffix(lastPermanentLocation);
}
Uri uri = Uri.parse(mServerInfo.mBaseUrl);
String username = mUsernameInput.getText().toString().trim();
if (isOAuth) {
username = "OAuth_user" + (new java.util.Random(System.currentTimeMillis())).nextLong();
}
String accountName = com.owncloud.android.lib.common.accounts.AccountUtils.buildAccountName(uri, username);
Account newAccount = new Account(accountName, MainApp.getAccountType());
if (AccountUtils.exists(newAccount, getApplicationContext())) {
// fail - not a new account, but an existing one; disallow
RemoteOperationResult result = new RemoteOperationResult(ResultCode.ACCOUNT_NOT_NEW);
updateAuthStatusIconAndText(result);
showAuthStatus();
Log_OC.d(TAG, result.getLogMessage());
return false;
} else {
mAccount = newAccount;
if (isOAuth || isSaml) {
// with external authorizations, the password is never input in the app
mAccountMgr.addAccountExplicitly(mAccount, "", null);
} else {
mAccountMgr.addAccountExplicitly(mAccount, mPasswordInput.getText().toString(), null);
}
// include account version with the new account
mAccountMgr.setUserData(mAccount, Constants.KEY_OC_ACCOUNT_VERSION, Integer.toString(AccountUtils.ACCOUNT_VERSION));
/// add the new account as default in preferences, if there is none already
Account defaultAccount = AccountUtils.getCurrentOwnCloudAccount(this);
if (defaultAccount == null) {
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
editor.putString("select_oc_account", accountName);
editor.commit();
}
/// prepare result to return to the Authenticator
// TODO check again what the Authenticator makes with it; probably has the same
// effect as addAccountExplicitly, but it's not well done
final Intent intent = new Intent();
intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, MainApp.getAccountType());
intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, mAccount.name);
intent.putExtra(AccountManager.KEY_USERDATA, username);
if (isOAuth || isSaml) {
mAccountMgr.setAuthToken(mAccount, mAuthTokenType, mAuthToken);
}
/// add user data to the new account; TODO probably can be done in the last parameter
// addAccountExplicitly, or in KEY_USERDATA
mAccountMgr.setUserData(mAccount, Constants.KEY_OC_VERSION, mServerInfo.mVersion.getVersion());
mAccountMgr.setUserData(mAccount, Constants.KEY_OC_BASE_URL, mServerInfo.mBaseUrl);
if (authResult.getData() != null) {
try {
UserInfo userInfo = (UserInfo) authResult.getData().get(0);
mAccountMgr.setUserData(mAccount, Constants.KEY_DISPLAY_NAME, userInfo.mDisplayName);
} catch (ClassCastException c) {
Log_OC.w(TAG, "Couldn't get display name for " + username);
}
} else {
Log_OC.w(TAG, "Couldn't get display name for " + username);
}
if (isSaml) {
mAccountMgr.setUserData(mAccount, Constants.KEY_SUPPORTS_SAML_WEB_SSO, "TRUE");
} else if (isOAuth) {
mAccountMgr.setUserData(mAccount, Constants.KEY_SUPPORTS_OAUTH2, "TRUE");
}
setAccountAuthenticatorResult(intent.getExtras());
setResult(RESULT_OK, intent);
return true;
}
}
use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by owncloud.
the class AuthenticatorAsyncTask method doInBackground.
@Override
protected RemoteOperationResult doInBackground(Object... params) {
RemoteOperationResult result;
if (params != null && params.length == 2) {
String url = (String) params[0];
OwnCloudCredentials credentials = (OwnCloudCredentials) params[1];
// Client
Uri uri = Uri.parse(url);
OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(uri, mContext, true);
client.setCredentials(credentials);
// Operation - try credentials
ExistenceCheckRemoteOperation operation = new ExistenceCheckRemoteOperation(REMOTE_PATH, mContext, SUCCESS_IF_ABSENT);
result = operation.execute(client);
String targetUrlAfterPermanentRedirection = null;
if (operation.wasRedirected()) {
RedirectionPath redirectionPath = operation.getRedirectionPath();
targetUrlAfterPermanentRedirection = redirectionPath.getLastPermanentLocation();
}
// Operation - get display name
if (result.isSuccess()) {
GetRemoteUserInfoOperation remoteUserNameOperation = new GetRemoteUserInfoOperation();
if (targetUrlAfterPermanentRedirection != null) {
// we can't assume that any subpath of the domain is correctly redirected; ugly stuff
client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(AccountUtils.trimWebdavSuffix(targetUrlAfterPermanentRedirection)), mContext, true);
client.setCredentials(credentials);
}
result = remoteUserNameOperation.execute(client);
}
// let the caller knows what is real URL that should be accessed for the account
// being authenticated if the initial URL is being redirected permanently (HTTP code 301)
result.setLastPermanentLocation(targetUrlAfterPermanentRedirection);
} else {
result = new RemoteOperationResult(RemoteOperationResult.ResultCode.UNKNOWN_ERROR);
}
return result;
}
use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by owncloud.
the class CopyFileOperation method run.
/**
* Performs the operation.
*
* @param client Client object to communicate with the remote ownCloud server.
*/
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
RemoteOperationResult result;
/// 1. check copy validity
if (mTargetParentPath.startsWith(mSrcPath)) {
return new RemoteOperationResult(ResultCode.INVALID_COPY_INTO_DESCENDANT);
}
mFile = getStorageManager().getFileByPath(mSrcPath);
if (mFile == null) {
return new RemoteOperationResult(ResultCode.FILE_NOT_FOUND);
}
/// 2. remote copy
String targetPath = mTargetParentPath + mFile.getFileName();
if (mFile.isFolder()) {
targetPath += OCFile.PATH_SEPARATOR;
}
CopyRemoteFileOperation operation = new CopyRemoteFileOperation(mSrcPath, targetPath, false);
result = operation.execute(client);
/// 3. local copy
if (result.isSuccess()) {
getStorageManager().copyLocalFile(mFile, targetPath);
}
return result;
}
Aggregations