port pr1883

This commit is contained in:
Terry Brady
2018-08-03 23:12:38 -07:00
parent 3eb16056c6
commit 7af1958d7e
5 changed files with 66 additions and 18 deletions

View File

@@ -92,6 +92,31 @@ public class BitstreamServiceImpl extends DSpaceObjectServiceImpl<Bitstream> imp
return bitstreamDAO.findAll(context, Bitstream.class); return bitstreamDAO.findAll(context, Bitstream.class);
} }
@Override
public Bitstream clone(Context context, Bitstream bitstream)
throws SQLException {
// Create a new bitstream with a new ID.
Bitstream clonedBitstream = bitstreamDAO.create(context, new Bitstream());
// Set the internal identifier, file size, checksum, and
// checksum algorithm as same as the given bitstream.
clonedBitstream.setInternalId(bitstream.getInternalId());
clonedBitstream.setSizeBytes(bitstream.getSize());
clonedBitstream.setChecksum(bitstream.getChecksum());
clonedBitstream.setChecksumAlgorithm(bitstream.getChecksumAlgorithm());
try {
//Update our bitstream but turn off the authorization system since permissions
//haven't been set at this point in time.
context.turnOffAuthorisationSystem();
update(context, clonedBitstream);
} catch (AuthorizeException e) {
log.error(e);
//Can never happen since we turn off authorization before we update
} finally {
context.restoreAuthSystemState();
}
return clonedBitstream;
}
@Override @Override
public Iterator<Bitstream> findAll(Context context, int limit, int offset) throws SQLException { public Iterator<Bitstream> findAll(Context context, int limit, int offset) throws SQLException {
return bitstreamDAO.findAll(context, limit, offset); return bitstreamDAO.findAll(context, limit, offset);

View File

@@ -35,6 +35,22 @@ public interface BitstreamService extends DSpaceObjectService<Bitstream>, DSpace
public Iterator<Bitstream> findAll(Context context, int limit, int offset) throws SQLException; public Iterator<Bitstream> findAll(Context context, int limit, int offset) throws SQLException;
/**
* Clone the given bitstream by firstly creating a new bitstream, with a new ID.
* Then set the internal identifier, file size, checksum, and
* checksum algorithm as same as the given bitstream.
* This allows multiple bitstreams to share the same internal identifier of assets .
* An example of such a use case scenario is versioning.
*
* @param context
* DSpace context object
* @param bitstream
* Bitstream to be cloned
* @return the clone
* @throws SQLException if database error
*/
public Bitstream clone(Context context, Bitstream bitstream) throws SQLException;
/** /**
* Create a new bitstream, with a new ID. The checksum and file size are * Create a new bitstream, with a new ID. The checksum and file size are
* calculated. No authorization checks are made in this method. * calculated. No authorization checks are made in this method.

View File

@@ -348,14 +348,18 @@ public class BitstreamStorageServiceImpl implements BitstreamStorageService, Ini
*/ */
@Override @Override
public Bitstream clone(Context context, Bitstream bitstream) throws SQLException, IOException, AuthorizeException { public Bitstream clone(Context context, Bitstream bitstream) throws SQLException, IOException, AuthorizeException {
Bitstream clonedBitstream = bitstreamService.create(context, bitstreamService.retrieve(context, bitstream)); Bitstream clonedBitstream = bitstreamService.clone(context, bitstream);
clonedBitstream.setStoreNumber(bitstream.getStoreNumber());
List<MetadataValue> metadataValues = bitstreamService List<MetadataValue> metadataValues = bitstreamService
.getMetadata(bitstream, Item.ANY, Item.ANY, Item.ANY, Item.ANY); .getMetadata(bitstream, Item.ANY, Item.ANY, Item.ANY, Item.ANY);
for (MetadataValue metadataValue : metadataValues) { for (MetadataValue metadataValue : metadataValues) {
bitstreamService bitstreamService.addMetadata(context, clonedBitstream, metadataValue.getMetadataField(),
.addMetadata(context, clonedBitstream, metadataValue.getMetadataField(), metadataValue.getLanguage(), metadataValue.getLanguage(), metadataValue.getValue(), metadataValue.getAuthority(),
metadataValue.getValue(), metadataValue.getAuthority(), metadataValue.getConfidence()); metadataValue.getConfidence());
} }
bitstreamService.update(context, clonedBitstream);
return clonedBitstream; return clonedBitstream;
} }

View File

@@ -140,6 +140,19 @@ public interface BitstreamStorageService {
*/ */
public void cleanup(boolean deleteDbRecords, boolean verbose) throws SQLException, IOException, AuthorizeException; public void cleanup(boolean deleteDbRecords, boolean verbose) throws SQLException, IOException, AuthorizeException;
/**
* Clone the given bitstream to a new bitstream with a new ID.
* Metadata of the given bitstream are also copied to the new bitstream.
*
* @param context
* DSpace context object
* @param bitstream
* the bitstream to be cloned
* @return id of the clone bitstream.
* @throws SQLException if database error
* @throws IOException if IO error
* @throws AuthorizeException if authorization error
*/
public Bitstream clone(Context context, Bitstream bitstream) throws SQLException, IOException, AuthorizeException; public Bitstream clone(Context context, Bitstream bitstream) throws SQLException, IOException, AuthorizeException;
/** /**

View File

@@ -81,7 +81,10 @@ public abstract class AbstractVersionProvider {
authorizeService.addPolicies(c, bundlePolicies, bundleNew); authorizeService.addPolicies(c, bundlePolicies, bundleNew);
for (Bitstream nativeBitstream : nativeBundle.getBitstreams()) { for (Bitstream nativeBitstream : nativeBundle.getBitstreams()) {
Bitstream bitstreamNew = createBitstream(c, nativeBitstream); // Metadata and additional information like internal identifier,
// file size, checksum, and checksum algorithm are set by the bitstreamStorageService.clone(...)
// and respectively bitstreamService.clone(...) method.
Bitstream bitstreamNew = bitstreamStorageService.clone(c, nativeBitstream);
bundleService.addBitstream(c, bundleNew, bitstreamNew); bundleService.addBitstream(c, bundleNew, bitstreamNew);
@@ -106,19 +109,6 @@ public abstract class AbstractVersionProvider {
} }
protected Bitstream createBitstream(Context context, Bitstream nativeBitstream)
throws AuthorizeException, SQLException, IOException {
Bitstream newBitstream = bitstreamStorageService.clone(context, nativeBitstream);
List<MetadataValue> bitstreamMeta = bitstreamService
.getMetadata(nativeBitstream, Item.ANY, Item.ANY, Item.ANY, Item.ANY);
for (MetadataValue value : bitstreamMeta) {
bitstreamService
.addMetadata(context, newBitstream, value.getMetadataField(), value.getLanguage(), value.getValue(),
value.getAuthority(), value.getConfidence());
}
return newBitstream;
}
public void setIgnoredMetadataFields(Set<String> ignoredMetadataFields) { public void setIgnoredMetadataFields(Set<String> ignoredMetadataFields) {
this.ignoredMetadataFields = ignoredMetadataFields; this.ignoredMetadataFields = ignoredMetadataFields;
} }