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/04/12 22:20:59 UTC

[1/3] git commit: catching "service resource not found" exception in create_entity

Repository: incubator-usergrid
Updated Branches:
  refs/pull/104/head [created] ab1acb8be
  refs/pull/104/merge [created] 76912bdb9


catching "service resource not found" exception in create_entity

create_entity tries to fetch an entity prior to creating one.
This might raise an UG_401_Unauthorized exception which is not caught though it is to be expected.
Now it is okay to save the new entity if the exception message equals 'org.apache.usergrid.services.exceptions.ServiceResourceNotFoundException' (are there any constants for that?), any other types of exceptions will be thrown on.

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

Branch: refs/pull/104/head
Commit: ab1acb8befe07d95265b86d216b10a1413fd6994
Parents: e7ea1a1
Author: timwillsie <ti...@gmail.com>
Authored: Sat Apr 12 21:22:24 2014 +0200
Committer: timwillsie <ti...@gmail.com>
Committed: Sat Apr 12 21:22:24 2014 +0200

----------------------------------------------------------------------
 sdks/php/lib/vendor/Apigee/Usergrid/Client.php | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ab1acb8b/sdks/php/lib/vendor/Apigee/Usergrid/Client.php
----------------------------------------------------------------------
diff --git a/sdks/php/lib/vendor/Apigee/Usergrid/Client.php b/sdks/php/lib/vendor/Apigee/Usergrid/Client.php
index ea98b42..dcc82f5 100755
--- a/sdks/php/lib/vendor/Apigee/Usergrid/Client.php
+++ b/sdks/php/lib/vendor/Apigee/Usergrid/Client.php
@@ -518,10 +518,23 @@ class Client {
    * @return \Apigee\Usergrid\Entity
    */
   public function create_entity($entity_data) {
-    $entity = new Entity($this, $entity_data);
-    $response = $entity->fetch();
+    $entity     = new Entity($this, $entity_data);
+    $ok_to_save = null;
+    
+    try {
+      $response = $entity->fetch();
+    } catch (UG_401_Unauthorized $ex) {
+      // this is to be expected if the resource doesn't exist yet...
+      if ('org.apache.usergrid.services.exceptions.ServiceResourceNotFoundException' !== $ex->getMessage()) {
+        // ...otherwise throw the exception
+        throw $ex;
+      }
+      $ok_to_save = true;
+    }  
 
     $ok_to_save = (
+      $ok_to_save
+      ||
       ($response->get_error() && ('service_resource_not_found' == $response->get_error_code() || 'no_name_specified' == $response->get_error_code() || 'null_pointer' == $response->get_error_code() ))
       ||
       (!$response->get_error() && array_key_exists('getOnExist', $entity_data) && $entity_data['getOnExist'])


[2/3] git commit: catching "service resource not found" exception in create_entity

Posted by sn...@apache.org.
catching "service resource not found" exception in create_entity

create_entity tries to fetch an entity prior to creating one.
This might raise an UG_401_Unauthorized exception which is not caught though it is to be expected.
Now it is okay to save the new entity if the exception message equals 'org.apache.usergrid.services.exceptions.ServiceResourceNotFoundException' (are there any constants for that?), any other types of exceptions will be thrown on.

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

Branch: refs/pull/104/merge
Commit: ab1acb8befe07d95265b86d216b10a1413fd6994
Parents: e7ea1a1
Author: timwillsie <ti...@gmail.com>
Authored: Sat Apr 12 21:22:24 2014 +0200
Committer: timwillsie <ti...@gmail.com>
Committed: Sat Apr 12 21:22:24 2014 +0200

----------------------------------------------------------------------
 sdks/php/lib/vendor/Apigee/Usergrid/Client.php | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ab1acb8b/sdks/php/lib/vendor/Apigee/Usergrid/Client.php
----------------------------------------------------------------------
diff --git a/sdks/php/lib/vendor/Apigee/Usergrid/Client.php b/sdks/php/lib/vendor/Apigee/Usergrid/Client.php
index ea98b42..dcc82f5 100755
--- a/sdks/php/lib/vendor/Apigee/Usergrid/Client.php
+++ b/sdks/php/lib/vendor/Apigee/Usergrid/Client.php
@@ -518,10 +518,23 @@ class Client {
    * @return \Apigee\Usergrid\Entity
    */
   public function create_entity($entity_data) {
-    $entity = new Entity($this, $entity_data);
-    $response = $entity->fetch();
+    $entity     = new Entity($this, $entity_data);
+    $ok_to_save = null;
+    
+    try {
+      $response = $entity->fetch();
+    } catch (UG_401_Unauthorized $ex) {
+      // this is to be expected if the resource doesn't exist yet...
+      if ('org.apache.usergrid.services.exceptions.ServiceResourceNotFoundException' !== $ex->getMessage()) {
+        // ...otherwise throw the exception
+        throw $ex;
+      }
+      $ok_to_save = true;
+    }  
 
     $ok_to_save = (
+      $ok_to_save
+      ||
       ($response->get_error() && ('service_resource_not_found' == $response->get_error_code() || 'no_name_specified' == $response->get_error_code() || 'null_pointer' == $response->get_error_code() ))
       ||
       (!$response->get_error() && array_key_exists('getOnExist', $entity_data) && $entity_data['getOnExist'])


[3/3] git commit: Merge ab1acb8befe07d95265b86d216b10a1413fd6994 into e7ea1a12caf1600bd8b4a216b2e6d9079f16ade9

Posted by sn...@apache.org.
Merge ab1acb8befe07d95265b86d216b10a1413fd6994 into e7ea1a12caf1600bd8b4a216b2e6d9079f16ade9


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

Branch: refs/pull/104/merge
Commit: 76912bdb99e6c0a27f8ea503d362444a0cbbc9a1
Parents: e7ea1a1 ab1acb8
Author: timwillsie <ti...@gmail.com>
Authored: Sat Apr 12 19:27:01 2014 +0000
Committer: timwillsie <ti...@gmail.com>
Committed: Sat Apr 12 19:27:01 2014 +0000

----------------------------------------------------------------------
 sdks/php/lib/vendor/Apigee/Usergrid/Client.php | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
----------------------------------------------------------------------