Revision 46829
Added by Miriam Baglioni about 7 years ago
modules/dnet-efg/trunk/src/main/java/eu/dnetlib/efg/thumbnails/ThumbnailController.java | ||
---|---|---|
11 | 11 |
import org.springframework.beans.factory.annotation.Autowired; |
12 | 12 |
import org.springframework.stereotype.Controller; |
13 | 13 |
import org.springframework.ui.ModelMap; |
14 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
15 |
import org.springframework.web.bind.annotation.RequestParam; |
|
16 |
import org.springframework.web.bind.annotation.ResponseBody; |
|
14 |
import org.springframework.web.bind.annotation.*; |
|
17 | 15 |
|
18 | 16 |
import javax.servlet.ServletOutputStream; |
19 | 17 |
import javax.servlet.http.HttpServletResponse; |
... | ... | |
40 | 38 |
private Map<String, String> objectStoresThumbnail; |
41 | 39 |
|
42 | 40 |
|
43 |
@RequestMapping(value = "/ui/thumbnail/objectStoresThumbnail")
|
|
41 |
@RequestMapping(value = "/thumbnail/objectStoresThumbnail") |
|
44 | 42 |
@ResponseBody |
45 | 43 |
public Map<String, String> getObjectStoresThumbnail(ModelMap map) throws Exception { |
46 | 44 |
if (objectStoresThumbnail == null) { |
... | ... | |
50 | 48 |
} |
51 | 49 |
|
52 | 50 |
|
53 |
@RequestMapping(value = "/ui/thumbnail/getThumbnail")
|
|
54 |
public void getThumbnail(final HttpServletResponse response, @RequestParam(name = "metadataId") final String metadataId,
|
|
55 |
@RequestParam(name = "imageSize") final int imageSize, @RequestParam(name = "imageType") String type) throws Exception {
|
|
56 |
if (imageSize != 96 && imageSize != 250) throw new Exception("Image size not supported!");
|
|
51 |
@RequestMapping(value = "/thumbnail/getThumbnail/{type}/{size}/{metadataId}", method= RequestMethod.GET)
|
|
52 |
public void getThumbnail(final HttpServletResponse response, @PathVariable final String metadataId,
|
|
53 |
@PathVariable final int size, @PathVariable String type) throws Exception {
|
|
54 |
if (size != 96 && size != 250) throw new Exception("Image size not supported!");
|
|
57 | 55 |
InputStream inputStream = null; |
58 | 56 |
if(!type.equalsIgnoreCase("video") && !type.equalsIgnoreCase("image") && !type.equalsIgnoreCase("text")){ |
59 | 57 |
type = "video"; |
... | ... | |
63 | 61 |
} |
64 | 62 |
|
65 | 63 |
if (objectStoresThumbnail.size() == 0){ |
66 |
inputStream = getClass().getResourceAsStream(String.format("/eu/dnetlib/thumbnail/NF%s_%d.jpg", type.toLowerCase(), imageSize));
|
|
64 |
inputStream = getClass().getResourceAsStream(String.format("/eu/dnetlib/thumbnail/NF%s_%d.jpg", type.toLowerCase(), size));
|
|
67 | 65 |
}else{ |
68 |
final GridFSObjectStore objectStore = (GridFSObjectStore) objectstoreDao.getObjectStore(objectStoresThumbnail.get(String.format("thumb%d", imageSize == 250 ? 256 : imageSize)));
|
|
66 |
final GridFSObjectStore objectStore = (GridFSObjectStore) objectstoreDao.getObjectStore(objectStoresThumbnail.get(String.format("thumb%d", size == 250 ? 256 : size)));
|
|
69 | 67 |
|
70 | 68 |
final ObjectStoreFile objectStoreFile = objectStore.deliverObjectFromMetadataIdentifier(metadataId); |
71 | 69 |
|
72 | 70 |
if (objectStoreFile == null) { |
73 |
inputStream = getClass().getResourceAsStream(String.format("/eu/dnetlib/thumbnail/NF%s_%d.jpg", type.toLowerCase(), imageSize));
|
|
71 |
inputStream = getClass().getResourceAsStream(String.format("/eu/dnetlib/thumbnail/NF%s_%d.jpg", type.toLowerCase(), size));
|
|
74 | 72 |
} else { |
75 | 73 |
inputStream = objectStore.deliverStream(objectStoreFile.getObjectID()); |
76 | 74 |
} |
Also available in: Unified diff
change in the url to get the thumbnail