/** * Is allowed manage (create, remove, edit) bitstream's policies in the * current context? * * @param context the DSpace Context Object * @param bitstream the bitstream that the policy refer to * @throws AuthorizeException if authorization error * if the current context (current user) is not allowed to * manage the bitstream's policies * @throws SQLException if database error * if a db error occur */ public static void authorizeManageBitstreamPolicy(Context context, Bitstream bitstream) throws AuthorizeException, SQLException { Bundle bundle = bitstream.getBundles().get(0); authorizeManageBundlePolicy(context, bundle); }
private Date getLastModified(Context context, Bitstream bitstream) throws SQLException { Date lm = null; List<Bundle> bundles = bitstream.getBundles(); for (Bundle bundle : bundles) { List<Item> items = bundle.getItems(); for (Item item : items) { Date possible = item.getLastModified(); if (lm == null) { lm = possible; } else if (possible.getTime() > lm.getTime()) { lm = possible; } } } if (lm == null) { return new Date(); } return lm; }
/** * Tests bitstreams for containment in an ORIGINAL bundle * * @param bitstream Bitstream * @return true if the bitstream is in the ORIGINAL bundle * @throws BitstreamFilterException if filter error */ @Override public boolean accept(Bitstream bitstream) throws BitstreamFilterException { try { List<Bundle> bundles = bitstream.getBundles(); for (Bundle bundle : bundles) { if (bundle.getName().equals("ORIGINAL")) { return true; } } } catch (SQLException e) { throw new BitstreamFilterException(e); } return false; }
/** * Tests bitstream for membership in specified bundles (ORIGINAL, TEXT, THUMBNAIL) * * @param bitstream Bitstream * @return true if bitstream is in specified bundles * @throws BitstreamFilterException if error */ @Override public boolean accept(Bitstream bitstream) throws BitstreamFilterException { try { List<Bundle> bundles = bitstream.getBundles(); for (Bundle b : bundles) { for (String bn : bundlesToEmpty) { if (b.getName().equals(bn)) { return true; } } } } catch (SQLException e) { throw new BitstreamFilterException(e); } return false; }
/** * Filter bitstream based on bundle name found in properties file * * @param bitstream Bitstream * @return whether bitstream is in bundle * @throws BitstreamFilterException if filter error */ @Override public boolean accept(Bitstream bitstream) throws BitstreamFilterException { if (bundleName == null) { bundleName = props.getProperty("bundle"); if (bundleName == null) { throw new BitstreamFilterException("Property 'bundle' not found."); } } try { List<Bundle> bundles = bitstream.getBundles(); for (Bundle b : bundles) { if (b.getName().equals(bundleName)) { return true; } } } catch (SQLException e) { throw new BitstreamFilterException(e); } return false; }
@Override public DSpaceObject getParentObject(Context context, Bitstream bitstream) throws SQLException { List<Bundle> bundles = bitstream.getBundles(); if (CollectionUtils.isNotEmpty(bundles)) { // the ADMIN action is not allowed on Bundle object so skip to the item Item item = (Item) bundleService.getParentObject(context, bundles.iterator().next()); if (item != null) { return item; } else { return null; } } else if (bitstream.getCommunity() != null) { return bitstream.getCommunity(); } else if (bitstream.getCollection() != null) { return bitstream.getCollection(); } return null; }
public void removeBitstream(Context context, Item item, Bitstream bitstream, boolean keep) throws SQLException, AuthorizeException, IOException { Bundle exempt = null; if (keep) { exempt = this.archiveBitstream(context, item, bitstream); } Iterator<Bundle> bundles = bitstream.getBundles() .iterator(); while (bundles.hasNext()) { Bundle bundle = bundles.next(); if (exempt != null && bundle.getID() != exempt.getID()) { bundles.remove(); bundleService .removeBitstream(context, bundle, bitstream); } } // there is nowhere in the metadata to say when this file was moved, so we // are going to drop it into the description SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); String desc = bitstream.getDescription(); String newDesc = "[Deleted on: " + sdf.format(new Date()) + "] "; if (desc != null) { newDesc += desc; } bitstream.setDescription(context, newDesc); bitstreamService.update(context, bitstream); }
throws DSpaceSWORDException { try { List<Bundle> bundles = bitstream.getBundles(); Bundle parent = null; if (!bundles.isEmpty()) {
public void deleteBitstream(Context context, Bitstream bitstream) throws SwordError, DSpaceSwordException { // this is equivalent to asking whether the media resource in the item can be deleted try { List<Bundle> bundles = bitstream.getBundles(); for (Bundle bundle : bundles) { // is the bitstream in the ORIGINAL bundle? If not, it can't be worked on if (!Constants.CONTENT_BUNDLE_NAME .equals(bundle.getName())) { throw new SwordError(UriRegistry.ERROR_METHOD_NOT_ALLOWED, "The file is not in a bundle which can be modified"); } List<Item> items = bundle.getItems(); for (Item item : items) { this.deleteMediaResource(context, item); } } } catch (SQLException e) { throw new DSpaceSwordException(e); } }
public void replaceBitstream(Context context, Bitstream bitstream) throws SwordError, DSpaceSwordException { // this is equivalent to asking whether the media resource in the item can be deleted try { List<Bundle> bundles = bitstream.getBundles(); for (Bundle bundle : bundles) { // is the bitstream in the ORIGINAL bundle? If not, it can't be worked on if (!Constants.CONTENT_BUNDLE_NAME .equals(bundle.getName())) { throw new SwordError(UriRegistry.ERROR_METHOD_NOT_ALLOWED, "The file is not in a bundle which can be modified"); } List<Item> items = bundle.getItems(); for (Item item : items) { this.replaceResourceContent(context, item); } } } catch (SQLException e) { throw new DSpaceSwordException(e); } }
public void deleteBitstream(Context context, Bitstream bitstream) throws SwordError, DSpaceSwordException { // this is equivalent to asking whether the media resource in the item can be deleted try { List<Bundle> bundles = bitstream.getBundles(); for (Bundle bundle : bundles) { // is the bitstream in the ORIGINAL bundle? If not, it can't be worked on if (!Constants.CONTENT_BUNDLE_NAME .equals(bundle.getName())) { throw new SwordError(UriRegistry.ERROR_METHOD_NOT_ALLOWED, "The file is not in a bundle which can be modified"); } List<Item> items = bundle.getItems(); for (Item item : items) { this.deleteMediaResource(context, item); } } } catch (SQLException e) { throw new DSpaceSwordException(e); } }
public void undoDeposit(DepositResult result) throws DSpaceSWORDException { try { SWORDContext sc = swordService.getSwordContext(); BundleService bundleService = ContentServiceFactory.getInstance() .getBundleService(); // obtain the bitstream's owning bundles and remove the bitstream // from them. This will ensure that the bitstream is physically // removed from the disk. Bitstream bs = result.getBitstream(); Iterator<Bundle> bundles = bs.getBundles().iterator(); while (bundles.hasNext()) { Bundle bundle = bundles.next(); bundles.remove(); bundleService.removeBitstream(sc.getContext(), bundle, bs); bundleService.update(sc.getContext(), bundle); } swordService.message("Removing temporary files from disk"); // abort the context, so no database changes are written sc.abort(); swordService.message("Database changes aborted"); } catch (IOException | AuthorizeException | SQLException e) { throw new DSpaceSWORDException(e); } } }
return; List<Bundle> bundles = bitstream.getBundles(); for (Bundle b : bundles) { List<Item> items = b.getItems();
@Override public void delete(Context context, Bitstream bitstream) throws SQLException, AuthorizeException { // changed to a check on delete // Check authorisation authorizeService.authorizeAction(context, bitstream, Constants.DELETE); log.info(LogManager.getHeader(context, "delete_bitstream", "bitstream_id=" + bitstream.getID())); context.addEvent(new Event(Event.DELETE, Constants.BITSTREAM, bitstream.getID(), String.valueOf(bitstream.getSequenceID()), getIdentifiers(context, bitstream))); // Remove bitstream itself bitstream.setDeleted(true); update(context, bitstream); //Remove our bitstream from all our bundles final List<Bundle> bundles = bitstream.getBundles(); for (Bundle bundle : bundles) { bundle.removeBitstream(bitstream); } //Remove all bundles from the bitstream object, clearing the connection in 2 ways bundles.clear(); // Remove policies only after the bitstream has been updated (otherwise the current user has not WRITE rights) authorizeService.removeAllPolicies(context, bitstream); }
List<Bundle> bundles = bitstream.getBundles(); for (Bundle bundle : bundles) {
if (bitstream.getBundles().size() <= 1) { } else { bundle.removeBitstream(bitstream); bitstream.getBundles().remove(bundle);
List<Bundle> bundles = bit.getBundles(); for (Bundle bundle : bundles) { doc1.addField("bundleName", bundle.getName());
List<Bundle> bundles = bit.getBundles(); for (Bundle bundle : bundles) { doc1.addField("bundleName", bundle.getName());
bitstream.getBundles().add(bundle);
List<Bundle> bundles = bitstream.getBundles(); for (Bundle bundle : bundles) { List<Item> items = bundle.getItems();