diff --git a/jcommune-service/src/main/java/org/jtalks/jcommune/service/nontransactional/ImageService.java b/jcommune-service/src/main/java/org/jtalks/jcommune/service/nontransactional/ImageService.java index 10ec19a4a3..4d148a5331 100644 --- a/jcommune-service/src/main/java/org/jtalks/jcommune/service/nontransactional/ImageService.java +++ b/jcommune-service/src/main/java/org/jtalks/jcommune/service/nontransactional/ImageService.java @@ -48,12 +48,11 @@ public class ImageService { * user-friendly string with all valid image types */ private static final String VALID_IMAGE_EXTENSIONS = "*.jpeg, *.jpg, *.gif, *.png, *.ico"; - + private static final Logger LOGGER = LoggerFactory.getLogger(ImageService.class); private ImageConverter imageConverter; private Base64Wrapper base64Wrapper; private JCommuneProperty imageSizeProperty; private String defaultImagePath; - private static final Logger LOGGER = LoggerFactory.getLogger(ImageService.class); /** * Create ImageService instance @@ -90,6 +89,23 @@ public byte[] getDefaultImage() { return result; } + /** + * Check image user avatar + * + * @param avatar image for compare with default image + * @return true if avatar image default + */ + public boolean isDefaultImage(byte[] avatar) { + boolean isDefaultImage = false; + try { + isDefaultImage = Arrays.equals(getDefaultImage(), avatar) ? true + : preProcessAndEncodeInString64(getDefaultImage()).equals(imageConverter.prepareHtmlImgSrc(avatar)); + } catch (ImageProcessException e) { + LOGGER.error("Can't convert default image user avatar", e); + } + return isDefaultImage; + } + /** * Pre process image to fit maximum size and be in the target format and * convert the contents of the result image into String64 format diff --git a/jcommune-view/jcommune-web-controller/src/main/java/org/jtalks/jcommune/web/controller/UserProfileController.java b/jcommune-view/jcommune-web-controller/src/main/java/org/jtalks/jcommune/web/controller/UserProfileController.java index f04a0e8d29..fafb9a0b8e 100644 --- a/jcommune-view/jcommune-web-controller/src/main/java/org/jtalks/jcommune/web/controller/UserProfileController.java +++ b/jcommune-view/jcommune-web-controller/src/main/java/org/jtalks/jcommune/web/controller/UserProfileController.java @@ -245,6 +245,7 @@ public ModelAndView showUserSecuritySettings(@PathVariable Long editedUserId) private void setAvatarToUserProfileView(EditUserProfileDto editUserProfileDto, JCUser user) { byte[] avatar = user.getAvatar(); editUserProfileDto.setAvatar(imageConverter.prepareHtmlImgSrc(avatar)); + editUserProfileDto.setDefaultAvatarFlag(imageService.isDefaultImage(avatar)); } /** diff --git a/jcommune-view/jcommune-web-controller/src/main/java/org/jtalks/jcommune/web/dto/EditUserProfileDto.java b/jcommune-view/jcommune-web-controller/src/main/java/org/jtalks/jcommune/web/dto/EditUserProfileDto.java index b3d0f81587..f04617d6d3 100644 --- a/jcommune-view/jcommune-web-controller/src/main/java/org/jtalks/jcommune/web/dto/EditUserProfileDto.java +++ b/jcommune-view/jcommune-web-controller/src/main/java/org/jtalks/jcommune/web/dto/EditUserProfileDto.java @@ -39,6 +39,7 @@ public class EditUserProfileDto { private long userId; private String username; private String avatar; + private boolean defaultAvatarFlag; private Long userProfileVersion; @Valid @@ -53,6 +54,14 @@ public class EditUserProfileDto { @Valid private UserContactsDto userContactsDto; + public boolean isDefaultAvatarFlag() { + return defaultAvatarFlag; + } + + public void setDefaultAvatarFlag(Boolean defaultAvatarFlag) { + this.defaultAvatarFlag = defaultAvatarFlag; + } + /** * Create instance with UserProfileDto. All required fields retrieved from JCUser. * @param userProfileDto dto for user profile fields diff --git a/jcommune-view/jcommune-web-view/src/main/webapp/WEB-INF/jsp/editUserProfile.jsp b/jcommune-view/jcommune-web-view/src/main/webapp/WEB-INF/jsp/editUserProfile.jsp index 0d74de562c..21b7513e7b 100644 --- a/jcommune-view/jcommune-web-view/src/main/webapp/WEB-INF/jsp/editUserProfile.jsp +++ b/jcommune-view/jcommune-web-view/src/main/webapp/WEB-INF/jsp/editUserProfile.jsp @@ -32,10 +32,12 @@ + "> +