/** * Predicate, does this bundle container meta-information. I.e. * does this bundle contain descriptive metadata or other metadata * such as license bitstreams? If so we probably don't want to put * it into the "content" section of a package; hence this predicate. * * @param bn -- the bundle * @return true if this bundle name indicates it is a meta-info bundle. */ public static boolean isMetaInfoBundle(Bundle bn) { return (bn.getName().equals(Constants.LICENSE_BUNDLE_NAME) || bn.getName().equals(CreativeCommonsService.CC_BUNDLE_NAME) || bn.getName().equals(Constants.METADATA_BUNDLE_NAME)); }
@Override public List<Bundle> getBundles(Item item, String name) throws SQLException { List<Bundle> matchingBundles = new ArrayList<>(); // now only keep bundles with matching names List<Bundle> bunds = item.getBundles(); for (Bundle bund : bunds) { if (name.equals(bund.getName())) { matchingBundles.add(bund); } } return matchingBundles; }
static boolean hasUnsupportedBundle(Item item, String[] bundleList) { if (bundleList == null) { return false; } ArrayList<String> bundles = new ArrayList<String>(); for (String bundleName : bundleList) { bundles.add(bundleName.trim()); } for (Bundle bundle : item.getBundles()) { if (!bundles.contains(bundle.getName())) { return true; } } return false; }
/** * Get the bundles matching a bundle name (name corresponds roughly to type) * * @param name * name of bundle (ORIGINAL/TEXT/THUMBNAIL) * * @return the bundles in an unordered array */ public List<Bundle> getBundles(String name) { List<Bundle> matchingBundles = new ArrayList<Bundle>(); // now only keep bundles with matching names List<Bundle> bunds = getBundles(); for (Bundle bundle : bunds) { if (name.equals(bundle.getName())) { matchingBundles.add(bundle); } } return matchingBundles; }
private String getNumberedName(Item item, String name, int number) throws SQLException { String nName = name + "." + Integer.toString(number); List<Bundle> bundles = item.getBundles(); for (Bundle bundle : bundles) { if (nName.equals(bundle.getName())) { return this.getNumberedName(item, name, number + 1); } } return nName; } }
public void removeBundle(Context context, Item item, String name) throws SQLException, AuthorizeException, IOException { boolean keep = ConfigurationManager .getBooleanProperty("swordv2-server", "versions.keep"); Iterator<Bundle> bundles = item.getBundles().iterator(); while (bundles.hasNext()) { Bundle b = bundles.next(); if (name.equals(b.getName())) { bundles.remove(); this.removeBundle(context, item, b, keep); } } }
static int countBitstream(BundleName bundleName, Item item) { int count = 0; for (Bundle bundle : item.getBundles()) { if (!bundle.getName().equals(bundleName.name())) { continue; } count += bundle.getBitstreams().size(); } return count; }
static List<String> getBitstreamNames(BundleName bundleName, Item item) { ArrayList<String> names = new ArrayList<String>(); for (Bundle bundle : item.getBundles()) { if (!bundle.getName().equals(bundleName.name())) { continue; } for (Bitstream bit : bundle.getBitstreams()) { names.add(bit.getName()); } } return names; }
public boolean testItem(Context context, Item item) { try { for (Bundle bundle : item.getBundles()) { if (!bundle.getName().equals(BundleName.ORIGINAL.name())) { continue; } for (Bitstream bit : bundle.getBitstreams()) { if (!authorizeService .authorizeActionBoolean(getAnonContext(), bit, org.dspace.core.Constants.READ)) { return true; } } } } catch (SQLException e) { ItemFilterDefsPerm.log.warn("SQL Exception testing original bitstream access " + e.getMessage(), e); } return false; } },
public boolean testItem(Context context, Item item) { try { for (Bundle bundle : item.getBundles()) { if (!bundle.getName().equals(BundleName.THUMBNAIL.name())) { continue; } for (Bitstream bit : bundle.getBitstreams()) { if (!authorizeService .authorizeActionBoolean(getAnonContext(), bit, org.dspace.core.Constants.READ)) { return true; } } } } catch (SQLException e) { ItemFilterDefsPerm.log .warn("SQL Exception testing thumbnail bitstream access " + e.getMessage(), e); } return false; } },
static int countBitstreamByDesc(BundleName bundleName, Item item, String[] descList) { int count = 0; for (Bundle bundle : item.getBundles()) { if (!bundle.getName().equals(bundleName.name())) { continue; } for (Bitstream bit : bundle.getBitstreams()) { for (String desc : descList) { String bitDesc = bit.getDescription(); if (bitDesc == null) { continue; } if (bitDesc.equals(desc.trim())) { count++; } } } } return count; }
static int countBitstreamMime(Context context, BundleName bundleName, Item item, String[] mimeList) { int count = 0; for (Bundle bundle : item.getBundles()) { if (!bundle.getName().equals(bundleName.name())) { continue; } for (Bitstream bit : bundle.getBitstreams()) { for (String mime : mimeList) { try { if (bit.getFormat(context).getMIMEType().equals(mime.trim())) { count++; } } catch (SQLException e) { log.error("Get format error for bitstream " + bit.getName()); } } } } return count; }
static int countBitstreamMimeStartsWith(Context context, BundleName bundleName, Item item, String prefix) { int count = 0; try { for (Bundle bundle : item.getBundles()) { if (!bundle.getName().equals(bundleName.name())) { continue; } for (Bitstream bit : bundle.getBitstreams()) { if (bit.getFormat(context).getMIMEType().startsWith(prefix)) { count++; } } } } catch (SQLException e) { // ignore } return count; }
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); } }
private void buildFullTextList(Item parentItem) { // now get full text of any bitstreams in the TEXT bundle // trundle through the bundles List<Bundle> myBundles = parentItem.getBundles(); for (Bundle myBundle : emptyIfNull(myBundles)) { if (StringUtils.equals(FULLTEXT_BUNDLE, myBundle.getName())) { // a-ha! grab the text out of the bitstreams List<Bitstream> bitstreams = myBundle.getBitstreams(); for (Bitstream fulltextBitstream : emptyIfNull(bitstreams)) { fullTextStreams.add(new FullTextBitstream(sourceInfo, fulltextBitstream)); log.debug("Added BitStream: " + fulltextBitstream.getStoreNumber() + " " + fulltextBitstream.getSequenceID() + " " + fulltextBitstream.getName()); } } } }
static int countBitstreamLargerThanMaxSize(Context context, BundleName bundleName, Item item, String[] mimeList, String prop) { long size = DSpaceServicesFactory.getInstance().getConfigurationService().getLongProperty(prop); int count = 0; try { for (Bundle bundle : item.getBundles()) { if (!bundle.getName().equals(bundleName.name())) { continue; } for (Bitstream bit : bundle.getBitstreams()) { for (String mime : mimeList) { if (bit.getFormat(context).getMIMEType().equals(mime.trim())) { if (bit.getSizeBytes() > size) { count++; } } } } } } catch (SQLException e) { // ignore } return count; }
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())); }
@Override public void removeBundle(Context context, Item item, Bundle bundle) throws SQLException, AuthorizeException, IOException { // Check authorisation authorizeService.authorizeAction(context, item, Constants.REMOVE); log.info(LogManager.getHeader(context, "remove_bundle", "item_id=" + item.getID() + ",bundle_id=" + bundle.getID())); context.addEvent(new Event(Event.REMOVE, Constants.ITEM, item.getID(), Constants.BUNDLE, bundle.getID(), bundle.getName(), getIdentifiers(context, item))); bundleService.delete(context, bundle); }
@Override public void delete(Context context, Bundle bundle) throws SQLException, AuthorizeException, IOException { log.info(LogManager.getHeader(context, "delete_bundle", "bundle_id=" + bundle.getID())); authorizeService.authorizeAction(context, bundle, Constants.DELETE); context.addEvent(new Event(Event.DELETE, Constants.BUNDLE, bundle.getID(), bundle.getName(), getIdentifiers(context, bundle))); // Remove bitstreams List<Bitstream> bitstreams = bundle.getBitstreams(); bundle.clearBitstreams(); for (Bitstream bitstream : bitstreams) { removeBitstream(context, bundle, bitstream); } List<Item> items = new LinkedList<>(bundle.getItems()); bundle.getItems().clear(); for (Item item : items) { item.removeBundle(bundle); } // Remove ourself bundleDAO.delete(context, bundle); }
@Override public void addBundle(Context context, Item item, Bundle bundle) throws SQLException, AuthorizeException { // Check authorisation authorizeService.authorizeAction(context, item, Constants.ADD); log.info(LogManager.getHeader(context, "add_bundle", "item_id=" + item.getID() + ",bundle_id=" + bundle.getID())); // Check it's not already there if (item.getBundles().contains(bundle)) { // Bundle is already there; no change return; } // now add authorization policies from owning item // hmm, not very "multiple-inclusion" friendly authorizeService.inheritPolicies(context, item, bundle); // Add the bundle to in-memory list item.addBundle(bundle); bundle.addItem(item); context.addEvent(new Event(Event.ADD, Constants.ITEM, item.getID(), Constants.BUNDLE, bundle.getID(), bundle.getName(), getIdentifiers(context, item))); }