@Test public void testResizeAvatar() { DocumentModel userWorkspace = userWorkspaceService.getCurrentUserPersonalWorkspace(session); userWorkspace.addFacet(UserProfileConstants.USER_PROFILE_FACET); ImagingService imagingService = Framework.getService(ImagingService.class); assertNotNull(imagingService); underTest = new ResizeAvatarPictureListener(); Blob tooBigAvatar = lookForAvatarBlob("data/BigAvatar.jpg"); assertNotNull(tooBigAvatar); underTest.resizeAvatar(userWorkspace, tooBigAvatar); Blob resizedImage = (Blob) userWorkspace.getPropertyValue(USER_PROFILE_AVATAR_FIELD); assertNotNull(resizedImage); assertNotEquals(tooBigAvatar, resizedImage); ImageInfo imageInfo = imagingService.getImageInfo(resizedImage); assertTrue(imageInfo.getWidth() < RESIZED_IMAGE_WIDTH); assertEquals(RESIZED_IMAGE_HEIGHT, imageInfo.getHeight()); Blob limitSizeAvatar = lookForAvatarBlob("data/MediumAvatar.jpg"); assertNotNull(tooBigAvatar); userWorkspace.setPropertyValue(USER_PROFILE_AVATAR_FIELD, (Serializable) limitSizeAvatar); underTest.resizeAvatar(userWorkspace, limitSizeAvatar); resizedImage = (Blob) userWorkspace.getPropertyValue(USER_PROFILE_AVATAR_FIELD); assertNotNull(resizedImage); imageInfo = imagingService.getImageInfo(resizedImage); assertEquals(RESIZED_IMAGE_WIDTH, imageInfo.getWidth()); assertEquals(RESIZED_IMAGE_HEIGHT, imageInfo.getHeight()); Blob underLimitSizeAvatar = lookForAvatarBlob("data/SmallAvatar.jpg"); assertNotNull(tooBigAvatar); userWorkspace.setPropertyValue(USER_PROFILE_AVATAR_FIELD, (Serializable) underLimitSizeAvatar); underTest.resizeAvatar(userWorkspace, underLimitSizeAvatar); resizedImage = (Blob) userWorkspace.getPropertyValue(USER_PROFILE_AVATAR_FIELD); assertNotNull(resizedImage); imageInfo = imagingService.getImageInfo(resizedImage); assertTrue(imageInfo.getWidth() < RESIZED_IMAGE_WIDTH); assertTrue(imageInfo.getHeight() < RESIZED_IMAGE_HEIGHT); }
protected void resizeAvatar(DocumentModel doc, Blob avatarImage) throws PropertyException { ConversionService conversionService = Framework.getService(ConversionService.class); BlobHolder bh = new SimpleBlobHolder(avatarImage); Map<String, Serializable> parameters = new HashMap<>(); parameters.put("targetWidth", String.valueOf(RESIZED_IMAGE_WIDTH)); parameters.put("targetHeight", String.valueOf(RESIZED_IMAGE_HEIGHT)); try { BlobHolder result = conversionService.convert("resizeAvatar", bh, parameters); if (result != null) { Blob blob = result.getBlob(); blob.setFilename(avatarImage.getFilename()); doc.setPropertyValue(USER_PROFILE_AVATAR_FIELD, (Serializable) blob); } } catch (NuxeoException e) { log.warn("Unable to resize avatar image"); log.debug(e, e); } }
ResizeAvatarPictureListener implements EventListener { protected void resizeAvatar(DocumentModel doc, Blob avatarImage) throws PropertyException { ConversionService conversionService = Framework.getService(ConversionService.class); BlobHolder bh = new SimpleBlobHolder(avatarImage); Map<String, Serializable> parameters = new HashMap<>(); parameters.put("targetWidth", String.valueOf(RESIZED_IMAGE_WIDTH)); parameters.put("targetHeight", String.valueOf(RESIZED_IMAGE_HEIGHT)); try { BlobHolder result = conversionService.convert("resizeAvatar", bh, parameters); if (result != null) { Blob blob = result.getBlob(); blob.setFilename(avatarImage.getFilename()); doc.setPropertyValue(USER_PROFILE_AVATAR_FIELD, (Serializable) blob); } } catch (NuxeoException e) { log.warn("Unable to resize avatar image"); log.debug(e, e); } } }
ResizeAvatarPictureListener implements EventListener { protected void resizeAvatar(DocumentModel doc, Blob avatarImage) throws PropertyException { ConversionService conversionService = Framework.getService(ConversionService.class); BlobHolder bh = new SimpleBlobHolder(avatarImage); Map<String, Serializable> parameters = new HashMap<>(); parameters.put("targetWidth", String.valueOf(RESIZED_IMAGE_WIDTH)); parameters.put("targetHeight", String.valueOf(RESIZED_IMAGE_HEIGHT)); try { BlobHolder result = conversionService.convert("resizeAvatar", bh, parameters); if (result != null) { Blob blob = result.getBlob(); blob.setFilename(avatarImage.getFilename()); doc.setPropertyValue(USER_PROFILE_AVATAR_FIELD, (Serializable) blob); } } catch (NuxeoException e) { log.warn("Unable to resize avatar image"); log.debug(e, e); } }  }
ResizeAvatarPictureListener implements EventListener { protected void resizeAvatar(DocumentModel doc, Blob avatarImage) throws PropertyException { ConversionService conversionService = Framework.getService(ConversionService.class); BlobHolder bh = new SimpleBlobHolder(avatarImage); Map<String, Serializable> parameters = new HashMap<>(); parameters.put("targetWidth", String.valueOf(RESIZED_IMAGE_WIDTH)); parameters.put("targetHeight", String.valueOf(RESIZED_IMAGE_HEIGHT)); try { BlobHolder result = conversionService.convert("resizeAvatar", bh, parameters); if (result != null) { Blob blob = result.getBlob(); blob.setFilename(avatarImage.getFilename()); doc.setPropertyValue(USER_PROFILE_AVATAR_FIELD, (Serializable) blob); } } catch (NuxeoException e) { log.warn("Unable to resize avatar image"); log.debug(e, e); } }  @Override void handleEvent(Event event); }
ResizeAvatarPictureListener implements EventListener { protected void resizeAvatar(DocumentModel doc, Blob avatarImage) throws PropertyException { ConversionService conversionService = Framework.getService(ConversionService.class); BlobHolder bh = new SimpleBlobHolder(avatarImage); Map<String, Serializable> parameters = new HashMap<>(); parameters.put("targetWidth", String.valueOf(RESIZED_IMAGE_WIDTH)); parameters.put("targetHeight", String.valueOf(RESIZED_IMAGE_HEIGHT)); try { BlobHolder result = conversionService.convert("resizeAvatar", bh, parameters); if (result != null) { Blob blob = result.getBlob(); blob.setFilename(avatarImage.getFilename()); doc.setPropertyValue(USER_PROFILE_AVATAR_FIELD, (Serializable) blob); } } catch (NuxeoException e) { log.warn("Unable to resize avatar image"); log.debug(e, e); } }  @Override void handleEvent(Event event);  }