You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2014/01/28 23:22:06 UTC
[56/96] [abbrv] USERGRID-2 package namespace to org.apache.usergrid
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3ccbfd8a/sdks/java/src/main/java/org/apache/usergrid/java/client/entities/Activity.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/entities/Activity.java b/sdks/java/src/main/java/org/apache/usergrid/java/client/entities/Activity.java
new file mode 100644
index 0000000..f2b77bd
--- /dev/null
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/entities/Activity.java
@@ -0,0 +1,627 @@
+/*******************************************************************************
+ * Copyright (c) 2010, 2011 Ed Anuff and Usergrid, all rights reserved.
+ * http://www.usergrid.com
+ *
+ * This file is part of Usergrid Core.
+ *
+ * Usergrid Core is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ *
+ * Usergrid Core is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * Usergrid Core. If not, see <http://www.gnu.org/licenses/>.
+ ******************************************************************************/
+package org.apache.usergrid.java.client.entities;
+
+
+import static org.apache.usergrid.java.client.utils.JsonUtils.getStringProperty;
+
+import java.util.Arrays;
+import java.util.Date;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.UUID;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+import com.fasterxml.jackson.annotation.JsonAnyGetter;
+import com.fasterxml.jackson.annotation.JsonAnySetter;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion;
+
+/**
+ * An entity type for representing activity stream actions. These are similar to
+ * the more generic message entity type except provide the necessary properties
+ * for supporting activity stream implementations.
+ *
+ * @see http://activitystrea.ms/specs/json/1.0/
+ */
+public class Activity extends Entity {
+
+ public static final String ENTITY_TYPE = "activity";
+
+ public static final String PROP_ACTOR = "actor";
+
+ public static final String VERB_ADD = "add";
+ public static final String VERB_CANCEL = "cancel";
+ public static final String VERB_CHECKIN = "checkin";
+ public static final String VERB_DELETE = "delete";
+ public static final String VERB_FAVORITE = "favorite";
+ public static final String VERB_FOLLOW = "follow";
+ public static final String VERB_GIVE = "give";
+ public static final String VERB_IGNORE = "ignore";
+ public static final String VERB_INVITE = "invite";
+ public static final String VERB_JOIN = "join";
+ public static final String VERB_LEAVE = "leave";
+ public static final String VERB_LIKE = "like";
+ public static final String VERB_MAKE_FRIEND = "make-friend";
+ public static final String VERB_PLAY = "play";
+ public static final String VERB_POST = "post";
+ public static final String VERB_RECEIVE = "receive";
+ public static final String VERB_REMOVE = "remove";
+ public static final String VERB_REMOVE_FRIEND = "remove-friend";
+ public static final String VERB_REQUEST_FRIEND = "request-friend";
+ public static final String VERB_RSVP_MAYBE = "rsvp-maybe";
+ public static final String VERB_RSVP_NO = "rsvp-no";
+ public static final String VERB_RSVP_YES = "rsvp-yes";
+ public static final String VERB_SAVE = "save";
+ public static final String VERB_SHARE = "share";
+ public static final String VERB_STOP_FOLLOWING = "stop-following";
+ public static final String VERB_TAG = "tag";
+ public static final String VERB_UNFAVORITE = "unfavorite";
+ public static final String VERB_UNLIKE = "unlike";
+ public static final String VERB_UNSAVE = "unsave";
+ public static final String VERB_UPDATE = "update";
+
+ public static final String OBJECT_TYPE_ARTICLE = "article";
+ public static final String OBJECT_TYPE_AUDIO = "audio";
+ public static final String OBJECT_TYPE_BADGE = "badge";
+ public static final String OBJECT_TYPE_BOOKMARK = "bookmark";
+ public static final String OBJECT_TYPE_COLLECTION = "collection";
+ public static final String OBJECT_TYPE_COMMENT = "comment";
+ public static final String OBJECT_TYPE_EVENT = "event";
+ public static final String OBJECT_TYPE_FILE = "file";
+ public static final String OBJECT_TYPE_GROUP = "group";
+ public static final String OBJECT_TYPE_IMAGE = "image";
+ public static final String OBJECT_TYPE_NOTE = "note";
+ public static final String OBJECT_TYPE_PERSON = "person";
+ public static final String OBJECT_TYPE_PLACE = "place";
+ public static final String OBJECT_TYPE_PRODUCT = "product";
+ public static final String OBJECT_TYPE_QUESTION = "question";
+ public static final String OBJECT_TYPE_REVIEW = "review";
+ public static final String OBJECT_TYPE_SERVICE = "service";
+ public static final String OBJECT_TYPE_VIDEO = "video";
+
+ protected ActivityObject actor;
+
+ protected String content;
+
+ protected ActivityObject generator;
+
+ protected MediaLink icon;
+
+ protected String category;
+
+ protected String verb;
+
+ protected Long published;
+
+ protected ActivityObject object;
+
+ // protected
+ // String objectType;
+
+ // protected
+ // String objectEntityType;
+
+ // protected
+ // String objectName;
+
+ protected String title;
+
+ protected Set<String> connections;
+
+ public Activity() {
+ setType("activity");
+ }
+
+ public Activity(UUID id) {
+ this();
+ setUuid(id);
+ }
+
+ public static Activity newActivity(String verb, String title,
+ String content, String category, Entity user, Entity object,
+ String objectType, String objectName, String objectContent){
+
+ Activity activity = new Activity();
+ activity.setVerb(verb);
+ activity.setCategory(category);
+ activity.setContent(content);
+ activity.setTitle(title);
+
+ ActivityObject actor = new ActivityObject();
+ actor.setObjectType("person");
+
+ if (user != null) {
+ actor.setDisplayName(getStringProperty(user.properties, "name"));
+ actor.setEntityType(user.getType());
+ actor.setUuid(user.getUuid());
+ }
+
+ activity.setActor(actor);
+
+ ActivityObject obj = new ActivityObject();
+ obj.setDisplayName(objectName);
+ obj.setObjectType(objectType);
+ if (object != null) {
+ obj.setEntityType(object.getType());
+ obj.setUuid(object.getUuid());
+ }
+ if (objectContent != null) {
+ obj.setContent(objectContent);
+ } else {
+ obj.setContent(content);
+ }
+ activity.setObject(obj);
+
+ return activity;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public ActivityObject getActor() {
+ return actor;
+ }
+
+ public void setActor(ActivityObject actor) {
+ this.actor = actor;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public ActivityObject getGenerator() {
+ return generator;
+ }
+
+ public void setGenerator(ActivityObject generator) {
+ this.generator = generator;
+ }
+
+ /*
+ * @JsonSerialize(include = Inclusion.NON_NULL) public String getActorName()
+ * { return actorName; }
+ *
+ * public void setActorName(String actorName) { this.actorName = actorName;
+ * }
+ */
+ @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 getVerb() {
+ return verb;
+ }
+
+ public void setVerb(String verb) {
+ this.verb = verb;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public Long getPublished() {
+ return published;
+ }
+
+ public void setPublished(Long published) {
+ this.published = published;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public ActivityObject getObject() {
+ return object;
+ }
+
+ public void setObject(ActivityObject object) {
+ this.object = object;
+ }
+
+ /*
+ * @JsonSerialize(include = Inclusion.NON_NULL) public String
+ * getObjectType() { return objectType; }
+ *
+ * public void setObjectType(String objectType) { this.objectType =
+ * objectType; }
+ *
+ * @JsonSerialize(include = Inclusion.NON_NULL) public String
+ * getObjectEntityType() { return objectEntityType; }
+ *
+ * public void setObjectEntityType(String objectEntityType) {
+ * this.objectEntityType = objectEntityType; }
+ *
+ * @JsonSerialize(include = Inclusion.NON_NULL) public String
+ * getObjectName() { return objectName; }
+ *
+ * public void setObjectName(String objectName) { this.objectName =
+ * objectName; }
+ */
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public MediaLink getIcon() {
+ return icon;
+ }
+
+ public void setIcon(MediaLink icon) {
+ this.icon = icon;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public String getContent() {
+ return content;
+ }
+
+ public void setContent(String content) {
+ this.content = content;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public Set<String> getConnections() {
+ return connections;
+ }
+
+ public void setConnections(Set<String> connections) {
+ this.connections = connections;
+ }
+
+ @XmlRootElement
+ static public class MediaLink {
+
+ int duration;
+
+ int height;
+
+ String url;
+
+ int width;
+
+ protected Map<String, Object> dynamic_properties = new TreeMap<String, Object>(
+ String.CASE_INSENSITIVE_ORDER);
+
+ public MediaLink() {
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public int getDuration() {
+ return duration;
+ }
+
+ public void setDuration(int duration) {
+ this.duration = duration;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public int getHeight() {
+ return height;
+ }
+
+ public void setHeight(int height) {
+ this.height = height;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public int getWidth() {
+ return width;
+ }
+
+ public void setWidth(int width) {
+ this.width = width;
+ }
+
+ @JsonAnySetter
+ public void setDynamicProperty(String key, Object value) {
+ dynamic_properties.put(key, value);
+ }
+
+ @JsonAnyGetter
+ public Map<String, Object> getDynamicProperties() {
+ return dynamic_properties;
+ }
+
+ @Override
+ public String toString() {
+ return "MediaLink [duration=" + duration + ", height=" + height
+ + ", url=" + url + ", width=" + width
+ + ", dynamic_properties=" + dynamic_properties + "]";
+ }
+
+ }
+
+ @XmlRootElement
+ static public class ActivityObject {
+
+ ActivityObject[] attachments;
+
+ ActivityObject author;
+
+ String content;
+
+ String displayName;
+
+ String[] downstreamDuplicates;
+
+ String id;
+
+ MediaLink image;
+
+ String objectType;
+
+ Date published;
+
+ String summary;
+
+ String updated;
+
+ String upstreamDuplicates;
+
+ String url;
+
+ UUID uuid;
+
+ String entityType;
+
+ protected Map<String, Object> dynamic_properties = new TreeMap<String, Object>(
+ String.CASE_INSENSITIVE_ORDER);
+
+ public ActivityObject() {
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public ActivityObject[] getAttachments() {
+ return attachments;
+ }
+
+ public void setAttachments(ActivityObject[] attachments) {
+ this.attachments = attachments;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public ActivityObject getAuthor() {
+ return author;
+ }
+
+ public void setAuthor(ActivityObject author) {
+ this.author = author;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public String getContent() {
+ return content;
+ }
+
+ public void setContent(String content) {
+ this.content = content;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public String getDisplayName() {
+ return displayName;
+ }
+
+ public void setDisplayName(String displayName) {
+ this.displayName = displayName;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public String[] getDownstreamDuplicates() {
+ return downstreamDuplicates;
+ }
+
+ public void setDownstreamDuplicates(String[] downstreamDuplicates) {
+ this.downstreamDuplicates = downstreamDuplicates;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public MediaLink getImage() {
+ return image;
+ }
+
+ public void setImage(MediaLink image) {
+ this.image = image;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public String getObjectType() {
+ return objectType;
+ }
+
+ public void setObjectType(String objectType) {
+ this.objectType = objectType;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public Date getPublished() {
+ return published;
+ }
+
+ public void setPublished(Date published) {
+ this.published = published;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public String getSummary() {
+ return summary;
+ }
+
+ public void setSummary(String summary) {
+ this.summary = summary;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public String getUpdated() {
+ return updated;
+ }
+
+ public void setUpdated(String updated) {
+ this.updated = updated;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public String getUpstreamDuplicates() {
+ return upstreamDuplicates;
+ }
+
+ public void setUpstreamDuplicates(String upstreamDuplicates) {
+ this.upstreamDuplicates = upstreamDuplicates;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public UUID getUuid() {
+ return uuid;
+ }
+
+ public void setUuid(UUID uuid) {
+ this.uuid = uuid;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public String getEntityType() {
+ return entityType;
+ }
+
+ public void setEntityType(String entityType) {
+ this.entityType = entityType;
+ }
+
+ @JsonAnySetter
+ public void setDynamicProperty(String key, Object value) {
+ dynamic_properties.put(key, value);
+ }
+
+ @JsonAnyGetter
+ public Map<String, Object> getDynamicProperties() {
+ return dynamic_properties;
+ }
+
+ @Override
+ public String toString() {
+ return "ActivityObject [attachments="
+ + Arrays.toString(attachments) + ", author=" + author
+ + ", content=" + content + ", displayName=" + displayName
+ + ", downstreamDuplicates="
+ + Arrays.toString(downstreamDuplicates) + ", id=" + id
+ + ", image=" + image + ", objectType=" + objectType
+ + ", published=" + published + ", summary=" + summary
+ + ", updated=" + updated + ", upstreamDuplicates="
+ + upstreamDuplicates + ", url=" + url + ", uuid=" + uuid
+ + ", entityType=" + entityType + ", dynamic_properties="
+ + dynamic_properties + "]";
+ }
+
+ }
+
+ @XmlRootElement
+ static public class ActivityCollection {
+
+ int totalItems;
+
+ ActivityObject[] items;
+
+ String url;
+
+ protected Map<String, Object> dynamic_properties = new TreeMap<String, Object>(
+ String.CASE_INSENSITIVE_ORDER);
+
+ public ActivityCollection() {
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public int getTotalItems() {
+ return totalItems;
+ }
+
+ public void setTotalItems(int totalItems) {
+ this.totalItems = totalItems;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public ActivityObject[] getItems() {
+ return items;
+ }
+
+ public void setItems(ActivityObject[] items) {
+ this.items = items;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ @JsonAnySetter
+ public void setDynamicProperty(String key, Object value) {
+ dynamic_properties.put(key, value);
+ }
+
+ @JsonAnyGetter
+ public Map<String, Object> getDynamicProperties() {
+ return dynamic_properties;
+ }
+
+ @Override
+ public String toString() {
+ return "ActivityCollection [totalItems=" + totalItems + ", items="
+ + Arrays.toString(items) + ", url=" + url
+ + ", dynamic_properties=" + dynamic_properties + "]";
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3ccbfd8a/sdks/java/src/main/java/org/apache/usergrid/java/client/entities/Device.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/entities/Device.java b/sdks/java/src/main/java/org/apache/usergrid/java/client/entities/Device.java
new file mode 100644
index 0000000..62947c2
--- /dev/null
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/entities/Device.java
@@ -0,0 +1,52 @@
+package org.apache.usergrid.java.client.entities;
+
+import static com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion.NON_NULL;
+import static org.apache.usergrid.java.client.utils.JsonUtils.getStringProperty;
+import static org.apache.usergrid.java.client.utils.JsonUtils.setStringProperty;
+
+import java.util.List;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+
+public class Device extends Entity {
+
+ public final static String ENTITY_TYPE = "device";
+
+ public final static String PROPERTY_NAME = "name";
+
+ public Device() {
+ super();
+ setType(ENTITY_TYPE);
+ }
+
+ public Device(Entity entity) {
+ super();
+ properties = entity.properties;
+ setType(ENTITY_TYPE);
+ }
+
+ @Override
+ @JsonIgnore
+ public String getNativeType() {
+ return ENTITY_TYPE;
+ }
+
+ @Override
+ @JsonIgnore
+ public List<String> getPropertyNames() {
+ List<String> properties = super.getPropertyNames();
+ properties.add(PROPERTY_NAME);
+ return properties;
+ }
+
+ @JsonSerialize(include = NON_NULL)
+ public String getName() {
+ return getStringProperty(properties, PROPERTY_NAME);
+ }
+
+ public void setName(String name) {
+ setStringProperty(properties, PROPERTY_NAME, name);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3ccbfd8a/sdks/java/src/main/java/org/apache/usergrid/java/client/entities/Entity.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/entities/Entity.java b/sdks/java/src/main/java/org/apache/usergrid/java/client/entities/Entity.java
new file mode 100644
index 0000000..a306db5
--- /dev/null
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/entities/Entity.java
@@ -0,0 +1,172 @@
+package org.apache.usergrid.java.client.entities;
+
+import static org.apache.usergrid.java.client.utils.JsonUtils.*;
+import static org.apache.usergrid.java.client.utils.MapUtils.newMapWithoutKeys;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.annotation.JsonAnyGetter;
+import com.fasterxml.jackson.annotation.JsonAnySetter;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
+public class Entity {
+
+ public final static String PROPERTY_UUID = "uuid";
+ public final static String PROPERTY_TYPE = "type";
+
+ protected Map<String, JsonNode> properties = new HashMap<String, JsonNode>();
+
+ public static Map<String, Class<? extends Entity>> CLASS_FOR_ENTITY_TYPE = new HashMap<String, Class<? extends Entity>>();
+ static {
+ CLASS_FOR_ENTITY_TYPE.put(User.ENTITY_TYPE, User.class);
+ }
+
+ public Entity() {
+ }
+
+ public Entity(String type) {
+ setType(type);
+ }
+
+ @JsonIgnore
+ public String getNativeType() {
+ return getType();
+ }
+
+ @JsonIgnore
+ public List<String> getPropertyNames() {
+ List<String> properties = new ArrayList<String>();
+ properties.add(PROPERTY_TYPE);
+ properties.add(PROPERTY_UUID);
+ return properties;
+ }
+
+ public String getType() {
+ return getStringProperty(properties, PROPERTY_TYPE);
+ }
+
+ public void setType(String type) {
+ setStringProperty(properties, PROPERTY_TYPE, type);
+ }
+
+ public UUID getUuid() {
+ return getUUIDProperty(properties, PROPERTY_UUID);
+ }
+
+ public void setUuid(UUID uuid) {
+ setUUIDProperty(properties, PROPERTY_UUID, uuid);
+ }
+
+ @JsonAnyGetter
+ public Map<String, JsonNode> getProperties() {
+ return newMapWithoutKeys(properties, getPropertyNames());
+ }
+
+ @JsonAnySetter
+ public void setProperty(String name, JsonNode value) {
+ if (value == null) {
+ properties.remove(name);
+ } else {
+ properties.put(name, value);
+ }
+ }
+
+
+ /**
+ * Set the property
+ *
+ * @param name
+ * @param value
+ */
+ public void setProperty(String name, String value) {
+ setStringProperty(properties, name, value);
+ }
+
+ /**
+ * Set the property
+ *
+ * @param name
+ * @param value
+ */
+ public void setProperty(String name, boolean value) {
+ setBooleanProperty(properties, name, value);
+ }
+
+ /**
+ * Set the property
+ *
+ * @param name
+ * @param value
+ */
+ public void setProperty(String name, long value) {
+ setLongProperty(properties, name, value);
+ }
+
+ /**
+ * Set the property
+ *
+ * @param name
+ * @param value
+ */
+ public void setProperty(String name, int value) {
+ setProperty(name, (long) value);
+ }
+
+ /**
+ * Set the property
+ *
+ * @param name
+ * @param value
+ */
+ public void setProperty(String name, float value) {
+ setFloatProperty(properties, name, value);
+ }
+
+ @Override
+ public String toString() {
+ return toJsonString(this);
+ }
+
+ public <T extends Entity> T toType(Class<T> t) {
+ return toType(this, t);
+ }
+
+ public static <T extends Entity> T toType(Entity entity, Class<T> t) {
+ if (entity == null) {
+ return null;
+ }
+ T newEntity = null;
+ if (entity.getClass().isAssignableFrom(t)) {
+ try {
+ newEntity = (t.newInstance());
+ if ((newEntity.getNativeType() != null)
+ && newEntity.getNativeType().equals(entity.getType())) {
+ newEntity.properties = entity.properties;
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ return newEntity;
+ }
+
+ public static <T extends Entity> List<T> toType(List<Entity> entities,
+ Class<T> t) {
+ List<T> l = new ArrayList<T>(entities != null ? entities.size() : 0);
+ if (entities != null) {
+ for (Entity entity : entities) {
+ T newEntity = entity.toType(t);
+ if (newEntity != null) {
+ l.add(newEntity);
+ }
+ }
+ }
+ return l;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3ccbfd8a/sdks/java/src/main/java/org/apache/usergrid/java/client/entities/Group.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/entities/Group.java b/sdks/java/src/main/java/org/apache/usergrid/java/client/entities/Group.java
new file mode 100644
index 0000000..12c8dff
--- /dev/null
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/entities/Group.java
@@ -0,0 +1,63 @@
+package org.apache.usergrid.java.client.entities;
+
+import static com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion.NON_NULL;
+import static org.apache.usergrid.java.client.utils.JsonUtils.getStringProperty;
+import static org.apache.usergrid.java.client.utils.JsonUtils.setStringProperty;
+
+import java.util.List;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+
+public class Group extends Entity {
+
+ public final static String ENTITY_TYPE = "group";
+
+ public final static String PROPERTY_PATH = "path";
+ public final static String PROPERTY_TITLE = "title";
+
+ public Group() {
+ super();
+ setType(ENTITY_TYPE);
+ }
+
+ public Group(Entity entity) {
+ super();
+ properties = entity.properties;
+ setType(ENTITY_TYPE);
+ }
+
+ @Override
+ @JsonIgnore
+ public String getNativeType() {
+ return ENTITY_TYPE;
+ }
+
+ @Override
+ @JsonIgnore
+ public List<String> getPropertyNames() {
+ List<String> properties = super.getPropertyNames();
+ properties.add(PROPERTY_PATH);
+ properties.add(PROPERTY_TITLE);
+ return properties;
+ }
+
+ @JsonSerialize(include = NON_NULL)
+ public String getPath() {
+ return getStringProperty(properties, PROPERTY_PATH);
+ }
+
+ public void setPath(String path) {
+ setStringProperty(properties, PROPERTY_PATH, path);
+ }
+
+ @JsonSerialize(include = NON_NULL)
+ public String getTitle() {
+ return getStringProperty(properties, PROPERTY_TITLE);
+ }
+
+ public void setTitle(String title) {
+ setStringProperty(properties, PROPERTY_TITLE, title);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3ccbfd8a/sdks/java/src/main/java/org/apache/usergrid/java/client/entities/Message.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/entities/Message.java b/sdks/java/src/main/java/org/apache/usergrid/java/client/entities/Message.java
new file mode 100644
index 0000000..70ee86e
--- /dev/null
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/entities/Message.java
@@ -0,0 +1,132 @@
+package org.apache.usergrid.java.client.entities;
+
+import static com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion.NON_NULL;
+import static org.apache.usergrid.java.client.utils.JsonUtils.getBooleanProperty;
+import static org.apache.usergrid.java.client.utils.JsonUtils.getLongProperty;
+import static org.apache.usergrid.java.client.utils.JsonUtils.getStringProperty;
+import static org.apache.usergrid.java.client.utils.JsonUtils.getUUIDProperty;
+import static org.apache.usergrid.java.client.utils.JsonUtils.setBooleanProperty;
+import static org.apache.usergrid.java.client.utils.JsonUtils.setLongProperty;
+import static org.apache.usergrid.java.client.utils.JsonUtils.setStringProperty;
+import static org.apache.usergrid.java.client.utils.JsonUtils.setUUIDProperty;
+
+import java.util.List;
+import java.util.UUID;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion;
+
+public class Message extends Entity {
+
+ public static final String ENTITY_TYPE = "message";
+
+ public static final String PROPERTY_CORRELATION_ID = "correlation_id";
+ public static final String PROPERTY_DESTINATION = "destination";
+ public static final String PROPERTY_REPLY_TO = "reply_to";
+ public static final String PROPERTY_TIMESTAMP = "timestamp";
+ public static final String PROPERTY_TYPE = "type";
+ public static final String PROPERTY_CATEGORY = "category";
+ public static final String PROPERTY_INDEXED = "indexed";
+ public static final String PROPERTY_PERSISTENT = "persistent";
+
+ public Message() {
+ super();
+ setType(ENTITY_TYPE);
+ }
+
+ public Message(Entity entity) {
+ super();
+ properties = entity.properties;
+ setType(ENTITY_TYPE);
+ }
+
+ @Override
+ @JsonIgnore
+ public String getNativeType() {
+ return ENTITY_TYPE;
+ }
+
+ @Override
+ @JsonIgnore
+ public List<String> getPropertyNames() {
+ List<String> properties = super.getPropertyNames();
+ properties.add(PROPERTY_CORRELATION_ID);
+ properties.add(PROPERTY_DESTINATION);
+ properties.add(PROPERTY_REPLY_TO);
+ properties.add(PROPERTY_TIMESTAMP);
+ properties.add(PROPERTY_CATEGORY);
+ properties.add(PROPERTY_INDEXED);
+ properties.add(PROPERTY_PERSISTENT);
+ return properties;
+ }
+
+ @JsonSerialize(include = NON_NULL)
+ @JsonProperty(PROPERTY_CORRELATION_ID)
+ public UUID getCorrelationId() {
+ return getUUIDProperty(properties, PROPERTY_CORRELATION_ID);
+ }
+
+ @JsonProperty(PROPERTY_CORRELATION_ID)
+ public void setCorrelationId(UUID uuid) {
+ setUUIDProperty(properties, PROPERTY_CORRELATION_ID, uuid);
+ }
+
+ @JsonSerialize(include = NON_NULL)
+ public String getDestination() {
+ return getStringProperty(properties, PROPERTY_DESTINATION);
+ }
+
+ public void setDestination(String destination) {
+ setStringProperty(properties, PROPERTY_DESTINATION, destination);
+ }
+
+ @JsonSerialize(include = NON_NULL)
+ @JsonProperty(PROPERTY_REPLY_TO)
+ public String getReplyTo() {
+ return getStringProperty(properties, PROPERTY_DESTINATION);
+ }
+
+ @JsonProperty(PROPERTY_REPLY_TO)
+ public void setReplyTo(String replyTo) {
+ setStringProperty(properties, PROPERTY_DESTINATION, replyTo);
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public Long getTimestamp() {
+ return getLongProperty(properties, PROPERTY_TIMESTAMP);
+ }
+
+ public void setTimestamp(Long timestamp) {
+ setLongProperty(properties, PROPERTY_TIMESTAMP, timestamp);
+ }
+
+ @JsonSerialize(include = NON_NULL)
+ public String getCategory() {
+ return getStringProperty(properties, PROPERTY_CATEGORY);
+ }
+
+ public void setCategory(String category) {
+ setStringProperty(properties, PROPERTY_CATEGORY, category);
+ }
+
+ @JsonSerialize(include = NON_NULL)
+ public Boolean isIndexed() {
+ return getBooleanProperty(properties, PROPERTY_INDEXED);
+ }
+
+ public void setIndexed(Boolean indexed) {
+ setBooleanProperty(properties, PROPERTY_INDEXED, indexed);
+ }
+
+ @JsonSerialize(include = NON_NULL)
+ public Boolean isPersistent() {
+ return getBooleanProperty(properties, PROPERTY_INDEXED);
+ }
+
+ public void setPersistent(Boolean persistent) {
+ setBooleanProperty(properties, PROPERTY_INDEXED, persistent);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3ccbfd8a/sdks/java/src/main/java/org/apache/usergrid/java/client/entities/User.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/entities/User.java b/sdks/java/src/main/java/org/apache/usergrid/java/client/entities/User.java
new file mode 100644
index 0000000..e249896
--- /dev/null
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/entities/User.java
@@ -0,0 +1,142 @@
+package org.apache.usergrid.java.client.entities;
+
+import static com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion.NON_NULL;
+import static org.apache.usergrid.java.client.utils.JsonUtils.getBooleanProperty;
+import static org.apache.usergrid.java.client.utils.JsonUtils.getStringProperty;
+import static org.apache.usergrid.java.client.utils.JsonUtils.setBooleanProperty;
+import static org.apache.usergrid.java.client.utils.JsonUtils.setStringProperty;
+
+import java.util.List;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+
+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 User() {
+ super();
+ setType(ENTITY_TYPE);
+ }
+
+ public User(Entity entity) {
+ super();
+ properties = entity.properties;
+ setType(ENTITY_TYPE);
+ }
+
+ @Override
+ @JsonIgnore
+ public String getNativeType() {
+ return ENTITY_TYPE;
+ }
+
+ @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;
+ }
+
+ @JsonSerialize(include = NON_NULL)
+ public String getUsername() {
+ return getStringProperty(properties, PROPERTY_USERNAME);
+ }
+
+ public void setUsername(String username) {
+ setStringProperty(properties, PROPERTY_USERNAME, username);
+ }
+
+ @JsonSerialize(include = NON_NULL)
+ public String getName() {
+ return getStringProperty(properties, PROPERTY_NAME);
+ }
+
+ public void setName(String name) {
+ setStringProperty(properties, PROPERTY_NAME, name);
+ }
+
+ @JsonSerialize(include = NON_NULL)
+ public String getEmail() {
+ return getStringProperty(properties, PROPERTY_EMAIL);
+ }
+
+ public void setEmail(String email) {
+ setStringProperty(properties, PROPERTY_EMAIL, email);
+ }
+
+ @JsonSerialize(include = NON_NULL)
+ public Boolean isActivated() {
+ return getBooleanProperty(properties, PROPERTY_ACTIVATED);
+ }
+
+ public void setActivated(Boolean activated) {
+ setBooleanProperty(properties, PROPERTY_ACTIVATED, activated);
+ }
+
+ @JsonSerialize(include = NON_NULL)
+ public Boolean isDisabled() {
+ return getBooleanProperty(properties, PROPERTY_DISABLED);
+ }
+
+ public void setDisabled(Boolean disabled) {
+ setBooleanProperty(properties, PROPERTY_DISABLED, disabled);
+ }
+
+ @JsonSerialize(include = NON_NULL)
+ public String getFirstname() {
+ return getStringProperty(properties, PROPERTY_FIRSTNAME);
+ }
+
+ public void setFirstname(String firstname) {
+ setStringProperty(properties, PROPERTY_FIRSTNAME, firstname);
+ }
+
+ @JsonSerialize(include = NON_NULL)
+ public String getMiddlename() {
+ return getStringProperty(properties, PROPERTY_MIDDLENAME);
+ }
+
+ public void setMiddlename(String middlename) {
+ setStringProperty(properties, PROPERTY_MIDDLENAME, middlename);
+ }
+
+ @JsonSerialize(include = NON_NULL)
+ public String getLastname() {
+ return getStringProperty(properties, PROPERTY_LASTNAME);
+ }
+
+ public void setLastname(String lastname) {
+ setStringProperty(properties, PROPERTY_LASTNAME, lastname);
+ }
+
+ @JsonSerialize(include = NON_NULL)
+ public String getPicture() {
+ return getStringProperty(properties, PROPERTY_PICTURE);
+ }
+
+ public void setPicture(String picture) {
+ setStringProperty(properties, PROPERTY_PICTURE, picture);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3ccbfd8a/sdks/java/src/main/java/org/apache/usergrid/java/client/exception/ClientException.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/exception/ClientException.java b/sdks/java/src/main/java/org/apache/usergrid/java/client/exception/ClientException.java
new file mode 100644
index 0000000..f85e2fe
--- /dev/null
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/exception/ClientException.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright 2012 Apigee Corporation
+ *
+ * Licensed 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.java.client.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/incubator-usergrid/blob/3ccbfd8a/sdks/java/src/main/java/org/apache/usergrid/java/client/response/AggregateCounter.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/response/AggregateCounter.java b/sdks/java/src/main/java/org/apache/usergrid/java/client/response/AggregateCounter.java
new file mode 100644
index 0000000..b0ba4ec
--- /dev/null
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/response/AggregateCounter.java
@@ -0,0 +1,36 @@
+package org.apache.usergrid.java.client.response;
+
+import static org.apache.usergrid.java.client.utils.JsonUtils.toJsonString;
+
+public class AggregateCounter {
+
+ private long timestamp;
+ private long value;
+
+ 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/incubator-usergrid/blob/3ccbfd8a/sdks/java/src/main/java/org/apache/usergrid/java/client/response/AggregateCounterSet.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/response/AggregateCounterSet.java b/sdks/java/src/main/java/org/apache/usergrid/java/client/response/AggregateCounterSet.java
new file mode 100644
index 0000000..a392b5f
--- /dev/null
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/response/AggregateCounterSet.java
@@ -0,0 +1,95 @@
+package org.apache.usergrid.java.client.response;
+
+import static org.apache.usergrid.java.client.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(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/incubator-usergrid/blob/3ccbfd8a/sdks/java/src/main/java/org/apache/usergrid/java/client/response/ApiResponse.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/response/ApiResponse.java b/sdks/java/src/main/java/org/apache/usergrid/java/client/response/ApiResponse.java
new file mode 100644
index 0000000..188ccef
--- /dev/null
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/response/ApiResponse.java
@@ -0,0 +1,406 @@
+package org.apache.usergrid.java.client.response;
+
+import static org.apache.usergrid.java.client.utils.JsonUtils.toJsonString;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import com.fasterxml.jackson.databind.JsonNode;
+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.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion;
+
+import org.apache.usergrid.java.client.entities.Entity;
+import org.apache.usergrid.java.client.entities.Message;
+import org.apache.usergrid.java.client.entities.User;
+
+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 final Map<String, JsonNode> properties = new HashMap<String, JsonNode>();
+
+ public ApiResponse() {
+ }
+
+ @JsonAnyGetter
+ public Map<String, JsonNode> getProperties() {
+ return properties;
+ }
+
+ @JsonAnySetter
+ public void setProperty(String key, JsonNode value) {
+ properties.put(key, value);
+ }
+
+ @JsonProperty("access_token")
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public String getAccessToken() {
+ return accessToken;
+ }
+
+ @JsonProperty("access_token")
+ public void setAccessToken(String accessToken) {
+ this.accessToken = accessToken;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public String getError() {
+ return error;
+ }
+
+ public void setError(String error) {
+ this.error = error;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ @JsonProperty("error_description")
+ public String getErrorDescription() {
+ return errorDescription;
+ }
+
+ @JsonProperty("error_description")
+ public void setErrorDescription(String errorDescription) {
+ this.errorDescription = errorDescription;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ @JsonProperty("error_uri")
+ public String getErrorUri() {
+ return errorUri;
+ }
+
+ @JsonProperty("error_uri")
+ public void setErrorUri(String errorUri) {
+ this.errorUri = errorUri;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public String getException() {
+ return exception;
+ }
+
+ public void setException(String exception) {
+ this.exception = exception;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public String getPath() {
+ return path;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public String getUri() {
+ return uri;
+ }
+
+ public void setUri(String uri) {
+ this.uri = uri;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+ public long getTimestamp() {
+ return timestamp;
+ }
+
+ public void setTimestamp(long timestamp) {
+ this.timestamp = timestamp;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public UUID getApplication() {
+ return application;
+ }
+
+ public void setApplication(UUID application) {
+ this.application = application;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public List<Entity> getEntities() {
+ return entities;
+ }
+
+ public void setEntities(List<Entity> entities) {
+ this.entities = entities;
+ }
+
+ public int getEntityCount() {
+ if (entities == null) {
+ return 0;
+ }
+ return entities.size();
+ }
+
+ public Entity getFirstEntity() {
+ if ((entities != null) && (entities.size() > 0)) {
+ return entities.get(0);
+ }
+ return null;
+ }
+
+ public <T extends Entity> T getFirstEntity(Class<T> t) {
+ return Entity.toType(getFirstEntity(), t);
+ }
+
+ public Entity getLastEntity() {
+ if ((entities != null) && (entities.size() > 0)) {
+ return entities.get(entities.size() - 1);
+ }
+ return null;
+ }
+
+ public <T extends Entity> T getLastEntity(Class<T> t) {
+ return Entity.toType(getLastEntity(), t);
+ }
+
+ public <T extends Entity> List<T> getEntities(Class<T> t) {
+ return Entity.toType(entities, t);
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public UUID getNext() {
+ return next;
+ }
+
+ public void setNext(UUID next) {
+ this.next = next;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public String getCursor() {
+ return cursor;
+ }
+
+ public void setCursor(String cursor) {
+ this.cursor = cursor;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public String getAction() {
+ return action;
+ }
+
+ public void setAction(String action) {
+ this.action = action;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public List<Object> getList() {
+ return list;
+ }
+
+ public void setList(List<Object> list) {
+ this.list = list;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public Object getData() {
+ return data;
+ }
+
+ public void setData(Object data) {
+ this.data = data;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public Map<String, UUID> getApplications() {
+ return applications;
+ }
+
+ public void setApplications(Map<String, UUID> applications) {
+ this.applications = applications;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public Map<String, JsonNode> getMetadata() {
+ return metadata;
+ }
+
+ public void setMetadata(Map<String, JsonNode> metadata) {
+ this.metadata = metadata;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public Map<String, List<String>> getParams() {
+ return params;
+ }
+
+ public void setParams(Map<String, List<String>> params) {
+ this.params = params;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public List<AggregateCounterSet> getCounters() {
+ return counters;
+ }
+
+ public void setCounters(List<AggregateCounterSet> counters) {
+ this.counters = counters;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public ClientCredentialsInfo getCredentials() {
+ return credentials;
+ }
+
+ public void setCredentials(ClientCredentialsInfo credentials) {
+ this.credentials = credentials;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public User getUser() {
+ return user;
+ }
+
+ public void setUser(User user) {
+ this.user = user;
+ }
+
+ @Override
+ public String toString() {
+ return toJsonString(this);
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public List<Message> getMessages() {
+ return messages;
+ }
+
+ public void setMessages(List<Message> messages) {
+ this.messages = messages;
+ }
+
+ @JsonIgnore
+ public int getMessageCount() {
+ if (messages == null) {
+ return 0;
+ }
+ return messages.size();
+ }
+
+ @JsonIgnore
+ public Message getFirstMessage() {
+ if ((messages != null) && (messages.size() > 0)) {
+ return messages.get(0);
+ }
+ return null;
+ }
+
+ @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;
+ }
+
+ public void setLast(UUID last) {
+ this.last = last;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public List<QueueInfo> getQueues() {
+ return queues;
+ }
+
+ public void setQueues(List<QueueInfo> queues) {
+ this.queues = queues;
+ }
+
+ @JsonIgnore
+ public QueueInfo getFirstQueue() {
+ if ((queues != null) && (queues.size() > 0)) {
+ return queues.get(0);
+ }
+ return null;
+ }
+
+ @JsonIgnore
+ public QueueInfo getLastQueue() {
+ if ((queues != null) && (queues.size() > 0)) {
+ return queues.get(queues.size() - 1);
+ }
+ return null;
+ }
+
+ @JsonIgnore
+ public UUID getLastQueueId() {
+ QueueInfo q = getLastQueue();
+ if (q != null) {
+ return q.getQueue();
+ }
+ return null;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public UUID getQueue() {
+ return queue;
+ }
+
+ public void setQueue(UUID queue) {
+ this.queue = queue;
+ }
+
+ @JsonSerialize(include = Inclusion.NON_NULL)
+ public UUID getConsumer() {
+ return consumer;
+ }
+
+ public void setConsumer(UUID consumer) {
+ this.consumer = consumer;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3ccbfd8a/sdks/java/src/main/java/org/apache/usergrid/java/client/response/ClientCredentialsInfo.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/response/ClientCredentialsInfo.java b/sdks/java/src/main/java/org/apache/usergrid/java/client/response/ClientCredentialsInfo.java
new file mode 100644
index 0000000..d23414b
--- /dev/null
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/response/ClientCredentialsInfo.java
@@ -0,0 +1,42 @@
+package org.apache.usergrid.java.client.response;
+
+import static org.apache.usergrid.java.client.utils.JsonUtils.toJsonString;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+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/incubator-usergrid/blob/3ccbfd8a/sdks/java/src/main/java/org/apache/usergrid/java/client/response/QueueInfo.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/response/QueueInfo.java b/sdks/java/src/main/java/org/apache/usergrid/java/client/response/QueueInfo.java
new file mode 100644
index 0000000..c0072bc
--- /dev/null
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/response/QueueInfo.java
@@ -0,0 +1,28 @@
+package org.apache.usergrid.java.client.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/incubator-usergrid/blob/3ccbfd8a/sdks/java/src/main/java/org/apache/usergrid/java/client/utils/JsonUtils.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/utils/JsonUtils.java b/sdks/java/src/main/java/org/apache/usergrid/java/client/utils/JsonUtils.java
new file mode 100644
index 0000000..81f287d
--- /dev/null
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/utils/JsonUtils.java
@@ -0,0 +1,167 @@
+package org.apache.usergrid.java.client.utils;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.UUID;
+
+import com.fasterxml.jackson.core.JsonGenerationException;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
+
+import org.apache.usergrid.java.client.exception.ClientException;
+
+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/incubator-usergrid/blob/3ccbfd8a/sdks/java/src/main/java/org/apache/usergrid/java/client/utils/MapUtils.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/utils/MapUtils.java b/sdks/java/src/main/java/org/apache/usergrid/java/client/utils/MapUtils.java
new file mode 100644
index 0000000..f7e4a1c
--- /dev/null
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/utils/MapUtils.java
@@ -0,0 +1,23 @@
+package org.apache.usergrid.java.client.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/incubator-usergrid/blob/3ccbfd8a/sdks/java/src/main/java/org/apache/usergrid/java/client/utils/ObjectUtils.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/utils/ObjectUtils.java b/sdks/java/src/main/java/org/apache/usergrid/java/client/utils/ObjectUtils.java
new file mode 100644
index 0000000..c47002b
--- /dev/null
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/utils/ObjectUtils.java
@@ -0,0 +1,20 @@
+package org.apache.usergrid.java.client.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/incubator-usergrid/blob/3ccbfd8a/sdks/java/src/main/java/org/apache/usergrid/java/client/utils/UrlUtils.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/utils/UrlUtils.java b/sdks/java/src/main/java/org/apache/usergrid/java/client/utils/UrlUtils.java
new file mode 100644
index 0000000..e2d101e
--- /dev/null
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/utils/UrlUtils.java
@@ -0,0 +1,108 @@
+package org.apache.usergrid.java.client.utils;
+
+import static java.net.URLEncoder.encode;
+import static org.apache.usergrid.java.client.utils.ObjectUtils.isEmpty;
+
+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.java.client.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;
+ }
+
+}