Changeset 4217 for DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/CachedRepresentationResource.java
- Timestamp:
- 01/06/14 17:20:05 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/CachedRepresentationResource.java
r4207 r4217 29 29 import javax.imageio.ImageIO; 30 30 import javax.servlet.http.HttpServletRequest; 31 import javax.servlet.http.HttpServletResponse; 31 32 import javax.ws.rs.GET; 32 33 import javax.ws.rs.Path; … … 49 50 @Component 50 51 @Path("/cached") 51 @Transactional(rollbackFor ={Exception.class, SQLException.class, IOException.class, ParserConfigurationException.class})52 @Transactional(rollbackFor = {Exception.class, SQLException.class, IOException.class, ParserConfigurationException.class}) 52 53 public class CachedRepresentationResource { 53 54 … … 56 57 @Context 57 58 private HttpServletRequest httpServletRequest; 59 @Context 60 private HttpServletResponse httpServletResponse; 58 61 @Context 59 62 private UriInfo uriInfo; … … 68 71 @Produces(MediaType.TEXT_XML) 69 72 @Path("{cachedid: " + BackendConstants.regExpIdentifier + "}/metadata") 70 @Secured("ROLE_USER") 71 @Transactional(readOnly =true)72 public JAXBElement<CachedRepresentationInfo> getCachedRepresentationInfo(@PathParam("cachedid") String externalId) throws SQLException {73 @Secured("ROLE_USER") 74 @Transactional(readOnly = true) 75 public JAXBElement<CachedRepresentationInfo> getCachedRepresentationInfo(@PathParam("cachedid") String externalId) throws SQLException, IOException { 73 76 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 74 77 final Number cachedID = dbIntegrityService.getCachedRepresentationInternalIdentifier(UUID.fromString(externalId)); 75 final CachedRepresentationInfo cachedInfo = dbIntegrityService.getCachedRepresentationInfo(cachedID); 76 return new ObjectFactory().createCashedRepresentationInfo(cachedInfo); 78 if (cachedID != null) { 79 final CachedRepresentationInfo cachedInfo = dbIntegrityService.getCachedRepresentationInfo(cachedID); 80 return new ObjectFactory().createCashedRepresentationInfo(cachedInfo); 81 } else { 82 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The cached representation with the given id is not found in the database"); 83 return null; 84 } 77 85 } 78 86 … … 80 88 @Produces({"image/jpeg", "image/png"}) 81 89 @Path("{cachedid: " + BackendConstants.regExpIdentifier + "}/content") 82 @Secured("ROLE_USER") 83 @Transactional(readOnly =true)90 @Secured("ROLE_USER") 91 @Transactional(readOnly = true) 84 92 public BufferedImage getCachedRepresentationContent(@PathParam("cachedid") String externalId) throws SQLException, IOException { 85 93 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 86 94 final Number cachedID = dbIntegrityService.getCachedRepresentationInternalIdentifier(UUID.fromString(externalId)); 87 InputStream dbRespond = dbIntegrityService.getCachedRepresentationBlob(cachedID); 88 ImageIO.setUseCache(false); 89 BufferedImage result = ImageIO.read(dbRespond); 90 return result; 95 if (cachedID != null) { 96 InputStream dbRespond = dbIntegrityService.getCachedRepresentationBlob(cachedID); 97 ImageIO.setUseCache(false); 98 BufferedImage result = ImageIO.read(dbRespond); 99 return result; 100 } else { 101 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The cached representation with the given id is not found in the database"); 102 return null; 103 } 91 104 } 92 93 94 105 }
Note: See TracChangeset
for help on using the changeset viewer.