User user = getUser(request);
Authorizations authorizations = getAuthorizations(request, user);
String graphVertexId = UrlUtils.urlDecode(getAttributeString(request, "graphVertexId"));
Vertex artifactVertex = graph.getVertex(graphVertexId, authorizations);
if (artifactVertex == null) {
respondWithNotFound(response);
return;
}
String widthStr = getOptionalParameter(request, "width");
int[] boundaryDims = new int[]{200, 200};
if (widthStr != null) {
boundaryDims[0] = boundaryDims[1] = Integer.parseInt(widthStr);
}
byte[] thumbnailData;
io.lumify.core.model.artifactThumbnails.ArtifactThumbnail thumbnail =
artifactThumbnailRepository.getThumbnail(artifactVertex.getId(), "raw", boundaryDims[0], boundaryDims[1], user);
if (thumbnail != null) {
String format = thumbnail.getFormat();
response.setContentType("image/" + format);
response.addHeader("Content-Disposition", "inline; filename=thumbnail" + boundaryDims[0] + "." + format);
setMaxAge(response, EXPIRES_1_HOUR);
thumbnailData = thumbnail.getThumbnailData();
if (thumbnailData != null) {
LOGGER.debug("Cache hit for: %s (raw) %d x %d", artifactVertex.getId(), boundaryDims[0], boundaryDims[1]);
ServletOutputStream out = response.getOutputStream();
out.write(thumbnailData);
out.close();
return;
}
}
LOGGER.info("Cache miss for: %s (raw) %d x %d", artifactVertex.getId(), boundaryDims[0], boundaryDims[1]);
StreamingPropertyValue rawPropertyValue = LumifyProperties.RAW.getPropertyValue(artifactVertex);
if (rawPropertyValue == null) {
respondWithNotFound(response);
return;
}