Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package org.usergrid.android.client;
import static org.springframework.util.StringUtils.arrayToDelimitedString;
import static org.springframework.util.StringUtils.tokenizeToStringArray;
import static org.usergrid.android.client.utils.ObjectUtils.isEmpty;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import org.codehaus.jackson.node.JsonNodeFactory;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;
import org.usergrid.android.client.callbacks.ApiResponseCallback;
import org.usergrid.android.client.callbacks.ClientAsyncTask;
import org.usergrid.android.client.callbacks.DeviceRegistrationCallback;
import org.usergrid.android.client.callbacks.GroupsRetrievedCallback;
import org.usergrid.android.client.callbacks.QueryResultsCallback;
import org.usergrid.java.client.entities.Device;
import org.usergrid.java.client.entities.Entity;
import org.usergrid.java.client.entities.Group;
import org.usergrid.java.client.entities.User;
import org.usergrid.java.client.response.ApiResponse;
import org.usergrid.android.client.utils.DeviceUuidFactory;
import android.content.Context;
import android.location.Location;
import android.util.Log;
/**
* The Client class for accessing the Usergrid API. Start by instantiating this
* class though the appropriate constructor.
*
*/
public class Client extends org.usergrid.java.client.Client {
private static final String TAG = "UsergridClient";
public static boolean FORCE_PUBLIC_API = false;
// Public API
public static String PUBLIC_API_URL = "http://api.usergrid.com";
// Local API of standalone server
public static String LOCAL_STANDALONE_API_URL = "http://localhost:8080";
// Local API of Tomcat server in Eclipse
public static String LOCAL_TOMCAT_API_URL = "http://localhost:8080/ROOT";
// Local API
public static String LOCAL_API_URL = LOCAL_STANDALONE_API_URL;
static RestTemplate restTemplate = new RestTemplate();
/**
* Default constructor for instantiating a client.
*/
public Client() {
init();
}
/**
* Instantiate client for a specific app
*
* @param applicationId
* the application id or name
*/
public Client(String applicationId) {
super(applicationId);
}
/**
* Log the user in and get a valid access token. Executes asynchronously in
* background and the callbacks are called in the UI thread.
*
* @param email
* @param password
* @param callback
*/
public void authorizeAppUserAsync(final String email,
final String password, final ApiResponseCallback callback) {
(new ClientAsyncTask(callback) {
@Override
public ApiResponse doTask() {
return authorizeAppUser(email, password);
}
}).execute();
}
/**
* Log the user in with their numeric pin-code and get a valid access token.
* Executes asynchronously in background and the callbacks are called in the
* UI thread.
*
* @param email
* @param pin
* @param callback
*/
public void authorizeAppUserViaPinAsync(final String email,
final String pin, final ApiResponseCallback callback) {
(new ClientAsyncTask(callback) {
@Override
public ApiResponse doTask() {
return authorizeAppUserViaPin(email, pin);
}
}).execute();
}
/**
* Log the user in with their numeric pin-code and get a valid access token.
* Executes asynchronously in background and the callbacks are called in the
* UI thread.
*
* @param email
* @param pin
* @param callback
*/
public void authorizeAppUserViaFacebookAsync(final String fb_access_token,
final ApiResponseCallback callback) {
(new ClientAsyncTask(callback) {
@Override
public ApiResponse doTask() {
return authorizeAppUserViaFacebook(fb_access_token);
}
}).execute();
}
/**
* Log the app in with it's client id and client secret key. Not recommended
* for production apps. Executes asynchronously in background and the
* callbacks are called in the UI thread.
*
* @param clientId
* @param clientSecret
* @param callback
*/
public void authorizeAppClientAsync(final String clientId,
final String clientSecret, final ApiResponseCallback callback) {
(new ClientAsyncTask(callback) {
@Override
public ApiResponse doTask() {
return authorizeAppClient(clientId, clientSecret);
}
}).execute();
}
/**
* Registers a device using the device's unique device ID. Executes
* asynchronously in background and the callbacks are called in the UI
* thread.
*
* @param context
* @param properties
* @param callback
*/
public void registerDeviceAsync(final Context context,
final Map properties,
final DeviceRegistrationCallback callback) {
(new ClientAsyncTask(callback) {
@Override
public Device doTask() {
UUID deviceId = new DeviceUuidFactory(context).getDeviceUuid();
return registerDevice(deviceId, properties);
}
}).execute();
}
/**
* Create a new entity on the server. Executes asynchronously in background
* and the callbacks are called in the UI thread.
*
* @param entity
* @param callback
*/
public void createEntityAsync(final Entity entity,
final ApiResponseCallback callback) {
(new ClientAsyncTask(callback) {
@Override
public ApiResponse doTask() {
return createEntity(entity);
}
}).execute();
}
/**
* Create a new entity on the server from a set of properties. Properties
* must include a "type" property. Executes asynchronously in background and
* the callbacks are called in the UI thread.
*
* @param properties
* @param callback
*/
public void createEntityAsync(final Map properties,
final ApiResponseCallback callback) {
(new ClientAsyncTask(callback) {
@Override
public ApiResponse doTask() {
return createEntity(properties);
}
}).execute();
}
/**
* Creates a user. Executes asynchronously in background and the callbacks
* are called in the UI thread.
*
* @param username
* @param name
* @param email
* @param password
* @param callback
*/
public void createUserAsync(final String username, final String name,
final String email, final String password,
final ApiResponseCallback callback) {
(new ClientAsyncTask(callback) {
@Override
public ApiResponse doTask() {
return createUser(username, name, email, password);
}
}).execute();
}
/**
* Get the groups for the user. Executes asynchronously in background and
* the callbacks are called in the UI thread.
*
* @param userId
* @param callback
*/
public void getGroupsForUserAsync(final String userId,
final GroupsRetrievedCallback callback) {
(new ClientAsyncTask