From db95271988c2fd7dcdd4346d324585b0438c045c Mon Sep 17 00:00:00 2001 From: mgrauer Date: Wed, 9 Dec 2015 23:02:47 +0000 Subject: [PATCH] Return item from item addmetadata PUT rest endpoint --- .../components/ApiitemComponent.php | 12 +++++------ core/tests/controllers/api/CMakeLists.txt | 2 +- .../api/RestCallItemMethodsTest.php | 20 +++++++++---------- .../controllers/components/ApiComponent.php | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/core/controllers/components/ApiitemComponent.php b/core/controllers/components/ApiitemComponent.php index 2da894499..a732f3783 100644 --- a/core/controllers/components/ApiitemComponent.php +++ b/core/controllers/components/ApiitemComponent.php @@ -180,7 +180,7 @@ public function itemSetmultiplemetadata($args) * @http PUT * @param id The id of the item * @param revision (Optional) Item Revision number to set metadata on, defaults to latest revision. - * @return true on success, + * @return item on success, * will fail if there are no revisions or the specified revision is not found. * * @param array $args parameters @@ -207,14 +207,14 @@ public function itemAddmetadata($args) if (!array_key_exists(0, $args)) { throw new Exception('Missing request body data.', MIDAS_INVALID_PARAMETER); } - $json_body = json_decode($args[0]); - if (null === $json_body) { + $jsonBody = json_decode($args[0]); + if ($jsonBody === null) { throw new Exception('Request body data must be valid JSON.', MIDAS_INVALID_PARAMETER); } - if (!array_key_exists('metadata', $json_body)) { + if (!array_key_exists('metadata', $jsonBody)) { throw new Exception("Request body data missing key 'metadata'.", MIDAS_INVALID_PARAMETER); } - $metadata = $json_body->metadata; + $metadata = $jsonBody->metadata; foreach ($metadata as $metadatum) { if (!isset($metadatum->element) || !isset($metadatum->value)) { throw new Exception("All metadata must have 'element' and 'value' keys.", MIDAS_INVALID_PARAMETER); @@ -232,7 +232,7 @@ public function itemAddmetadata($args) ); } - return true; + return $item; } /** diff --git a/core/tests/controllers/api/CMakeLists.txt b/core/tests/controllers/api/CMakeLists.txt index 543970c59..dd25795cd 100644 --- a/core/tests/controllers/api/CMakeLists.txt +++ b/core/tests/controllers/api/CMakeLists.txt @@ -17,6 +17,6 @@ # limitations under the License. #============================================================================= +add_midas_test(CoreRestCallItemMethodsTest RestCallItemMethodsTest.php) add_midas_test(CoreRestCallUserMethodsTest RestCallUserMethodsTest.php) add_midas_test(CoreRestKeyControllerTest RestKeyControllerTest.php) -add_midas_test(CoreRestCallItemMethodsTest RestCallItemMethodsTest.php) diff --git a/core/tests/controllers/api/RestCallItemMethodsTest.php b/core/tests/controllers/api/RestCallItemMethodsTest.php index 4d80bce4e..f13d52b66 100644 --- a/core/tests/controllers/api/RestCallItemMethodsTest.php +++ b/core/tests/controllers/api/RestCallItemMethodsTest.php @@ -20,10 +20,10 @@ require_once BASE_PATH.'/core/tests/controllers/api/RestCallMethodsTestCase.php'; -/** Tests the functionality of the web API Rest Item methods */ +/** Tests the functionality of the web API Rest Item methods. */ class Core_RestCallItemMethodsTest extends RestCallMethodsTestCase { - /** set up tests */ + /** Set up tests. */ public function setUp() { parent::setUp(); @@ -35,11 +35,11 @@ public function testItemAddmetadata() $itemsFile = $this->loadData('Item', 'default'); $itemDao = $this->Item->load($itemsFile[1]->getKey()); - $apipath = '/item/addmetadata/'.$itemDao->getItemId(); + $apiPath = '/item/addmetadata/'.$itemDao->getItemId(); // No user will fail. $this->resetAll(); - $resp = $this->_callRestApi('PUT', $apipath); + $resp = $this->_callRestApi('PUT', $apiPath); $this->_assertStatusFail($resp); $usersFile = $this->loadData('User', 'default'); @@ -48,28 +48,28 @@ public function testItemAddmetadata() // Lack of request body will fail. $this->resetAll(); $this->params['useSession'] = 'true'; - $resp = $this->_callRestApi('PUT', $apipath, $userDao); + $resp = $this->_callRestApi('PUT', $apiPath, $userDao); $this->_assertStatusFail($resp); // Request body without a 'metadata' key will fail. $this->resetAll(); $this->params['useSession'] = 'true'; $this->params[0] = json_encode(array('murkydata' => array())); - $resp = $this->_callRestApi('PUT', $apipath, $userDao); + $resp = $this->_callRestApi('PUT', $apiPath, $userDao); $this->_assertStatusFail($resp); // Metadatum needs 'value' key. $this->resetAll(); $this->params['useSession'] = 'true'; $this->params[0] = json_encode(array('metadata' => array('element' => 'key1'))); - $resp = $this->_callRestApi('PUT', $apipath, $userDao); + $resp = $this->_callRestApi('PUT', $apiPath, $userDao); $this->_assertStatusFail($resp); // Metadatum needs 'element' key. $this->resetAll(); $this->params['useSession'] = 'true'; $this->params[0] = json_encode(array('metadata' => array('value' => 'val1'))); - $resp = $this->_callRestApi('PUT', $apipath, $userDao); + $resp = $this->_callRestApi('PUT', $apiPath, $userDao); $this->_assertStatusFail($resp); // Write some metadata correctly. @@ -79,7 +79,7 @@ public function testItemAddmetadata() array('element' => 'key1', 'value' => 'val1'), array('element' => 'key2', 'value' => 'val2'), ))); - $resp = $this->_callRestApi('PUT', $apipath, $userDao); + $resp = $this->_callRestApi('PUT', $apiPath, $userDao); $this->_assertStatusOk($resp); /** @var ItemModel $itemModel */ @@ -108,7 +108,7 @@ public function testItemAddmetadata() array('element' => 'key1', 'value' => 'newval1'), array('element' => 'key3', 'value' => 'val3'), ))); - $resp = $this->_callRestApi('PUT', $apipath, $userDao); + $resp = $this->_callRestApi('PUT', $apiPath, $userDao); $this->_assertStatusOk($resp); $metadata = $itemRevisionModel->getMetadata($revisionDao); diff --git a/modules/api/controllers/components/ApiComponent.php b/modules/api/controllers/components/ApiComponent.php index 8c6b67a03..d82245c57 100644 --- a/modules/api/controllers/components/ApiComponent.php +++ b/modules/api/controllers/components/ApiComponent.php @@ -777,7 +777,7 @@ public function itemSetmultiplemetadata($args) * @param token Authentication token * @param itemid The id of the item * @param revision (Optional) Item Revision number to set metadata on, defaults to latest revision. - * @return true on success, + * @return item on success, * will fail if there are no revisions or the specified revision is not found. */ public function itemAddmetadata($args)