Repository: usergrid Updated Branches: refs/heads/master 49e0f50bd -> ae5684164
http://git-wip-us.apache.org/repos/asf/usergrid/blob/7e0ffbc0/sdks/android/src/main/java/org/apache/usergrid/android/sdk/entities/User.java ---------------------------------------------------------------------- diff --git a/sdks/android/src/main/java/org/apache/usergrid/android/sdk/entities/User.java b/sdks/android/src/main/java/org/apache/usergrid/android/sdk/entities/User.java deleted file mode 100755 index 8807ada..0000000 --- a/sdks/android/src/main/java/org/apache/usergrid/android/sdk/entities/User.java +++ /dev/null @@ -1,315 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.usergrid.android.sdk.entities; - -import static org.apache.usergrid.android.sdk.utils.JsonUtils.getBooleanProperty; -import static org.apache.usergrid.android.sdk.utils.JsonUtils.setBooleanProperty; -import static org.apache.usergrid.android.sdk.utils.JsonUtils.setStringProperty; -import static com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion.NON_NULL; - -import java.util.List; - -import org.apache.usergrid.android.sdk.UGClient; -import org.apache.usergrid.android.sdk.response.ApiResponse; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; - -/** - * Models the 'user' entity as a local object. - * - * @see <a href="http://apigee.com/docs/app-services/content/user-management">User entity documentation</a> - */ -public class User extends Entity { - - public final static String ENTITY_TYPE = "user"; - - public final static String PROPERTY_USERNAME = "username"; - public final static String PROPERTY_EMAIL = "email"; - public final static String PROPERTY_NAME = "name"; - public final static String PROPERTY_FIRSTNAME = "firstname"; - public final static String PROPERTY_MIDDLENAME = "middlename"; - public final static String PROPERTY_LASTNAME = "lastname"; - public final static String PROPERTY_ACTIVATED = "activated"; - public final static String PROPERTY_PICTURE = "picture"; - public final static String PROPERTY_DISABLED = "disabled"; - - public static final String OLD_PASSWORD = "oldpassword"; - public static final String NEW_PASSWORD = "newpassword"; - - /** - * Checks if the provided entity 'type' equals 'user'. - * - * @return Boolen true/false - */ - public static boolean isSameType(String type) { - return type.equals(ENTITY_TYPE); - } - - /** - * Default constructor for the User object. Sets the 'type' property to 'user'. - */ - public User() { - setType(ENTITY_TYPE); - } - - /** - * Constructs the User object with a UGClient. - * Sets the 'type' property to 'user'. - * - * @param UGClient an instance of the UGClient class - */ - public User(UGClient client) { - super(client); - setType(ENTITY_TYPE); - } - - /** - * Constructs the User object from an Entity object. Sets the - * properties of the User identical to Entity, except the 'type' - * property is set to 'user' no matter what the Entity type is. - * - * @param entity an Entity object - */ - public User(Entity entity) { - super(entity.getUGClient()); - properties = entity.properties; - setType(ENTITY_TYPE); - } - - /** - * Returns the type property of the User object. Should always - * be 'user' - * - * @return the type property of the User object - */ - @Override - @JsonIgnore - public String getNativeType() { - return ENTITY_TYPE; - } - - /** - * Gets the properties already set in User and adds the following - * user-specific properties: username, email. name, firstname, - * middlename, lastname, activated, picture, disabled. - * - * @return a List object containing the properties of the User - */ - @Override - @JsonIgnore - public List<String> getPropertyNames() { - List<String> properties = super.getPropertyNames(); - properties.add(PROPERTY_USERNAME); - properties.add(PROPERTY_EMAIL); - properties.add(PROPERTY_NAME); - properties.add(PROPERTY_FIRSTNAME); - properties.add(PROPERTY_MIDDLENAME); - properties.add(PROPERTY_LASTNAME); - properties.add(PROPERTY_ACTIVATED); - properties.add(PROPERTY_PICTURE); - properties.add(PROPERTY_DISABLED); - return properties; - } - - /** - * Returns the value of the 'username' property currently - * set in the User object. - * - * @return the value of the username property - */ - @JsonSerialize(include = NON_NULL) - public String getUsername() { - return getStringProperty(PROPERTY_USERNAME); - } - - /** - * Sets the username property in the User object. - * - * @param username the username - */ - public void setUsername(String username) { - setStringProperty(properties, PROPERTY_USERNAME, username); - } - - /** - * Returns the value of the 'name' property currently set in - * the User object. - * - * @return the value of the name property - */ - @JsonSerialize(include = NON_NULL) - public String getName() { - return getStringProperty(PROPERTY_NAME); - } - - /** - * Sets the value of the 'name' property in the User object. - * - * @param name the name of the entity - */ - public void setName(String name) { - setStringProperty(properties, PROPERTY_NAME, name); - } - - /** - * Returns the value of the 'email' property currently set in the User object. - * - * @return the value of the email property - */ - @JsonSerialize(include = NON_NULL) - public String getEmail() { - return getStringProperty(PROPERTY_EMAIL); - } - - /** - * Sets the value of the 'email' property in the User object. - * - * @param email the user's email address - */ - public void setEmail(String email) { - setStringProperty(properties, PROPERTY_EMAIL, email); - } - - /** - * Returns the value of the 'activated' property in the User object. - * - * @return a Boolean true/false - */ - @JsonSerialize(include = NON_NULL) - public Boolean isActivated() { - return getBooleanProperty(properties, PROPERTY_ACTIVATED); - } - - /** - * Sets the value of the 'activated' property in the User object. - * - * @param activated boolean whether the user is activated - */ - public void setActivated(Boolean activated) { - setBooleanProperty(properties, PROPERTY_ACTIVATED, activated); - } - - /** - * Returns the value of the 'disabled' property in the User object. - * - * @return a Boolean true/false - */ - @JsonSerialize(include = NON_NULL) - public Boolean isDisabled() { - return getBooleanProperty(properties, PROPERTY_DISABLED); - } - - /** - * Sets the value of the 'disabled' property in the User object. - * - * @param disabled Boolean true/false - */ - public void setDisabled(Boolean disabled) { - setBooleanProperty(properties, PROPERTY_DISABLED, disabled); - } - - /** - * Returns the value of the 'firstname' property in the User object. - * - * @return the user's first name - */ - @JsonSerialize(include = NON_NULL) - public String getFirstname() { - return getStringProperty(PROPERTY_FIRSTNAME); - } - - /** - * Sets the value of the 'firstname' property in the User object. - * - * @param firstname the user's first name - */ - public void setFirstname(String firstname) { - setStringProperty(properties, PROPERTY_FIRSTNAME, firstname); - } - - /** - * Returns the value of the 'middlename' property in the User object. - * - * @return the user's middle name - */ - @JsonSerialize(include = NON_NULL) - public String getMiddlename() { - return getStringProperty(PROPERTY_MIDDLENAME); - } - - /** - * Sets the value of the 'middlename' property in the User object. - * - * @param middlename the user's middle name - */ - public void setMiddlename(String middlename) { - setStringProperty(properties, PROPERTY_MIDDLENAME, middlename); - } - - /** - * Returns the value of the 'lastname' property in the User object. - * - * @return the user's last name - */ - @JsonSerialize(include = NON_NULL) - public String getLastname() { - return getStringProperty(PROPERTY_LASTNAME); - } - - /** - * Sets the value of the 'lastname' property in the User object. - * - * @param lastname the user's last name - */ - public void setLastname(String lastname) { - setStringProperty(properties, PROPERTY_LASTNAME, lastname); - } - - /** - * Returns the value of the 'picture' property in the User object. - * - * @return the URL of the user's picture - */ - @JsonSerialize(include = NON_NULL) - public String getPicture() { - return getStringProperty(PROPERTY_PICTURE); - } - - /** - * Sets the value of the 'picture' property in the User object. - * - * @param picture the URL of the user's picture - */ - public void setPicture(String picture) { - setStringProperty(properties, PROPERTY_PICTURE, picture); - } - - /** - * Saves the current state of the User object on the server. Any property - * conflicts will overwrite what is on the server. - * - * @return an ApiResponse object - */ - public ApiResponse save() { - ApiResponse response = super.save(); - return response; - } - -} http://git-wip-us.apache.org/repos/asf/usergrid/blob/7e0ffbc0/sdks/android/src/main/java/org/apache/usergrid/android/sdk/exception/ClientException.java ---------------------------------------------------------------------- diff --git a/sdks/android/src/main/java/org/apache/usergrid/android/sdk/exception/ClientException.java b/sdks/android/src/main/java/org/apache/usergrid/android/sdk/exception/ClientException.java deleted file mode 100755 index 7d39193..0000000 --- a/sdks/android/src/main/java/org/apache/usergrid/android/sdk/exception/ClientException.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.usergrid.android.sdk.exception; - -/** - * Simple wrapper for client exceptions - * @author tnine - * - */ -public class ClientException extends RuntimeException{ - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * @param message - * @param cause - */ - public ClientException(String message, Throwable cause) { - super(message, cause); - } - - - -} http://git-wip-us.apache.org/repos/asf/usergrid/blob/7e0ffbc0/sdks/android/src/main/java/org/apache/usergrid/android/sdk/response/AggregateCounter.java ---------------------------------------------------------------------- diff --git a/sdks/android/src/main/java/org/apache/usergrid/android/sdk/response/AggregateCounter.java b/sdks/android/src/main/java/org/apache/usergrid/android/sdk/response/AggregateCounter.java deleted file mode 100755 index d085acb..0000000 --- a/sdks/android/src/main/java/org/apache/usergrid/android/sdk/response/AggregateCounter.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.usergrid.android.sdk.response; - -import static org.apache.usergrid.android.sdk.utils.JsonUtils.toJsonString; - -public class AggregateCounter { - - private long timestamp; - private long value; - - public AggregateCounter() { - } - - public AggregateCounter(long timestamp, long value) { - this.timestamp = timestamp; - this.value = value; - } - - public long getTimestamp() { - return timestamp; - } - - public void setTimestamp(long timestamp) { - this.timestamp = timestamp; - } - - public long getValue() { - return value; - } - - public void setValue(long value) { - this.value = value; - } - - @Override - public String toString() { - return toJsonString(this); - } - -} http://git-wip-us.apache.org/repos/asf/usergrid/blob/7e0ffbc0/sdks/android/src/main/java/org/apache/usergrid/android/sdk/response/AggregateCounterSet.java ---------------------------------------------------------------------- diff --git a/sdks/android/src/main/java/org/apache/usergrid/android/sdk/response/AggregateCounterSet.java b/sdks/android/src/main/java/org/apache/usergrid/android/sdk/response/AggregateCounterSet.java deleted file mode 100755 index f127946..0000000 --- a/sdks/android/src/main/java/org/apache/usergrid/android/sdk/response/AggregateCounterSet.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.usergrid.android.sdk.response; - -import static org.apache.usergrid.android.sdk.utils.JsonUtils.toJsonString; - -import java.util.List; -import java.util.UUID; - -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion; - -public class AggregateCounterSet { - private String name; - private UUID user; - private UUID group; - private UUID queue; - private String category; - private List<AggregateCounter> values; - - public AggregateCounterSet() { - } - - public AggregateCounterSet(String name, UUID user, UUID group, - String category, List<AggregateCounter> values) { - this.name = name; - this.user = user; - this.group = group; - this.category = category; - this.values = values; - } - - public AggregateCounterSet(String name, UUID queue, String category, - List<AggregateCounter> values) { - this.name = name; - setQueue(queue); - this.category = category; - this.values = values; - } - - @JsonSerialize(include = Inclusion.NON_NULL) - public UUID getUser() { - return user; - } - - public void setUser(UUID user) { - this.user = user; - } - - @JsonSerialize(include = Inclusion.NON_NULL) - public UUID getGroup() { - return group; - } - - public void setGroup(UUID group) { - this.group = group; - } - - @JsonSerialize(include = Inclusion.NON_NULL) - public String getCategory() { - return category; - } - - public void setCategory(String category) { - this.category = category; - } - - @JsonSerialize(include = Inclusion.NON_NULL) - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - @JsonSerialize(include = Inclusion.NON_NULL) - public List<AggregateCounter> getValues() { - return values; - } - - public void setValues(List<AggregateCounter> values) { - this.values = values; - } - - @JsonSerialize(include = Inclusion.NON_NULL) - public UUID getQueue() { - return queue; - } - - public void setQueue(UUID queue) { - this.queue = queue; - } - - @Override - public String toString() { - return toJsonString(this); - } - -} http://git-wip-us.apache.org/repos/asf/usergrid/blob/7e0ffbc0/sdks/android/src/main/java/org/apache/usergrid/android/sdk/response/ApiResponse.java ---------------------------------------------------------------------- diff --git a/sdks/android/src/main/java/org/apache/usergrid/android/sdk/response/ApiResponse.java b/sdks/android/src/main/java/org/apache/usergrid/android/sdk/response/ApiResponse.java deleted file mode 100755 index 68df46f..0000000 --- a/sdks/android/src/main/java/org/apache/usergrid/android/sdk/response/ApiResponse.java +++ /dev/null @@ -1,774 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.usergrid.android.sdk.response; - -import static org.apache.usergrid.android.sdk.utils.JsonUtils.toJsonString; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import org.apache.usergrid.android.sdk.UGClient; -import org.apache.usergrid.android.sdk.entities.Entity; -import org.apache.usergrid.android.sdk.entities.Message; -import org.apache.usergrid.android.sdk.entities.User; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion; - -public class ApiResponse { - - private String accessToken; - - private String error; - private String errorDescription; - private String errorUri; - private String exception; - - private String path; - private String uri; - private String status; - private long timestamp; - private UUID application; - private List<Entity> entities; - private UUID next; - private String cursor; - private String action; - private List<Object> list; - private Object data; - private Map<String, UUID> applications; - private Map<String, JsonNode> metadata; - private Map<String, List<String>> params; - private List<AggregateCounterSet> counters; - private ClientCredentialsInfo credentials; - - private List<Message> messages; - private List<QueueInfo> queues; - private UUID last; - private UUID queue; - private UUID consumer; - - private User user; - private String rawResponse; - - private final Map<String, JsonNode> properties = new HashMap<String, JsonNode>(); - - /** - * @y.exclude - */ - public ApiResponse() { - } - - /** - * Returns the 'properties' property of the request. - * - * @return a Map object of the properties - */ - @JsonAnyGetter - public Map<String, JsonNode> getProperties() { - return properties; - } - - /** - * @y.exclude - */ - @JsonAnySetter - public void setProperty(String key, JsonNode value) { - properties.put(key, value); - } - - /** - * Returns the OAuth token that was sent with the request - * - * @return the OAuth token - */ - @JsonProperty("access_token") - @JsonSerialize(include = Inclusion.NON_NULL) - public String getAccessToken() { - return accessToken; - } - - /** - * @y.exclude - */ - @JsonProperty("access_token") - public void setAccessToken(String accessToken) { - this.accessToken = accessToken; - } - - /** - * Returns the 'error' property of the response. - * - * @return the error - */ - @JsonSerialize(include = Inclusion.NON_NULL) - public String getError() { - return error; - } - - /** - * Sets the 'error' property of the response. - * - * @param error the error - */ - public void setError(String error) { - this.error = error; - } - - /** - * Returns the 'error_description' property of the response. - * - * @return the error description - */ - @JsonSerialize(include = Inclusion.NON_NULL) - @JsonProperty("error_description") - public String getErrorDescription() { - return errorDescription; - } - - /** - * Sets the 'error_description' property of the response. - * - * @param errorDescription the error description - */ - @JsonProperty("error_description") - public void setErrorDescription(String errorDescription) { - this.errorDescription = errorDescription; - } - - /** - * Returns the 'error_uri' property of the response. - * - * @return the error URI - */ - @JsonSerialize(include = Inclusion.NON_NULL) - @JsonProperty("error_uri") - public String getErrorUri() { - return errorUri; - } - - /** - * Sets the 'error_uri' property of the response. - * - * @param errorUri the error URI - */ - @JsonProperty("error_uri") - public void setErrorUri(String errorUri) { - this.errorUri = errorUri; - } - - /** - * Returns the 'exception' property of the response. - * - * @return the exception - */ - @JsonSerialize(include = Inclusion.NON_NULL) - public String getException() { - return exception; - } - - /** - * Sets the 'exception' property of the response. - * - * @param exception the exception - */ - public void setException(String exception) { - this.exception = exception; - } - - /** - * Returns the path of the request, i.e. the portion of the - * request URI after the application name. - * - * @return the request path - */ - @JsonSerialize(include = Inclusion.NON_NULL) - public String getPath() { - return path; - } - - /** - * @y.exclude - */ - public void setPath(String path) { - this.path = path; - } - - /** - * Returns the full URI of the request. - * - * @return the full request URI - */ - @JsonSerialize(include = Inclusion.NON_NULL) - public String getUri() { - return uri; - } - - /** - * @y.exclude - */ - public void setUri(String uri) { - this.uri = uri; - } - - /** - * Returns the status property from the response. Only - * applies to certain organization and application-level requests. - * - * @return the status - */ - @JsonSerialize(include = Inclusion.NON_NULL) - public String getStatus() { - return status; - } - - /** - * @y.exclude - */ - public void setStatus(String status) { - this.status = status; - } - - /** - * Returns the timestamp of the response - * - * @return the UNIX timestamp - */ - public long getTimestamp() { - return timestamp; - } - - /** - * @y.exclude - */ - public void setTimestamp(long timestamp) { - this.timestamp = timestamp; - } - - /** - * Returns the UUID of the application that was targeted - * by the request. - * - * @return the application UUID - */ - @JsonSerialize(include = Inclusion.NON_NULL) - public UUID getApplication() { - return application; - } - - /** - * @y.exclude - */ - public void setApplication(UUID application) { - this.application = application; - } - - /** - * Returns the entities from the response as a List - * of Entity objects. - * - * @return the entities - */ - @JsonSerialize(include = Inclusion.NON_NULL) - public List<Entity> getEntities() { - return entities; - } - - /** - * @y.exclude - */ - public void setEntities(List<Entity> entities) { - this.entities = entities; - } - - /** - * Returns a count of the number of entities in the response. - * - * @return the number of entities in the response - */ - public int getEntityCount() { - if (entities == null) { - return 0; - } - return entities.size(); - } - - /** - * Returns the first entity in the result set, or null - * if there were no entities. - * - * @return an Entity object - * @see org.apache.usergrid.android.sdk.entities.Entity - */ - public Entity getFirstEntity() { - if ((entities != null) && (entities.size() > 0)) { - return entities.get(0); - } - return null; - } - - /** - * Returns the first entity in the result set. - * - * @return an Entity object - * @see org.apache.usergrid.android.sdk.entities.Entity - */ - public <T extends Entity> T getFirstEntity(Class<T> t) { - return Entity.toType(getFirstEntity(), t); - } - - /** - * Returns the last entity in the result set. - * - * @return an Entity object - * @see org.apache.usergrid.android.sdk.entities.Entity - */ - public Entity getLastEntity() { - if ((entities != null) && (entities.size() > 0)) { - return entities.get(entities.size() - 1); - } - return null; - } - - /** - * Returns the last entity in the result set. - * - * @return an Entity object - * @see org.apache.usergrid.android.sdk.entities.Entity - */ - public <T extends Entity> T getLastEntity(Class<T> t) { - return Entity.toType(getLastEntity(), t); - } - - /** - * Returns the a List of all entitie from the response. - * - * @return a List object - * @see org.apache.usergrid.android.sdk.entities.Entity - */ - public <T extends Entity> List<T> getEntities(Class<T> t) { - return Entity.toType(entities, t); - } - - /** - * Returns the 'next' property of the response. - * - * @return the 'next' property - */ - @JsonSerialize(include = Inclusion.NON_NULL) - public UUID getNext() { - return next; - } - - /** - * @y.exclude - */ - public void setNext(UUID next) { - this.next = next; - } - - /** - * Returns the cursor for retrieving the next page of results - * - * @return the cursor - */ - @JsonSerialize(include = Inclusion.NON_NULL) - public String getCursor() { - return cursor; - } - - /** - * @y.exclude - */ - public void setCursor(String cursor) { - this.cursor = cursor; - } - - /** - * Returns the 'action' property from the response. - * - * @return the 'action' property - */ - @JsonSerialize(include = Inclusion.NON_NULL) - public String getAction() { - return action; - } - - /** - * @y.exclude - */ - public void setAction(String action) { - this.action = action; - } - - /** - * Returns the 'list' property from the response. - * - * @return the 'list' property - */ - @JsonSerialize(include = Inclusion.NON_NULL) - public List<Object> getList() { - return list; - } - - /** - * @y.exclude - */ - public void setList(List<Object> list) { - this.list = list; - } - - /** - * Returns the 'data' property of the response from a - * request to create, retrieve or update an admin user. - * - * @return the 'data' property of the user entity - */ - @JsonSerialize(include = Inclusion.NON_NULL) - public Object getData() { - return data; - } - - /** - * @y.exclude - */ - public void setData(Object data) { - this.data = data; - } - - /** - * For requests to get all applications in an organization, returns - * the applications and their UUIDs as a Map object. - * - * @return the applications in the organization - */ - @JsonSerialize(include = Inclusion.NON_NULL) - public Map<String, UUID> getApplications() { - return applications; - } - - /** - * @y.exclude - */ - public void setApplications(Map<String, UUID> applications) { - this.applications = applications; - } - - /** - * Returns the 'metadata' property of the response as a Map object. - * - * @return the 'metadata' property - */ - @JsonSerialize(include = Inclusion.NON_NULL) - public Map<String, JsonNode> getMetadata() { - return metadata; - } - - /** - * @y.exclude - */ - public void setMetadata(Map<String, JsonNode> metadata) { - this.metadata = metadata; - } - - /** - * Returns the URL parameters that were sent with the request. - * - * @return the URL parameters of the request - */ - @JsonSerialize(include = Inclusion.NON_NULL) - public Map<String, List<String>> getParams() { - return params; - } - - /** - * @y.exclude - */ - public void setParams(Map<String, List<String>> params) { - this.params = params; - } - - /** - * Returns the counters from the response. - * - * @return a List of the counters - */ - @JsonSerialize(include = Inclusion.NON_NULL) - public List<AggregateCounterSet> getCounters() { - return counters; - } - - /** - * @y.exclude - */ - public void setCounters(List<AggregateCounterSet> counters) { - this.counters = counters; - } - - /** - * Returns the client id and client secret from the response. This is - * used only for requests that generate or retrieve credentials. - * - * @return the client id and client secret - */ - @JsonSerialize(include = Inclusion.NON_NULL) - public ClientCredentialsInfo getCredentials() { - return credentials; - } - - /** - * @y.exclude - */ - public void setCredentials(ClientCredentialsInfo credentials) { - this.credentials = credentials; - } - - - /** - * For requests to retrieve the admin users in an organization, returns - * the 'user' property from the response. - * - * @return a User object - */ - @JsonSerialize(include = Inclusion.NON_NULL) - public User getUser() { - return user; - } - - /** - * @y.exclude - */ - public void setUser(User user) { - this.user = user; - } - - /** - * Returns the ApiResponse as a String - * - * @return the ApiResponse in String format - */ - @Override - public String toString() { - return toJsonString(this); - } - - /** - * For messaging queue requests, returns the 'messages' property. - * - * @return the 'messages' property - */ - @JsonSerialize(include = Inclusion.NON_NULL) - public List<Message> getMessages() { - return messages; - } - - /** - * @y.exclude - */ - public void setMessages(List<Message> messages) { - this.messages = messages; - } - - /** - * For messaging queue requests, returns the number of messages - * in the response. - * - * @return the number of messages in the 'messages' property - */ - @JsonIgnore - public int getMessageCount() { - if (messages == null) { - return 0; - } - return messages.size(); - } - - /** - * For messaging queue requests, returns the first message - * in the response. - * - * @return the first message in the 'messages' property - */ - @JsonIgnore - public Message getFirstMessage() { - if ((messages != null) && (messages.size() > 0)) { - return messages.get(0); - } - return null; - } - - /** - * For messaging queue requests, returns the last message - * in the response. - * - * @return the last message in the 'messages' property - */ - @JsonIgnore - public Entity getLastMessage() { - if ((messages != null) && (messages.size() > 0)) { - return messages.get(messages.size() - 1); - } - return null; - } - - @JsonSerialize(include = Inclusion.NON_NULL) - public UUID getLast() { - return last; - } - - /** - * @y.exclude - */ - public void setLast(UUID last) { - this.last = last; - } - - /** - * For messaging queue requests, returns the queues - * in the response. - * - * @return the 'queues' property - */ - @JsonSerialize(include = Inclusion.NON_NULL) - public List<QueueInfo> getQueues() { - return queues; - } - - /** - * @y.exclude - */ - public void setQueues(List<QueueInfo> queues) { - this.queues = queues; - } - - /** - * For messaging queue requests, returns the first queue - * in the response. - * - * @return the first queue in the 'queues' property - */ - @JsonIgnore - public QueueInfo getFirstQueue() { - if ((queues != null) && (queues.size() > 0)) { - return queues.get(0); - } - return null; - } - - /** - * For messaging queue requests, returns the last queue - * in the response. - * - * @return the last queue in the 'queues' property - */ - @JsonIgnore - public QueueInfo getLastQueue() { - if ((queues != null) && (queues.size() > 0)) { - return queues.get(queues.size() - 1); - } - return null; - } - - /** - * For messaging queue requests, returns the UUID of the - * last queue in the response. - * - * @return the queue UUID - */ - @JsonIgnore - public UUID getLastQueueId() { - QueueInfo q = getLastQueue(); - if (q != null) { - return q.getQueue(); - } - return null; - } - - /** - * For messaging queue requests, returns the UUID of the - * queue in the response. - * - * @return the queue UUID - */ - @JsonSerialize(include = Inclusion.NON_NULL) - public UUID getQueue() { - return queue; - } - - /** - * @y.exclude - */ - public void setQueue(UUID queue) { - this.queue = queue; - } - - /** - * Returns the 'consumer' property from message queue requests. - * - * @return the 'consumer' property - */ - @JsonSerialize(include = Inclusion.NON_NULL) - public UUID getConsumer() { - return consumer; - } - - /** - * @y.exclude - */ - public void setConsumer(UUID consumer) { - this.consumer = consumer; - } - - /** - * @y.exclude - */ - public void setRawResponse(String rawResponse) { - this.rawResponse = rawResponse; - } - - /** - * Returns the raw JSON response as a String. - * - * @return the JSON response - */ - public String getRawResponse() { - return rawResponse; - } - - /** - * Sets the UGClient instance for all Entity objects in the response. - * - * @param UGClient an instance of UGClient - */ - public void setUGClient(UGClient client) { - if( (entities != null) && !entities.isEmpty() ) { - for ( Entity entity : entities ) { - entity.setUGClient(client); - } - } - } - -} http://git-wip-us.apache.org/repos/asf/usergrid/blob/7e0ffbc0/sdks/android/src/main/java/org/apache/usergrid/android/sdk/response/ClientCredentialsInfo.java ---------------------------------------------------------------------- diff --git a/sdks/android/src/main/java/org/apache/usergrid/android/sdk/response/ClientCredentialsInfo.java b/sdks/android/src/main/java/org/apache/usergrid/android/sdk/response/ClientCredentialsInfo.java deleted file mode 100755 index 95c3a68..0000000 --- a/sdks/android/src/main/java/org/apache/usergrid/android/sdk/response/ClientCredentialsInfo.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.usergrid.android.sdk.response; - -import static org.apache.usergrid.android.sdk.utils.JsonUtils.toJsonString; - -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * @y.exclude - */ -public class ClientCredentialsInfo { - - private String id; - private String secret; - - public ClientCredentialsInfo(String id, String secret) { - this.id = id; - this.secret = secret; - } - - @JsonProperty("client_id") - public String getId() { - return id; - } - - @JsonProperty("client_id") - public void setId(String id) { - this.id = id; - } - - @JsonProperty("client_secret") - public String getSecret() { - return secret; - } - - @JsonProperty("client_secret") - public void setSecret(String secret) { - this.secret = secret; - } - - @Override - public String toString() { - return toJsonString(this); - } - -} http://git-wip-us.apache.org/repos/asf/usergrid/blob/7e0ffbc0/sdks/android/src/main/java/org/apache/usergrid/android/sdk/response/QueueInfo.java ---------------------------------------------------------------------- diff --git a/sdks/android/src/main/java/org/apache/usergrid/android/sdk/response/QueueInfo.java b/sdks/android/src/main/java/org/apache/usergrid/android/sdk/response/QueueInfo.java deleted file mode 100755 index 1f049b0..0000000 --- a/sdks/android/src/main/java/org/apache/usergrid/android/sdk/response/QueueInfo.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.usergrid.android.sdk.response; - -import java.util.UUID; - -public class QueueInfo { - - String path; - UUID queue; - - public QueueInfo() { - } - - public String getPath() { - return path; - } - - public void setPath(String path) { - this.path = path; - } - - public UUID getQueue() { - return queue; - } - - public void setQueue(UUID queue) { - this.queue = queue; - } -} http://git-wip-us.apache.org/repos/asf/usergrid/blob/7e0ffbc0/sdks/android/src/main/java/org/apache/usergrid/android/sdk/utils/DeviceUuidFactory.java ---------------------------------------------------------------------- diff --git a/sdks/android/src/main/java/org/apache/usergrid/android/sdk/utils/DeviceUuidFactory.java b/sdks/android/src/main/java/org/apache/usergrid/android/sdk/utils/DeviceUuidFactory.java deleted file mode 100755 index b3b3dd9..0000000 --- a/sdks/android/src/main/java/org/apache/usergrid/android/sdk/utils/DeviceUuidFactory.java +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.usergrid.android.sdk.utils; - -import static org.apache.usergrid.android.sdk.utils.ObjectUtils.isEmpty; - -import java.io.UnsupportedEncodingException; -import java.util.UUID; - -import android.content.Context; -import android.content.SharedPreferences; -import android.net.wifi.WifiManager; -import android.os.Build; -import android.provider.Settings.Secure; -import android.telephony.TelephonyManager; - -/** - * Tries to get the device ID as a UUID and fallsback to a generated UUID value - * if it doesn't work. - * - * @see http - * ://stackoverflow.com/questions/2785485/is-there-a-unique-android-device - * -id - * - */ -public class DeviceUuidFactory { - protected static final String PREFS_FILE = "device_id.xml"; - protected static final String PREFS_DEVICE_ID = "device_id"; - - protected static UUID uuid; - - public DeviceUuidFactory(Context context) { - - if (uuid == null) { - synchronized (DeviceUuidFactory.class) { - if (uuid == null) { - final SharedPreferences prefs = context - .getSharedPreferences(PREFS_FILE, 0); - final String id = prefs.getString(PREFS_DEVICE_ID, null); - - if (id != null) { - // Use the ids previously computed and stored in the - // prefs file - uuid = UUID.fromString(id); - - } else { - - final String androidId = Secure - .getString(context.getContentResolver(), - Secure.ANDROID_ID); - - // Use the Android ID unless it's broken, in which case - // fallback on deviceId, - // unless it's not available, then fallback on a random - // number which we store - // to a prefs file - try { - if (!"9774d56d682e549c".equals(androidId)) { - uuid = UUID.nameUUIDFromBytes(androidId - .getBytes("utf8")); - } else { - final String deviceId = ((TelephonyManager) context - .getSystemService(Context.TELEPHONY_SERVICE)) - .getDeviceId(); - uuid = deviceId != null ? UUID - .nameUUIDFromBytes(deviceId - .getBytes("utf8")) - : generateDeviceUuid(context); - } - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); - } - - // Write the value out to the prefs file - prefs.edit() - .putString(PREFS_DEVICE_ID, uuid.toString()) - .commit(); - - } - - } - } - } - - } - - private UUID generateDeviceUuid(Context context) { - - // Get some of the hardware information - String buildParams = Build.BOARD + Build.BRAND + Build.CPU_ABI - + Build.DEVICE + Build.DISPLAY + Build.FINGERPRINT + Build.HOST - + Build.ID + Build.MANUFACTURER + Build.MODEL + Build.PRODUCT - + Build.TAGS + Build.TYPE + Build.USER; - - // Requires READ_PHONE_STATE - TelephonyManager tm = (TelephonyManager) context - .getSystemService(Context.TELEPHONY_SERVICE); - - // gets the imei (GSM) or MEID/ESN (CDMA) - String imei = tm.getDeviceId(); - - // gets the android-assigned id - String androidId = Secure.getString(context.getContentResolver(), - Secure.ANDROID_ID); - - // requires ACCESS_WIFI_STATE - WifiManager wm = (WifiManager) context - .getSystemService(Context.WIFI_SERVICE); - - // gets the MAC address - String mac = wm.getConnectionInfo().getMacAddress(); - - // if we've got nothing, return a random UUID - if (isEmpty(imei) && isEmpty(androidId) && isEmpty(mac)) { - return UUID.randomUUID(); - } - - // concatenate the string - String fullHash = buildParams.toString() + imei + androidId + mac; - - return UUID.nameUUIDFromBytes(fullHash.getBytes()); - } - - /** - * Returns a unique UUID for the current android device. As with all UUIDs, - * this unique ID is "very highly likely" to be unique across all Android - * devices. Much more so than ANDROID_ID is. - * - * The UUID is generated by using ANDROID_ID as the base key if appropriate, - * falling back on TelephonyManager.getDeviceID() if ANDROID_ID is known to - * be incorrect, and finally falling back on a random UUID that's persisted - * to SharedPreferences if getDeviceID() does not return a usable value. - * - * In some rare circumstances, this ID may change. In particular, if the - * device is factory reset a new device ID may be generated. In addition, if - * a user upgrades their phone from certain buggy implementations of Android - * 2.2 to a newer, non-buggy version of Android, the device ID may change. - * Or, if a user uninstalls your app on a device that has neither a proper - * Android ID nor a Device ID, this ID may change on reinstallation. - * - * Note that if the code falls back on using TelephonyManager.getDeviceId(), - * the resulting ID will NOT change after a factory reset. Something to be - * aware of. - * - * Works around a bug in Android 2.2 for many devices when using ANDROID_ID - * directly. - * - * @see http://code.google.com/p/android/issues/detail?id=10603 - * - * @return a UUID that may be used to uniquely identify your device for most - * purposes. - */ - public UUID getDeviceUuid() { - return uuid; - } -} http://git-wip-us.apache.org/repos/asf/usergrid/blob/7e0ffbc0/sdks/android/src/main/java/org/apache/usergrid/android/sdk/utils/JsonUtils.java ---------------------------------------------------------------------- diff --git a/sdks/android/src/main/java/org/apache/usergrid/android/sdk/utils/JsonUtils.java b/sdks/android/src/main/java/org/apache/usergrid/android/sdk/utils/JsonUtils.java deleted file mode 100755 index 5f617a2..0000000 --- a/sdks/android/src/main/java/org/apache/usergrid/android/sdk/utils/JsonUtils.java +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.usergrid.android.sdk.utils; - -import java.io.IOException; -import java.util.Map; -import java.util.UUID; - -import org.apache.usergrid.android.sdk.exception.ClientException; -import com.fasterxml.jackson.core.JsonGenerationException; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.JsonNodeFactory; - -public class JsonUtils { - - - static ObjectMapper mapper = new ObjectMapper(); - - public static String getStringProperty(Map<String, JsonNode> properties, - String name) { - JsonNode value = properties.get(name); - if (value != null) { - return value.asText(); - } - return null; - } - - public static void setStringProperty(Map<String, JsonNode> properties, - String name, String value) { - if (value == null) { - properties.remove(name); - } else { - properties.put(name, JsonNodeFactory.instance.textNode(value)); - } - } - - public static Long getLongProperty(Map<String, JsonNode> properties, - String name) { - JsonNode value = properties.get(name); - if (value != null) { - return value.asLong(0); - } - return null; - } - - public static void setLongProperty(Map<String, JsonNode> properties, - String name, Long value) { - if (value == null) { - properties.remove(name); - } else { - properties.put(name, JsonNodeFactory.instance.numberNode(value)); - } - } - - public static void setFloatProperty(Map<String, JsonNode> properties, String name, Float value){ - if(value == null){ - properties.remove(name); - }else{ - properties.put(name, JsonNodeFactory.instance.numberNode(value)); - } - } - - public static Boolean getBooleanProperty(Map<String, JsonNode> properties, - String name) { - JsonNode value = properties.get(name); - if (value != null) { - return value.asBoolean(); - } - return false; - } - - public static void setBooleanProperty(Map<String, JsonNode> properties, - String name, Boolean value) { - if (value == null) { - properties.remove(name); - } else { - properties.put(name, JsonNodeFactory.instance.booleanNode(value)); - } - } - - public static UUID getUUIDProperty(Map<String, JsonNode> properties, - String name) { - JsonNode value = properties.get(name); - if (value != null) { - UUID uuid = null; - try { - uuid = UUID.fromString(value.asText()); - } catch (Exception e) { - } - return uuid; - } - return null; - } - - public static void setUUIDProperty(Map<String, JsonNode> properties, - String name, UUID value) { - if (value == null) { - properties.remove(name); - } else { - properties.put(name, - JsonNodeFactory.instance.textNode(value.toString())); - } - } - - public static String toJsonString(Object obj) { - try { - return mapper.writeValueAsString(obj); - } catch (JsonGenerationException e) { - throw new ClientException("Unable to generate json", e); - } catch (JsonMappingException e) { - throw new ClientException("Unable to map json", e); - } catch (IOException e) { - throw new ClientException("IO error", e); - } - } - - public static <T> T parse(String json, Class<T> c) { - try { - return mapper.readValue(json, c); - } catch (JsonGenerationException e) { - throw new ClientException("Unable to generate json", e); - } catch (JsonMappingException e) { - throw new ClientException("Unable to map json", e); - } catch (IOException e) { - throw new ClientException("IO error", e); - } - } - - public static JsonNode toJsonNode(Object obj) { - return mapper.convertValue(obj, JsonNode.class); - } - - public static <T> T fromJsonNode(JsonNode json, Class<T> c) { - try { - JsonParser jp = json.traverse(); - return mapper.readValue(jp, c); - } catch (JsonGenerationException e) { - throw new ClientException("Unable to generate json", e); - } catch (JsonMappingException e) { - throw new ClientException("Unable to map json", e); - } catch (IOException e) { - throw new ClientException("IO error", e); - } - } - - public static <T> T getObjectProperty(Map<String, JsonNode> properties, - String name, Class<T> c) { - JsonNode value = properties.get(name); - if (value != null) { - return fromJsonNode(value, c); - } - return null; - } - - public static void setObjectProperty(Map<String, JsonNode> properties, - String name, Object value) { - if (value == null) { - properties.remove(name); - } else { - properties.put(name, - JsonNodeFactory.instance.textNode(value.toString())); - } - } - -} http://git-wip-us.apache.org/repos/asf/usergrid/blob/7e0ffbc0/sdks/android/src/main/java/org/apache/usergrid/android/sdk/utils/MapUtils.java ---------------------------------------------------------------------- diff --git a/sdks/android/src/main/java/org/apache/usergrid/android/sdk/utils/MapUtils.java b/sdks/android/src/main/java/org/apache/usergrid/android/sdk/utils/MapUtils.java deleted file mode 100755 index 8da5b45..0000000 --- a/sdks/android/src/main/java/org/apache/usergrid/android/sdk/utils/MapUtils.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.usergrid.android.sdk.utils; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class MapUtils { - - public static <T> Map<String, T> newMapWithoutKeys(Map<String, T> map, - List<String> keys) { - Map<String, T> newMap = null; - if (map != null) { - newMap = new HashMap<String, T>(map); - } else { - newMap = new HashMap<String, T>(); - } - for (String key : keys) { - newMap.remove(key); - } - return newMap; - } - -} http://git-wip-us.apache.org/repos/asf/usergrid/blob/7e0ffbc0/sdks/android/src/main/java/org/apache/usergrid/android/sdk/utils/ObjectUtils.java ---------------------------------------------------------------------- diff --git a/sdks/android/src/main/java/org/apache/usergrid/android/sdk/utils/ObjectUtils.java b/sdks/android/src/main/java/org/apache/usergrid/android/sdk/utils/ObjectUtils.java deleted file mode 100755 index efdcaca..0000000 --- a/sdks/android/src/main/java/org/apache/usergrid/android/sdk/utils/ObjectUtils.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.usergrid.android.sdk.utils; - -import java.util.Map; - -public class ObjectUtils { - - public static boolean isEmpty(Object s) { - if (s == null) { - return true; - } - if ((s instanceof String) && (((String) s).trim().length() == 0)) { - return true; - } - if (s instanceof Map) { - return ((Map<?, ?>) s).isEmpty(); - } - return false; - } - -} http://git-wip-us.apache.org/repos/asf/usergrid/blob/7e0ffbc0/sdks/android/src/main/java/org/apache/usergrid/android/sdk/utils/UrlUtils.java ---------------------------------------------------------------------- diff --git a/sdks/android/src/main/java/org/apache/usergrid/android/sdk/utils/UrlUtils.java b/sdks/android/src/main/java/org/apache/usergrid/android/sdk/utils/UrlUtils.java deleted file mode 100755 index b7e6be3..0000000 --- a/sdks/android/src/main/java/org/apache/usergrid/android/sdk/utils/UrlUtils.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.usergrid.android.sdk.utils; - -import static org.apache.usergrid.android.sdk.utils.ObjectUtils.isEmpty; -import static java.net.URLEncoder.encode; - -import java.io.UnsupportedEncodingException; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import org.apache.usergrid.android.sdk.exception.ClientException; - -public class UrlUtils { - - - public static URL url(String s) { - try { - return new URL(s); - } catch (MalformedURLException e) { - throw new ClientException("Incorrect URL format", e); - } - } - - public static URL url(URL u, String s) { - try { - return new URL(u, s); - } catch (MalformedURLException e) { - throw new ClientException("Incorrect URL format", e); - } - } - - public static String path(Object... segments) { - String path = ""; - boolean first = true; - for (Object segment : segments) { - if (segment instanceof Object[]) { - segment = path((Object[]) segment); - } - if (!isEmpty(segment)) { - if (first) { - path = segment.toString(); - first = false; - } else { - if (!path.endsWith("/")) { - path += "/"; - } - path += segment.toString(); - } - } - } - return path; - } - - @SuppressWarnings("rawtypes") - public static String encodeParams(Map<String, Object> params) { - if (params == null) { - return ""; - } - boolean first = true; - StringBuilder results = new StringBuilder(); - for (Entry<String, Object> entry : params.entrySet()) { - if (entry.getValue() instanceof List) { - for (Object o : (List) entry.getValue()) { - if (!isEmpty(o)) { - if (!first) { - results.append('&'); - } - first = false; - results.append(entry.getKey()); - results.append("="); - try { - results.append(encode(o.toString(), "UTF-8")); - } catch (UnsupportedEncodingException e) { - throw new ClientException("Unknown encoding", e); - } - } - } - } else if (!isEmpty(entry.getValue())) { - if (!first) { - results.append('&'); - } - first = false; - results.append(entry.getKey()); - results.append("="); - try { - results.append(encode(entry.getValue().toString(), "UTF-8")); - } catch (UnsupportedEncodingException e) { - throw new ClientException("Unsupported string encoding", e); - } - } - } - return results.toString(); - } - - public static String addQueryParams(String url, Map<String, Object> params) { - if (params == null) { - return url; - } - if (!url.contains("?")) { - url += "?"; - } - url += encodeParams(params); - return url; - } - -}