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;
}
use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by owncloud.
the class UploadFileOperation 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 CreateShareWithShareeOperation method run.
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
CreateRemoteShareOperation operation = new CreateRemoteShareOperation(mPath, mShareType, mShareeName, false, "", mPermissions);
operation.setGetShareDetails(true);
RemoteOperationResult result = operation.execute(client);
if (result.isSuccess()) {
if (result.getData().size() > 0) {
OCShare share = (OCShare) result.getData().get(0);
updateData(share);
}
}
return result;
}
Aggregations