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

Commit

Permalink
ENH: refs #236. Add download by checksum capability
Browse files Browse the repository at this point in the history
  • Loading branch information
zachmullen committed Oct 5, 2011
1 parent 33a81d7 commit 7e2abe7
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions modules/api/controllers/components/ApiComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -977,18 +977,40 @@ function userApikeyDefault($args)
return array('apikey' => $defaultApiKey);
}

/**
* Download a bitstream either by its id or by a checksum. Either an id or checksum parameter is required.
* @param token (Optional) Authentication token
* @param id (Optional) The id of the bitstream
* @param checksum (Optional) The checksum of the bitstream
* @param name (Optional) Alternate filename to download as
*/
function bitstreamDownload($args)
{
$this->_validateParams($args, array('id'));
if(!array_key_exists('id', $args) && !array_key_exists('checksum', $args))
{
throw new Exception('Either an id or checksum parameter is required', MIDAS_INVALID_PARAMETER);
}
$userDao = $this->_getUser($args);
$modelLoader = new MIDAS_ModelLoader();
$bitstreamModel = $modelLoader->loadModel('Bitstream');
$bitstream = $bitstreamModel->load($args['id']);
if(array_key_exists('id', $args))
{
$bitstream = $bitstreamModel->load($args['id']);
}
else
{
$bitstream = $bitstreamModel->getByChecksum($args['checksum']);
}

if(!$bitstream)
{
throw new Exception('Invalid bitstream id', MIDAS_INVALID_PARAMETER);
}

if(array_key_exists('name', $args))
{
$bitstream->setName($args['name']);
}
$revisionModel = $modelLoader->loadModel('ItemRevision');
$revision = $revisionModel->load($bitstream->getItemrevisionId());

Expand Down

0 comments on commit 7e2abe7

Please sign in to comment.