private List<Bitstream> unzipToBundle(Context context, File depositFile, Bundle target) throws DSpaceSwordException, SwordError, SwordAuthException { try { // get the zip file into a usable form ZipFile zip = new ZipFile(depositFile); List<Bitstream> derivedResources = new ArrayList<Bitstream>(); Enumeration zenum = zip.entries(); while (zenum.hasMoreElements()) { ZipEntry entry = (ZipEntry) zenum.nextElement(); InputStream stream = zip.getInputStream(entry); Bitstream bs = bitstreamService.create(context, target, stream); BitstreamFormat format = this .getFormat(context, entry.getName()); bs.setFormat(context, format); bs.setName(context, entry.getName()); bitstreamService.update(context, bs); derivedResources.add(bs); } return derivedResources; } catch (ZipException e) { throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "unable to unzip provided package", e); } catch (IOException | SQLException e) { throw new DSpaceSwordException(e); } catch (AuthorizeException e) { throw new SwordAuthException(e); } }
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); }
bs.setDescription(c, description); bitstreamService.update(c, bs);
newBitstream.setUserFormatDescription(context, bitstream .getUserFormatDescription()); bitstreamService.update(context, newBitstream);
@Override public void setLicense(Context context, Item item, InputStream licenseStm, String mimeType) throws SQLException, IOException, AuthorizeException { Bundle bundle = getCcBundle(context, item); // set the format BitstreamFormat bs_format; if (mimeType.equalsIgnoreCase("text/xml")) { bs_format = bitstreamFormatService.findByShortDescription(context, "CC License"); } else if (mimeType.equalsIgnoreCase("text/rdf")) { bs_format = bitstreamFormatService.findByShortDescription(context, "RDF XML"); } else { bs_format = bitstreamFormatService.findByShortDescription(context, "License"); } Bitstream bs = bitstreamService.create(context, bundle, licenseStm); bs.setSource(context, CC_BS_SOURCE); bs.setName(context, (mimeType != null && (mimeType.equalsIgnoreCase("text/xml") || mimeType.equalsIgnoreCase("text/rdf"))) ? BSN_LICENSE_RDF : BSN_LICENSE_TEXT); bs.setFormat(context, bs_format); bitstreamService.update(context, bs); }
/** * This helper method takes some bytes and stores them as a bitstream for an * item, under the CC bundle, with the given bitstream name * * Note: This helper method assumes that the CC * bitstreams are short and easily expressed as byte arrays in RAM * * @param context The relevant DSpace Context. * @param item parent item * @param bundle parent bundle * @param bitstream_name bitstream name to set * @param format bitstream format * @param bytes bitstream data * @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 void setBitstreamFromBytes(Context context, Item item, Bundle bundle, String bitstream_name, BitstreamFormat format, byte[] bytes) throws SQLException, IOException, AuthorizeException { ByteArrayInputStream bais = new ByteArrayInputStream(bytes); Bitstream bs = bitstreamService.create(context, bundle, bais); bs.setName(context, bitstream_name); bs.setSource(context, CC_BS_SOURCE); bs.setFormat(context, format); // commit everything bitstreamService.update(context, bs); }
bitstreamService.update(c, bs);
bitstreamService.update(context, bs);
stores.get(assetstoreDestination).put(bitstream, inputStream); bitstream.setStoreNumber(assetstoreDestination); bitstreamService.update(context, bitstream);
lbs.setName(context, Constants.LICENSE_BITSTREAM_NAME); lbs.setSource(context, Constants.LICENSE_BITSTREAM_NAME); bitstreamService.update(context, lbs);
bundle.addBitstream(bitstream); bitstream.getBundles().add(bundle); bitstreamService.update(context, bitstream);
bitstreamService.update(context, bitstream); } catch (AuthorizeException e) { log.error(e);
b.setFormat(bf); bitstreamService.update(context, b);
manifestBitstream.setName(context, METSManifest.MANIFEST_FILE); manifestBitstream.setSource(context, METSManifest.MANIFEST_FILE); bitstreamService.update(context, manifestBitstream); "application/xml", fmtName + " package manifest"); manifestBitstream.setFormat(context, manifestFormat); bitstreamService.update(context, manifestBitstream);
bitstreamService.update(context, bitstream);
/** * @param context The relevant DSpace Context. * @param bitstream the bitstream to be cloned * @return id of the clone bitstream. * 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. */ @Override public Bitstream clone(Context context, Bitstream bitstream) throws SQLException, IOException, AuthorizeException { Bitstream clonedBitstream = bitstreamService.clone(context, bitstream); clonedBitstream.setStoreNumber(bitstream.getStoreNumber()); List<MetadataValue> metadataValues = bitstreamService .getMetadata(bitstream, Item.ANY, Item.ANY, Item.ANY, Item.ANY); for (MetadataValue metadataValue : metadataValues) { bitstreamService.addMetadata(context, clonedBitstream, metadataValue.getMetadataField(), metadataValue.getLanguage(), metadataValue.getValue(), metadataValue.getAuthority(), metadataValue.getConfidence()); } bitstreamService.update(context, clonedBitstream); return clonedBitstream; }
bitstreamService.update(c, bitstreamNew);
stream.setSequenceID(sequence); sequence++; bitstreamService.update(context, stream);
bs.setFormat(context, format); bs.setName(context, deposit.getFilename()); bitstreamService.update(context, bs);