Author: chabotc Date: Mon Aug 3 10:55:41 2009 New Revision: 800295 URL: http://svn.apache.org/viewvc?rev=800295&view=rev Log: SHINDIG-1136 by Jinhui Du, Content uploading support (partial)
Modified: incubator/shindig/trunk/php/src/social/converters/InputJsonConverter.php incubator/shindig/trunk/php/src/social/sample/JsonDbOpensocialService.php incubator/shindig/trunk/php/src/social/service/MediaItemHandler.php incubator/shindig/trunk/php/src/social/service/ResponseError.php incubator/shindig/trunk/php/src/social/service/RestRequestItem.php incubator/shindig/trunk/php/src/social/spi/MediaItemService.php incubator/shindig/trunk/php/test/index.php incubator/shindig/trunk/php/test/social/MediaItemRestTest.php 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=800295&r1=800294&r2=800295&view=diff ============================================================================== --- incubator/shindig/trunk/php/src/social/converters/InputJsonConverter.php (original) +++ incubator/shindig/trunk/php/src/social/converters/InputJsonConverter.php Mon Aug 3 10:55:41 2009 @@ -70,7 +70,9 @@ public function convertMediaItems($requestParam) { $ret = json_decode($requestParam, true); if ($ret == $requestParam) { - throw new Exception("Mallformed album json string. " . $requestParam); + // The content upload specification allows the content-type in the post + // body to be the binary data of the content. + return null; } return $ret; } 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=800295&r1=800294&r2=800295&view=diff ============================================================================== --- incubator/shindig/trunk/php/src/social/sample/JsonDbOpensocialService.php (original) +++ incubator/shindig/trunk/php/src/social/sample/JsonDbOpensocialService.php Mon Aug 3 10:55:41 2009 @@ -814,7 +814,7 @@ return self::paginateResults($results, $options); } - public function createMediaItem($userId, $groupId, $mediaItem, $data, $token) { + public function createMediaItem($userId, $groupId, $mediaItem, $token) { $all = $this->getAllMediaItems(); $albumId = $mediaItem['albumId']; $id = isset($all[$albumId]) ? (count($all[$albumId]) + 1) : 0; @@ -836,7 +836,7 @@ return $mediaItem; } - public function updateMediaItem($userId, $groupId, $mediaItem, $data, $token) { + public function updateMediaItem($userId, $groupId, $mediaItem, $token) { $all = $this->getAllMediaItems(); if (! $all[$mediaItem['albumId']] || ! $all[$mediaItem['albumId']][$mediaItem['id']]) { throw new SocialSpiException("MediaItem not found.", ResponseError::$BAD_REQUEST); Modified: incubator/shindig/trunk/php/src/social/service/MediaItemHandler.php URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social/service/MediaItemHandler.php?rev=800295&r1=800294&r2=800295&view=diff ============================================================================== --- incubator/shindig/trunk/php/src/social/service/MediaItemHandler.php (original) +++ incubator/shindig/trunk/php/src/social/service/MediaItemHandler.php Mon Aug 3 10:55:41 2009 @@ -20,18 +20,18 @@ class MediaItemHandler extends DataRequestHandler { private static $MEDIA_ITEM_PATH = "/mediaitems/{userId}/{groupId}/{albumId}/{mediaItemId}"; - + public function __construct() { parent::__construct('media_item_service'); } - + /** * Deletes the media items. The URI structure: /{userId}/{groupId}/{albumId}/{mediaItemId}+ */ public function handleDelete(RequestItem $requestItem) { $this->checkService(); $requestItem->applyUrlTemplate(self::$MEDIA_ITEM_PATH); - + $userIds = $requestItem->getUsers(); $groupId = $requestItem->getGroup(); $albumIds = $requestItem->getListParameter('albumId'); @@ -50,12 +50,12 @@ public function handleGet(RequestItem $requestItem) { $this->checkService(); $requestItem->applyUrlTemplate(self::$MEDIA_ITEM_PATH); - + $userIds = $requestItem->getUsers(); $groupId = $requestItem->getGroup(); $albumIds = $requestItem->getListParameter("albumId"); $mediaItemIds = $requestItem->getListParameter("mediaItemId"); - + HandlerPreconditions::requireSingular($userIds, "userId must be singular value."); HandlerPreconditions::requireNotEmpty($groupId, "groupId must be specified."); HandlerPreconditions::requireSingular($albumIds, "albumId must be singular value."); @@ -72,19 +72,33 @@ public function handlePost(RequestItem $requestItem) { $this->checkService(); $requestItem->applyUrlTemplate(self::$MEDIA_ITEM_PATH); - + $userIds = $requestItem->getUsers(); $groupId = $requestItem->getGroup(); $albumIds = $requestItem->getListParameter('albumId'); $mediaItem = $requestItem->getParameter('mediaItem'); + if (! isset($mediaItem)) { + // For the content upload REST api. The param is mediaType in the spec now. As there is no mediaType + // field in MediaItem. It should be 'type'. + $type = $requestItem->getParameter('mediaType'); + if (! isset($type)) { + $type = $requestItem->getParameter('type'); + } + if (in_array($type, MediaItem::$TYPES)) { + $mediaItem = array('type' => $type); + // Only support title and description for now. + $mediaItem['title'] = $requestItem->getParameter('title'); + $mediaItem['description'] = $requestItem->getParameter('description'); + } + } HandlerPreconditions::requireSingular($userIds, "userId must be of singular value"); HandlerPreconditions::requireNotEmpty($groupId, "groupId must be specified."); HandlerPreconditions::requireSingular($albumIds, "albumId must be sigular value."); HandlerPreconditions::requireNotEmpty($mediaItem, "mediaItem must be specified."); - - // The null param is the content data(image, video and audio binaries) uploaded by the user. - return $this->service->createMediaItem($userIds[0], $groupId, $mediaItem, null, $requestItem->getToken()); + $mediaItem['albumId'] = $albumIds[0]; + + return $this->service->createMediaItem($userIds[0], $groupId, $mediaItem, $requestItem->getToken()); } /** @@ -93,22 +107,21 @@ public function handlePut(RequestItem $requestItem) { $this->checkService(); $requestItem->applyUrlTemplate(self::$MEDIA_ITEM_PATH); - + $userIds = $requestItem->getUsers(); $groupId = $requestItem->getGroup(); $albumIds = $requestItem->getListParameter('albumId'); $mediaItemIds = $requestItem->getListParameter('mediaItemId'); $mediaItem = $requestItem->getParameter('mediaItem'); - + HandlerPreconditions::requireSingular($userIds, "userId must be singular value."); HandlerPreconditions::requireNotEmpty($groupId, "groupId must be specified."); HandlerPreconditions::requireSingular($albumIds, "albumId must be sigular value."); HandlerPreconditions::requireSingular($mediaItemIds, "mediaItemId must be sigular value."); HandlerPreconditions::requireNotEmpty($mediaItem, "mediaItem must be specified."); - + $mediaItem['id'] = $mediaItemIds[0]; $mediaItem['albumId'] = $albumIds[0]; - // The null param is the content data(image, video and audio binaries) uploaded by the user. - return $this->service->updateMediaItem($userIds[0], $groupId, $mediaItem, null, $requestItem->getToken()); + return $this->service->updateMediaItem($userIds[0], $groupId, $mediaItem, $requestItem->getToken()); } } Modified: incubator/shindig/trunk/php/src/social/service/ResponseError.php URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social/service/ResponseError.php?rev=800295&r1=800294&r2=800295&view=diff ============================================================================== --- incubator/shindig/trunk/php/src/social/service/ResponseError.php (original) +++ incubator/shindig/trunk/php/src/social/service/ResponseError.php Mon Aug 3 10:55:41 2009 @@ -32,11 +32,13 @@ public static $BAD_REQUEST = 400; /** value representing NOT FOUND. */ public static $NOT_FOUND = 404; + /** value representing content uploading exceeds the quota.*/ + public static $REQUEST_TOO_LARGE = 413; /** value representing INTERNAL SERVER ERROR. */ public static $INTERNAL_ERROR = 500; /** value representing EXPECTATION FAILED. */ public static $LIMIT_EXCEEDED = 409; - + /** * The json value of the error. */ @@ -45,7 +47,7 @@ * The http error code associated with the error. */ private $httpErrorCode; - + /** * The HTTP response header */ 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=800295&r1=800294&r2=800295&view=diff ============================================================================== --- incubator/shindig/trunk/php/src/social/service/RestRequestItem.php (original) +++ incubator/shindig/trunk/php/src/social/service/RestRequestItem.php Mon Aug 3 10:55:41 2009 @@ -103,7 +103,9 @@ break; case DataServiceServlet::$MEDIA_ITEM_ROUTE: $data = $this->inputConverter->convertMediaItems($this->postData); - $this->params['mediaItem'] = $data; + if (isset($data)) { + $this->params['mediaItem'] = $data; + } break; default: throw new Exception("Invalid or unknown service endpoint: $service"); Modified: incubator/shindig/trunk/php/src/social/spi/MediaItemService.php URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social/spi/MediaItemService.php?rev=800295&r1=800294&r2=800295&view=diff ============================================================================== --- incubator/shindig/trunk/php/src/social/spi/MediaItemService.php (original) +++ incubator/shindig/trunk/php/src/social/spi/MediaItemService.php Mon Aug 3 10:55:41 2009 @@ -44,11 +44,10 @@ * @param userId id of the user for whom a media item is to be created * @param groupId group id * @param mediaItem specifies album-id and media item fields - * @param data the image binary data to be uploaded * @param token security token to authorize this request * @return the created media item */ - public function createMediaItem($userId, $groupId, $mediaItem, $data, $token); + public function createMediaItem($userId, $groupId, $mediaItem, $token); /** * Updates a media item in an album. Album id and media item id is taken in @@ -60,7 +59,7 @@ * @param token security token * @return updated album media item */ - public function updateMediaItem($userId, $groupId, $mediaItem, $data, $token); + public function updateMediaItem($userId, $groupId, $mediaItem, $token); /** * Deletes an album media item. Modified: incubator/shindig/trunk/php/test/index.php URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/index.php?rev=800295&r1=800294&r2=800295&view=diff ============================================================================== --- incubator/shindig/trunk/php/test/index.php (original) +++ incubator/shindig/trunk/php/test/index.php Mon Aug 3 10:55:41 2009 @@ -31,7 +31,7 @@ function __autoload($className) { $basePath = realpath('../'); $locations = array('src/common', 'src/common/sample', 'src/gadgets', 'src/gadgets/http', 'src/gadgets/oauth', - 'src/gadgets/render', 'src/gadgets/rewrite', 'src/gadgets/sample', 'src/social', + 'src/gadgets/render', 'src/gadgets/rewrite', 'src/gadgets/sample', 'src/gadgets/templates', 'src/social', 'src/social/http', 'src/social/service', 'src/social/converters', 'src/social/opensocial', 'src/social/spi', 'src/social/model', 'src/social/sample', 'src/social/oauth'); $extension_class_paths = Config::get('extension_class_paths'); Modified: incubator/shindig/trunk/php/test/social/MediaItemRestTest.php URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/social/MediaItemRestTest.php?rev=800295&r1=800294&r2=800295&view=diff ============================================================================== --- incubator/shindig/trunk/php/test/social/MediaItemRestTest.php (original) +++ incubator/shindig/trunk/php/test/social/MediaItemRestTest.php Mon Aug 3 10:55:41 2009 @@ -91,7 +91,7 @@ $this->verifyLifeCycle($postData, 'application/json'); } - public function xxtestLifeCycleInXml() { + public function testLifeCycleInXml() { $postData = '<?xml version="1.0" encoding="UTF-8"?> <mediaItem xmlns="http://ns.opensocial.org/2008/opensocial"> <id>11223344</id> @@ -104,7 +104,7 @@ $this->verifyLifeCycle($postData, 'application/xml'); } - public function xxtestLifeCycleInAtom() { + public function testLifeCycleInAtom() { $postData = '<entry xmlns="http://www.w3.org/2005/Atom"> <content type="application/xml"> <mediaItem xmlns="http://ns.opensocial.org/2008/opensocial">