Search in sources :

Example 1 with Logo

use of org.openforis.collect.model.Logo in project collect by openforis.

the class LogoController method downloadLogo.

@RequestMapping(value = "/downloadLogo.htm", method = RequestMethod.GET)
@ResponseBody
public void downloadLogo(HttpServletRequest request, HttpServletResponse response, @RequestParam String position) {
    LogoPosition p = LogoPosition.valueOf(position.toUpperCase());
    Logo logo = logoManager.loadLogo(p);
    if (logo != null) {
        byte[] data = logo.getImage();
        ByteArrayInputStream is = new ByteArrayInputStream(data);
        try {
            String contentType = logo.getContentType();
            if (contentType == null) {
                contentType = "image/jpg";
            }
            // TODO get extension from db
            String extension = "jpg";
            Controllers.writeFileToResponse(response, is, "logo." + extension, contentType, data.length);
        } catch (IOException e) {
            log.error("Error writing logo in position: " + position, e);
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) LogoPosition(org.openforis.collect.model.LogoPosition) IOException(java.io.IOException) Logo(org.openforis.collect.model.Logo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with Logo

use of org.openforis.collect.model.Logo in project collect by openforis.

the class LogoDaoIntegrationTest method testCRUD.

@Test
public void testCRUD() throws Exception {
    // SAVE NEW
    Logo logo = createTestLogo(TEST_LOGO_ID, LogoPosition.TOP_RIGHT, "test_logo.jpg");
    byte[] savedData = logo.getImage();
    logoDao.insert(logo);
    // RELOAD
    Logo reloadedLogo = logoDao.loadById(TEST_LOGO_ID);
    assertNotNull(reloadedLogo);
    byte[] reloadedData = reloadedLogo.getImage();
    assertTrue(Arrays.equals(savedData, reloadedData));
}
Also used : Logo(org.openforis.collect.model.Logo) CollectTest(org.openforis.collect.CollectTest) Test(org.junit.Test)

Example 3 with Logo

use of org.openforis.collect.model.Logo in project collect by openforis.

the class LogoDaoIntegrationTest method createTestLogo.

private Logo createTestLogo(int id, LogoPosition p, String fileName) throws IOException {
    URL imageUrl = ClassLoader.getSystemResource(fileName);
    InputStream is = imageUrl.openStream();
    byte[] data = IOUtils.toByteArray(is);
    Logo logo = new Logo(id, p, data, null);
    return logo;
}
Also used : InputStream(java.io.InputStream) URL(java.net.URL) Logo(org.openforis.collect.model.Logo)

Example 4 with Logo

use of org.openforis.collect.model.Logo in project collect by openforis.

the class LogoController method uploadLogo.

@RequestMapping(value = "/uploadLogo.htm", method = RequestMethod.POST)
@ResponseBody
public String uploadLogo(UploadItem uploadItem, BindingResult result, @RequestParam String position) throws IOException, SurveyImportException, IdmlParseException {
    CommonsMultipartFile fileData = uploadItem.getFileData();
    InputStream is = fileData.getInputStream();
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    IOUtils.copy(is, output);
    byte[] byteArray = output.toByteArray();
    String contentType = fileData.getContentType();
    LogoPosition p = LogoPosition.valueOf(position.toUpperCase());
    Logo logo = new Logo(p, byteArray, contentType);
    logoManager.save(logo);
    return "ok";
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) LogoPosition(org.openforis.collect.model.LogoPosition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CommonsMultipartFile(org.springframework.web.multipart.commons.CommonsMultipartFile) Logo(org.openforis.collect.model.Logo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

Logo (org.openforis.collect.model.Logo)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 LogoPosition (org.openforis.collect.model.LogoPosition)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 URL (java.net.URL)1 Test (org.junit.Test)1 CollectTest (org.openforis.collect.CollectTest)1 CommonsMultipartFile (org.springframework.web.multipart.commons.CommonsMultipartFile)1