Search in sources :

Example 36 with RemoteOperationResult

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

Example 37 with RemoteOperationResult

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

Example 38 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 39 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 40 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)

Aggregations

RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)46 OCFile (com.owncloud.android.datamodel.OCFile)11 ArrayList (java.util.ArrayList)9 RemoteOperation (com.owncloud.android.lib.common.operations.RemoteOperation)7 OCShare (com.owncloud.android.lib.resources.shares.OCShare)7 FileDataStorageManager (com.owncloud.android.datamodel.FileDataStorageManager)6 ExistenceCheckRemoteOperation (com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation)6 OwnCloudAccount (com.owncloud.android.lib.common.OwnCloudAccount)5 OperationCancelledException (com.owncloud.android.lib.common.operations.OperationCancelledException)5 File (java.io.File)5 IOException (java.io.IOException)5 Account (android.accounts.Account)4 Uri (android.net.Uri)4 Intent (android.content.Intent)3 RemoteFile (com.owncloud.android.lib.resources.files.RemoteFile)3 GetRemoteSharesForFileOperation (com.owncloud.android.lib.resources.shares.GetRemoteSharesForFileOperation)3 UserInfo (com.owncloud.android.lib.resources.users.GetRemoteUserInfoOperation.UserInfo)3 AccountManager (android.accounts.AccountManager)2 Pair (android.util.Pair)2 OwnCloudClient (com.owncloud.android.lib.common.OwnCloudClient)2