NIHVIVO-1277 When referencing a file, assume that the FileByteStream resource contains the alias URL.

This commit is contained in:
jeb228 2010-10-29 20:28:08 +00:00
parent a79b203a15
commit cb7fdf17ca

View file

@ -103,21 +103,15 @@ public class FileInfo {
log.debug("mimeType for '" + uri + "' was '" + mimeType + "'");
}
String bytestreamUri;
Individual byteStream = surrogate
.getRelatedIndividual(VitroVocabulary.FS_DOWNLOAD_LOCATION);
if (byteStream == null) {
bytestreamUri = null;
log.error("File surrogate '" + uri
+ "' had no associated bytestream.");
} else {
bytestreamUri = byteStream.getURI();
log.debug("File surroage'" + uri + "' had associated bytestream: '"
+ byteStream.getURI() + "'");
}
String bytestreamAliasUrl = FileServingHelper.getBytestreamAliasUrl(
bytestreamUri, filename);
String bytestreamUri = findBytestreamUri(byteStream, uri);
String bytestreamAliasUrl = findBytestreamAliasUrl(byteStream, uri);
return new FileInfo.Builder().setUri(uri).setFilename(filename)
.setMimeType(mimeType).setBytestreamUri(bytestreamUri)
@ -154,6 +148,40 @@ public class FileInfo {
return false;
}
/**
* Get the URI of the bytestream, or null if there is none.
*/
private static String findBytestreamUri(Individual byteStream,
String surrogateUri) {
if (byteStream == null) {
return null;
}
String bytestreamUri = byteStream.getURI();
log.debug("File surrogate'" + surrogateUri
+ "' had associated bytestream: '" + byteStream.getURI() + "'");
return bytestreamUri;
}
/**
* Get the alias URL from the bytestream, or null if there is none.
*/
private static String findBytestreamAliasUrl(Individual byteStream,
String surrogateUri) {
if (byteStream == null) {
return null;
}
String aliasUrl = byteStream.getDataValue(VitroVocabulary.FS_ALIAS_URL);
if (aliasUrl == null) {
log.error("File had no aliasUrl: '" + surrogateUri + "'");
} else {
log.debug("aliasUrl for '" + surrogateUri + "' was '" + aliasUrl
+ "'");
}
return aliasUrl;
}
// ----------------------------------------------------------------------
// The instance variables and methods.
// ----------------------------------------------------------------------