Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit db95271

Browse files
author
mgrauer
committed
Return item from item addmetadata PUT rest endpoint
1 parent fd566cb commit db95271

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

core/controllers/components/ApiitemComponent.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public function itemSetmultiplemetadata($args)
180180
* @http PUT
181181
* @param id The id of the item
182182
* @param revision (Optional) Item Revision number to set metadata on, defaults to latest revision.
183-
* @return true on success,
183+
* @return item on success,
184184
* will fail if there are no revisions or the specified revision is not found.
185185
*
186186
* @param array $args parameters
@@ -207,14 +207,14 @@ public function itemAddmetadata($args)
207207
if (!array_key_exists(0, $args)) {
208208
throw new Exception('Missing request body data.', MIDAS_INVALID_PARAMETER);
209209
}
210-
$json_body = json_decode($args[0]);
211-
if (null === $json_body) {
210+
$jsonBody = json_decode($args[0]);
211+
if ($jsonBody === null) {
212212
throw new Exception('Request body data must be valid JSON.', MIDAS_INVALID_PARAMETER);
213213
}
214-
if (!array_key_exists('metadata', $json_body)) {
214+
if (!array_key_exists('metadata', $jsonBody)) {
215215
throw new Exception("Request body data missing key 'metadata'.", MIDAS_INVALID_PARAMETER);
216216
}
217-
$metadata = $json_body->metadata;
217+
$metadata = $jsonBody->metadata;
218218
foreach ($metadata as $metadatum) {
219219
if (!isset($metadatum->element) || !isset($metadatum->value)) {
220220
throw new Exception("All metadata must have 'element' and 'value' keys.", MIDAS_INVALID_PARAMETER);
@@ -232,7 +232,7 @@ public function itemAddmetadata($args)
232232
);
233233
}
234234

235-
return true;
235+
return $item;
236236
}
237237

238238
/**

core/tests/controllers/api/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
# limitations under the License.
1818
#=============================================================================
1919

20+
add_midas_test(CoreRestCallItemMethodsTest RestCallItemMethodsTest.php)
2021
add_midas_test(CoreRestCallUserMethodsTest RestCallUserMethodsTest.php)
2122
add_midas_test(CoreRestKeyControllerTest RestKeyControllerTest.php)
22-
add_midas_test(CoreRestCallItemMethodsTest RestCallItemMethodsTest.php)

core/tests/controllers/api/RestCallItemMethodsTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020

2121
require_once BASE_PATH.'/core/tests/controllers/api/RestCallMethodsTestCase.php';
2222

23-
/** Tests the functionality of the web API Rest Item methods */
23+
/** Tests the functionality of the web API Rest Item methods. */
2424
class Core_RestCallItemMethodsTest extends RestCallMethodsTestCase
2525
{
26-
/** set up tests */
26+
/** Set up tests. */
2727
public function setUp()
2828
{
2929
parent::setUp();
@@ -35,11 +35,11 @@ public function testItemAddmetadata()
3535
$itemsFile = $this->loadData('Item', 'default');
3636
$itemDao = $this->Item->load($itemsFile[1]->getKey());
3737

38-
$apipath = '/item/addmetadata/'.$itemDao->getItemId();
38+
$apiPath = '/item/addmetadata/'.$itemDao->getItemId();
3939

4040
// No user will fail.
4141
$this->resetAll();
42-
$resp = $this->_callRestApi('PUT', $apipath);
42+
$resp = $this->_callRestApi('PUT', $apiPath);
4343
$this->_assertStatusFail($resp);
4444

4545
$usersFile = $this->loadData('User', 'default');
@@ -48,28 +48,28 @@ public function testItemAddmetadata()
4848
// Lack of request body will fail.
4949
$this->resetAll();
5050
$this->params['useSession'] = 'true';
51-
$resp = $this->_callRestApi('PUT', $apipath, $userDao);
51+
$resp = $this->_callRestApi('PUT', $apiPath, $userDao);
5252
$this->_assertStatusFail($resp);
5353

5454
// Request body without a 'metadata' key will fail.
5555
$this->resetAll();
5656
$this->params['useSession'] = 'true';
5757
$this->params[0] = json_encode(array('murkydata' => array()));
58-
$resp = $this->_callRestApi('PUT', $apipath, $userDao);
58+
$resp = $this->_callRestApi('PUT', $apiPath, $userDao);
5959
$this->_assertStatusFail($resp);
6060

6161
// Metadatum needs 'value' key.
6262
$this->resetAll();
6363
$this->params['useSession'] = 'true';
6464
$this->params[0] = json_encode(array('metadata' => array('element' => 'key1')));
65-
$resp = $this->_callRestApi('PUT', $apipath, $userDao);
65+
$resp = $this->_callRestApi('PUT', $apiPath, $userDao);
6666
$this->_assertStatusFail($resp);
6767

6868
// Metadatum needs 'element' key.
6969
$this->resetAll();
7070
$this->params['useSession'] = 'true';
7171
$this->params[0] = json_encode(array('metadata' => array('value' => 'val1')));
72-
$resp = $this->_callRestApi('PUT', $apipath, $userDao);
72+
$resp = $this->_callRestApi('PUT', $apiPath, $userDao);
7373
$this->_assertStatusFail($resp);
7474

7575
// Write some metadata correctly.
@@ -79,7 +79,7 @@ public function testItemAddmetadata()
7979
array('element' => 'key1', 'value' => 'val1'),
8080
array('element' => 'key2', 'value' => 'val2'),
8181
)));
82-
$resp = $this->_callRestApi('PUT', $apipath, $userDao);
82+
$resp = $this->_callRestApi('PUT', $apiPath, $userDao);
8383
$this->_assertStatusOk($resp);
8484

8585
/** @var ItemModel $itemModel */
@@ -108,7 +108,7 @@ public function testItemAddmetadata()
108108
array('element' => 'key1', 'value' => 'newval1'),
109109
array('element' => 'key3', 'value' => 'val3'),
110110
)));
111-
$resp = $this->_callRestApi('PUT', $apipath, $userDao);
111+
$resp = $this->_callRestApi('PUT', $apiPath, $userDao);
112112
$this->_assertStatusOk($resp);
113113

114114
$metadata = $itemRevisionModel->getMetadata($revisionDao);

modules/api/controllers/components/ApiComponent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ public function itemSetmultiplemetadata($args)
777777
* @param token Authentication token
778778
* @param itemid The id of the item
779779
* @param revision (Optional) Item Revision number to set metadata on, defaults to latest revision.
780-
* @return true on success,
780+
* @return item on success,
781781
* will fail if there are no revisions or the specified revision is not found.
782782
*/
783783
public function itemAddmetadata($args)

0 commit comments

Comments
 (0)