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

Commit fd7c97f

Browse files
committed
ENH: refs #236. Add bitstream.get web api function
1 parent 8b4b889 commit fd7c97f

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

modules/api/controllers/components/ApiComponent.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,52 @@ function userApikeyDefault($args)
977977
return array('apikey' => $defaultApiKey);
978978
}
979979

980+
/**
981+
* Fetch the information about a bitstream
982+
* @param token (Optional) Authentication token
983+
* @param id The id of the bitstream
984+
* @return Bitstream dao
985+
*/
986+
function bitstreamGet($args)
987+
{
988+
$this->_validateParams($args, array('id'));
989+
$userDao = $this->_getUser($args);
990+
$modelLoader = new MIDAS_ModelLoader();
991+
$bitstreamModel = $modelLoader->loadModel('Bitstream');
992+
$bitstream = $bitstreamModel->load($args['id']);
993+
994+
if(!$bitstream)
995+
{
996+
throw new Exception('Invalid bitstream id', MIDAS_INVALID_PARAMETER);
997+
}
998+
999+
if(array_key_exists('name', $args))
1000+
{
1001+
$bitstream->setName($args['name']);
1002+
}
1003+
$revisionModel = $modelLoader->loadModel('ItemRevision');
1004+
$revision = $revisionModel->load($bitstream->getItemrevisionId());
1005+
1006+
if(!$revision)
1007+
{
1008+
throw new Exception('Invalid revision id', MIDAS_INTERNAL_ERROR);
1009+
}
1010+
$itemModel = $modelLoader->loadModel('Item');
1011+
$item = $itemModel->load($revision->getItemId());
1012+
if(!$item || !$itemModel->policyCheck($item, $userDao, MIDAS_POLICY_READ))
1013+
{
1014+
throw new Exception("This item doesn't exist or you don't have the permissions.", MIDAS_INVALID_POLICY);
1015+
}
1016+
$bitstreamArray = array();
1017+
$bitstreamArray['name'] = $bitstream->getName();
1018+
$bitstreamArray['size'] = $bitstream->getSizebytes();
1019+
$bitstreamArray['mimetype'] = $bitstream->getMimetype();
1020+
$bitstreamArray['checksum'] = $bitstream->getChecksum();
1021+
$bitstreamArray['itemrevision_id'] = $bitstream->getItemrevisionId();
1022+
$bitstreamArray['item_id'] = $revision->getItemId();
1023+
return $bitstreamArray;
1024+
}
1025+
9801026
/**
9811027
* Download a bitstream either by its id or by a checksum. Either an id or checksum parameter is required.
9821028
* @param token (Optional) Authentication token

0 commit comments

Comments
 (0)