@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; }
@Override public void removeAllBundles(Context context, Item item) throws AuthorizeException, SQLException, IOException { Iterator<Bundle> bundles = item.getBundles().iterator(); while (bundles.hasNext()) { Bundle bundle = bundles.next(); bundles.remove(); deleteBundle(context, item, bundle); } }
@Override public void replaceAllBitstreamPolicies(Context context, Item item, List<ResourcePolicy> newpolicies) throws SQLException, AuthorizeException { // remove all policies from bundles, add new ones List<Bundle> bunds = item.getBundles(); for (Bundle mybundle : bunds) { bundleService.replaceAllBitstreamPolicies(context, mybundle, newpolicies); } }
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; }
private static Bitstream getItemBitstreamByName(Item item, String bsName) throws SQLException { Bundle[] bundles = item.getBundles(); for (int i = 0; i < bundles.length; i++) { Bitstream[] bitstreams = bundles[i].getBitstreams(); for (int k = 0; k < bitstreams.length; k++) { if (bsName.equals(bitstreams[k].getName())) { return bitstreams[k]; } } } return null; }
@Override public List<Bitstream> getNonInternalBitstreams(Context context, Item item) throws SQLException { List<Bitstream> bitstreamList = new ArrayList<>(); // Go through the bundles and bitstreams picking out ones which aren't // of internal formats List<Bundle> bunds = item.getBundles(); for (Bundle bund : bunds) { List<Bitstream> bitstreams = bund.getBitstreams(); for (Bitstream bitstream : bitstreams) { if (!bitstream.getFormat(context).isInternal()) { // Bitstream is not of an internal format bitstreamList.add(bitstream); } } } return bitstreamList; }
@Override protected void performItem(Item item) throws SQLException, IOException { for (Bundle bundle : item.getBundles()) { for (Bitstream bs : bundle.getBitstreams()) { String fmt = bs.getFormat(Curator.curationContext()).getShortDescription(); Integer count = fmtTable.get(fmt); if (count == null) { count = 1; } else { count += 1; } fmtTable.put(fmt, count); } } }
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; } },
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; }
protected void addPolicyToItem(Context context, Item item, int type, EPerson epa, String policyType) throws AuthorizeException, SQLException { if (epa != null) { authorizeService.addPolicy(context, item, type, epa, policyType); List<Bundle> bundles = item.getBundles(); for (Bundle bundle : bundles) { authorizeService.addPolicy(context, bundle, type, epa, policyType); List<Bitstream> bits = bundle.getBitstreams(); for (Bitstream bit : bits) { authorizeService.addPolicy(context, bit, type, epa, policyType); } } } }
protected void addGroupPolicyToItem(Context context, Item item, int type, Group group) throws AuthorizeException, SQLException { if (group != null) { authorizeService.addPolicy(context, item, type, group); List<Bundle> bundles = item.getBundles(); for (Bundle bundle : bundles) { authorizeService.addPolicy(context, bundle, type, group); List<Bitstream> bits = bundle.getBitstreams(); for (Bitstream bit : bits) { authorizeService.addPolicy(context, bit, type, group); } } } }
@Override public void removeGroupPolicies(Context context, Item item, Group group) throws SQLException, AuthorizeException { // remove Group's policies from Item authorizeService.removeGroupPolicies(context, item, group); // remove all policies from bundles List<Bundle> bunds = item.getBundles(); for (Bundle mybundle : bunds) { List<Bitstream> bs = mybundle.getBitstreams(); for (Bitstream bitstream : bs) { // remove bitstream policies authorizeService.removeGroupPolicies(context, bitstream, group); } // change bundle policies authorizeService.removeGroupPolicies(context, mybundle, group); } }
protected void removeGroupItemPolicies(Context context, Item item, Group e) throws SQLException, AuthorizeException { if (e != null) { //Also remove any lingering authorizations from this user authorizeService.removeGroupPolicies(context, item, e); //Remove the bundle rights List<Bundle> bundles = item.getBundles(); for (Bundle bundle : bundles) { authorizeService.removeGroupPolicies(context, bundle, e); List<Bitstream> bitstreams = bundle.getBitstreams(); for (Bitstream bitstream : bitstreams) { authorizeService.removeGroupPolicies(context, bitstream, 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()); } } } }
public void removeUserItemPolicies(Context context, Item item, EPerson e) throws SQLException, AuthorizeException { if (e != null) { //Also remove any lingering authorizations from this user authorizeService.removeEPersonPolicies(context, item, e); //Remove the bundle rights List<Bundle> bundles = item.getBundles(); for (Bundle bundle : bundles) { authorizeService.removeEPersonPolicies(context, bundle, e); List<Bitstream> bitstreams = bundle.getBitstreams(); for (Bitstream bitstream : bitstreams) { authorizeService.removeEPersonPolicies(context, bitstream, e); } } // Ensure that the submitter always retains his resource policies if (e.getID().equals(item.getSubmitter().getID())) { grantSubmitterReadPolicies(context, item); } } }