@@ -977,6 +977,52 @@ function userApikeyDefault($args)
977
977
return array ('apikey ' => $ defaultApiKey );
978
978
}
979
979
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
+
980
1026
/**
981
1027
* Download a bitstream either by its id or by a checksum. Either an id or checksum parameter is required.
982
1028
* @param token (Optional) Authentication token
0 commit comments