@Override public boolean hasUploadedFiles(Item item) throws SQLException { List<Bundle> bundles = getBundles(item, "ORIGINAL"); for (Bundle bundle : bundles) { if (CollectionUtils.isNotEmpty(bundle.getBitstreams())) { return true; } } return false; }
@Override public Bitstream getFirstBitstream(Item item, String bundleName) throws SQLException { List<Bundle> bundles = itemService.getBundles(item, bundleName); if (CollectionUtils.isNotEmpty(bundles)) { List<Bitstream> bitstreams = bundles.get(0).getBitstreams(); if (CollectionUtils.isNotEmpty(bitstreams)) { return bitstreams.get(0); } } return null; }
@Override public List<ResourcePolicy> getBitstreamPolicies(Context context, Bundle bundle) throws SQLException { List<ResourcePolicy> list = new ArrayList<ResourcePolicy>(); List<Bitstream> bitstreams = bundle.getBitstreams(); if (CollectionUtils.isNotEmpty(bitstreams)) { for (Bitstream bs : bitstreams) { list.addAll(authorizeService.getPolicies(context, bs)); } } return list; }
@Override public Bitstream getBitstreamByName(Bundle bundle, String name) { Bitstream target = null; for (Bitstream bitstream : bundle.getBitstreams()) { if (name.equals(bitstream.getName())) { target = bitstream; break; } } return target; }
@Override public Bitstream getBitstreamByName(Item item, String bundleName, String bitstreamName) throws SQLException { List<Bundle> bundles = itemService.getBundles(item, bundleName); for (int i = 0; i < bundles.size(); i++) { Bundle bundle = bundles.get(i); List<Bitstream> bitstreams = bundle.getBitstreams(); for (int j = 0; j < bitstreams.size(); j++) { Bitstream bitstream = bitstreams.get(j); if (StringUtils.equals(bitstream.getName(), bitstreamName)) { return bitstream; } } } return null; }
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); } }
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; }
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; }
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; }
@Override public boolean filterItem(Context context, Item myItem) throws Exception { // get 'original' bundles List<Bundle> myBundles = itemService.getBundles(myItem, "ORIGINAL"); boolean done = false; for (Bundle myBundle : myBundles) { // now look at all of the bitstreams List<Bitstream> myBitstreams = myBundle.getBitstreams(); for (Bitstream myBitstream : myBitstreams) { done |= filterBitstream(context, myItem, myBitstream); } } return done; }
private List<String> getFileFormats(Item item) { List<String> formats = new ArrayList<>(); try { for (Bundle b : itemService.getBundles(item, "ORIGINAL")) { for (Bitstream bs : b.getBitstreams()) { if (!formats.contains(bs.getFormat(context).getMIMEType())) { formats.add(bs.getFormat(context).getMIMEType()); } } } } catch (SQLException ex) { log.error(ex.getMessage(), ex); } return formats; }
@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); } } }
@Override public void replaceAllBitstreamPolicies(Context context, Bundle bundle, List<ResourcePolicy> newpolicies) throws SQLException, AuthorizeException { List<Bitstream> bitstreams = bundle.getBitstreams(); if (CollectionUtils.isNotEmpty(bitstreams)) { for (Bitstream bs : bitstreams) { // change bitstream policies authorizeService.removeAllPolicies(context, bs); authorizeService.addPolicies(context, newpolicies, bs); } } // change bundle policies authorizeService.removeAllPolicies(context, bundle); authorizeService.addPolicies(context, newpolicies, bundle); }
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); } } } }
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); } } } }
@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); } }
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()); } } } }