Author: chabotc
Date: Thu Jun 25 09:09:37 2009
New Revision: 788298

URL: http://svn.apache.org/viewvc?rev=788298&view=rev
Log:
SHINDIG-1099 by Jinhui Du - 0.9 album php shindig implementation

Modified:
    incubator/shindig/trunk/php/config/container.php
    incubator/shindig/trunk/php/src/social/converters/InputAtomConverter.php
    incubator/shindig/trunk/php/src/social/converters/InputBasicXmlConverter.php
    incubator/shindig/trunk/php/src/social/converters/InputConverter.php
    incubator/shindig/trunk/php/src/social/converters/InputJsonConverter.php
    incubator/shindig/trunk/php/src/social/converters/InputXmlConverter.php
    incubator/shindig/trunk/php/src/social/model/MediaItem.php
    incubator/shindig/trunk/php/src/social/sample/JsonDbOpensocialService.php
    incubator/shindig/trunk/php/src/social/service/RestRequestItem.php
    incubator/shindig/trunk/php/src/social/servlet/ApiServlet.php
    incubator/shindig/trunk/php/src/social/servlet/DataServiceServlet.php
    incubator/shindig/trunk/php/test/social/InputAtomConverterTest.php
    incubator/shindig/trunk/php/test/social/InputJsonConverterTest.php
    incubator/shindig/trunk/php/test/social/InputXmlConverterTest.php
    incubator/shindig/trunk/php/test/social/MediaItemTest.php
    incubator/shindig/trunk/php/test/social/OutputAtomConverterTest.php

Modified: incubator/shindig/trunk/php/config/container.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/config/container.php?rev=788298&r1=788297&r2=788298&view=diff
==============================================================================
--- incubator/shindig/trunk/php/config/container.php (original)
+++ incubator/shindig/trunk/php/config/container.php Thu Jun 25 09:09:37 2009
@@ -131,6 +131,8 @@
   'app_data_service' => 'JsonDbOpensocialService',
   'messages_service' => 'JsonDbOpensocialService',
   'invalidate_service' => 'DefaultInvalidateService',
+  'album_service' => 'JsonDbOpensocialService',
+  'media_item_service' => 'JsonDbOpensocialService',
 
   // Also scan these directories when looking for <Class>.php files. You can 
include multiple paths by seperating them with a ,
   'extension_class_paths' => '',

Modified: 
incubator/shindig/trunk/php/src/social/converters/InputAtomConverter.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social/converters/InputAtomConverter.php?rev=788298&r1=788297&r2=788298&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social/converters/InputAtomConverter.php 
(original)
+++ incubator/shindig/trunk/php/src/social/converters/InputAtomConverter.php 
Thu Jun 25 09:09:37 2009
@@ -48,4 +48,14 @@
     $xml = InputBasicXmlConverter::loadString($requestParam);
     return InputBasicXmlConverter::convertMessages($requestParam, $xml, 
$xml->content);
   }
+  
+  public function convertAlbums($requestParam) {
+    $xml = InputBasicXmlConverter::loadString($requestParam);
+    return InputBasicXmlConverter::convertAlbums($xml, $xml->content->album);
+  }
+  
+  public function convertMediaItems($requestParam) {
+    $xml = InputBasicXmlConverter::loadString($requestParam);
+    return InputBasicXmlConverter::convertMediaItems($xml, 
$xml->content->mediaItem);
+  }
 }

Modified: 
incubator/shindig/trunk/php/src/social/converters/InputBasicXmlConverter.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social/converters/InputBasicXmlConverter.php?rev=788298&r1=788297&r2=788298&view=diff
==============================================================================
--- 
incubator/shindig/trunk/php/src/social/converters/InputBasicXmlConverter.php 
(original)
+++ 
incubator/shindig/trunk/php/src/social/converters/InputBasicXmlConverter.php 
Thu Jun 25 09:09:37 2009
@@ -56,7 +56,68 @@
     }
     return $activity;
   }
-
+  
+  public static function convertAlbums($xml, $albumXml) {
+    $fields = array('id', 'description', 'mediaItemCount', 'thumbnailUrl', 
'ownerId', 'mediaMimeType');
+    $album = self::copyFields($albumXml, $fields);
+    if (isset($xml->title) && !empty($xml->title)) {
+      $album['title'] = trim($xml->title);
+    } else if (isset($albumXml->caption)) {
+      $album['title'] = trim($albumXml->caption); 
+    }
+    if (isset($albumXml->mediaType) && 
in_array(strtoupper(trim($albumXml->mediaType)), MediaItem::$TYPES)) {
+      $album['mediaType'] = strtoupper(trim($albumXml->mediaType));
+    }
+    if (isset($albumXml->location)) {
+      $address = self::convertAddresses($albumXml->location);      
+      if ($address) {
+        $album['location'] = $address;
+      }
+    }
+    return $album;
+  }
+  
+  public static function convertMediaItems($xml, $mediaItemXml) {
+    $fields = array('albumId', 'created', 'description', 'duration', 
'fileSize', 'id', 'language',
+      'lastUpdated', 'mimeType', 'numComments', 'numViews', 'numVotes', 
'rating',
+      'startTime', 'taggedPeople', 'tags', 'thumbnailUrl', 'url');
+    $mediaItem = self::copyFields($mediaItemXml, $fields);
+    if (isset($xml->title) && !empty($xml->title)) {
+      $mediaItem['title'] = trim($xml->title);
+    } else if (isset($mediaItemXml->caption)) {
+      $mediaItem['title'] = trim($mediaItemXml->caption);
+    }
+    if (isset($mediaItemXml->type) && 
in_array(strtoupper(trim($mediaItemXml->type)), MediaItem::$TYPES)) {
+      $mediaItem['type'] = strtoupper(trim($mediaItemXml->type));
+    }
+    if (isset($mediaItemXml->location)) {
+      $address = self::convertAddresses($mediaItemXml->location);      
+      if ($address) {
+        $mediaItem['location'] = $address;
+      }
+    }
+    return $mediaItem;
+  }
+  
+  public static function convertAddresses($xml) {
+    $fields = array('country', 'extendedAddress', 'latitude', 'locality', 
'longitude', 'poBox',
+      'postalCode', 'region', 'streetAddress', 'type', 'unstructuredAddress', 
'formatted');
+    return self::copyFields($xml, $fields);
+  }
+  
+  public static function copyFields($xml, $fields) {
+    $object = array();
+    if (!is_array($fields)) {
+      $fields = array($fields);
+    }
+    foreach ($fields as $field) {
+      if ($xml && isset($xml->$field)) {
+        $object[$field] = trim($xml->$field);
+      }
+    }
+    return $object;
+  }
+  
   public static function convertMessages($requestParam, $xml, $content) {
     // As only message handler has the context to know whether it's a message 
or a message
     // collection request. All the fields for both the Message and the 
MessageCollection

Modified: incubator/shindig/trunk/php/src/social/converters/InputConverter.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social/converters/InputConverter.php?rev=788298&r1=788297&r2=788298&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social/converters/InputConverter.php 
(original)
+++ incubator/shindig/trunk/php/src/social/converters/InputConverter.php Thu 
Jun 25 09:09:37 2009
@@ -34,4 +34,8 @@
   abstract public function convertAppData($requestParam);
 
   abstract public function convertMessages($requestParam);
+  
+  abstract public function convertAlbums($requestParam);
+  
+  abstract public function convertMediaItems($requestParam);
 }
\ No newline at end of file

Modified: 
incubator/shindig/trunk/php/src/social/converters/InputJsonConverter.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social/converters/InputJsonConverter.php?rev=788298&r1=788297&r2=788298&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social/converters/InputJsonConverter.php 
(original)
+++ incubator/shindig/trunk/php/src/social/converters/InputJsonConverter.php 
Thu Jun 25 09:09:37 2009
@@ -58,4 +58,20 @@
     }
     return $ret;
   }
+  
+  public function convertAlbums($requestParam) {
+    $ret = json_decode($requestParam, true);
+    if ($ret == $requestParam) {
+      throw new Exception("Mallformed album json string. " . $requestParam);
+    }
+    return $ret;
+  }
+  
+  public function convertMediaItems($requestParam) {
+    $ret = json_decode($requestParam, true);
+    if ($ret == $requestParam) {
+      throw new Exception("Mallformed album json string. " . $requestParam);
+    }
+    return $ret;
+  }
 }

Modified: 
incubator/shindig/trunk/php/src/social/converters/InputXmlConverter.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social/converters/InputXmlConverter.php?rev=788298&r1=788297&r2=788298&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social/converters/InputXmlConverter.php 
(original)
+++ incubator/shindig/trunk/php/src/social/converters/InputXmlConverter.php Thu 
Jun 25 09:09:37 2009
@@ -50,4 +50,14 @@
     $xml = InputBasicXmlConverter::loadString($requestParam);
     return InputBasicXmlConverter::convertMessages($requestParam, $xml, 
$xml->body);
   }
+  
+  public function convertAlbums($requestParam) {
+    $xml = InputBasicXmlConverter::loadString($requestParam);
+    return InputBasicXmlConverter::convertAlbums($xml, $xml);
+  }
+  
+  public function convertMediaItems($requestParam) {
+    $xml = InputBasicXmlConverter::loadString($requestParam);
+    return InputBasicXmlConverter::convertMediaItems($xml, $xml);
+  }
 }

Modified: incubator/shindig/trunk/php/src/social/model/MediaItem.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social/model/MediaItem.php?rev=788298&r1=788297&r2=788298&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social/model/MediaItem.php (original)
+++ incubator/shindig/trunk/php/src/social/model/MediaItem.php Thu Jun 25 
09:09:37 2009
@@ -19,15 +19,33 @@
  */
 
 /**
- * see
- * 
http://www.opensocial.org/Technical-Resources/opensocial-spec-v081/opensocial-reference#opensocial.MediaItem
+ * 
http://opensocial-resources.googlecode.com/svn/spec/0.9/OpenSocial-Specification.xml#opensocial.MediaItem
  */
 class MediaItem {
+  
+  public $albumId;
+  public $created;
+  public $description;
+  public $duration;
+  public $fileSize;
+  public $id;
+  public $language;
+  public $lastUpdated;
+  public $location;
   public $mimeType;
+  public $numComments;
+  public $numViews;
+  public $numVotes;
+  public $rating;
+  public $startTime;
+  public $taggedPeople;
+  public $tags;
+  public $thumbnailUrl;
+  public $title;
   public $type;
   public $url;
-
-  public $types = array('AUDIO' => 'audio', 'VIDEO' => 'video', 'IMAGE' => 
'image');
+  
+  public static $TYPES = array('AUDIO', 'VIDEO', 'IMAGE');
 
   public function __construct($mimeType, $type, $url) {
     $this->setMimeType($mimeType);
@@ -35,6 +53,150 @@
     $this->setUrl($url);
   }
 
+  public function getId() {
+    return $this->id;
+  }
+
+  public function setId($id) {
+    $this->id = $id;
+  }
+  
+  public function getAlbumId() {
+    return $this->albumId;
+  }
+
+  public function setAlbumId($albumId) {
+    $this->albumId = $albumId;
+  }
+  
+  public function getCreated() {
+    return $this->created;
+  }
+
+  public function setCreated($created) {
+    $this->created = $created;
+  }
+
+  public function getDescription() {
+    return $this->$description;
+  }
+
+  public function setDescription($description) {
+    $this->description = $description;
+  }
+  
+  public function getDuration() {
+    return $this->duration;
+  }
+
+  public function setDuration($duration) {
+    $this->duration = $duration;
+  }
+  
+  public function getFileSize() {
+    return $this->fileSize;
+  }
+
+  public function setFileSize($fileSize) {
+    $this->fileSize = $fileSize;
+  }
+  
+  public function getLanguage() {
+    return $this->language;
+  }
+
+  public function setLanguage($language) {
+    $this->language = $language;
+  }
+  
+  public function getLastUpdated() {
+    return $this->lastUpdated;
+  }
+
+  public function setLastUpdated($lastUpdated) {
+    $this->lastUpdated = $lastUpdated;
+  }
+  
+  public function getLocation() {
+    return $this->location;
+  }
+
+  public function setLocation($location) {
+    $this->location = $location;
+  }
+  
+  public function getNumComments() {
+    return $this->numComments;
+  }
+
+  public function setNumComments($numComments) {
+    $this->numComments = $numComments;
+  }
+  
+  public function getNumViews() {
+    return $this->numViews;
+  }
+
+  public function setNumViews($numViews) {
+    $this->numViews = $numViews;
+  }
+  
+  public function getNumVotes() {
+    return $this->numVotes;
+  }
+
+  public function setNumVotes($numVotes) {
+    $this->numVotes = $numVotes;
+  }
+  
+  public function getRating() {
+    return $this->rating;
+  }
+
+  public function setRating($rating) {
+    $this->rating = $rating;
+  }
+  
+  public function getStartTime() {
+    return $this->startTime;
+  }
+
+  public function setStartTime($startTime) {
+    $this->startTime = $startTime;
+  }
+  
+  public function getTaggedPeople() {
+    return $this->taggedPeople;
+  }
+
+  public function setTaggedPeople($taggedPeople) {
+    $this->taggedPeople = $taggedPeople;
+  }
+  
+  public function getTags() {
+    return $this->tags;
+  }
+
+  public function setTags($tags) {
+    $this->tags = $tags;
+  }
+  
+  public function getThumbnailUrl() {
+    return $this->thumbnailUrl;
+  }
+
+  public function setThumbnailUrl($thumbnailUrl) {
+    $this->thumbnailUrl = $thumbnailUrl;
+  }
+  
+  public function getTitle() {
+    return $this->title;
+  }
+
+  public function setTitle($title) {
+    $this->title = $title;
+  }
+  
   public function getMimeType() {
     return $this->mimeType;
   }
@@ -48,10 +210,10 @@
   }
 
   public function setType($type) {
-    if (! array_key_exists($type, $this->types)) {
+    if (! in_array($type, self::$TYPES)) {
       throw new Exception("Invalid Media type");
     }
-    $this->type = $this->types[$type];
+    $this->type = $type;
   }
 
   public function getUrl() {

Modified: 
incubator/shindig/trunk/php/src/social/sample/JsonDbOpensocialService.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social/sample/JsonDbOpensocialService.php?rev=788298&r1=788297&r2=788298&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social/sample/JsonDbOpensocialService.php 
(original)
+++ incubator/shindig/trunk/php/src/social/sample/JsonDbOpensocialService.php 
Thu Jun 25 09:09:37 2009
@@ -21,7 +21,7 @@
 /**
  * Implementation of supported services backed by a JSON DB
  */
-class JsonDbOpensocialService implements ActivityService, PersonService, 
AppDataService, MessagesService {
+class JsonDbOpensocialService implements ActivityService, PersonService, 
AppDataService, MessagesService, AlbumService, MediaItemService {
 
   /**
    * The DB
@@ -42,6 +42,16 @@
    * db["messages"] : Map<Person.Id, MessageCollection>
    */
   private static $MESSAGES_TABLE = "messages";
+  
+  /**
+   * db["albums"] -> Map<Person.Id, Map<Album.Id, Album>>
+   */
+  private static $ALBUMS_TABLE = "albums";
+  
+  /**
+   * db["mediaItems"] -> Map<Album.Id, Map<MediaItem.Id, MediaItem>>
+   */
+  private static $MEDIA_ITEMS_TABLE = "mediaItems";
 
   /**
    * db["data"] -> Map<Person.Id, Map<String, String>>
@@ -145,7 +155,27 @@
     $db[self::$MESSAGES_TABLE] = $this->allMessageCollections;
     return $this->allMessageCollections;
   }
-
+  
+  private function getAllAlbums() {
+    $db = $this->getDb();
+    $albumTable = $db[self::$ALBUMS_TABLE] ? $db[self::$ALBUMS_TABLE] : 
array();
+    $allAlbums = array();
+    foreach ($albumTable as $key => $value) {
+      $allAlbums[$key] = $value;
+    }
+    return $allAlbums;
+  }
+  
+  private function getAllMediaItems() {
+    $db = $this->getDb();
+    $mediaItemsTable = $db[self::$MEDIA_ITEMS_TABLE] ? 
$db[self::$MEDIA_ITEMS_TABLE] : array();
+    $allMediaItems = array();
+    foreach ($mediaItemsTable as $key => $value) {
+      $allMediaItems[$key] = $value;
+    }
+    return $allMediaItems;
+  }
+  
   private function getPeopleWithApp($appId) {
     $peopleWithApp = array();
     $db = $this->getDb();
@@ -654,7 +684,177 @@
     }
     return self::paginateResults($results, $options);
   }
-
+  
+  public function getAlbums($userId, $groupId, $albumIds, $options, $fields, 
$token) {
+    $all = $this->getAllAlbums();
+    $allMediaItems = $this->getAllMediaItems();
+    $results = array();
+    if (!isset($all[$userId->getUserId($token)])) {
+      return RestfulCollection::createFromEntry(array());
+    }
+    $albumIds = array_unique($albumIds);
+    foreach ($all[$userId->getUserId($token)] as $id => $album) {
+      if (empty($albumIds) || in_array($id, $albumIds)) {
+        $results[] = $album;
+        $album['mediaItemCount'] = count($allMediaItems[$id]);
+      }
+    }
+    if ($options) {
+      $results = $this->filterResults($results, $options);
+    }
+    if ($fields) {
+      $results = self::adjustFields($results, $fields);
+    }
+    return self::paginateResults($results, $options);
+  }
+  
+  public function createAlbum($userId, $groupId, $album, $token) {
+    $all = $this->getAllAlbums();
+    $cnt = 0;
+    foreach ($all as $key => $value) {
+      $cnt += count($value);
+    }
+    $id = 'testIdPrefix' . $cnt;
+    $album['id'] = $id;
+    $album['ownerId'] = $userId->getUserId($token);
+    if (isset($album['mediaType'])) {
+      $album['mediaType'] = strtoupper($album['mediaType']);
+      if (!in_array($album['mediaType'], MediaItem::$TYPES)) {
+        unset($album['mediaType']);
+      }
+    }
+    if (!isset($all[$userId->getUserId($token)])) {
+      $all[$userId->getUserId($token)] = array();  
+    }
+    $all[$userId->getUserId($token)][$id] = $album;
+    $db = $this->getDb();
+    $db[self::$ALBUMS_TABLE] = $all;
+    $this->saveDb($db);
+    return $album;
+  }
+  
+  public function updateAlbum($userId, $groupId, $album, $token) {
+    $all = $this->getAllAlbums();
+    if (!$all[$userId->getUserId($token)] || 
!$all[$userId->getUserId($token)][$album['id']]) {
+      throw new SocialSpiException("Album not found.", 
ResponseError::$BAD_REQUEST);
+    }
+    $origin =  $all[$userId->getUserId($token)][$album['id']];
+    if ($origin['ownerId'] != $userId->getUserId($token)) {
+      throw new SocialSpiException("Not the owner.", 
ResponseError::$UNAUTHORIZED);
+    }
+    $album['ownerId'] = $origin['ownerId'];
+    if (isset($album['mediaType'])) {
+      $album['mediaType'] = strtoupper($album['mediaType']);  
+      if (!in_array($album['mediaType'], MediaItem::$TYPES)) {
+        unset($album['mediaType']);
+      }
+    }
+    $all[$userId->getUserId($token)][$album['id']] = $album;
+    
+    $db = $this->getDb();
+    $db[self::$ALBUMS_TABLE] = $all;
+    $this->saveDb($db);
+  }
+  
+  public function deleteAlbum($userId, $groupId, $albumId, $token) {
+    $all = $this->getAllAlbums();
+    if (!$all[$userId->getUserId($token)] || 
!$all[$userId->getUserId($token)][$albumId]) {
+      throw new SocialSpiException("Album not found.", 
ResponseError::$BAD_REQUEST);
+    }
+    if ($all[$userId->getUserId($token)][$albumId]['ownerId'] != 
$userId->getUserId($token)) {
+      throw new SocialSpiException("Not the owner.", 
ResponseError::$UNAUTHORIZED);
+    }
+    unset($all[$userId->getUserId($token)][$albumId]);
+    $db = $this->getDb();
+    $db[self::$ALBUMS_TABLE] = $all;
+    $this->saveDb($db);
+  }
+  
+  public function getMediaItems($userId, $groupId, $albumId, $mediaItemIds, 
$options, $fields, $token) {
+    $all = $this->getAllMediaItems();
+    $results = array();
+    if (!isset($all[$albumId])) {
+      return RestfulCollection::createFromEntry(array());
+    }
+    $mediaItemIds = array_unique($mediaItemIds);
+    foreach ($all[$albumId] as $id => $mediaItem) {
+      if (empty($mediaItemIds) || in_array($id, $mediaItemIds)) {
+        $results[] = $mediaItem;
+      }
+    }
+    if ($options) {
+      $results = $this->filterResults($results, $options);
+    }
+    if ($fields) {
+      $results = self::adjustFields($results, $fields);
+    }
+    return self::paginateResults($results, $options);
+  }
+  
+  public function createMediaItem($userId, $groupId, $mediaItem, $data, 
$token) {
+    $all = $this->getAllMediaItems();
+    $albumId = $mediaItem['albumId'];
+    $id = count($all[$albumId]) + 1;
+    $mediaItem['id'] = $id;
+    $mediaItem['lastUpdated'] = time();
+    if (isset($mediaItem['type'])) {
+      $mediaItem['type'] = strtoupper($mediaItem['type']);
+      if (!in_array($mediaItem['type'], MediaItem::$TYPES)) {
+        unset($mediaItem['type']);
+      }
+    }
+    if (!$all[$albumId]) {
+      $all[$albumId] = array();
+    }
+    $all[$albumId][$id] = $mediaItem;
+    $db = $this->getDb();
+    $db[self::$MEDIA_ITEMS_TABLE] = $all;
+    $this->saveDb($db);
+    return $mediaItem;
+  }
+  
+  public function updateMediaItem($userId, $groupId, $mediaItem, $data, 
$token) {
+    $all = $this->getAllMediaItems();
+    if (!$all[$mediaItem['albumId']] || 
!$all[$mediaItem['albumId']][$mediaItem['id']]) {
+      throw new SocialSpiException("MediaItem not found.", 
ResponseError::$BAD_REQUEST);
+    }
+    
+    $origin = $all[$mediaItem['albumId']][$mediaItem['id']];
+    $mediaItem['lastUpdated'] = time();
+    $mediaItem['created'] = $origin['created'];
+    $mediaItem['fileSize'] = $orgin['fileSize'];
+    $mediaItem['numComments'] = $origin['numComments'];
+    if (isset($mediaItem['type'])) {
+      $mediaItem['type'] = strtoupper($mediaItem['type']);
+      if (!in_array($mediaItem['type'], MediaItem::$TYPES)) {
+        unset($mediaItem['type']);
+      }
+    }
+    
+    $all[$mediaItem['albumId']][$mediaItem['id']] = $mediaItem;
+    $db = $this->getDb();
+    $db[self::$MEDIA_ITEMS_TABLE] = $all;
+    $this->saveDb($db);
+  }
+  
+  public function deleteMediaItems($userId, $groupId, $albumId, $mediaItemIds, 
$token) {
+    $all = $this->getAllMediaItems();
+    if (!$all[$albumId]) {
+      throw new SocialSpiException("MediaItem not found.", 
ResponseError::$BAD_REQUEST);
+    }
+    foreach ($mediaItemIds as $id) {
+      if (!$all[$albumId][$id]) {
+        throw new SocialSpiException("MediaItem not found.", 
ResponseError::$BAD_REQUEST);
+      }
+    }
+    foreach ($mediaItemIds as $id) {
+      unset($all[$albumId][$id]);
+    } 
+    $db = $this->getDb();
+    $db[self::$MEDIA_ITEMS_TABLE] = $all;
+    $this->saveDb($db);
+  }
+  
   /**
    * Paginates the results set according to the critera specified by the 
options.
    */

Modified: incubator/shindig/trunk/php/src/social/service/RestRequestItem.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social/service/RestRequestItem.php?rev=788298&r1=788297&r2=788298&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social/service/RestRequestItem.php 
(original)
+++ incubator/shindig/trunk/php/src/social/service/RestRequestItem.php Thu Jun 
25 09:09:37 2009
@@ -97,13 +97,21 @@
       case DataServiceServlet::$INVALIDATE_ROUTE:
         $this->params = json_decode($this->postData, true);
         break;
+      case DataServiceServlet::$ALBUM_ROUTE:
+        $data = $this->inputConverter->convertAlbums($this->postData);
+        $this->params['album'] = $data;
+        break;
+      case DataServiceServlet::$MEDIA_ITEM_ROUTE:
+        $data = $this->inputConverter->convertMediaItems($this->postData);
+        $this->params['mediaItem'] = $data;
+        break;
       default:
         throw new Exception("Invalid or unknown service endpoint: $service");
         break;
     }
   
   }
-
+  
   /**
    * '/people/@me/@self' => 'people'
    * '/invalidate?invalidationKey=1' => 'invalidate'

Modified: incubator/shindig/trunk/php/src/social/servlet/ApiServlet.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social/servlet/ApiServlet.php?rev=788298&r1=788297&r2=788298&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social/servlet/ApiServlet.php (original)
+++ incubator/shindig/trunk/php/src/social/servlet/ApiServlet.php Thu Jun 25 
09:09:37 2009
@@ -64,6 +64,8 @@
   public static $APPDATA_ROUTE = "appdata";
   public static $MESSAGE_ROUTE = "messages";
   public static $INVALIDATE_ROUTE = "cache";
+  public static $ALBUM_ROUTE = "albums";
+  public static $MEDIA_ITEM_ROUTE = "mediaitems";
 
   public function __construct() {
     parent::__construct();
@@ -73,6 +75,8 @@
     $this->handlers[self::$APPDATA_ROUTE] = new AppDataHandler();
     $this->handlers[self::$MESSAGE_ROUTE] = new MessagesHandler();
     $this->handlers[self::$INVALIDATE_ROUTE] = new InvalidateHandler();
+    $this->handlers[self::$ALBUM_ROUTE] = new AlbumHandler();
+    $this->handlers[self::$MEDIA_ITEM_ROUTE] = new MediaItemHandler();
     if (isset($_SERVER['CONTENT_TYPE']) && 
(strtolower($_SERVER['CONTENT_TYPE']) != $_SERVER['CONTENT_TYPE'])) {
       // make sure the content type is in all lower case since that's what 
we'll check for in the handlers
       $_SERVER['CONTENT_TYPE'] = strtolower($_SERVER['CONTENT_TYPE']);

Modified: incubator/shindig/trunk/php/src/social/servlet/DataServiceServlet.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social/servlet/DataServiceServlet.php?rev=788298&r1=788297&r2=788298&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social/servlet/DataServiceServlet.php 
(original)
+++ incubator/shindig/trunk/php/src/social/servlet/DataServiceServlet.php Thu 
Jun 25 09:09:37 2009
@@ -30,6 +30,9 @@
   public static $APPDATA_ROUTE = "appdata";
   public static $MESSAGE_ROUTE = "messages";
   public static $INVALIDATE_ROUTE = "cache";
+  public static $ALBUM_ROUTE = "albums";
+  public static $MEDIA_ITEM_ROUTE = "mediaitems";
+    
 
   public function doGet() {
     $this->doPost();

Modified: incubator/shindig/trunk/php/test/social/InputAtomConverterTest.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/social/InputAtomConverterTest.php?rev=788298&r1=788297&r2=788298&view=diff
==============================================================================
--- incubator/shindig/trunk/php/test/social/InputAtomConverterTest.php 
(original)
+++ incubator/shindig/trunk/php/test/social/InputAtomConverterTest.php Thu Jun 
25 09:09:37 2009
@@ -26,21 +26,21 @@
   /**
    * @var InputAtomConverter
    */
-  private $InputAtomConverter;
+  private $inputAtomConverter;
 
   /**
    * Prepares the environment before running a test.
    */
   protected function setUp() {
     parent::setUp();
-    $this->InputAtomConverter = new InputAtomConverter(/* parameters */);
+    $this->inputAtomConverter = new InputAtomConverter(/* parameters */);
   }
 
   /**
    * Cleans up the environment after running a test.
    */
   protected function tearDown() {
-    $this->InputAtomConverter = null;
+    $this->inputAtomConverter = null;
     parent::tearDown();
   }
 
@@ -80,7 +80,7 @@
   <summary>example summary</summary>
 </entry>
 ';
-    $activity = $this->InputAtomConverter->convertActivities($xml);
+    $activity = $this->inputAtomConverter->convertActivities($xml);
     $this->assertEquals('urn:guid:220', $activity['id']);
     $this->assertEquals('example title', $activity['title']);
     $this->assertEquals('example summary', $activity['body']);
@@ -111,7 +111,7 @@
     <title>appdata id 1</title>
     <updated>2008-08-06T22:36:20+02:00</updated>
   </entry>';
-    $appdata = $this->InputAtomConverter->convertAppData($xml);
+    $appdata = $this->inputAtomConverter->convertAppData($xml);
     $expect = array('sign' => 'Virgo');
     $this->assertEquals($expect, $appdata);
   }
@@ -130,7 +130,7 @@
   <link rel="alternate" href="http://app.example.org/invites/{msgid}"/>
   <content>Click &lt;a 
href="http://app.example.org/invites/{msgid}"&gt;here&lt;/a&gt; to review your 
invitation.</content>
 </entry>';
-    $message = $this->InputAtomConverter->convertMessages($xml);
+    $message = $this->inputAtomConverter->convertMessages($xml);
     $this->assertEquals('{msgid}', $message['id']);
     $this->assertEquals('You have an invitation from Joe', $message['title']);
     $this->assertEquals('Click <a 
href="http://app.example.org/invites/{msgid}";>here</a> to review your 
invitation.', $message['body']);
@@ -143,6 +143,62 @@
    */
   public function testConvertPeople() {
     $this->setExpectedException('Exception');
-    $this->InputAtomConverter->convertPeople('');
+    $this->inputAtomConverter->convertPeople('');
+  }
+  
+  public function testConvertAlbums() {
+    $xml = '<entry xmlns="http://www.w3.org/2005/Atom";>
+            <content type="application/xml">
+              <album xmlns="http://ns.opensocial.org/2008/opensocial";>
+                <id>44332211</id>
+                
<thumbnailUrl>http://pages.example.org/albums/4433221-tn.png</thumbnailUrl>
+                <caption>Example Album</caption>
+                <description>This is an example album, and this text is an 
example description</description>
+                <location>
+                  <latitude>0</latitude>
+                  <longitude>0</longitude>
+                </location>
+                <ownerId>example.org:55443322</ownerId>
+              </album>
+            </content>
+            <title/>
+            <updated>2003-12-13T18:30:02Z</updated>
+            <author><url>example.org:55443322</url></author>
+            <id>urn:guid:example.org:44332211</id>
+            </entry>';
+    $album = $this->inputAtomConverter->convertAlbums($xml);
+    $this->assertEquals('44332211', $album['id']);
+    $this->assertEquals('http://pages.example.org/albums/4433221-tn.png', 
$album['thumbnailUrl']);
+    $this->assertEquals('This is an example album, and this text is an example 
description', $album['description']);
+    $this->assertEquals('Example Album', $album['title']);
+    $this->assertEquals('example.org:55443322', $album['ownerId']);
+    $this->assertFalse(empty($album['location']));
+    $this->assertEquals(0, $album['location']['latitude']);
+    $this->assertEquals(0, $album['location']['longitude']);
+  }
+  
+  public function testConvertMediaItems() {
+    $xml = '<entry xmlns="http://www.w3.org/2005/Atom";>
+              <content type="application/xml">
+                <mediaItem xmlns="http://ns.opensocial.org/2008/opensocial";>
+                  <id>11223344</id>
+                  
<thumbnailUrl>http://pages.example.org/images/11223344-tn.png</thumbnailUrl>
+                  <mimeType>image/png</mimeType>
+                  <type>image</type>
+                  <url>http://pages.example.org/images/11223344.png</url>
+                  <albumId>44332211</albumId>
+                </mediaItem>
+              </content>
+              <title/>
+              <updated>2003-12-13T18:30:02Z</updated>
+              <author><url>example.org:55443322</url></author>
+              <id>urn:guid:example.org:11223344</id>
+            </entry>';
+    $mediaItem = $this->inputAtomConverter->convertMediaItems($xml);
+    $this->assertEquals('11223344', $mediaItem['id']);
+    $this->assertEquals('http://pages.example.org/images/11223344-tn.png', 
$mediaItem['thumbnailUrl']);
+    $this->assertEquals('44332211', $mediaItem['albumId']);
+    $this->assertEquals('http://pages.example.org/images/11223344.png', 
$mediaItem['url']);
+    $this->assertEquals('image/png', $mediaItem['mimeType']);
   }
 }

Modified: incubator/shindig/trunk/php/test/social/InputJsonConverterTest.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/social/InputJsonConverterTest.php?rev=788298&r1=788297&r2=788298&view=diff
==============================================================================
--- incubator/shindig/trunk/php/test/social/InputJsonConverterTest.php 
(original)
+++ incubator/shindig/trunk/php/test/social/InputJsonConverterTest.php Thu Jun 
25 09:09:37 2009
@@ -26,21 +26,21 @@
   /**
    * @var InputJsonConverter
    */
-  private $InputJsonConverter;
+  private $inputJsonConverter;
 
   /**
    * Prepares the environment before running a test.
    */
   protected function setUp() {
     parent::setUp();
-    $this->InputJsonConverter = new InputJsonConverter();
+    $this->inputJsonConverter = new InputJsonConverter();
   }
 
   /**
    * Cleans up the environment after running a test.
    */
   protected function tearDown() {
-    $this->InputJsonConverter = null;
+    $this->inputJsonConverter = null;
     parent::tearDown();
   }
 
@@ -57,7 +57,7 @@
                "title":"test title",
                "userId":"1"
                }';
-    $activity = $this->InputJsonConverter->convertActivities($json);
+    $activity = $this->inputJsonConverter->convertActivities($json);
     $this->assertEquals('write back!', $activity['body']);
     $this->assertEquals('202', $activity['id']);
     $this->assertEquals('image', $activity['mediaItems'][0]['mimeType']);
@@ -77,7 +77,7 @@
                "pokes" : 3,
                "last_poke" : "2008-02-13T18:30:02Z"
                }';
-    $appData = $this->InputJsonConverter->convertAppData($json);
+    $appData = $this->inputJsonConverter->convertAppData($json);
     $this->assertEquals('3', $appData['pokes']);
     $this->assertEquals('2008-02-13T18:30:02Z', $appData['last_poke']);
   }
@@ -91,7 +91,7 @@
                "title" : "You have an invitation from Joe",
                "body" : "Click here to review your invitation"
                }';
-    $message = $this->InputJsonConverter->convertMessages($json);
+    $message = $this->inputJsonConverter->convertMessages($json);
     file_put_contents('/tmp/message.txt', print_r($json, true));
     $this->assertEquals('msgid', $message['id']);
     $this->assertEquals('You have an invitation from Joe', $message['title']);
@@ -103,8 +103,36 @@
    */
   public function testConvertPeople() {
     $this->setExpectedException('Exception');
-    $this->InputJsonConverter->convertPeople();
+    $this->inputJsonConverter->convertPeople();
+  }
+  
+  public function testConvertAlbum() {
+    $json = '{ "id": "albumId",
+               "title": "The album title.",
+               "location": {"latitude": 100.0, "longitude": 200.0}
+    }';
+    $album = $this->inputJsonConverter->convertAlbums($json);
+    $this->assertEquals('albumId', $album['id']);
+    $this->assertEquals('The album title.', $album['title']);
+    $this->assertFalse(empty($album['location']));
+    $this->assertEquals(100.0, $album['location']['latitude']);
+    $this->assertEquals(200.0, $album['location']['longitude']);
+  }
+  
+  public function testConvertMediaItem() {
+    $json = '{ "id" : "11223344",
+               "thumbnailUrl" : 
"http://pages.example.org/images/11223344-tn.png";,
+               "mimeType" : "image/png",
+               "type" : "image",
+               "url" : "http://pages.example.org/images/11223344.png";,
+               "albumId" : "44332211"
+             }';
+    $mediaItem = $this->inputJsonConverter->convertMediaItems($json);
+    $this->assertEquals('11223344', $mediaItem['id']);
+    $this->assertEquals('http://pages.example.org/images/11223344-tn.png', 
$mediaItem['thumbnailUrl']);
+    $this->assertEquals('44332211', $mediaItem['albumId']);
+    $this->assertEquals('http://pages.example.org/images/11223344.png', 
$mediaItem['url']);
+    $this->assertEquals('image/png', $mediaItem['mimeType']);
   }
-
 }
 

Modified: incubator/shindig/trunk/php/test/social/InputXmlConverterTest.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/social/InputXmlConverterTest.php?rev=788298&r1=788297&r2=788298&view=diff
==============================================================================
--- incubator/shindig/trunk/php/test/social/InputXmlConverterTest.php (original)
+++ incubator/shindig/trunk/php/test/social/InputXmlConverterTest.php Thu Jun 
25 09:09:37 2009
@@ -26,21 +26,21 @@
   /**
    * @var InputXmlConverter
    */
-  private $InputXmlConverter;
+  private $inputXmlConverter;
 
   /**
    * Prepares the environment before running a test.
    */
   protected function setUp() {
     parent::setUp();
-    $this->InputXmlConverter = new InputXmlConverter(/* parameters */);
+    $this->inputXmlConverter = new InputXmlConverter(/* parameters */);
   }
 
   /**
    * Cleans up the environment after running a test.
    */
   protected function tearDown() {
-    $this->InputXmlConverter = null;
+    $this->inputXmlConverter = null;
     parent::tearDown();
   }
 
@@ -74,7 +74,7 @@
   <summary>example summary</summary>
 </response>
 ';
-    $activity = $this->InputXmlConverter->convertActivities($xml);
+    $activity = $this->inputXmlConverter->convertActivities($xml);
     $this->assertEquals('urn:guid:220', $activity['id']);
     $this->assertEquals('example title', $activity['title']);
     $this->assertEquals('example summary', $activity['body']);
@@ -87,7 +87,7 @@
   }
 
   /**
-   * Tests InputXmlConverter->convertAppData()
+   * Tests inputXmlConverter->convertAppData()
    */
   public function testConvertAppData() {
     $xml = '<?xml version="1.0" encoding="UTF-8"?>
@@ -97,13 +97,13 @@
     <value>Virgo</value>
   </entry>
 </response>';
-    $appdata = $this->InputXmlConverter->convertAppData($xml);
+    $appdata = $this->inputXmlConverter->convertAppData($xml);
     $expect = array('sign' => 'Virgo');
     $this->assertEquals($expect, $appdata);
   }
 
   /**
-   * Tests InputXmlConverter->convertMessages()
+   * Tests inputXmlConverter->convertMessages()
    */
   public function testConvertMessages() {
     $xml = '<?xml version="1.0" encoding="UTF-8"?>
@@ -114,7 +114,7 @@
   <id>{msgid}</id>
   <body>Click &lt;a 
href="http://app.example.org/invites/{msgid}"&gt;here&lt;/a&gt; to review your 
invitation.</body>
 </response>';
-    $message = $this->InputXmlConverter->convertMessages($xml);
+    $message = $this->inputXmlConverter->convertMessages($xml);
     $this->assertEquals('{msgid}', $message['id']);
     $this->assertEquals('You have an invitation from Joe', $message['title']);
     $this->assertEquals('Click <a 
href="http://app.example.org/invites/{msgid}";>here</a> to review your 
invitation.', $message['body']);
@@ -123,10 +123,52 @@
   }
 
   /**
-   * Tests InputXmlConverter->convertPeople()
+   * Tests inputXmlConverter->convertPeople()
    */
   public function testConvertPeople() {
     $this->setExpectedException('Exception');
-    $this->InputXmlConverter->convertPeople('');
+    $this->inputXmlConverter->convertPeople('');
+  }
+  
+  public function testConvertAlbums() {
+    $xml = '<?xml version="1.0" encoding="UTF-8"?>
+            <album xmlns="http://ns.opensocial.org/2008/opensocial";>
+            <id>44332211</id>
+            
<thumbnailUrl>http://pages.example.org/albums/4433221-tn.png</thumbnailUrl>
+            <caption>Example Album</caption>
+            <description>This is an example album, and this text is an example 
description</description>
+            <location>
+               <latitude>0</latitude>
+               <longitude>0</longitude>
+            </location>
+            <ownerId>example.org:55443322</ownerId>
+            </album>';
+    $album = $this->inputXmlConverter->convertAlbums($xml);
+    $this->assertEquals('44332211', $album['id']);
+    $this->assertEquals('http://pages.example.org/albums/4433221-tn.png', 
$album['thumbnailUrl']);
+    $this->assertEquals('This is an example album, and this text is an example 
description', $album['description']);
+    $this->assertEquals('Example Album', $album['title']);
+    $this->assertEquals('example.org:55443322', $album['ownerId']);
+    $this->assertFalse(empty($album['location']));
+    $this->assertEquals(0, $album['location']['latitude']);
+    $this->assertEquals(0, $album['location']['longitude']);
+  }
+  
+  public function testConvertMediaItems() {
+    $xml = '<?xml version="1.0" encoding="UTF-8"?>
+            <mediaItem xmlns="http://ns.opensocial.org/2008/opensocial";>
+              <id>11223344</id>
+              
<thumbnailUrl>http://pages.example.org/images/11223344-tn.png</thumbnailUrl>
+              <mimeType>image/png</mimeType>
+              <type>image</type>
+              <url>http://pages.example.org/images/11223344.png</url>
+              <albumId>44332211</albumId>
+            </mediaItem>';
+    $mediaItem = $this->inputXmlConverter->convertMediaItems($xml);
+    $this->assertEquals('11223344', $mediaItem['id']);
+    $this->assertEquals('http://pages.example.org/images/11223344-tn.png', 
$mediaItem['thumbnailUrl']);
+    $this->assertEquals('44332211', $mediaItem['albumId']);
+    $this->assertEquals('http://pages.example.org/images/11223344.png', 
$mediaItem['url']);
+    $this->assertEquals('image/png', $mediaItem['mimeType']);
   }
 }
\ No newline at end of file

Modified: incubator/shindig/trunk/php/test/social/MediaItemTest.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/social/MediaItemTest.php?rev=788298&r1=788297&r2=788298&view=diff
==============================================================================
--- incubator/shindig/trunk/php/test/social/MediaItemTest.php (original)
+++ incubator/shindig/trunk/php/test/social/MediaItemTest.php Thu Jun 25 
09:09:37 2009
@@ -55,7 +55,7 @@
    * Tests MediaItem->getType()
    */
   public function testGetType() {
-    $this->assertEquals('audio', $this->MediaItem->getType());
+    $this->assertEquals('AUDIO', $this->MediaItem->getType());
   }
 
   /**
@@ -78,7 +78,7 @@
    */
   public function testSetType() {
     $this->MediaItem->setType('VIDEO');
-    $this->assertEquals('video', $this->MediaItem->type);
+    $this->assertEquals('VIDEO', $this->MediaItem->type);
   }
 
   /**

Modified: incubator/shindig/trunk/php/test/social/OutputAtomConverterTest.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/social/OutputAtomConverterTest.php?rev=788298&r1=788297&r2=788298&view=diff
==============================================================================
--- incubator/shindig/trunk/php/test/social/OutputAtomConverterTest.php 
(original)
+++ incubator/shindig/trunk/php/test/social/OutputAtomConverterTest.php Thu Jun 
25 09:09:37 2009
@@ -75,7 +75,7 @@
       <isViewer></isViewer>
       <displayName>1 1</displayName>
       <id>1</id>
-    </person>
+    </entry>
   </content>
 </entry>
 ';


Reply via email to