mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-12 12:33:18 +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.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
@@ -462,7 +464,9 @@ public class BitstreamServiceImpl extends DSpaceObjectServiceImpl<Bitstream> imp
|
|||||||
return bitstreamDAO.getNotReferencedBitstreams(context);
|
return bitstreamDAO.getNotReferencedBitstreams(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getLastModified(Bitstream bitstream) {
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public Long getLastModified(Bitstream bitstream) throws IOException {
|
||||||
return bitstreamStorageService.getLastModified(bitstream);
|
return bitstreamStorageService.getLastModified(bitstream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -14,6 +14,8 @@ import java.util.Iterator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
import org.dspace.content.Bitstream;
|
import org.dspace.content.Bitstream;
|
||||||
import org.dspace.content.BitstreamFormat;
|
import org.dspace.content.BitstreamFormat;
|
||||||
@@ -222,5 +224,13 @@ public interface BitstreamService extends DSpaceObjectService<Bitstream>, DSpace
|
|||||||
|
|
||||||
List<Bitstream> getNotReferencedBitstreams(Context context) throws SQLException;
|
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.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import org.apache.commons.collections4.MapUtils;
|
import org.apache.commons.collections4.MapUtils;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
@@ -326,15 +328,16 @@ public class BitstreamStorageServiceImpl implements BitstreamStorageService, Ini
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getLastModified(Bitstream bitstream) {
|
@Nullable
|
||||||
Map wantedMetadata = new HashMap();
|
@Override
|
||||||
wantedMetadata.put("modified", null);
|
public Long getLastModified(Bitstream bitstream) throws IOException {
|
||||||
try {
|
Map attrs = new HashMap();
|
||||||
wantedMetadata = stores.get(incoming).about(bitstream, wantedMetadata);
|
attrs.put("modified", null);
|
||||||
} catch (IOException e) {
|
attrs = stores.get(bitstream.getStoreNumber()).about(bitstream, attrs);
|
||||||
log.error(e);
|
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.sql.SQLException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
import org.dspace.content.Bitstream;
|
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
|
* @param bitstream the bitstream.
|
||||||
* @return The last modified timestamp in milliseconds
|
* @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())
|
.withLength(bitstreamTuple.getRight())
|
||||||
.withChecksum(bit.getChecksum())
|
.withChecksum(bit.getChecksum())
|
||||||
.withMimetype(mimetype)
|
.withMimetype(mimetype)
|
||||||
.withLastModified(lastModified)
|
|
||||||
.with(request)
|
.with(request)
|
||||||
.with(response);
|
.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
|
//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");
|
long dispositionThreshold = configurationService.getLongProperty("webui.content_disposition_threshold");
|
||||||
if (dispositionThreshold >= 0 && bitstreamTuple.getRight() > dispositionThreshold) {
|
if (dispositionThreshold >= 0 && bitstreamTuple.getRight() > dispositionThreshold) {
|
||||||
|
Reference in New Issue
Block a user