branch develop updated (84c3b973 -> 650ba35e)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository pollen. See https://gitlab.nuiton.org/chorem/pollen.git from 84c3b973 suppression de code mort new 650ba35e dimension de la prévisualisation d'une image (ref #48) The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 650ba35ef9f9e3be581049748adaa466a3134caa Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Thu Jul 27 16:57:09 2017 +0200 dimension de la prévisualisation d'une image (ref #48) Summary of changes: .../pollen/rest/api/v1/PollenResourceApi.java | 43 +--------------- pollen-services/src/main/config/PollenServices.ini | 6 +++ .../services/service/PollenResourceService.java | 54 +++++++++++++++++++++ .../src/main/resources/default.jpg | Bin .../i18n/pollen-services_en_GB.properties | 1 + .../i18n/pollen-services_fr_FR.properties | 1 + 6 files changed, 64 insertions(+), 41 deletions(-) rename {pollen-rest-api => pollen-services}/src/main/resources/default.jpg (100%) -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository pollen. See https://gitlab.nuiton.org/chorem/pollen.git commit 650ba35ef9f9e3be581049748adaa466a3134caa Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Thu Jul 27 16:57:09 2017 +0200 dimension de la prévisualisation d'une image (ref #48) --- .../pollen/rest/api/v1/PollenResourceApi.java | 43 +--------------- pollen-services/src/main/config/PollenServices.ini | 6 +++ .../services/service/PollenResourceService.java | 54 +++++++++++++++++++++ .../src/main/resources/default.jpg | Bin .../i18n/pollen-services_en_GB.properties | 1 + .../i18n/pollen-services_fr_FR.properties | 1 + 6 files changed, 64 insertions(+), 41 deletions(-) diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenResourceApi.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenResourceApi.java index 4b3dee65..fd44cb39 100644 --- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenResourceApi.java +++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenResourceApi.java @@ -32,7 +32,6 @@ import org.chorem.pollen.services.service.InvalidFormException; import org.chorem.pollen.services.service.PollenResourceService; import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; -import javax.imageio.ImageIO; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; @@ -43,10 +42,6 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import java.awt.Graphics2D; -import java.awt.image.BufferedImage; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.IOException; /** @@ -86,42 +81,8 @@ public class PollenResourceApi { public Response getPreviewResource(@Context PollenResourceService pollenResourceService, @PathParam("resourceId") PollenEntityId<PollenResource> resourceId) throws IOException { - ResourceStreamBean resource = pollenResourceService.getResource(resourceId.getEntityId()); - String contentType; - BufferedImage source; - - switch (resource.getContentType()) { - case "image/jpeg": - case "image/png": - case "image/gif": - source = ImageIO.read(resource.getResourceContent()); - contentType = resource.getContentType(); - - break; - - default: - source = ImageIO.read(PollenResourceApi.class.getResourceAsStream("/default.jpg")); - contentType = "image/jpeg"; - } - - int width, height; - if (source.getWidth() > source.getHeight()) { - width = 200; - height = width * source.getHeight() / source.getWidth(); - } else { - height = 200; - width = height * source.getWidth() / source.getHeight(); - } - - BufferedImage destination = new BufferedImage(width, height, source.getType()); - Graphics2D g = destination.createGraphics(); - g.drawImage(source, 0, 0, width, height, null); - g.dispose(); - - ByteArrayOutputStream output = new ByteArrayOutputStream(); - ImageIO.write(destination, contentType.split("/")[1], output); - - return Response.ok(new ByteArrayInputStream(output.toByteArray()), contentType).build(); + ResourceStreamBean resource = pollenResourceService.getResourcePreview(resourceId.getEntityId()); + return Response.ok(resource.getResourceContent(), resource.getContentType()).build(); } @Path("/resources/{resourceId}/meta") diff --git a/pollen-services/src/main/config/PollenServices.ini b/pollen-services/src/main/config/PollenServices.ini index 93c92d2c..3e0eeb89 100644 --- a/pollen-services/src/main/config/PollenServices.ini +++ b/pollen-services/src/main/config/PollenServices.ini @@ -155,6 +155,12 @@ key = pollen.resource.maxSize type = long defaultValue = 10000000 +[option resourcePreviewMax] +description = pollen.configuration.resource.preview.max +key = pollen.resource.preview.max +type = int +defaultValue = 200 + [option emailAddressPatternForRegistration] description = pollen.configuration.registration.emailAddressPattern key = pollen.registration.emailAddressPattern diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenResourceService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenResourceService.java index ac248f28..b3098624 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenResourceService.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenResourceService.java @@ -23,6 +23,7 @@ package org.chorem.pollen.services.service; import org.chorem.pollen.persistence.entity.PollenResource; import org.chorem.pollen.services.PollenService; +import org.chorem.pollen.services.PollenTechnicalException; import org.chorem.pollen.services.UnitHuman; import org.chorem.pollen.services.bean.PollenEntityId; import org.chorem.pollen.services.bean.PollenEntityRef; @@ -31,6 +32,11 @@ import org.chorem.pollen.services.bean.ResourceMetaBean; import org.chorem.pollen.services.bean.ResourceStreamBean; import org.nuiton.topia.persistence.TopiaIdFactory; +import javax.imageio.ImageIO; +import java.awt.Graphics2D; +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.sql.SQLException; @@ -59,6 +65,54 @@ public class PollenResourceService extends PollenServiceSupport implements Polle return toBean(ResourceMetaBean.class, resource); } + public ResourceStreamBean getResourcePreview(String resourceId) { + + checkNotNull(resourceId); + + PollenResource resource = getResource0(resourceId); + + String contentType; + BufferedImage source; + try { + if (resource.getContentType().matches("image/(jpeg|png|gif)")) { + source = ImageIO.read(resource.getResourceContent().getBinaryStream()); + contentType = resource.getContentType(); + } else { + source = ImageIO.read(PollenResourceService.class.getResourceAsStream("/default.jpg")); + contentType = "image/jpeg"; + } + + int width, height; + + int previewMax = getPollenServiceConfig().getResourcePreviewMax(); + + if (source.getWidth() > source.getHeight()) { + width = previewMax; + height = width * source.getHeight() / source.getWidth(); + } else { + height = previewMax; + width = height * source.getWidth() / source.getHeight(); + } + + BufferedImage destination = new BufferedImage(width, height, source.getType()); + Graphics2D g = destination.createGraphics(); + g.drawImage(source, 0, 0, width, height, null); + g.dispose(); + + ByteArrayOutputStream output = new ByteArrayOutputStream(); + ImageIO.write(destination, contentType.split("/")[1], output); + + ResourceStreamBean bean = new ResourceStreamBean(); + bean.setName(resource.getName()); + bean.setContentType(contentType); + bean.setResourceContent(new ByteArrayInputStream(output.toByteArray())); + + return bean; + } catch (SQLException | IOException e) { + throw new PollenTechnicalException("error get preview resource", e); + } + } + public PollenEntityRef<PollenResource> createResource(ResourceFileBean resource) throws InvalidFormException { checkNotNull(resource); checkIsNotPersisted(resource); diff --git a/pollen-rest-api/src/main/resources/default.jpg b/pollen-services/src/main/resources/default.jpg similarity index 100% rename from pollen-rest-api/src/main/resources/default.jpg rename to pollen-services/src/main/resources/default.jpg diff --git a/pollen-services/src/main/resources/i18n/pollen-services_en_GB.properties b/pollen-services/src/main/resources/i18n/pollen-services_en_GB.properties index 1ba0fd60..fb24a918 100644 --- a/pollen-services/src/main/resources/i18n/pollen-services_en_GB.properties +++ b/pollen-services/src/main/resources/i18n/pollen-services_en_GB.properties @@ -26,6 +26,7 @@ pollen.configuration.registration.emailAddressPattern=Regular expression that th pollen.configuration.report.maxScore=Maximum score for reporting before administrators are notified pollen.configuration.resendEmailsCronSchedule=Time between two cron jobs of email resending pollen.configuration.resource.maxSize=Maximum size of pollen resource +pollen.configuration.resource.preview.max=Maximum dimension of image preview pollen.configuration.secret= pollen.configuration.sendEndPollRemindersCronSchedule=Time between two cron jobs of poll end reminder sending pollen.configuration.sessionTimeoutDelay=Inactivity delay before invalidate the session of a user (in seconds) diff --git a/pollen-services/src/main/resources/i18n/pollen-services_fr_FR.properties b/pollen-services/src/main/resources/i18n/pollen-services_fr_FR.properties index 497bc4ab..4f3b232a 100644 --- a/pollen-services/src/main/resources/i18n/pollen-services_fr_FR.properties +++ b/pollen-services/src/main/resources/i18n/pollen-services_fr_FR.properties @@ -26,6 +26,7 @@ pollen.configuration.registration.emailAddressPattern=Expression régulière que pollen.configuration.report.maxScore=Score maximum pour un signalement avant que les administrateurs soient avertis pollen.configuration.resendEmailsCronSchedule=Intervalle entre deux lancements de la tâche de renvoi des emails en erreur pollen.configuration.resource.maxSize=Taille maximal pour un fichier de resource de Pollen +pollen.configuration.resource.preview.max=Dimension maximal de la prévisualisation d'un image pollen.configuration.secret= pollen.configuration.sendEndPollRemindersCronSchedule=Intervalle entre deux lancements de la tâche d'envoi de mails de rappel de fin de sondage pollen.configuration.sessionTimeoutDelay=Temps autorisé d'inactivité avant d'invalider une session utilisateur (en secondes) -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm