use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by owncloud.
the class FileSyncAdapter method updateOCVersion.
/**
* Updates the locally stored version value of the ownCloud server
*/
private void updateOCVersion() {
UpdateOCVersionOperation update = new UpdateOCVersionOperation(getAccount(), getContext());
RemoteOperationResult result = update.execute(getClient());
if (!result.isSuccess()) {
mLastFailedResult = result;
}
}
use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by owncloud.
the class SynchronizeFolderOperation method run.
/**
* Performs the synchronization.
*
* {@inheritDoc}
*/
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
RemoteOperationResult result;
mFailsInFileSyncsFound = 0;
mConflictsFound = 0;
mForgottenLocalFiles.clear();
try {
// get locally cached information about folder
mLocalFolder = getStorageManager().getFileByPath(mRemotePath);
if (mPushOnly) {
// assuming there is no update in the server side, still need to handle local changes
Log_OC.i(TAG, "Push only sync of " + mAccount.name + mRemotePath);
preparePushOfLocalChanges();
syncContents();
//pushOnlySync();
result = new RemoteOperationResult(ResultCode.OK);
} else {
// get list of files in folder from remote server
result = fetchRemoteFolder(client);
if (result.isSuccess()) {
// success - merge updates in server with local state
mergeRemoteFolder(result.getData());
syncContents();
} else {
// fail fetching the server
if (result.getCode() == ResultCode.FILE_NOT_FOUND) {
removeLocalFolder();
}
if (result.isException()) {
Log_OC.e(TAG, "Checked " + mAccount.name + mRemotePath + " : " + result.getLogMessage(), result.getException());
} else {
Log_OC.e(TAG, "Checked " + mAccount.name + mRemotePath + " : " + result.getLogMessage());
}
}
}
} catch (OperationCancelledException e) {
result = new RemoteOperationResult(e);
}
return result;
}
use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by owncloud.
the class UnshareOperation method existsFile.
private boolean existsFile(OwnCloudClient client, String remotePath) {
ExistenceCheckRemoteOperation existsOperation = new ExistenceCheckRemoteOperation(remotePath, mContext, false);
RemoteOperationResult result = existsOperation.execute(client);
return result.isSuccess();
}
use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by owncloud.
the class UnshareOperation method run.
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
RemoteOperationResult result = null;
// Get Share for a file
OCShare share = getStorageManager().getFirstShareByPathAndType(mRemotePath, mShareType, mShareWith);
if (share != null) {
OCFile file = getStorageManager().getFileByPath(mRemotePath);
RemoveRemoteShareOperation operation = new RemoveRemoteShareOperation((int) share.getRemoteId());
result = operation.execute(client);
if (result.isSuccess()) {
Log_OC.d(TAG, "Share id = " + share.getRemoteId() + " deleted");
if (ShareType.PUBLIC_LINK.equals(mShareType)) {
file.setShareViaLink(false);
file.setPublicLink("");
} else if (ShareType.USER.equals(mShareType) || ShareType.GROUP.equals(mShareType) || ShareType.FEDERATED.equals(mShareType)) {
// Check if it is the last share
ArrayList<OCShare> sharesWith = getStorageManager().getSharesWithForAFile(mRemotePath, getStorageManager().getAccount().name);
if (sharesWith.size() == 1) {
file.setShareWithSharee(false);
}
}
getStorageManager().saveFile(file);
getStorageManager().removeShare(share);
} else if (result.getCode() != ResultCode.SERVICE_UNAVAILABLE && !existsFile(client, file.getRemotePath())) {
// unshare failed because file was deleted before
getStorageManager().removeFile(file, true, true);
}
} else {
result = new RemoteOperationResult(ResultCode.SHARE_NOT_FOUND);
}
return result;
}
use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by owncloud.
the class UpdateOCVersionOperation method run.
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
AccountManager accountMngr = AccountManager.get(mContext);
String statUrl = accountMngr.getUserData(mAccount, Constants.KEY_OC_BASE_URL);
statUrl += AccountUtils.STATUS_PATH;
RemoteOperationResult result = null;
GetMethod getMethod = null;
try {
getMethod = new GetMethod(statUrl);
int status = client.executeMethod(getMethod);
if (status != HttpStatus.SC_OK) {
result = new RemoteOperationResult(false, getMethod);
client.exhaustResponse(getMethod.getResponseBodyAsStream());
} else {
String response = getMethod.getResponseBodyAsString();
if (response != null) {
JSONObject json = new JSONObject(response);
if (json != null && json.getString("version") != null) {
String version = json.getString("version");
mOwnCloudVersion = new OwnCloudVersion(version);
if (mOwnCloudVersion.isVersionValid()) {
accountMngr.setUserData(mAccount, Constants.KEY_OC_VERSION, mOwnCloudVersion.getVersion());
Log_OC.d(TAG, "Got new OC version " + mOwnCloudVersion.toString());
result = new RemoteOperationResult(ResultCode.OK);
} else {
Log_OC.w(TAG, "Invalid version number received from server: " + json.getString("version"));
result = new RemoteOperationResult(RemoteOperationResult.ResultCode.BAD_OC_VERSION);
}
}
}
if (result == null) {
result = new RemoteOperationResult(RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED);
}
}
Log_OC.i(TAG, "Check for update of ownCloud server version at " + client.getWebdavUri() + ": " + result.getLogMessage());
} catch (JSONException e) {
result = new RemoteOperationResult(RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED);
Log_OC.e(TAG, "Check for update of ownCloud server version at " + client.getWebdavUri() + ": " + result.getLogMessage(), e);
} catch (Exception e) {
result = new RemoteOperationResult(e);
Log_OC.e(TAG, "Check for update of ownCloud server version at " + client.getWebdavUri() + ": " + result.getLogMessage(), e);
} finally {
if (getMethod != null)
getMethod.releaseConnection();
}
return result;
}
Aggregations