Search in sources :

Example 6 with RemoteOperation

use of com.owncloud.android.lib.common.operations.RemoteOperation in project android by owncloud.

the class CreateShareViaLinkOperation method run.

@Override
protected RemoteOperationResult run(OwnCloudClient client) {
    // Check if the share link already exists
    RemoteOperation operation = new GetRemoteSharesForFileOperation(mPath, false, false);
    RemoteOperationResult result = operation.execute(client);
    // Create public link if doesn't exist yet
    boolean publicShareExists = false;
    if (result.isSuccess()) {
        OCShare share = null;
        for (int i = 0; i < result.getData().size(); i++) {
            share = (OCShare) result.getData().get(i);
            if (ShareType.PUBLIC_LINK.equals(share.getShareType())) {
                publicShareExists = true;
                break;
            }
        }
    }
    if (!publicShareExists) {
        CreateRemoteShareOperation createOp = new CreateRemoteShareOperation(mPath, ShareType.PUBLIC_LINK, "", false, mPassword, OCShare.DEFAULT_PERMISSION);
        createOp.setGetShareDetails(true);
        result = createOp.execute(client);
    }
    if (result.isSuccess()) {
        if (result.getData().size() > 0) {
            Object item = result.getData().get(0);
            if (item instanceof OCShare) {
                updateData((OCShare) item);
            } else {
                ArrayList<Object> data = result.getData();
                result = new RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND);
                result.setData(data);
            }
        } else {
            result = new RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND);
        }
    }
    return result;
}
Also used : CreateRemoteShareOperation(com.owncloud.android.lib.resources.shares.CreateRemoteShareOperation) RemoteOperation(com.owncloud.android.lib.common.operations.RemoteOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) OCShare(com.owncloud.android.lib.resources.shares.OCShare) GetRemoteSharesForFileOperation(com.owncloud.android.lib.resources.shares.GetRemoteSharesForFileOperation)

Example 7 with RemoteOperation

use of com.owncloud.android.lib.common.operations.RemoteOperation in project android by owncloud.

the class OperationsService method onStartCommand.

/**
     * Entry point to add a new operation to the queue of operations.
     * <p/>
     * New operations are added calling to startService(), resulting in a call to this method.
     * This ensures the service will keep on working although the caller activity goes away.
     */
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log_OC.d(TAG, "Starting command with id " + startId);
    // the rest of the operations are requested through the Binder
    if (ACTION_SYNC_FOLDER.equals(intent.getAction())) {
        if (!intent.hasExtra(EXTRA_ACCOUNT) || !intent.hasExtra(EXTRA_REMOTE_PATH)) {
            Log_OC.e(TAG, "Not enough information provided in intent");
            return START_NOT_STICKY;
        }
        Account account = intent.getParcelableExtra(EXTRA_ACCOUNT);
        String remotePath = intent.getStringExtra(EXTRA_REMOTE_PATH);
        Pair<Account, String> itemSyncKey = new Pair<Account, String>(account, remotePath);
        Pair<Target, RemoteOperation> itemToQueue = newOperation(intent);
        if (itemToQueue != null) {
            mSyncFolderHandler.add(account, remotePath, (SynchronizeFolderOperation) itemToQueue.second);
            Message msg = mSyncFolderHandler.obtainMessage();
            msg.arg1 = startId;
            msg.obj = itemSyncKey;
            mSyncFolderHandler.sendMessage(msg);
        }
    } else {
        Message msg = mOperationsHandler.obtainMessage();
        msg.arg1 = startId;
        mOperationsHandler.sendMessage(msg);
    }
    return START_NOT_STICKY;
}
Also used : Account(android.accounts.Account) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) RemoteOperation(com.owncloud.android.lib.common.operations.RemoteOperation) Message(android.os.Message) Pair(android.util.Pair)

Example 8 with RemoteOperation

use of com.owncloud.android.lib.common.operations.RemoteOperation in project android by owncloud.

the class OperationsService method dispatchResultToOperationListeners.

/**
     * Notifies the currently subscribed listeners about the end of an operation.
     *
     * @param operation         Finished operation.
     * @param result            Result of the operation.
     */
protected void dispatchResultToOperationListeners(final RemoteOperation operation, final RemoteOperationResult result) {
    int count = 0;
    Iterator<OnRemoteOperationListener> listeners = mOperationsBinder.mBoundListeners.keySet().iterator();
    while (listeners.hasNext()) {
        final OnRemoteOperationListener listener = listeners.next();
        final Handler handler = mOperationsBinder.mBoundListeners.get(listener);
        if (handler != null) {
            handler.post(new Runnable() {

                @Override
                public void run() {
                    listener.onRemoteOperationFinish(operation, result);
                }
            });
            count += 1;
        }
    }
    if (count == 0) {
        Pair<RemoteOperation, RemoteOperationResult> undispatched = new Pair<RemoteOperation, RemoteOperationResult>(operation, result);
        mUndispatchedFinishedOperations.put(((Runnable) operation).hashCode(), undispatched);
    }
    Log_OC.d(TAG, "Called " + count + " listeners");
}
Also used : RemoteOperation(com.owncloud.android.lib.common.operations.RemoteOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) OnRemoteOperationListener(com.owncloud.android.lib.common.operations.OnRemoteOperationListener) Handler(android.os.Handler) Pair(android.util.Pair)

Example 9 with RemoteOperation

use of com.owncloud.android.lib.common.operations.RemoteOperation in project android by owncloud.

the class DetectAuthenticationMethodOperation method run.

/**
     *  Performs the operation.
     * 
     *  Triggers a check of existence on the root folder of the server, granting
     *  that the request is not authenticated.
     *  
     *  Analyzes the result of check to find out what authentication method, if
     *  any, is requested by the server.
     */
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
    RemoteOperationResult result = null;
    AuthenticationMethod authMethod = AuthenticationMethod.UNKNOWN;
    RemoteOperation operation = new ExistenceCheckRemoteOperation("", mContext, false);
    client.clearCredentials();
    client.setFollowRedirects(false);
    // try to access the root folder, following redirections but not SAML SSO redirections
    result = operation.execute(client);
    String redirectedLocation = result.getRedirectedLocation();
    while (redirectedLocation != null && redirectedLocation.length() > 0 && !result.isIdPRedirection()) {
        client.setBaseUri(Uri.parse(result.getRedirectedLocation()));
        result = operation.execute(client);
        redirectedLocation = result.getRedirectedLocation();
    }
    // analyze response  
    if (result.getHttpCode() == HttpStatus.SC_UNAUTHORIZED) {
        String authRequest = ((result.getAuthenticateHeader()).trim()).toLowerCase();
        if (authRequest.startsWith("basic")) {
            authMethod = AuthenticationMethod.BASIC_HTTP_AUTH;
        } else if (authRequest.startsWith("bearer")) {
            authMethod = AuthenticationMethod.BEARER_TOKEN;
        }
    // else - fall back to UNKNOWN
    } else if (result.isSuccess()) {
        authMethod = AuthenticationMethod.NONE;
    } else if (result.isIdPRedirection()) {
        authMethod = AuthenticationMethod.SAML_WEB_SSO;
    }
    // else - fall back to UNKNOWN
    Log_OC.d(TAG, "Authentication method found: " + authenticationMethodToString(authMethod));
    if (!authMethod.equals(AuthenticationMethod.UNKNOWN)) {
        result = new RemoteOperationResult(true, result.getHttpCode(), result.getHttpPhrase(), null);
    }
    ArrayList<Object> data = new ArrayList<Object>();
    data.add(authMethod);
    result.setData(data);
    // same result instance, so that other errors
    return result;
// can be handled by the caller transparently
}
Also used : ExistenceCheckRemoteOperation(com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation) RemoteOperation(com.owncloud.android.lib.common.operations.RemoteOperation) ExistenceCheckRemoteOperation(com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) ArrayList(java.util.ArrayList)

Aggregations

RemoteOperation (com.owncloud.android.lib.common.operations.RemoteOperation)9 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)7 Pair (android.util.Pair)3 ExistenceCheckRemoteOperation (com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation)3 OCShare (com.owncloud.android.lib.resources.shares.OCShare)3 Account (android.accounts.Account)2 OwnCloudAccount (com.owncloud.android.lib.common.OwnCloudAccount)2 GetRemoteShareOperation (com.owncloud.android.lib.resources.shares.GetRemoteShareOperation)2 UpdateRemoteShareOperation (com.owncloud.android.lib.resources.shares.UpdateRemoteShareOperation)2 ArrayList (java.util.ArrayList)2 Handler (android.os.Handler)1 Message (android.os.Message)1 OCFile (com.owncloud.android.datamodel.OCFile)1 OnRemoteOperationListener (com.owncloud.android.lib.common.operations.OnRemoteOperationListener)1 CreateRemoteShareOperation (com.owncloud.android.lib.resources.shares.CreateRemoteShareOperation)1 GetRemoteSharesForFileOperation (com.owncloud.android.lib.resources.shares.GetRemoteSharesForFileOperation)1 ShareType (com.owncloud.android.lib.resources.shares.ShareType)1 GetRemoteUserInfoOperation (com.owncloud.android.lib.resources.users.GetRemoteUserInfoOperation)1 CheckCurrentCredentialsOperation (com.owncloud.android.operations.CheckCurrentCredentialsOperation)1 CopyFileOperation (com.owncloud.android.operations.CopyFileOperation)1