Android Open Source - cloudmine-android Access List Controller






From Project

Back to project page cloudmine-android.

License

The source code is released under:

Copyright (c) 2012 CloudMine LLC, http://cloudmine.me Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software")...

If you think the Android project cloudmine-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.cloudmine.api;
//from   w  w  w .ja  v a  2  s . c  om
import android.content.Context;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.cloudmine.api.rest.BaseAccessListCreateRequest;
import com.cloudmine.api.rest.BaseAccessListLoadRequest;
import com.cloudmine.api.rest.CloudMineRequest;
import com.cloudmine.api.rest.SharedRequestQueueHolders;
import com.cloudmine.api.rest.callbacks.LoginResponseCallback;
import com.cloudmine.api.rest.response.CMObjectResponse;
import com.cloudmine.api.rest.response.CreationResponse;
import com.cloudmine.api.rest.response.LoginResponse;
import org.apache.http.auth.AuthenticationException;

/**
 * <br>Copyright CloudMine LLC. All rights reserved
 * <br> See LICENSE file included with SDK for details.
 */
public class AccessListController extends JavaAccessListController {

    /**
     * Load the ACLs belonging to the user who is associated with the given sessionToken
     * @param context the activity context that will be used to cancel this request
     * @param sessionToken A valid sessionToken for the user who is going to log in
     * @param successListener
     * @param errorListener
     * @return
     */
    public static CloudMineRequest load(Context context, CMSessionToken sessionToken, Response.Listener<CMObjectResponse> successListener, Response.ErrorListener errorListener) {
        BaseAccessListLoadRequest request = new BaseAccessListLoadRequest(sessionToken, null, null, successListener,  errorListener);
        SharedRequestQueueHolders.getRequestQueue(context).add(request);
        return request;
    }


    /**
     * Create a new JavaAccessListController that grants no privileges and contains no users. It grants permissions to
     * objects owned by the given user
     */
    public AccessListController(JavaCMUser owner) {
        super(owner);
    }

    /**
     * Instantiate a new JavaAccessListController owned by the specified user that grants the specified permissions
     * @param owner
     * @param permissions permissions
     */
    public AccessListController(JavaCMUser owner, CMAccessPermission... permissions) {
        super(owner, permissions);
    }

    protected AccessListController() {
        super();
    }

    /**
     * WARNING: If the user associated with this ACL is not logged in, you will NOT receive the ACL create
     * request as a return value; instead, you will return {@link com.cloudmine.api.rest.CloudMineRequest#FAKE_REQUEST}
     * as the system needs to log the user in first. If you want to guarantee you will receive the actual request,
     * you should make use of the {@link #save(android.content.Context, CMSessionToken, com.android.volley.Response.Listener, com.android.volley.Response.ErrorListener)} method
     * @param context the activity context that will be used to cancel this request
     * @param successListener
     * @param errorListener
     * @return the submitted request IFF the associated user is logged in; {@link com.cloudmine.api.rest.CloudMineRequest#FAKE_REQUEST} otherwise
     */
    public CloudMineRequest save(final Context context, final Response.Listener<CreationResponse> successListener, final Response.ErrorListener errorListener) {
        JavaCMUser user = getUser();
        if(user == null) {
            errorListener.onErrorResponse(new VolleyError(new IllegalStateException("Cannot save an ACL without an owner")));
            return CloudMineRequest.FAKE_REQUEST;
        }
        CMSessionToken sessionToken = user.getSessionToken();
        if(sessionToken == null || sessionToken.getSessionToken().equals(CMSessionToken.INVALID_TOKEN)) {
            if(user instanceof BaseCMUser) {
                ((BaseCMUser)user).login(context, null, null, new Response.Listener<LoginResponse>() {
                    @Override
                    public void onResponse(LoginResponse loginResponse) {
                        save(context, loginResponse.getSessionToken(), successListener, errorListener);
                    }
                }, errorListener);
            } else {
                user.login(new LoginResponseCallback() {
                    public void onCompletion(LoginResponse loginResponse) {
                        if(loginResponse.wasSuccess()) {
                            save(context, loginResponse.getSessionToken(), successListener, errorListener);
                        } else {
                            errorListener.onErrorResponse(new VolleyError(new AuthenticationException("Unable to log user in to save ACL")));
                        }
                    }

                    public void onFailure(Throwable throwable,  String msg) {
                        errorListener.onErrorResponse(new VolleyError(throwable));
                    }
                });
            }
        } else {
            return save(context, sessionToken, successListener, errorListener);
        }
        return CloudMineRequest.FAKE_REQUEST;
    }

    /**
     * Save this ACL with the user associated with the given CMSessionToken as the owner.
     * Note: this overrides the user specified in the constructor
     * @param context the activity context that will be used to cancel this request
     * @param sessionToken a sessionToken belonging to the user who will own this ACL
     * @param successListener
     * @param errorListener
     * @return the submitted request
     */
    public CloudMineRequest save(Context context, CMSessionToken sessionToken, Response.Listener<CreationResponse> successListener, Response.ErrorListener errorListener) {
        CloudMineRequest request = new BaseAccessListCreateRequest(this, sessionToken, null, successListener, errorListener);
        SharedRequestQueueHolders.getRequestQueue(context).add(request);
        return request;
    }
}




Java Source Code List

com.cloudmine.api.AccessListController.java
com.cloudmine.api.BaseCMUser.java
com.cloudmine.api.BaseCacheableCMFile.java
com.cloudmine.api.CMAndroidSocial.java
com.cloudmine.api.CMCreditCard.java
com.cloudmine.api.CMSharedPreferencesConstants.java
com.cloudmine.api.CurrentHandlerHavers.java
com.cloudmine.api.DeviceIdentifier.java
com.cloudmine.api.HasHandler.java
com.cloudmine.api.LocallySavable.java
com.cloudmine.api.db.BaseLocallySavableCMAccessList.java
com.cloudmine.api.db.BaseLocallySavableCMObject.java
com.cloudmine.api.db.CMObjectDBOpenHelper.java
com.cloudmine.api.db.LocallySavableCMGeoPoint.java
com.cloudmine.api.db.RequestConstants.java
com.cloudmine.api.db.RequestDBObject.java
com.cloudmine.api.db.RequestDBOpenHelper.java
com.cloudmine.api.db.RequestPerformerService.java
com.cloudmine.api.gui.AuthenticationDialog.java
com.cloudmine.api.gui.VolleyAuthenticationDialog.java
com.cloudmine.api.loopj.AsyncHttpClient.java
com.cloudmine.api.loopj.AsyncHttpRequest.java
com.cloudmine.api.loopj.AsyncHttpResponseHandler.java
com.cloudmine.api.loopj.PersistentCookieStore.java
com.cloudmine.api.loopj.RequestParams.java
com.cloudmine.api.loopj.RetryHandler.java
com.cloudmine.api.loopj.SerializableCookie.java
com.cloudmine.api.loopj.SimpleMultipartEntity.java
com.cloudmine.api.rest.AndroidAsynchronousHttpClient.java
com.cloudmine.api.rest.AndroidBase64Encoder.java
com.cloudmine.api.rest.AndroidHeaderFactory.java
com.cloudmine.api.rest.AndroidUserCMWebService.java
com.cloudmine.api.rest.BaseAccessListCreateRequest.java
com.cloudmine.api.rest.BaseAccessListLoadRequest.java
com.cloudmine.api.rest.BaseAccessListModificationRequest.java
com.cloudmine.api.rest.BaseAddPaymentMethodRequest.java
com.cloudmine.api.rest.BaseChangeUserIdentifierRequest.java
com.cloudmine.api.rest.BaseChangeUserPasswordRequest.java
com.cloudmine.api.rest.BaseChargeCardRequest.java
com.cloudmine.api.rest.BaseFileCreationRequest.java
com.cloudmine.api.rest.BaseFileDeleteRequest.java
com.cloudmine.api.rest.BaseFileLoadRequest.java
com.cloudmine.api.rest.BaseImageLoadRequest.java
com.cloudmine.api.rest.BaseLoadPaymentMethodsRequest.java
com.cloudmine.api.rest.BaseLoadUserProfilesRequest.java
com.cloudmine.api.rest.BaseObjectDeleteRequest.java
com.cloudmine.api.rest.BaseObjectLoadRequest.java
com.cloudmine.api.rest.BaseObjectModificationRequest.java
com.cloudmine.api.rest.BaseProfileLoadRequest.java
com.cloudmine.api.rest.BaseProfileUpdateRequest.java
com.cloudmine.api.rest.BaseRemovePaymentMethodRequest.java
com.cloudmine.api.rest.BaseResetPasswordRequest.java
com.cloudmine.api.rest.BaseSnippetRequest.java
com.cloudmine.api.rest.BaseUserCreationRequest.java
com.cloudmine.api.rest.BaseUserLoginRequest.java
com.cloudmine.api.rest.BaseUserLogoutRequest.java
com.cloudmine.api.rest.CMImageLoader.java
com.cloudmine.api.rest.CMNetwork.java
com.cloudmine.api.rest.CloudMineRequest.java
com.cloudmine.api.rest.CompleteSocialLoginRequest.java
com.cloudmine.api.rest.DialogListener.java
com.cloudmine.api.rest.DiskBitmapCache.java
com.cloudmine.api.rest.ObjectLoadRequestBuilder.java
com.cloudmine.api.rest.OkHttpStack.java
com.cloudmine.api.rest.RequestBuilder.java
com.cloudmine.api.rest.SharedRequestQueueHolders.java
com.cloudmine.api.rest.VolleyAsynchronousHttpClient.java
com.cloudmine.api.rest.callbacks.AndroidCallback.java
com.cloudmine.api.rest.callbacks.PaymentResponseCallback.java
com.cloudmine.api.rest.response.PaymentResponse.java