mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-11 20:13:17 +00:00
DS-4391 Get modified date from the right store
This also tightens up the contract and improves javadocs a bit, so callers know what to expect.
This commit is contained in:
@@ -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<Bitstream> imp
|
||||
return bitstreamDAO.getNotReferencedBitstreams(context);
|
||||
}
|
||||
|
||||
public Long getLastModified(Bitstream bitstream) {
|
||||
@Nullable
|
||||
@Override
|
||||
public Long getLastModified(Bitstream bitstream) throws IOException {
|
||||
return bitstreamStorageService.getLastModified(bitstream);
|
||||
}
|
||||
}
|
||||
|
@@ -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<Bitstream>, DSpace
|
||||
|
||||
List<Bitstream> 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;
|
||||
}
|
||||
|
@@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -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;
|
||||
|
||||
}
|
||||
|
@@ -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) {
|
||||
|
Reference in New Issue
Block a user