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

Commit 55ea20f

Browse files
committed
ENH: refs #236. Add an optional "head" param to midas.item.get
1 parent 5cd8ac9 commit 55ea20f

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

modules/api/controllers/components/ApiComponent.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,7 @@ function folderDownload($args)
737737
* Get an item's information
738738
* @param token (Optional) Authentication token
739739
* @param id The item id
740+
* @param head (Optional) only list the most recent revision
740741
* @return The item object
741742
*/
742743
function itemGet($args)
@@ -755,8 +756,16 @@ function itemGet($args)
755756
}
756757

757758
$itemArray = $item->toArray();
758-
$revisions = $item->getRevisions();
759759
$revisionsArray = array();
760+
761+
if(array_key_exists('head', $args))
762+
{
763+
$revisions = array($itemModel->getLastRevision($item));
764+
}
765+
else //get all revisions
766+
{
767+
$revisions = $item->getRevisions();
768+
}
760769
foreach($revisions as $revision)
761770
{
762771
$bitstreamArray = array();

modules/api/tests/controllers/ApiCallMethodsTest.php

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public function setUp()
1919
$this->setupDatabase(array('default')); //core dataset
2020
$this->setupDatabase(array('default'), 'api'); // module dataset
2121
$this->enabledModules = array('api');
22-
$this->_models = array('User', 'Folder');
23-
$this->_daos = array('User', 'Folder');
22+
$this->_models = array('User', 'Folder', 'Item');
23+
$this->_daos = array('User', 'Folder', 'Item');
2424

2525
parent::setUp();
2626
}
@@ -164,6 +164,46 @@ public function testFolderChildren()
164164
$this->assertEquals($resp->data->items[1]->description, 'Description 2');
165165
}
166166

167+
/** Test the item.get method */
168+
public function testItemGet()
169+
{
170+
$itemsFile = $this->loadData('Item', 'default');
171+
$itemDao = $this->Item->load($itemsFile[0]->getKey());
172+
173+
$this->resetAll();
174+
$token = $this->_loginUsingApiKey();
175+
$this->params['token'] = $token;
176+
$this->params['method'] = 'midas.item.get';
177+
$this->params['id'] = $itemsFile[0]->getKey();
178+
$this->request->setMethod('POST');
179+
$resp = $this->_callJsonApi();
180+
$this->_assertStatusOk($resp);
181+
182+
$this->assertEquals($resp->data->item_id, $itemDao->getKey());
183+
$this->assertEquals($resp->data->uuid, $itemDao->getUuid());
184+
$this->assertEquals($resp->data->description, $itemDao->getDescription());
185+
$this->assertTrue(is_array($resp->data->revisions));
186+
$this->assertEquals(count($resp->data->revisions), 2); //make sure we get both revisions
187+
$this->assertTrue(is_array($resp->data->revisions[0]->bitstreams));
188+
$this->assertEquals($resp->data->revisions[0]->revision, '1');
189+
$this->assertEquals($resp->data->revisions[1]->revision, '2');
190+
191+
// Test the 'head' parameter
192+
$this->resetAll();
193+
$token = $this->_loginUsingApiKey();
194+
$this->params['token'] = $token;
195+
$this->params['method'] = 'midas.item.get';
196+
$this->params['id'] = $itemsFile[0]->getKey();
197+
$this->params['head'] = 'true';
198+
$this->request->setMethod('POST');
199+
$resp = $this->_callJsonApi();
200+
$this->_assertStatusOk($resp);
201+
202+
$this->assertEquals(count($resp->data->revisions), 1); //make sure we get only one revision
203+
$this->assertTrue(is_array($resp->data->revisions[0]->bitstreams));
204+
$this->assertEquals($resp->data->revisions[0]->revision, '2');
205+
}
206+
167207
/** Test get user's default API key using username and password */
168208
public function testUserApikeyDefault()
169209
{

0 commit comments

Comments
 (0)