Search in sources :

Example 1 with FileBlobMetadata

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);
    }
}
Also used : FileBlobMetadata(alfio.model.FileBlobMetadata) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with FileBlobMetadata

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);
    });
}
Also used : HashMap(java.util.HashMap) FileBlobMetadata(alfio.model.FileBlobMetadata) Event(alfio.model.Event) FileUploadManager(alfio.manager.FileUploadManager)

Example 3 with FileBlobMetadata

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());
}
Also used : UploadBase64FileModification(alfio.model.modification.UploadBase64FileModification) FileBlobMetadata(alfio.model.FileBlobMetadata) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 4 with FileBlobMetadata

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"));
}
Also used : UploadBase64FileModification(alfio.model.modification.UploadBase64FileModification) FileBlobMetadata(alfio.model.FileBlobMetadata) Test(org.junit.Test)

Aggregations

FileBlobMetadata (alfio.model.FileBlobMetadata)4 UploadBase64FileModification (alfio.model.modification.UploadBase64FileModification)2 Test (org.junit.Test)2 FileUploadManager (alfio.manager.FileUploadManager)1 Event (alfio.model.Event)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 HashMap (java.util.HashMap)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1