You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by li...@apache.org on 2010/04/13 03:15:54 UTC

svn commit: r933458 - in /shindig/trunk: java/samples/src/test/resources/sampledata/ javascript/sampledata/ php/config/ php/src/social/sample/ php/src/social/service/ php/src/social/servlet/ php/src/social/spi/ php/test/social/

Author: lindner
Date: Tue Apr 13 01:15:53 2010
New Revision: 933458

URL: http://svn.apache.org/viewvc?rev=933458&view=rev
Log:
SHINDIG-1307 | Patch from Evgeny Bogdanov | Group Rest support for PHP

Added:
    shindig/trunk/php/src/social/service/GroupHandler.php
    shindig/trunk/php/src/social/spi/GroupService.php
    shindig/trunk/php/test/social/GroupsRestTest.php
Modified:
    shindig/trunk/java/samples/src/test/resources/sampledata/canonicaldb.json
    shindig/trunk/javascript/sampledata/canonicaldb.json
    shindig/trunk/php/config/container.php
    shindig/trunk/php/src/social/sample/JsonDbOpensocialService.php
    shindig/trunk/php/src/social/servlet/ApiServlet.php

Modified: shindig/trunk/java/samples/src/test/resources/sampledata/canonicaldb.json
URL: http://svn.apache.org/viewvc/shindig/trunk/java/samples/src/test/resources/sampledata/canonicaldb.json?rev=933458&r1=933457&r2=933458&view=diff
==============================================================================
--- shindig/trunk/java/samples/src/test/resources/sampledata/canonicaldb.json (original)
+++ shindig/trunk/java/samples/src/test/resources/sampledata/canonicaldb.json Tue Apr 13 01:15:53 2010
@@ -361,6 +361,13 @@
 "maija.m" : []
 },
 //
+// ----------------------------- Groups ---------------------------------------
+//
+"groups" : {
+"john.doe" :  ["1", "2", "3"],
+"george.doe" : ["13","14"],
+},
+//
 //---------------------------- Data For User Applications --------------------------------------------
 //
 "userApplications" : {

Modified: shindig/trunk/javascript/sampledata/canonicaldb.json
URL: http://svn.apache.org/viewvc/shindig/trunk/javascript/sampledata/canonicaldb.json?rev=933458&r1=933457&r2=933458&view=diff
==============================================================================
--- shindig/trunk/javascript/sampledata/canonicaldb.json (original)
+++ shindig/trunk/javascript/sampledata/canonicaldb.json Tue Apr 13 01:15:53 2010
@@ -361,6 +361,13 @@
 "maija.m" : []
 },
 //
+// ----------------------------- Groups ---------------------------------------
+//
+"groups" : {
+"john.doe" :  ["1", "2", "3"],
+"george.doe" : ["13","14"]
+},
+//
 //---------------------------- Data For User Applications --------------------------------------------
 //
 "userApplications" : {

Modified: shindig/trunk/php/config/container.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/config/container.php?rev=933458&r1=933457&r2=933458&view=diff
==============================================================================
--- shindig/trunk/php/config/container.php (original)
+++ shindig/trunk/php/config/container.php Tue Apr 13 01:15:53 2010
@@ -138,6 +138,7 @@ $shindigConfig = array(
   'person_service' => 'JsonDbOpensocialService',
   'activity_service' => 'JsonDbOpensocialService',
   'app_data_service' => 'JsonDbOpensocialService',
+  'group_service' => 'JsonDbOpensocialService',
   'messages_service' => 'JsonDbOpensocialService',
   'invalidate_service' => 'DefaultInvalidateService',
   'album_service' => 'JsonDbOpensocialService',

Modified: shindig/trunk/php/src/social/sample/JsonDbOpensocialService.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/src/social/sample/JsonDbOpensocialService.php?rev=933458&r1=933457&r2=933458&view=diff
==============================================================================
--- shindig/trunk/php/src/social/sample/JsonDbOpensocialService.php (original)
+++ shindig/trunk/php/src/social/sample/JsonDbOpensocialService.php Tue Apr 13 01:15:53 2010
@@ -22,7 +22,7 @@
 /**
  * Implementation of supported services backed by a JSON DB
  */
-class JsonDbOpensocialService implements ActivityService, PersonService, AppDataService, MessagesService, AlbumService, MediaItemService {
+class JsonDbOpensocialService implements ActivityService, PersonService, AppDataService, GroupService, MessagesService, AlbumService, MediaItemService {
 
   /**
    * The DB
@@ -60,6 +60,11 @@ class JsonDbOpensocialService implements
   private static $DATA_TABLE = "data";
 
   /**
+   * db["groups"] -> Map<Person.Id, Array<Group>>
+   */
+  private static $GROUPS_TABLE = "groups";
+
+  /**
    * db["friendLinks"] -> Map<Person.Id, Array<Person.Id>>
    */
   private static $FRIEND_LINK_TABLE = "friendLinks";
@@ -73,6 +78,8 @@ class JsonDbOpensocialService implements
 
   private $allData = null;
 
+  private $allGroups = null;
+  
   private $allActivities = null;
 
   private $allMessageCollections = null;
@@ -137,6 +144,12 @@ class JsonDbOpensocialService implements
     return $this->allData;
   }
 
+  private function getAllGroups() {
+    $db = $this->getDb();
+    $this->allGroups = $db[self::$GROUPS_TABLE];
+    return $this->allGroups;
+  }
+
   private function getAllActivities() {
     $db = $this->getDb();
     $activitiesTable = $db[self::$ACTIVITIES_TABLE];
@@ -413,6 +426,19 @@ class JsonDbOpensocialService implements
     return null;
   }
 
+  public function getPersonGroups($userId, GroupId $groupId, SecurityToken $token) {
+    $allGroups = $this->getAllGroups();
+    $ids = $this->getIdSet($userId, $groupId, $token);
+    $output = array();
+    foreach ($ids as $id) {
+      if (isset($allGroups[$id])) {
+        $output[$id] = $allGroups[$id];
+      }
+    }
+    return $output;
+  }
+
+
   public function getActivity($userId, $groupId, $appdId, $fields, $activityId, SecurityToken $token) {
     $activities = $this->getActivities($userId, $groupId, $appdId, null, null, null, null, $fields, array(
         $activityId), $token);

Added: shindig/trunk/php/src/social/service/GroupHandler.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/src/social/service/GroupHandler.php?rev=933458&view=auto
==============================================================================
--- shindig/trunk/php/src/social/service/GroupHandler.php (added)
+++ shindig/trunk/php/src/social/service/GroupHandler.php Tue Apr 13 01:15:53 2010
@@ -0,0 +1,56 @@
+<?php
+/**
+ * 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.
+ */
+
+class GroupHandler extends DataRequestHandler {
+  private static $GROUPS_PATH = "/groups/{userId}";
+
+  public function __construct() {
+    parent::__construct('group_service');
+  }
+
+  /**
+   * /groups/{userId}
+   *
+   * examples:
+   * /groups/john.doe?fields=count
+   * /groups/@me
+   */
+  public function handleGet(RequestItem $requestItem) {
+    $this->checkService();
+    $requestItem->applyUrlTemplate(self::$GROUPS_PATH);
+    $userIds = $requestItem->getUsers();
+    if (count($userIds) < 1) {
+      throw new InvalidArgumentException("No userId(s) specified");
+    }
+    return $this->service->getPersonGroups($userIds[0], $requestItem->getGroup(), $requestItem->getToken());
+  }
+  public function handleDelete(RequestItem $requestItem) {
+    throw new SocialSpiException("You can't delete groups.", ResponseError::$BAD_REQUEST);
+  }
+
+  public function handlePut(RequestItem $requestItem) {
+    throw new SocialSpiException("You can't update groups.", ResponseError::$NOT_IMPLEMENTED);
+  }
+
+  public function handlePost(RequestItem $requestItem) {
+    throw new SocialSpiException("You can't add groups.", ResponseError::$NOT_IMPLEMENTED);
+  }
+
+}

Modified: shindig/trunk/php/src/social/servlet/ApiServlet.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/src/social/servlet/ApiServlet.php?rev=933458&r1=933457&r2=933458&view=diff
==============================================================================
--- shindig/trunk/php/src/social/servlet/ApiServlet.php (original)
+++ shindig/trunk/php/src/social/servlet/ApiServlet.php Tue Apr 13 01:15:53 2010
@@ -54,6 +54,7 @@ abstract class ApiServlet extends HttpSe
   public static $PEOPLE_ROUTE = "people";
   public static $ACTIVITY_ROUTE = "activities";
   public static $APPDATA_ROUTE = "appdata";
+  public static $GROUP_ROUTE = "groups";
   public static $MESSAGE_ROUTE = "messages";
   public static $INVALIDATE_ROUTE = "cache";
   public static $SYSTEM_ROUTE = "system";
@@ -166,6 +167,11 @@ abstract class ApiServlet extends HttpSe
           require_once 'src/social/service/AppDataHandler.php';
           $this->handlers[self::$APPDATA_ROUTE] = new AppDataHandler();
           break;
+        case self::$GROUP_ROUTE:
+          require_once 'src/social/spi/GroupService.php';
+          require_once 'src/social/service/GroupHandler.php';
+          $this->handlers[self::$GROUP_ROUTE] = new GroupHandler();
+          break;
         case self::$MESSAGE_ROUTE:
           require_once 'src/social/spi/MessagesService.php';
           require_once 'src/social/service/MessagesHandler.php';

Added: shindig/trunk/php/src/social/spi/GroupService.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/src/social/spi/GroupService.php?rev=933458&view=auto
==============================================================================
--- shindig/trunk/php/src/social/spi/GroupService.php (added)
+++ shindig/trunk/php/src/social/spi/GroupService.php Tue Apr 13 01:15:53 2010
@@ -0,0 +1,33 @@
+<?php
+/**
+ * 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.
+ */
+
+interface GroupService {
+
+  /**
+   * Fetch groups for a list of ids.
+   * @param UserId The user id to perform the action for
+   * @param GroupId optional grouping ID
+   * @param token The SecurityToken for this request
+   * @return ResponseItem a response item with the error code set if
+   *     there was a problem
+   */
+  function getPersonGroups($userId, GroupId $groupId, SecurityToken $token);
+
+}

Added: shindig/trunk/php/test/social/GroupsRestTest.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/test/social/GroupsRestTest.php?rev=933458&view=auto
==============================================================================
--- shindig/trunk/php/test/social/GroupsRestTest.php (added)
+++ shindig/trunk/php/test/social/GroupsRestTest.php Tue Apr 13 01:15:53 2010
@@ -0,0 +1,35 @@
+<?php
+/**
+ * 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.
+ */
+
+require_once 'RestBase.php';
+
+class GroupsRestTest extends RestBase {
+
+  
+  public function testGroupsLifeCycleInJson() {	
+    // Get the groups for the user.
+    $ret = $this->curlRest('/groups/john.doe', '', 'application/json', 'GET');
+    $retDecoded = json_decode($ret, true);
+    $this->assertTrue($ret != $retDecoded && $ret != null, "Invalid json string in return: $ret.");
+    $this->assertTrue(isset($retDecoded['entry']) && isset($retDecoded['entry']["john.doe"])
+        && isset($retDecoded['entry']["john.doe"][0]) 
+        && $retDecoded['entry']["john.doe"][0] == '1', "Unexpected return value: $ret.");     
+  }
+}