usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [12/50] [abbrv] git commit: [USERGRID-184]Adds connection reverse lookup support to JS SDK
Date Mon, 07 Jul 2014 18:16:29 GMT
[USERGRID-184]Adds connection reverse lookup support to JS SDK

	-Adds getConnectedEntities to support requests of type GET /<someCollection>/<someEntity>/connecting/<someConnection>
	-Adds connectionsGetter worker so getConnectedEntities and getConnection share one set of
request logic


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/1143d43a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/1143d43a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/1143d43a

Branch: refs/pull/231/merge
Commit: 1143d43aae0e6ee6754f3feffbd82bc4e2e75413
Parents: 8d4140e
Author: amuramoto <amuramoto@apigee.com>
Authored: Fri Jun 27 10:24:34 2014 -0700
Committer: amuramoto <amuramoto@apigee.com>
Committed: Fri Jun 27 10:24:34 2014 -0700

----------------------------------------------------------------------
 sdks/html5-javascript/lib/modules/Entity.js | 54 ++++++++++++++++++++++--
 1 file changed, 50 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/1143d43a/sdks/html5-javascript/lib/modules/Entity.js
----------------------------------------------------------------------
diff --git a/sdks/html5-javascript/lib/modules/Entity.js b/sdks/html5-javascript/lib/modules/Entity.js
index 029951c..63e9a29 100644
--- a/sdks/html5-javascript/lib/modules/Entity.js
+++ b/sdks/html5-javascript/lib/modules/Entity.js
@@ -381,18 +381,60 @@ Usergrid.Entity.prototype.getEntityId = function(entity) {
 };
 
 /*
- *  gets an entities connections
+ *  gets entities this entity is connecting to
  *
  *  @method getConnections
  *  @public
  *  @param {string} connection
- *  @param {object} entity
  *  @param {function} callback
  *  @return {callback} callback(err, data, connections)
  *
  */
 Usergrid.Entity.prototype.getConnections = function(connection, callback) {
 
+  this.connectionGetter (connection, 'connecting', function (err, data) {
+    if (!err) {
+      doCallback(callback, [err, data, data.entities], self);
+    } else {
+      doCallback(callback, [null, data, data.entities], self);
+    }
+  });
+
+};
+
+/*
+ *  gets the entities that are connected to this entity
+ *
+ *  @method getConnections
+ *  @public
+ *  @param {string} connection
+ *  @param {function} callback
+ *  @return {callback} callback(err, data, connections)
+ *
+ */
+Usergrid.Entity.prototype.getConnectedEntities = function(connection, callback) {
+
+  this.connectionGetter (connection, 'connected', function (err, data) {
+    if (!err) {
+      doCallback(callback, [err, data, data.entities], self);
+    } else {
+      doCallback(callback, [null, data, data.entities], self);
+    }
+  });
+};
+
+/*
+ *  Worker that gets the entities that an entity are connecting to or connected by
+ *
+ *  @method connectionGetter
+ *  @public
+ *  @param {string} connection
+ *  @param connectedOrConnecting
+ *  @return {callback} callback(err, data, connections)
+ *
+ */
+Usergrid.Entity.prototype.connectionGetter = function(connection, connectedOrConnecting,
callback) {
+
   var self = this;
 
   //connector info
@@ -409,14 +451,18 @@ Usergrid.Entity.prototype.getConnections = function(connection, callback)
{
     return;
   }
 
-  var endpoint = connectorType + '/' + connector + '/' + connection + '/';
+  if (connectedOrConnecting == 'connected') {
+    var endpoint = connectorType + '/' + connector + '/connecting/' + connection + '/';
+  } else if (connectedOrConnecting == 'connecting') {
+    var endpoint = connectorType + '/' + connector + '/' + connection + '/';
+  }
   var options = {
     method: 'GET',
     endpoint: endpoint
   };
   this._client.request(options, function(err, data) {
     if (err && self._client.logging) {
-      console.log('entity could not be connected');
+      console.log('could not get connections');
     }
 
     self[connection] = {};


Mime
View raw message