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:
Chris Wilper
2019-11-23 07:18:17 -05:00
parent 3b578c6766
commit ccf047cd63
5 changed files with 38 additions and 15 deletions

View File

@@ -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);
} }
} }

View File

@@ -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;
} }

View File

@@ -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());
} }
/** /**

View File

@@ -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;
} }

View File

@@ -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) {