use of alfio.model.FileBlobMetadata in project alf.io by alfio-event.
the class FileController method showFile.
@RequestMapping(value = "/file/{digest}", method = RequestMethod.GET)
public void showFile(@PathVariable("digest") String digest, HttpServletRequest request, HttpServletResponse response) throws IOException {
Optional<FileBlobMetadata> res = manager.findMetadata(digest);
if (res.isPresent()) {
FileBlobMetadata metadata = res.get();
if (digest.equals(request.getHeader("If-None-Match"))) {
response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
} else {
response.setContentType(metadata.getContentType());
response.setContentLength(metadata.getContentSize());
response.setHeader("ETag", digest);
response.setHeader("Cache-Control", MAX_AGE_6_MONTH);
manager.outputFile(digest, response.getOutputStream());
}
} else {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
}
use of alfio.model.FileBlobMetadata in project alf.io by alfio-event.
the class TemplateProcessorTest method assertDimensionsUnder300x150.
private void assertDimensionsUnder300x150(Pair<String, String> p) {
Map<String, String> parameters = new HashMap<>();
parameters.put(FileBlobMetadata.ATTR_IMG_WIDTH, p.getLeft());
parameters.put(FileBlobMetadata.ATTR_IMG_HEIGHT, p.getRight());
FileBlobMetadata metadata = mock(FileBlobMetadata.class);
when(metadata.getAttributes()).thenReturn(parameters);
Event e = mock(Event.class);
when(e.getFileBlobIdIsPresent()).thenReturn(true);
FileUploadManager fileUploadManager = mock(FileUploadManager.class);
when(fileUploadManager.findMetadata(e.getFileBlobId())).thenReturn(Optional.of(metadata));
TemplateProcessor.extractImageModel(e, fileUploadManager).ifPresent(imageData -> {
assertTrue(imageData.getImageWidth() <= 300);
assertTrue(imageData.getImageHeight() <= 150);
});
}
use of alfio.model.FileBlobMetadata in project alf.io by alfio-event.
the class FileUploadManagerIntegrationTest method testInsert.
@Test
public void testInsert() {
UploadBase64FileModification toInsert = new UploadBase64FileModification();
toInsert.setFile(FILE);
toInsert.setName("myfile.txt");
toInsert.setType("text/plain");
String id = fileUploadManager.insertFile(toInsert);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
fileUploadManager.outputFile(id, baos);
Assert.assertArrayEquals(FILE, baos.toByteArray());
Optional<FileBlobMetadata> metadata = fileUploadManager.findMetadata(id);
Assert.assertTrue(metadata.isPresent());
Assert.assertEquals("myfile.txt", metadata.get().getName());
Assert.assertEquals("text/plain", metadata.get().getContentType());
}
use of alfio.model.FileBlobMetadata in project alf.io by alfio-event.
the class FileUploadManagerIntegrationTest method testInsertImage.
@Test
public void testInsertImage() {
UploadBase64FileModification toInsert = new UploadBase64FileModification();
toInsert.setFile(ONE_PIXEL_BLACK_GIF);
toInsert.setName("image.gif");
toInsert.setType("image/gif");
String id = fileUploadManager.insertFile(toInsert);
Optional<FileBlobMetadata> metadata = fileUploadManager.findMetadata(id);
Assert.assertTrue(metadata.isPresent());
Assert.assertEquals("1", metadata.get().getAttributes().get("width"));
Assert.assertEquals("1", metadata.get().getAttributes().get("height"));
}
Aggregations