You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by mr...@apache.org on 2016/06/02 17:07:22 UTC
[04/54] [abbrv] usergrid git commit: Initial commit for new JavaSDK.
http://git-wip-us.apache.org/repos/asf/usergrid/blob/2e127e62/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridClient.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridClient.java b/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridClient.java
new file mode 100644
index 0000000..396c8f6
--- /dev/null
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridClient.java
@@ -0,0 +1,420 @@
+/*
+ * 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.java.client;
+
+import org.apache.usergrid.java.client.UsergridEnums.*;
+import org.apache.usergrid.java.client.auth.UsergridAppAuth;
+import org.apache.usergrid.java.client.auth.UsergridAuth;
+import org.apache.usergrid.java.client.auth.UsergridUserAuth;
+import org.apache.usergrid.java.client.model.*;
+import org.apache.usergrid.java.client.query.UsergridQuery;
+import org.apache.usergrid.java.client.response.UsergridResponse;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@SuppressWarnings("unused")
+public class UsergridClient {
+
+ @NotNull public static String DEFAULT_BASE_URL = "https://api.usergrid.com";
+
+ @NotNull private UsergridClientConfig config;
+ @Nullable private UsergridUser currentUser = null;
+ @Nullable private UsergridAuth tempAuth = null;
+
+ @NotNull private final UsergridRequestManager requestManager;
+
+ public UsergridClient(@NotNull final UsergridClientConfig config) {
+ this.config = config;
+ this.requestManager = new UsergridRequestManager(this);
+ }
+
+ public UsergridClient(@NotNull final String orgId, @NotNull final String appId) {
+ this(new UsergridClientConfig(orgId, appId));
+ }
+
+ public UsergridClient(@NotNull final String orgId, @NotNull final String appId, @NotNull final String baseUrl) {
+ this(new UsergridClientConfig(orgId, appId, baseUrl));
+ }
+
+ public UsergridClient(@NotNull final String orgId, @NotNull final String appId, @NotNull final String baseUrl, @NotNull final UsergridAuthMode authMode) {
+ this(new UsergridClientConfig(orgId, appId, baseUrl, authMode));
+ }
+
+ @NotNull public UsergridClientConfig getConfig() { return this.config; }
+ public void setConfig(@NotNull final UsergridClientConfig config) { this.config = config; }
+
+ @NotNull public String getAppId() { return this.config.appId; }
+ public void setAppId(@NotNull final String appId) { this.config.appId = appId; }
+
+ @NotNull public String getOrgId() { return this.config.orgId; }
+ public void setOrgId(@NotNull final String orgId) { this.config.orgId = orgId; }
+
+ @NotNull public String getBaseUrl() { return this.config.baseUrl; }
+ public void setBaseUrl(@NotNull final String baseUrl) { this.config.baseUrl = baseUrl; }
+
+ @NotNull public String clientAppUrl() { return getBaseUrl() + "/" + getOrgId() + "/" + getAppId(); }
+
+ @NotNull public UsergridAuthMode getAuthMode() { return this.config.authMode; }
+ public void setAuthMode(@NotNull final UsergridAuthMode authMode) { this.config.authMode = authMode; }
+
+ @Nullable public UsergridUser getCurrentUser() { return this.currentUser; }
+ public void setCurrentUser(@Nullable final UsergridUser currentUser) { this.currentUser = currentUser; }
+
+ @Nullable public UsergridUserAuth getUserAuth() { return (this.currentUser != null) ? this.currentUser.getUserAuth() : null; }
+
+ @Nullable public UsergridAppAuth getAppAuth() { return this.config.appAuth; }
+ public void setAppAuth(@Nullable final UsergridAppAuth appAuth) { this.config.appAuth = appAuth; }
+
+ @Nullable
+ public UsergridAuth authForRequests() {
+ UsergridAuth authForRequests = null;
+ if (tempAuth != null) {
+ if (tempAuth.isValidToken()) {
+ authForRequests = tempAuth;
+ }
+ tempAuth = null;
+ } else {
+ switch (config.authMode) {
+ case USER: {
+ if (this.currentUser != null && this.currentUser.getUserAuth() != null && this.currentUser.getUserAuth().isValidToken()) {
+ authForRequests = this.currentUser.getUserAuth();
+ }
+ break;
+ }
+ case APP: {
+ if (this.config.appAuth != null && this.config.appAuth.isValidToken()) {
+ authForRequests = this.config.appAuth;
+ }
+ break;
+ }
+ }
+ }
+ return authForRequests;
+ }
+
+ @NotNull
+ public UsergridClient usingAuth(@Nullable final UsergridAuth auth) {
+ this.tempAuth = auth;
+ return this;
+ }
+
+ @NotNull
+ public UsergridClient usingToken(@NotNull final String accessToken) {
+ this.tempAuth = new UsergridAuth(accessToken);
+ return this;
+ }
+
+ @NotNull
+ public UsergridResponse authenticateApp() {
+ if( this.config.appAuth == null ) {
+ return UsergridResponse.fromError(this, "Invalid UsergridAppAuth.", "UsergridClient's appAuth is null.");
+ }
+ return this.authenticateApp(this.config.appAuth);
+ }
+
+ @NotNull
+ public UsergridResponse authenticateApp(@NotNull final UsergridAppAuth auth) {
+ this.config.appAuth = auth;
+ return this.requestManager.authenticateApp(auth);
+ }
+
+ @NotNull
+ public UsergridResponse authenticateUser(@NotNull final UsergridUserAuth userAuth) {
+ return this.authenticateUser(userAuth,true);
+ }
+
+ @NotNull
+ public UsergridResponse authenticateUser(@NotNull final UsergridUserAuth userAuth, final boolean setAsCurrentUser) {
+ UsergridResponse response = this.requestManager.authenticateUser(userAuth);
+ if( response.ok() && setAsCurrentUser ) {
+ this.setCurrentUser(response.user());
+ }
+ return response;
+ }
+
+ @NotNull
+ public UsergridResponse resetPassword(@NotNull final UsergridUser user, @NotNull final String oldPassword, @NotNull final String newPassword) {
+ String usernameOrEmail = user.usernameOrEmail();
+ if( usernameOrEmail == null ) {
+ return UsergridResponse.fromError(this, "Error resetting password.", "The UsergridUser object must contain a valid username or email to reset the password.");
+ }
+ Map<String, Object> data = new HashMap<>();
+ data.put("newpassword", newPassword);
+ data.put("oldpassword", oldPassword);
+ String[] pathSegments = { "users", usernameOrEmail, "password"};
+ UsergridRequest request = new UsergridRequest(UsergridHttpMethod.POST, UsergridRequest.APPLICATION_JSON_MEDIA_TYPE, this.clientAppUrl(), null, data, this.authForRequests() ,pathSegments);
+ return this.sendRequest(request);
+ }
+
+ @NotNull
+ public UsergridResponse logoutCurrentUser() {
+ UsergridUser currentUser = this.currentUser;
+ if( currentUser != null ) {
+ String uuidOrUsername = currentUser.uuidOrUsername();
+ UsergridUserAuth userAuth = currentUser.getUserAuth();
+ if( uuidOrUsername != null && userAuth != null ) {
+ String accessToken = userAuth.getAccessToken();
+ if( accessToken != null ) {
+ return logoutUser(uuidOrUsername, accessToken);
+ }
+ }
+ }
+ return UsergridResponse.fromError(this,"UsergridClient's currentUser is not valid.", "UsergridClient's currentUser is null or has no uuid or username.");
+ }
+
+ @NotNull
+ public UsergridResponse logoutUserAllTokens(@NotNull final String uuidOrUsername) {
+ return logoutUser(uuidOrUsername, null);
+ }
+
+ @NotNull
+ public UsergridResponse logoutUser(@NotNull final String uuidOrUsername, @Nullable final String token){
+ String[] pathSegments = {"users", uuidOrUsername, ""};
+ int len = pathSegments.length;
+ Map<String, Object> param = new HashMap<>();
+ if(token != null){
+ pathSegments[len-1] = "revoketoken";
+ param.put("token",token);
+ }
+ else{
+ pathSegments[len-1] = "revoketokens";
+ }
+ UsergridRequest request = new UsergridRequest(UsergridHttpMethod.PUT, UsergridRequest.APPLICATION_JSON_MEDIA_TYPE, this.clientAppUrl(), param, null, this.authForRequests() , pathSegments);
+ return this.sendRequest(request);
+ }
+
+ @NotNull
+ public UsergridResponse sendRequest(@NotNull final UsergridRequest request) {
+ return this.requestManager.performRequest(request);
+ }
+
+ @NotNull
+ public UsergridResponse GET(@NotNull final String type, @NotNull final String uuidOrName) {
+ String[] pathSegments = {type, uuidOrName};
+ UsergridRequest request = new UsergridRequest(UsergridHttpMethod.GET, UsergridRequest.APPLICATION_JSON_MEDIA_TYPE, this.clientAppUrl(), this.authForRequests() , pathSegments);
+ return this.sendRequest(request);
+ }
+
+ @NotNull
+ public UsergridResponse GET(@NotNull final String type) {
+ String[] pathSegments = {type};
+ UsergridRequest request = new UsergridRequest(UsergridHttpMethod.GET, UsergridRequest.APPLICATION_JSON_MEDIA_TYPE, this.clientAppUrl(), this.authForRequests() , pathSegments);
+ return this.sendRequest(request);
+ }
+
+ @NotNull
+ public UsergridResponse GET(@NotNull final UsergridQuery query) {
+ String collectionName = query.getCollection();
+ if( collectionName == null ) {
+ return UsergridResponse.fromError(this, "Query collection name missing.", "Query collection name is missing.");
+ }
+ UsergridRequest request = new UsergridRequest(UsergridHttpMethod.GET, UsergridRequest.APPLICATION_JSON_MEDIA_TYPE, this.clientAppUrl(), query, this.authForRequests() , collectionName);
+ return this.sendRequest(request);
+ }
+
+ @NotNull
+ public UsergridResponse PUT(@NotNull final String type, @NotNull final String uuidOrName, @NotNull final Map<String, Object> jsonBody) {
+ String[] pathSegments = { type, uuidOrName };
+ UsergridRequest request = new UsergridRequest(UsergridHttpMethod.PUT, UsergridRequest.APPLICATION_JSON_MEDIA_TYPE, this.clientAppUrl(), null, jsonBody, this.authForRequests() , pathSegments);
+ return this.sendRequest(request);
+ }
+
+ @NotNull
+ public UsergridResponse PUT(@NotNull final String type, @NotNull final Map<String, Object> jsonBody) {
+ String uuidOrName = null;
+ Object uuid = jsonBody.get(UsergridEntityProperties.UUID.toString());
+ if( uuid != null ) {
+ uuidOrName = uuid.toString();
+ } else {
+ Object name = jsonBody.get(UsergridEntityProperties.NAME.toString());
+ if( name != null ) {
+ uuidOrName = name.toString();
+ }
+ }
+ if( uuidOrName == null ) {
+ return UsergridResponse.fromError(this, "jsonBody not valid..", "The `jsonBody` must contain a valid value for either `uuid` or `name`.");
+ }
+ String[] pathSegments = { type, uuidOrName };
+ UsergridRequest request = new UsergridRequest(UsergridHttpMethod.PUT, UsergridRequest.APPLICATION_JSON_MEDIA_TYPE, this.clientAppUrl(), null, jsonBody, this.authForRequests() , pathSegments);
+ return this.sendRequest(request);
+ }
+
+ @NotNull
+ public UsergridResponse PUT(@NotNull final UsergridEntity entity) {
+ String entityUuidOrName = entity.uuidOrName();
+ if( entityUuidOrName == null ) {
+ return UsergridResponse.fromError(this, "No UUID or name found.", "The entity object must have a `uuid` or `name` assigned.");
+ }
+ String[] pathSegments = { entity.getType(), entityUuidOrName };
+ UsergridRequest request = new UsergridRequest(UsergridHttpMethod.PUT, UsergridRequest.APPLICATION_JSON_MEDIA_TYPE, this.clientAppUrl(), null, entity, this.authForRequests() , pathSegments);
+ return this.sendRequest(request);
+ }
+
+ @NotNull
+ public UsergridResponse PUT(@NotNull final UsergridQuery query, @NotNull final Map<String, Object> jsonBody) {
+ String collectionName = query.getCollection();
+ if( collectionName == null ) {
+ return UsergridResponse.fromError(this, "Query collection name missing.", "Query collection name is missing.");
+ }
+ UsergridRequest request = new UsergridRequest(UsergridHttpMethod.PUT, UsergridRequest.APPLICATION_JSON_MEDIA_TYPE, this.clientAppUrl(), null, jsonBody, null, query, this.authForRequests(),collectionName);
+ return this.sendRequest(request);
+ }
+
+ @NotNull
+ public UsergridResponse POST(final @NotNull UsergridEntity entity) {
+ String[] pathSegments = {entity.getType()};
+ UsergridRequest request = new UsergridRequest(UsergridHttpMethod.POST, UsergridRequest.APPLICATION_JSON_MEDIA_TYPE, this.clientAppUrl(), null, entity, this.authForRequests() , pathSegments);
+ return this.sendRequest(request);
+ }
+
+ @NotNull
+ public UsergridResponse POST(@NotNull final List<UsergridEntity> entities) {
+ if( entities.isEmpty() ) {
+ return UsergridResponse.fromError(this, "Unable to POST entities.", "entities array is empty.");
+ }
+ String[] pathSegments = {entities.get(0).getType()};
+ UsergridRequest request = new UsergridRequest(UsergridHttpMethod.POST, UsergridRequest.APPLICATION_JSON_MEDIA_TYPE, this.clientAppUrl(), null, entities, this.authForRequests() , pathSegments);
+ return this.sendRequest(request);
+ }
+
+ @NotNull
+ public UsergridResponse POST(@NotNull final String type, @NotNull final String uuidOrName, @NotNull final Map<String, Object> jsonBody) {
+ String[] pathSegments = {type, uuidOrName};
+ UsergridRequest request = new UsergridRequest(UsergridHttpMethod.POST, UsergridRequest.APPLICATION_JSON_MEDIA_TYPE, this.clientAppUrl(), null, jsonBody, this.authForRequests() , pathSegments);
+ return this.sendRequest(request);
+ }
+
+ @NotNull
+ public UsergridResponse POST(@NotNull final String type, @NotNull final Map<String, Object> jsonBody) {
+ UsergridRequest request = new UsergridRequest(UsergridHttpMethod.POST, UsergridRequest.APPLICATION_JSON_MEDIA_TYPE, this.clientAppUrl(), null, jsonBody, this.authForRequests() , type);
+ return this.sendRequest(request);
+ }
+
+ @NotNull
+ public UsergridResponse POST(@NotNull final String type, @NotNull final List<Map<String, Object>> jsonBodies) {
+ UsergridRequest request = new UsergridRequest(UsergridHttpMethod.POST, UsergridRequest.APPLICATION_JSON_MEDIA_TYPE, this.clientAppUrl(), null, jsonBodies, this.authForRequests() , type);
+ return this.sendRequest(request);
+ }
+
+ @NotNull
+ public UsergridResponse DELETE(@NotNull final UsergridEntity entity) {
+ String entityUuidOrName = entity.uuidOrName();
+ if( entityUuidOrName == null ) {
+ return UsergridResponse.fromError(this, "No UUID or name found.", "The entity object must have a `uuid` or `name` assigned.");
+ }
+ String[] pathSegments = {entity.getType(), entityUuidOrName};
+ UsergridRequest request = new UsergridRequest(UsergridHttpMethod.DELETE, UsergridRequest.APPLICATION_JSON_MEDIA_TYPE, this.clientAppUrl(), this.authForRequests() , pathSegments);
+ return this.sendRequest(request);
+ }
+
+ @NotNull
+ public UsergridResponse DELETE(@NotNull final String type, @NotNull final String uuidOrName) {
+ String[] pathSegments = {type, uuidOrName};
+ UsergridRequest request = new UsergridRequest(UsergridHttpMethod.DELETE, UsergridRequest.APPLICATION_JSON_MEDIA_TYPE, this.clientAppUrl(), this.authForRequests() , pathSegments);
+ return this.sendRequest(request);
+ }
+
+ @NotNull
+ public UsergridResponse DELETE(@NotNull final UsergridQuery query) {
+ String collectionName = query.getCollection();
+ if( collectionName == null ) {
+ return UsergridResponse.fromError(this, "Query collection name missing.", "Query collection name is missing.");
+ }
+ UsergridRequest request = new UsergridRequest(UsergridHttpMethod.DELETE, UsergridRequest.APPLICATION_JSON_MEDIA_TYPE, this.clientAppUrl(), query, this.authForRequests() , collectionName);
+ return this.sendRequest(request);
+ }
+
+ @NotNull
+ public UsergridResponse connect(@NotNull final UsergridEntity entity, @NotNull final String relationship, @NotNull final UsergridEntity to) {
+ String entityUuidOrName = entity.uuidOrName();
+ String toUuidOrName = to.uuidOrName();
+ if( entityUuidOrName == null || toUuidOrName == null ) {
+ return UsergridResponse.fromError(this, "Invalid Entity Connection Attempt.", "One or both entities that are attempting to be connected do not contain a valid UUID or Name property.");
+ }
+ return this.connect(entity.getType(), entityUuidOrName, relationship, to.getType(), toUuidOrName);
+ }
+
+ @NotNull
+ public UsergridResponse connect(@NotNull final String entityType, @NotNull final String entityId, @NotNull final String relationship, @NotNull final String toType, @NotNull final String toName) {
+ String[] pathSegments = {entityType, entityId, relationship, toType, toName};
+ UsergridRequest request = new UsergridRequest(UsergridHttpMethod.POST, UsergridRequest.APPLICATION_JSON_MEDIA_TYPE, this.clientAppUrl(), this.authForRequests() , pathSegments);
+ return this.sendRequest(request);
+ }
+
+ @NotNull
+ public UsergridResponse connect(@NotNull final String entityType, @NotNull final String entityId, @NotNull final String relationship, @NotNull final String toId) {
+ String[] pathSegments = { entityType, entityId, relationship, toId};
+ UsergridRequest request = new UsergridRequest(UsergridHttpMethod.POST, UsergridRequest.APPLICATION_JSON_MEDIA_TYPE, this.clientAppUrl(), this.authForRequests() , pathSegments);
+ return this.sendRequest(request);
+ }
+
+ @NotNull
+ public UsergridResponse disconnect(@NotNull final String entityType, @NotNull final String entityId, @NotNull final String relationship, @NotNull final String fromUuid) {
+ String[] pathSegments = {entityType, entityId, relationship, fromUuid};
+ UsergridRequest request = new UsergridRequest(UsergridHttpMethod.DELETE, UsergridRequest.APPLICATION_JSON_MEDIA_TYPE, this.clientAppUrl(), this.authForRequests() , pathSegments);
+ return this.sendRequest(request);
+ }
+
+ @NotNull
+ public UsergridResponse disconnect(@NotNull final String entityType, @NotNull final String entityId, @NotNull final String relationship, @NotNull final String fromType, @NotNull final String fromName) {
+ String[] pathSegments = {entityType, entityId, relationship, fromType, fromName};
+ UsergridRequest request = new UsergridRequest(UsergridHttpMethod.DELETE, UsergridRequest.APPLICATION_JSON_MEDIA_TYPE, this.clientAppUrl(), this.authForRequests() , pathSegments);
+ return this.sendRequest(request);
+ }
+
+ @NotNull
+ public UsergridResponse disconnect(@NotNull final UsergridEntity entity, @NotNull final String relationship, @NotNull final UsergridEntity from) {
+ String entityUuidOrName = entity.uuidOrName();
+ String fromUuidOrName = from.uuidOrName();
+ if( entityUuidOrName == null || fromUuidOrName == null ) {
+ return UsergridResponse.fromError(this, "Invalid Entity Disconnect Attempt.", "One or both entities that are attempting to be disconnected do not contain a valid UUID or Name property.");
+ }
+ return this.disconnect(entity.getType(), entityUuidOrName, relationship, from.getType(), fromUuidOrName);
+ }
+
+ @NotNull
+ public UsergridResponse getConnections(@NotNull final UsergridDirection direction, @NotNull final UsergridEntity entity, @NotNull final String relationship) {
+ return this.getConnections(direction,entity,relationship,null);
+ }
+
+ @NotNull
+ public UsergridResponse getConnections(@NotNull final UsergridDirection direction, @NotNull final UsergridEntity entity, @NotNull final String relationship, @Nullable final UsergridQuery query) {
+ String entityUuidOrName = entity.uuidOrName();
+ if( entityUuidOrName == null ) {
+ return UsergridResponse.fromError(this, "Invalid Entity Get Connections Attempt.", "The entity must have a `uuid` or `name` assigned.");
+ }
+ return this.getConnections(direction,entity.getType(),entityUuidOrName,relationship,query);
+ }
+
+ @NotNull
+ public UsergridResponse getConnections(@NotNull final UsergridDirection direction, @NotNull final String type, @NotNull final String uuidOrName, @NotNull final String relationship, @Nullable final UsergridQuery query) {
+ String[] pathSegments = {type, uuidOrName, direction.connectionValue(), relationship};
+ UsergridRequest request = new UsergridRequest(UsergridHttpMethod.GET, UsergridRequest.APPLICATION_JSON_MEDIA_TYPE, this.clientAppUrl(), query, this.authForRequests() , pathSegments);
+ return this.sendRequest(request);
+ }
+
+ @NotNull
+ public UsergridResponse getConnections(@NotNull final UsergridDirection direction, @NotNull final String uuid, @NotNull final String relationship, @Nullable final UsergridQuery query) {
+ String[] pathSegments = {uuid, direction.connectionValue(), relationship};
+ UsergridRequest request = new UsergridRequest(UsergridHttpMethod.GET, UsergridRequest.APPLICATION_JSON_MEDIA_TYPE, this.clientAppUrl(), query, this.authForRequests() , pathSegments);
+ return this.sendRequest(request);
+ }
+}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/2e127e62/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridClientConfig.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridClientConfig.java b/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridClientConfig.java
new file mode 100644
index 0000000..b27d914
--- /dev/null
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridClientConfig.java
@@ -0,0 +1,57 @@
+/*
+ * 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.java.client;
+
+import org.apache.usergrid.java.client.UsergridEnums.UsergridAuthMode;
+import org.apache.usergrid.java.client.auth.UsergridAppAuth;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+public class UsergridClientConfig {
+
+ // The organization identifier.
+ @NotNull public String orgId;
+
+ // The application identifier.
+ @NotNull public String appId;
+
+ // The base URL that all calls will be made with.
+ @NotNull public String baseUrl = UsergridClient.DEFAULT_BASE_URL;
+
+ // The `UsergridAuthMode` value used to determine what type of token will be sent, if any.
+ @NotNull public UsergridAuthMode authMode = UsergridAuthMode.USER;
+
+ @Nullable public UsergridAppAuth appAuth = null;
+
+ public UsergridClientConfig(@NotNull final String orgId, @NotNull final String appId) {
+ this.orgId = orgId;
+ this.appId = appId;
+ }
+
+ public UsergridClientConfig(@NotNull final String orgId, @NotNull final String appId, @NotNull final String baseUrl) {
+ this.orgId = orgId;
+ this.appId = appId;
+ this.baseUrl = baseUrl;
+ }
+
+ public UsergridClientConfig(@NotNull final String orgId, @NotNull final String appId, @NotNull final String baseUrl, @NotNull final UsergridAuthMode authMode) {
+ this.orgId = orgId;
+ this.appId = appId;
+ this.baseUrl = baseUrl;
+ this.authMode = authMode;
+ }
+}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/2e127e62/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridEnums.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridEnums.java b/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridEnums.java
new file mode 100644
index 0000000..4e2a8b0
--- /dev/null
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridEnums.java
@@ -0,0 +1,170 @@
+/*
+ * 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.java.client;
+
+import org.apache.usergrid.java.client.model.UsergridEntity;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+@SuppressWarnings("unused")
+public class UsergridEnums {
+ public enum UsergridAuthMode {
+ NONE,
+ USER,
+ APP
+ }
+
+ public enum UsergridDirection {
+ IN("connecting"),
+ OUT("connections");
+
+ @NotNull private final String connectionValue;
+
+ UsergridDirection(@NotNull final String connectionValue) {
+ this.connectionValue = connectionValue;
+ }
+
+ @NotNull
+ public String connectionValue() {
+ return this.connectionValue;
+ }
+ }
+
+ public enum UsergridHttpMethod {
+ GET,
+ PUT,
+ POST,
+ DELETE;
+
+ @Nullable
+ public static UsergridHttpMethod fromString(@NotNull final String stringValue) {
+ try {
+ return UsergridHttpMethod.valueOf(stringValue.toUpperCase());
+ } catch(Exception e) {
+ return null;
+ }
+ }
+
+ @Override @NotNull
+ public String toString() {
+ return super.toString().toUpperCase();
+ }
+ }
+
+ public enum UsergridQueryOperator {
+ EQUAL("="),
+ GREATER_THAN(">"),
+ GREATER_THAN_EQUAL_TO(">="),
+ LESS_THAN("<"),
+ LESS_THAN_EQUAL_TO("<=");
+
+ @NotNull private final String operatorValue;
+
+ UsergridQueryOperator(@NotNull final String operatorValue) {
+ this.operatorValue = operatorValue;
+ }
+
+ @NotNull
+ public String operatorValue() {
+ return this.operatorValue;
+ }
+ }
+
+ public enum UsergridQuerySortOrder {
+ ASC,
+ DESC;
+
+ @Nullable
+ public static UsergridQuerySortOrder fromString(@NotNull final String stringValue) {
+ try {
+ return UsergridQuerySortOrder.valueOf(stringValue.toUpperCase());
+ } catch(Exception e) {
+ return null;
+ }
+ }
+
+ @Override @NotNull
+ public String toString() {
+ return super.toString().toLowerCase();
+ }
+ }
+
+ public enum UsergridEntityProperties {
+ TYPE,
+ UUID,
+ NAME,
+ CREATED,
+ MODIFIED,
+ LOCATION;
+
+ @Nullable
+ public static UsergridEntityProperties fromString(@NotNull final String stringValue) {
+ try {
+ return UsergridEntityProperties.valueOf(stringValue.toUpperCase());
+ } catch(Exception e) {
+ return null;
+ }
+ }
+
+ @Override @NotNull
+ public String toString() {
+ return super.toString().toLowerCase();
+ }
+
+ public boolean isMutableForEntity(@NotNull final UsergridEntity entity) {
+ switch(this) {
+ case LOCATION: {
+ return true;
+ }
+ case NAME: {
+ return entity.isUser();
+ }
+ case TYPE:
+ case UUID:
+ case CREATED:
+ case MODIFIED:
+ default: {
+ return false;
+ }
+ }
+ }
+ }
+
+ public enum UsergridUserProperties {
+ NAME,
+ USERNAME,
+ PASSWORD,
+ EMAIL,
+ ACTIVATED,
+ DISABLED,
+ PICTURE;
+
+ @Nullable
+ public static UsergridUserProperties fromString(@NotNull final String stringValue) {
+ try {
+ return UsergridUserProperties.valueOf(stringValue.toUpperCase());
+ } catch(Exception e) {
+ return null;
+ }
+ }
+
+ @Override @NotNull
+ public String toString() {
+ return super.toString().toLowerCase();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/2e127e62/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridRequest.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridRequest.java b/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridRequest.java
new file mode 100644
index 0000000..77ee148
--- /dev/null
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridRequest.java
@@ -0,0 +1,202 @@
+/*
+ * 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.java.client;
+
+import okhttp3.HttpUrl;
+import okhttp3.MediaType;
+import okhttp3.Request;
+import okhttp3.RequestBody;
+import org.apache.usergrid.java.client.UsergridEnums.UsergridHttpMethod;
+import org.apache.usergrid.java.client.auth.UsergridAuth;
+import org.apache.usergrid.java.client.query.UsergridQuery;
+import org.apache.usergrid.java.client.utils.JsonUtils;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.Map;
+
+@SuppressWarnings("unused")
+public class UsergridRequest {
+ @NotNull public static final MediaType APPLICATION_JSON_MEDIA_TYPE = MediaType.parse("application/json; charset=utf-8");
+
+ @NotNull private UsergridHttpMethod method;
+ @NotNull private String baseUrl;
+ @NotNull private MediaType contentType;
+
+ @Nullable private UsergridQuery query;
+ @Nullable private Map<String, Object> headers;
+ @Nullable private Map<String, Object> parameters;
+ @Nullable private Object data;
+ @Nullable private UsergridAuth auth;
+ @Nullable private String[] pathSegments;
+
+ @NotNull
+ public UsergridHttpMethod getMethod() { return method; }
+ public void setMethod(@NotNull final UsergridHttpMethod method) { this.method = method; }
+
+ @NotNull
+ public String getBaseUrl() { return baseUrl; }
+ public void setBaseUrl(@NotNull final String baseUrl) { this.baseUrl = baseUrl; }
+
+ @NotNull
+ public MediaType getContentType() { return contentType; }
+ public void setContentType(@NotNull final MediaType contentType) { this.contentType = contentType; }
+
+ @Nullable
+ public UsergridQuery getQuery() { return query; }
+ public void setQuery(@Nullable final UsergridQuery query) { this.query = query; }
+
+ @Nullable
+ public Map<String,Object> getHeaders() { return headers; }
+ public void setHeaders(@Nullable final Map<String,Object> headers) { this.headers = headers; }
+
+ @Nullable
+ public Map<String,Object> getParameters() { return parameters; }
+ public void setParameters(@Nullable final Map<String,Object> parameters) { this.parameters = parameters; }
+
+ @Nullable
+ public Object getData() { return data; }
+ public void setData(@Nullable final Object data) { this.data = data; }
+
+ @Nullable
+ public UsergridAuth getAuth() { return auth; }
+ public void setAuth(@Nullable final UsergridAuth auth) { this.auth = auth; }
+
+ @Nullable
+ public String[] getPathSegments() { return pathSegments; }
+ public void setPathSegments(@Nullable final String[] pathSegments) { this.pathSegments = pathSegments; }
+
+ public UsergridRequest(@NotNull final UsergridHttpMethod method,
+ @NotNull final MediaType contentType,
+ @NotNull final String url,
+ @Nullable final UsergridQuery query,
+ @Nullable final UsergridAuth auth,
+ @Nullable final String... pathSegments) {
+ this.method = method;
+ this.contentType = contentType;
+ this.baseUrl = url;
+ this.query = query;
+ this.auth = auth;
+ this.pathSegments = pathSegments;
+ }
+
+ public UsergridRequest(@NotNull final UsergridHttpMethod method,
+ @NotNull final MediaType contentType,
+ @NotNull final String url,
+ @Nullable final UsergridAuth auth,
+ @Nullable final String... pathSegments) {
+ this.method = method;
+ this.contentType = contentType;
+ this.baseUrl = url;
+ this.auth = auth;
+ this.pathSegments = pathSegments;
+ }
+
+ public UsergridRequest(@NotNull final UsergridHttpMethod method,
+ @NotNull final MediaType contentType,
+ @NotNull final String url,
+ @Nullable final Map<String, Object> params,
+ @Nullable final Object data,
+ @Nullable final UsergridAuth auth,
+ @Nullable final String... pathSegments) {
+ this.method = method;
+ this.contentType = contentType;
+ this.baseUrl = url;
+ this.parameters = params;
+ this.data = data;
+ this.headers = null;
+ this.query = null;
+ this.auth = auth;
+ this.pathSegments = pathSegments;
+ }
+
+ public UsergridRequest(@NotNull final UsergridHttpMethod method,
+ @NotNull final MediaType contentType,
+ @NotNull final String url,
+ @Nullable final Map<String, Object> params,
+ @Nullable final Object data,
+ @Nullable final Map<String, Object> headers,
+ @Nullable final UsergridQuery query,
+ @Nullable final UsergridAuth auth,
+ @Nullable final String... pathSegments) {
+ this.method = method;
+ this.contentType = contentType;
+ this.baseUrl = url;
+ this.parameters = params;
+ this.data = data;
+ this.headers = headers;
+ this.query = query;
+ this.pathSegments = pathSegments;
+ }
+
+ @NotNull
+ public Request buildRequest() {
+ Request.Builder requestBuilder = new Request.Builder();
+ requestBuilder.url(this.constructUrl());
+ this.addHeaders(requestBuilder);
+ requestBuilder.method(this.method.toString(),this.constructRequestBody());
+ return requestBuilder.build();
+ }
+
+ @NotNull
+ private HttpUrl constructUrl() {
+ String url = this.baseUrl;
+ if( this.query != null ) {
+ url += this.query.build();
+ }
+ HttpUrl.Builder urlBuilder = HttpUrl.parse(url).newBuilder();
+ if( this.pathSegments != null ) {
+ for( String path : this.pathSegments ) {
+ urlBuilder.addPathSegment(path);
+ }
+ }
+ if( this.parameters != null ) {
+ for (Map.Entry<String, Object> param : this.parameters.entrySet()) {
+ urlBuilder.addQueryParameter(param.getKey(),param.getValue().toString());
+ }
+ }
+ return urlBuilder.build();
+ }
+
+ private void addHeaders(@NotNull final Request.Builder requestBuilder) {
+ requestBuilder.addHeader("User-Agent", UsergridRequestManager.USERGRID_USER_AGENT);
+ if (this.auth != null ) {
+ String accessToken = this.auth.getAccessToken();
+ if( accessToken != null ) {
+ requestBuilder.addHeader("Authorization", "Bearer " + accessToken);
+ }
+ }
+ if( this.headers != null ) {
+ for( Map.Entry<String,Object> header : this.headers.entrySet() ) {
+ requestBuilder.addHeader(header.getKey(),header.getValue().toString());
+ }
+ }
+ }
+
+ @Nullable
+ private RequestBody constructRequestBody() {
+ RequestBody requestBody = null;
+ if (method == UsergridHttpMethod.POST || method == UsergridHttpMethod.PUT) {
+ String jsonString = "";
+ if( this.data != null ) {
+ jsonString = JsonUtils.toJsonString(this.data);
+ }
+ requestBody = RequestBody.create(this.contentType,jsonString);
+ }
+ return requestBody;
+ }
+}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/2e127e62/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridRequestManager.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridRequestManager.java b/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridRequestManager.java
new file mode 100644
index 0000000..b3e3597
--- /dev/null
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridRequestManager.java
@@ -0,0 +1,86 @@
+/*
+ * 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.java.client;
+
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.Response;
+import org.apache.usergrid.java.client.UsergridEnums.UsergridHttpMethod;
+import org.apache.usergrid.java.client.auth.UsergridAppAuth;
+import org.apache.usergrid.java.client.auth.UsergridAuth;
+import org.apache.usergrid.java.client.model.UsergridUser;
+import org.apache.usergrid.java.client.auth.UsergridUserAuth;
+import org.apache.usergrid.java.client.response.UsergridResponse;
+import org.jetbrains.annotations.NotNull;
+
+import java.io.IOException;
+import java.util.Map;
+
+import static org.apache.usergrid.java.client.utils.ObjectUtils.isEmpty;
+
+public class UsergridRequestManager {
+
+ @NotNull public static final String USERGRID_USER_AGENT = "usergrid-java/v" + Usergrid.UsergridSDKVersion;
+
+ @NotNull private final UsergridClient usergridClient;
+ @NotNull private final OkHttpClient httpClient;
+
+ public UsergridRequestManager(@NotNull final UsergridClient usergridClient) {
+ this.usergridClient = usergridClient;
+ this.httpClient = new OkHttpClient();
+ }
+
+ @NotNull
+ public UsergridResponse performRequest(@NotNull final UsergridRequest usergridRequest) {
+ Request request = usergridRequest.buildRequest();
+ UsergridResponse usergridResponse;
+ try {
+ Response response = this.httpClient.newCall(request).execute();
+ usergridResponse = UsergridResponse.fromResponse(this.usergridClient,usergridRequest,response);
+ } catch( IOException exception ) {
+ usergridResponse = UsergridResponse.fromException(this.usergridClient,exception);
+ }
+ return usergridResponse;
+ }
+
+ @NotNull
+ private UsergridResponse authenticate(@NotNull final UsergridAuth auth) {
+ Map<String, String> credentials = auth.credentialsMap();
+ UsergridRequest request = new UsergridRequest(UsergridHttpMethod.POST, UsergridRequest.APPLICATION_JSON_MEDIA_TYPE, this.usergridClient.clientAppUrl(), null, credentials, this.usergridClient.authForRequests(), "token");
+ UsergridResponse response = performRequest(request);
+ if (!isEmpty(response.getAccessToken()) && !isEmpty(response.getExpires())) {
+ auth.setAccessToken(response.getAccessToken());
+ auth.setExpiry(System.currentTimeMillis() + response.getExpires() - 5000);
+ }
+ return response;
+ }
+
+ @NotNull
+ public UsergridResponse authenticateApp(@NotNull final UsergridAppAuth appAuth) {
+ return this.authenticate(appAuth);
+ }
+
+ @NotNull
+ public UsergridResponse authenticateUser(@NotNull final UsergridUserAuth userAuth) {
+ UsergridResponse response = this.authenticate(userAuth);
+ UsergridUser responseUser = response.user();
+ if ( response.ok() && responseUser != null) {
+ responseUser.setUserAuth(userAuth);
+ }
+ return response;
+ }
+}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/2e127e62/sdks/java/src/main/java/org/apache/usergrid/java/client/auth/UsergridAppAuth.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/auth/UsergridAppAuth.java b/sdks/java/src/main/java/org/apache/usergrid/java/client/auth/UsergridAppAuth.java
new file mode 100644
index 0000000..3ad7251
--- /dev/null
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/auth/UsergridAppAuth.java
@@ -0,0 +1,50 @@
+/*
+ * 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.java.client.auth;
+
+import org.jetbrains.annotations.NotNull;
+
+import java.util.HashMap;
+
+@SuppressWarnings("unused")
+public class UsergridAppAuth extends UsergridAuth {
+
+ @NotNull private String clientId;
+ @NotNull private String clientSecret;
+
+ @NotNull public String getClientId() { return clientId; }
+ public void setClientId(@NotNull final String clientId) { this.clientId = clientId; }
+
+ @NotNull private String getClientSecret() { return clientSecret; }
+ public void setClientSecret(@NotNull final String clientSecret) { this.clientSecret = clientSecret; }
+
+ @NotNull
+ @Override
+ public HashMap<String, String> credentialsMap() {
+ HashMap<String,String> credentials = super.credentialsMap();
+ credentials.put("grant_type", "client_credentials");
+ credentials.put("client_id", this.clientId);
+ credentials.put("client_secret", this.clientSecret);
+ return credentials;
+ }
+
+ public UsergridAppAuth(@NotNull final String clientId, @NotNull final String clientSecret) {
+ super();
+ this.clientId = clientId;
+ this.clientSecret = clientSecret;
+ }
+}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/2e127e62/sdks/java/src/main/java/org/apache/usergrid/java/client/auth/UsergridAuth.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/auth/UsergridAuth.java b/sdks/java/src/main/java/org/apache/usergrid/java/client/auth/UsergridAuth.java
new file mode 100644
index 0000000..81d9187
--- /dev/null
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/auth/UsergridAuth.java
@@ -0,0 +1,74 @@
+/*
+ * 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.java.client.auth;
+
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.HashMap;
+
+@SuppressWarnings("unused")
+public class UsergridAuth {
+
+ @Nullable private String accessToken = null;
+ @Nullable private Long expiry = null;
+ private boolean usingToken = false;
+
+ public UsergridAuth() { }
+
+ public UsergridAuth(@Nullable final String accessToken) {
+ this.usingToken = true;
+ setAccessToken(accessToken);
+ }
+
+ public UsergridAuth(@Nullable final String accessToken, @Nullable final Long expiry) {
+ this.usingToken = true;
+ setAccessToken(accessToken);
+ setExpiry(expiry);
+ }
+
+ public void destroy() {
+ setAccessToken(null);
+ setExpiry(null);
+ }
+
+ @Nullable public String getAccessToken() { return accessToken; }
+ public void setAccessToken(@Nullable final String accessToken) {
+ this.accessToken = accessToken;
+ }
+
+ @Nullable public Long getExpiry() { return expiry; }
+ public void setExpiry(@Nullable final Long tokenExpiry) { this.expiry = tokenExpiry; }
+
+ public boolean isValidToken() { return (hasToken() && !isExpired()); }
+
+ public boolean hasToken() { return accessToken != null; }
+
+ public boolean isExpired() {
+ if (expiry != null) {
+ Long currentTime = System.currentTimeMillis() / 1000;
+ return ((expiry / 1000) < currentTime);
+ } else {
+ return !this.usingToken;
+ }
+ }
+
+ @NotNull
+ public HashMap<String,String> credentialsMap() {
+ return new HashMap<>();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/usergrid/blob/2e127e62/sdks/java/src/main/java/org/apache/usergrid/java/client/auth/UsergridUserAuth.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/auth/UsergridUserAuth.java b/sdks/java/src/main/java/org/apache/usergrid/java/client/auth/UsergridUserAuth.java
new file mode 100644
index 0000000..961be70
--- /dev/null
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/auth/UsergridUserAuth.java
@@ -0,0 +1,50 @@
+/*
+ * 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.java.client.auth;
+
+import org.jetbrains.annotations.NotNull;
+
+import java.util.HashMap;
+
+@SuppressWarnings("unused")
+public class UsergridUserAuth extends UsergridAuth {
+
+ @NotNull private String username;
+ @NotNull private String password;
+
+ @NotNull public String getUsername() { return username; }
+ public void setUsername(@NotNull final String username) { this.username = username; }
+
+ @NotNull private String getPassword() { return password; }
+ public void setPassword(@NotNull final String password) { this.password = password; }
+
+ @NotNull
+ @Override
+ public HashMap<String, String> credentialsMap() {
+ HashMap<String,String> credentials = super.credentialsMap();
+ credentials.put("grant_type", "password");
+ credentials.put("username", this.username);
+ credentials.put("password", this.password);
+ return credentials;
+ }
+
+ public UsergridUserAuth(@NotNull final String username, @NotNull final String password) {
+ super();
+ this.username = username;
+ this.password = password;
+ }
+}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/2e127e62/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
deleted file mode 100644
index faff3c3..0000000
--- a/sdks/java/src/main/java/org/apache/usergrid/java/client/entities/Activity.java
+++ /dev/null
@@ -1,625 +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.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/usergrid/blob/2e127e62/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
deleted file mode 100644
index 8db415c..0000000
--- a/sdks/java/src/main/java/org/apache/usergrid/java/client/entities/Device.java
+++ /dev/null
@@ -1,68 +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.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/usergrid/blob/2e127e62/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
deleted file mode 100644
index 2a8c544..0000000
--- a/sdks/java/src/main/java/org/apache/usergrid/java/client/entities/Entity.java
+++ /dev/null
@@ -1,191 +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.java.client.entities;
-
-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.setStringProperty;
-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/usergrid/blob/2e127e62/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
deleted file mode 100644
index 0e80532..0000000
--- a/sdks/java/src/main/java/org/apache/usergrid/java/client/entities/Group.java
+++ /dev/null
@@ -1,79 +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.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/usergrid/blob/2e127e62/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
deleted file mode 100644
index 8af64f9..0000000
--- a/sdks/java/src/main/java/org/apache/usergrid/java/client/entities/Message.java
+++ /dev/null
@@ -1,148 +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.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);
- }
-
-}