Bitstream bitstream = bundleService.getBitstreamByName(bundle, "license_rdf"); bitstreamService.update(context, newBitstream); bundleService.removeBitstream(context, bundle, bitstream); bundleService.update(context, bundle);
private void archiveBundle(Context context, Item item, Bundle source) throws SQLException, AuthorizeException, IOException { // get the datestamped root bundle name SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String oldName = "VER" + sdf.format(new Date()); oldName = this.getNumberedName(item, oldName, 0); Bundle old = bundleService.create(context, item, oldName); List<Bitstream> bitstreams = source.getBitstreams(); for (Bitstream bitstream : bitstreams) { bundleService .addBitstream(context, old, bitstream); } }
OREBundle = OREBundles.get(0); } else { OREBundle = bundleService.create(ourContext, item, "ORE"); ByteArrayInputStream OREStream = new ByteArrayInputStream(OREString.getBytes()); OREBitstream = bundleService.getBitstreamByName(OREBundle, "ORE.xml"); bundleService.removeBitstream(ourContext, OREBundle, OREBitstream); bitstreamService.update(ourContext, OREBitstream); bundleService.addBitstream(ourContext, OREBundle, OREBitstream); bundleService.update(ourContext, OREBundle);
protected Bundle getCcBundle(Context context, Item item) throws SQLException, AuthorizeException, IOException { List<Bundle> bundles = itemService.getBundles(item, CC_BUNDLE_NAME); if ((bundles.size() > 0) && (bundles.get(0) != null)) { itemService.removeBundle(context, item, bundles.get(0)); } return bundleService.create(context, item, CC_BUNDLE_NAME); }
targetBundle = bundleService.create(context, item, bundleName); itemService.addBundle(context, item, targetBundle); } else { bitstreamService.update(context, newBitstream); bundleService.addBitstream(context, targetBundle, newBitstream); bundleService.update(context, targetBundle); } else { throw new CrosswalkException("Could not retrieve bitstream: " + entryId);
original = bundleService.create(context, myitem, "ORIGINAL"); bundleService.removeBitstream(context, original, bs);
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); } } }
public void removeBundle(Context context, Item item, Bundle source, boolean archive) throws SQLException, AuthorizeException, IOException { // archive the bundle contents if desired if (archive) { this.archiveBundle(context, item, source); } // remove all the bitstreams from the bundle Iterator<Bitstream> bitstreams = source.getBitstreams() .iterator(); while (bitstreams.hasNext()) { Bitstream bitstream = bitstreams.next(); bitstreams.remove(); bundleService.removeBitstream(context, source, bitstream); } // delete the bundle itself itemService.removeBundle(context, item, source); }
bundleService.addBitstream(context, pBundle, bitstream); bundleService.removeBitstream(context, bundle, bitstream); List<Bitstream> bitstreams = bundle.getBitstreams(); if (bitstreams == null || bitstreams.size() == 0) { bundleService.removeBitstream(context, dBundle, displayMap.get(bitstream.getName()));
private void archiveBitstream(Context context, Bundle target, Bitstream bitstream) throws SQLException, AuthorizeException, IOException { bundleService.addBitstream(context, target, bitstream); }
protected void deleteBundle(Context context, Item item, Bundle b) throws AuthorizeException, SQLException, IOException { // Check authorisation authorizeService.authorizeAction(context, item, Constants.REMOVE); bundleService.delete(context, b); log.info(LogManager.getHeader(context, "remove_bundle", "item_id=" + item.getID() + ",bundle_id=" + b.getID())); context .addEvent(new Event(Event.REMOVE, Constants.ITEM, item.getID(), Constants.BUNDLE, b.getID(), b.getName())); }
for (Bundle bundle : bundles) { List<org.dspace.authorize.ResourcePolicy> bitstreamsPolicies = bundleService .getBitstreamPolicies(context, bundle); for (org.dspace.authorize.ResourcePolicy policy : bitstreamsPolicies) { if (policy.getdSpaceObject().equals(bitstream)) {
/** * This helper method retrieves the bytes of a bitstream for an item under * the CC bundle, with the given bitstream name * * @param item parent item * @param bitstream_name bitstream name to set * @return the bitstream * @throws IOException A general class of exceptions produced by failed or interrupted I/O operations. * @throws SQLException An exception that provides information on a database access error or other errors. * @throws AuthorizeException Exception indicating the current user of the context does not have permission * to perform a particular action. */ protected Bitstream getBitstream(Item item, String bitstream_name) throws SQLException, IOException, AuthorizeException { Bundle cc_bundle = null; // look for the CC bundle try { List<Bundle> bundles = itemService.getBundles(item, CC_BUNDLE_NAME); if ((bundles != null) && (bundles.size() > 0)) { cc_bundle = bundles.get(0); } else { return null; } } catch (Exception exc) { // this exception catching is a bit generic, // but basically it happens if there is no CC bundle return null; } return bundleService.getBitstreamByName(cc_bundle, bitstream_name); }
public String getObjectSizesInfo(Context context) throws SQLException { StringBuilder sb = new StringBuilder(); sb.append(String.format("Count %-14s: %s\n", "Bitstream", String.valueOf(bitstreamService.countTotal(context)))); sb.append(String.format("Count %-14s: %s\n", "Bundle", String.valueOf(bundleService.countTotal(context)))); sb.append(String.format("Count %-14s: %s\n", "Collection", String.valueOf(collectionService.countTotal(context)))); sb.append(String.format("Count %-14s: %s\n", "Community", String.valueOf(communityService.countTotal(context)))); sb.append(String.format("Count %-14s: %s\n", "MetadataValue", String.valueOf(metadataValueService.countTotal(context)))); sb.append(String.format("Count %-14s: %s\n", "EPerson", String.valueOf(ePersonService.countTotal(context)))); sb.append(String.format("Count %-14s: %s\n", "Item", String.valueOf(itemService.countTotal(context)))); sb.append(String.format("Count %-14s: %s\n", "Handle", String.valueOf(handleService.countTotal(context)))); sb.append(String.format("Count %-14s: %s\n", "Group", String.valueOf(groupService.countTotal(context)))); sb.append(String.format("Count %-14s: %s\n", "BasicWorkflowItem", String.valueOf(basicWorkflowItemService.countTotal(context)))); sb.append(String.format("Count %-14s: %s\n", "WorkspaceItem", String.valueOf(workspaceItemService.countTotal(context)))); return sb.toString(); }
Bundle bundle = bundleService.find(ctx, event.getSubjectID()); if (bundle == null) { log.debug("Cannot find bundle " + event.getSubjectID() + "! "
@Override public Bitstream createSingleBitstream(Context context, InputStream is, Item item, String name) throws AuthorizeException, IOException, SQLException { // Authorisation is checked by methods below // Create a bundle Bundle bnd = bundleService.create(context, item, name); Bitstream bitstream = bitstreamService.create(context, bnd, is); addBundle(context, item, bnd); // FIXME: Create permissions for new bundle + bitstream return bitstream; }
targetBundle = bundleService.create(context, item, formatFilter.getBundleName()); } else { bundleService.removeBitstream(context, existingBundle, existingBitstream);
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); }
@Override public Bitstream create(Context context, Bundle bundle, InputStream is) throws IOException, SQLException, AuthorizeException { // Check authorisation authorizeService.authorizeAction(context, bundle, Constants.ADD); Bitstream b = create(context, is); bundleService.addBitstream(context, bundle, b); return b; }