diff --git a/dspace-api/src/main/java/org/dspace/content/BitstreamServiceImpl.java b/dspace-api/src/main/java/org/dspace/content/BitstreamServiceImpl.java index 78d65800b1..83e91a2d7b 100644 --- a/dspace-api/src/main/java/org/dspace/content/BitstreamServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/content/BitstreamServiceImpl.java @@ -14,6 +14,8 @@ import java.util.Iterator; import java.util.List; import java.util.UUID; +import javax.annotation.Nullable; + import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.Logger; @@ -462,7 +464,9 @@ public class BitstreamServiceImpl extends DSpaceObjectServiceImpl imp return bitstreamDAO.getNotReferencedBitstreams(context); } - public Long getLastModified(Bitstream bitstream) { + @Nullable + @Override + public Long getLastModified(Bitstream bitstream) throws IOException { return bitstreamStorageService.getLastModified(bitstream); } } diff --git a/dspace-api/src/main/java/org/dspace/content/service/BitstreamService.java b/dspace-api/src/main/java/org/dspace/content/service/BitstreamService.java index 87f380cbca..4250041b5d 100644 --- a/dspace-api/src/main/java/org/dspace/content/service/BitstreamService.java +++ b/dspace-api/src/main/java/org/dspace/content/service/BitstreamService.java @@ -14,6 +14,8 @@ import java.util.Iterator; import java.util.List; import java.util.UUID; +import javax.annotation.Nullable; + import org.dspace.authorize.AuthorizeException; import org.dspace.content.Bitstream; import org.dspace.content.BitstreamFormat; @@ -222,5 +224,13 @@ public interface BitstreamService extends DSpaceObjectService, DSpace List getNotReferencedBitstreams(Context context) throws SQLException; - public Long getLastModified(Bitstream bitstream); + /** + * Gets the last modified timestamp of the the given bitstream's content, if known. + * + * @param bitstream the bitstream. + * @return the timestamp in milliseconds, or {@code null} if unknown. + * @throws IOException if an unexpected io error occurs. + */ + @Nullable + Long getLastModified(Bitstream bitstream) throws IOException; } diff --git a/dspace-api/src/main/java/org/dspace/storage/bitstore/BitstreamStorageServiceImpl.java b/dspace-api/src/main/java/org/dspace/storage/bitstore/BitstreamStorageServiceImpl.java index c63b4ebe7e..a0d9101fb8 100644 --- a/dspace-api/src/main/java/org/dspace/storage/bitstore/BitstreamStorageServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/storage/bitstore/BitstreamStorageServiceImpl.java @@ -16,6 +16,8 @@ import java.util.List; import java.util.Map; import java.util.UUID; +import javax.annotation.Nullable; + import org.apache.commons.collections4.MapUtils; import org.apache.logging.log4j.Logger; import org.dspace.authorize.AuthorizeException; @@ -326,15 +328,16 @@ public class BitstreamStorageServiceImpl implements BitstreamStorageService, Ini } } - public Long getLastModified(Bitstream bitstream) { - Map wantedMetadata = new HashMap(); - wantedMetadata.put("modified", null); - try { - wantedMetadata = stores.get(incoming).about(bitstream, wantedMetadata); - } catch (IOException e) { - log.error(e); + @Nullable + @Override + public Long getLastModified(Bitstream bitstream) throws IOException { + Map attrs = new HashMap(); + attrs.put("modified", null); + attrs = stores.get(bitstream.getStoreNumber()).about(bitstream, attrs); + if (attrs == null || !attrs.containsKey("modified")) { + return null; } - return Long.valueOf(wantedMetadata.get("modified").toString()); + return Long.valueOf(attrs.get("modified").toString()); } /** diff --git a/dspace-api/src/main/java/org/dspace/storage/bitstore/service/BitstreamStorageService.java b/dspace-api/src/main/java/org/dspace/storage/bitstore/service/BitstreamStorageService.java index 95963b14ca..209ef5d16b 100644 --- a/dspace-api/src/main/java/org/dspace/storage/bitstore/service/BitstreamStorageService.java +++ b/dspace-api/src/main/java/org/dspace/storage/bitstore/service/BitstreamStorageService.java @@ -12,6 +12,7 @@ import java.io.InputStream; import java.sql.SQLException; import java.util.Map; import java.util.UUID; +import javax.annotation.Nullable; import org.dspace.authorize.AuthorizeException; import org.dspace.content.Bitstream; @@ -181,11 +182,13 @@ public interface BitstreamStorageService { /** - * Get the last modified timestamp of the file linked to the given bitstream + * Gets the last modified timestamp of the the given bitstream's content, if known. * - * @param bitstream The bitstream for which to get the last modified timestamp - * @return The last modified timestamp in milliseconds + * @param bitstream the bitstream. + * @return the timestamp in milliseconds, or {@code null} if unknown. + * @throws IOException if an unexpected io error occurs. */ - public Long getLastModified(Bitstream bitstream); + @Nullable + Long getLastModified(Bitstream bitstream) throws IOException; } diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/BitstreamRestController.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/BitstreamRestController.java index 773c33d8a6..dbfa707476 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/BitstreamRestController.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/BitstreamRestController.java @@ -140,10 +140,13 @@ public class BitstreamRestController { .withLength(bitstreamTuple.getRight()) .withChecksum(bit.getChecksum()) .withMimetype(mimetype) - .withLastModified(lastModified) .with(request) .with(response); + if (lastModified != null) { + sender.withLastModified(lastModified); + } + //Determine if we need to send the file as a download or if the browser can open it inline long dispositionThreshold = configurationService.getLongProperty("webui.content_disposition_threshold"); if (dispositionThreshold >= 0 && bitstreamTuple.getRight() > dispositionThreshold) {