use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by nextcloud.
the class GetCapabilitiesOperation method run.
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
final FileDataStorageManager storageManager = getStorageManager();
OCCapability currentCapability = null;
if (!storageManager.getUser().isAnonymous()) {
currentCapability = storageManager.getCapability(storageManager.getUser().getAccountName());
}
RemoteOperationResult result = new GetCapabilitiesRemoteOperation(currentCapability).execute(client);
if (result.isSuccess() && result.getData() != null && result.getData().size() > 0) {
// Read data from the result
OCCapability capability = (OCCapability) result.getData().get(0);
// Save the capabilities into database
storageManager.saveCapabilities(capability);
}
return result;
}
use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by nextcloud.
the class MoveFileOperation method run.
/**
* Performs the operation.
*
* @param client Client object to communicate with the remote ownCloud server.
*/
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
// / 1. check move validity
if (targetParentPath.startsWith(srcPath)) {
return new RemoteOperationResult(ResultCode.INVALID_MOVE_INTO_DESCENDANT);
}
OCFile file = getStorageManager().getFileByPath(srcPath);
if (file == null) {
return new RemoteOperationResult(ResultCode.FILE_NOT_FOUND);
}
// / 2. remote move
String targetPath = targetParentPath + file.getFileName();
if (file.isFolder()) {
targetPath += OCFile.PATH_SEPARATOR;
}
RemoteOperationResult result = new MoveFileRemoteOperation(srcPath, targetPath, false).execute(client);
// / 3. local move
if (result.isSuccess()) {
getStorageManager().moveLocalFile(file, targetPath, targetParentPath);
}
return result;
}
use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by nextcloud.
the class RichDocumentsCreateAssetOperation method run.
protected RemoteOperationResult run(OwnCloudClient client) {
RemoteOperationResult result;
Utf8PostMethod postMethod = null;
try {
postMethod = new Utf8PostMethod(client.getBaseUri() + ASSET_URL);
postMethod.setParameter(PARAMETER_PATH, path);
postMethod.setParameter(PARAMETER_FORMAT, PARAMETER_FORMAT_VALUE);
// remote request
postMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
int status = client.executeMethod(postMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT);
if (status == HttpStatus.SC_OK) {
String response = postMethod.getResponseBodyAsString();
// Parse the response
JSONObject respJSON = new JSONObject(response);
String url = respJSON.getString(NODE_URL);
result = new RemoteOperationResult(true, postMethod);
result.setSingleData(url);
} else {
result = new RemoteOperationResult(false, postMethod);
client.exhaustResponse(postMethod.getResponseBodyAsStream());
}
} catch (Exception e) {
result = new RemoteOperationResult(e);
Log_OC.e(TAG, "Create asset for richdocuments with path " + path + " failed: " + result.getLogMessage(), result.getException());
} finally {
if (postMethod != null) {
postMethod.releaseConnection();
}
}
return result;
}
use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by nextcloud.
the class RefreshFolderOperation method updateOCVersion.
private void updateOCVersion(OwnCloudClient client) {
UpdateOCVersionOperation update = new UpdateOCVersionOperation(user.toPlatformAccount(), mContext);
RemoteOperationResult result = update.execute(client);
if (result.isSuccess()) {
// Update Capabilities for this account
updateCapabilities();
}
}
use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by nextcloud.
the class RefreshFolderOperation method refreshSharesForFolder.
/**
* Syncs the Share resources for the files contained in the folder refreshed (children, not deeper descendants).
*
* @param client Handler of a session with an OC server.
* @return The result of the remote operation retrieving the Share resources in the folder refreshed by
* the operation.
*/
private RemoteOperationResult refreshSharesForFolder(OwnCloudClient client) {
RemoteOperationResult result;
// remote request
GetSharesForFileRemoteOperation operation = new GetSharesForFileRemoteOperation(mLocalFolder.getRemotePath(), true, true);
result = operation.execute(client);
if (result.isSuccess()) {
// update local database
ArrayList<OCShare> shares = new ArrayList<>();
OCShare share;
for (Object obj : result.getData()) {
share = (OCShare) obj;
if (!ShareType.NO_SHARED.equals(share.getShareType())) {
shares.add(share);
}
}
mStorageManager.saveSharesInFolder(shares, mLocalFolder);
}
return result;
}
Aggregations