Search in sources :

Example 86 with RemoteOperationResult

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();
}
Also used : ExistenceCheckRemoteOperation(com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult)

Example 87 with RemoteOperationResult

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;
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) RemoveRemoteShareOperation(com.owncloud.android.lib.resources.shares.RemoveRemoteShareOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) OCShare(com.owncloud.android.lib.resources.shares.OCShare) ArrayList(java.util.ArrayList)

Example 88 with RemoteOperationResult

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;
}
Also used : JSONObject(org.json.JSONObject) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) GetMethod(org.apache.commons.httpclient.methods.GetMethod) JSONException(org.json.JSONException) AccountManager(android.accounts.AccountManager) OwnCloudVersion(com.owncloud.android.lib.resources.status.OwnCloudVersion) JSONException(org.json.JSONException)

Example 89 with RemoteOperationResult

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();
}
Also used : ExistenceCheckRemoteOperation(com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult)

Example 90 with RemoteOperationResult

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;
}
Also used : CreateRemoteShareOperation(com.owncloud.android.lib.resources.shares.CreateRemoteShareOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) OCShare(com.owncloud.android.lib.resources.shares.OCShare)

Aggregations

RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)172 OCFile (com.owncloud.android.datamodel.OCFile)48 RemoteOperation (com.owncloud.android.lib.common.operations.RemoteOperation)24 ArrayList (java.util.ArrayList)24 FileDataStorageManager (com.owncloud.android.datamodel.FileDataStorageManager)22 IOException (java.io.IOException)22 Account (android.accounts.Account)19 User (com.nextcloud.client.account.User)18 OCShare (com.owncloud.android.lib.resources.shares.OCShare)18 File (java.io.File)18 OperationCancelledException (com.owncloud.android.lib.common.operations.OperationCancelledException)17 OwnCloudAccount (com.owncloud.android.lib.common.OwnCloudAccount)16 Context (android.content.Context)15 OwnCloudClient (com.owncloud.android.lib.common.OwnCloudClient)12 RemoteFile (com.owncloud.android.lib.resources.files.model.RemoteFile)12 FileNotFoundException (java.io.FileNotFoundException)12 Intent (android.content.Intent)11 JSONObject (org.json.JSONObject)11 Test (org.junit.Test)11 Uri (android.net.Uri)10