Revision 46819
Added by Miriam Baglioni almost 7 years ago
ThumbnailController.java | ||
---|---|---|
54 | 54 |
public void getThumbnail(final HttpServletResponse response, @RequestParam(name = "metadataId") final String metadataId, |
55 | 55 |
@RequestParam(name = "imageSize") final int imageSize, @RequestParam(name = "imageType") String type) throws Exception { |
56 | 56 |
if (imageSize != 96 && imageSize != 250) throw new Exception("Image size not supported!"); |
57 |
|
|
57 |
InputStream inputStream = null; |
|
58 | 58 |
if(!type.equalsIgnoreCase("video") && !type.equalsIgnoreCase("image") && !type.equalsIgnoreCase("text")){ |
59 | 59 |
type = "video"; |
60 | 60 |
} |
61 | 61 |
if (objectStoresThumbnail == null) { |
62 | 62 |
createObjectStoreThumbnail(); |
63 | 63 |
} |
64 |
final GridFSObjectStore objectStore = (GridFSObjectStore) objectstoreDao.getObjectStore(objectStoresThumbnail.get(String.format("thumb%d", imageSize == 250 ? 256 : imageSize))); |
|
65 | 64 |
|
66 |
final ObjectStoreFile objectStoreFile = objectStore.deliverObjectFromMetadataIdentifier(metadataId); |
|
67 |
InputStream inputStream = null; |
|
68 |
if (objectStoreFile == null) { |
|
65 |
if (objectStoresThumbnail.size() == 0){ |
|
69 | 66 |
inputStream = getClass().getResourceAsStream(String.format("/eu/dnetlib/thumbnail/NF%s_%d.jpg", type.toLowerCase(), imageSize)); |
70 |
} else { |
|
71 |
inputStream = objectStore.deliverStream(objectStoreFile.getObjectID()); |
|
67 |
}else{ |
|
68 |
final GridFSObjectStore objectStore = (GridFSObjectStore) objectstoreDao.getObjectStore(objectStoresThumbnail.get(String.format("thumb%d", imageSize == 250 ? 256 : imageSize))); |
|
69 |
|
|
70 |
final ObjectStoreFile objectStoreFile = objectStore.deliverObjectFromMetadataIdentifier(metadataId); |
|
71 |
|
|
72 |
if (objectStoreFile == null) { |
|
73 |
inputStream = getClass().getResourceAsStream(String.format("/eu/dnetlib/thumbnail/NF%s_%d.jpg", type.toLowerCase(), imageSize)); |
|
74 |
} else { |
|
75 |
inputStream = objectStore.deliverStream(objectStoreFile.getObjectID()); |
|
76 |
} |
|
72 | 77 |
} |
78 |
|
|
73 | 79 |
if (inputStream != null) { |
74 | 80 |
try { |
75 | 81 |
final ServletOutputStream outputStream = response.getOutputStream(); |
... | ... | |
100 | 106 |
}); |
101 | 107 |
|
102 | 108 |
|
109 |
|
|
103 | 110 |
} |
104 | 111 |
|
105 | 112 |
} |
Also available in: Unified diff
check for empty thumbnail object store