mirror of
https://github.com/sismics/docs.git
synced 2025-12-13 17:56:20 +00:00
Closes #42: Gravatar images in comments
This commit is contained in:
@@ -90,7 +90,7 @@ public class CommentDao {
|
||||
*/
|
||||
public List<CommentDto> getByDocumentId(String documentId) {
|
||||
EntityManager em = ThreadLocalContext.get().getEntityManager();
|
||||
StringBuilder sb = new StringBuilder("select c.COM_ID_C, c.COM_CONTENT_C, c.COM_CREATEDATE_D, u.USE_USERNAME_C from T_COMMENT c, T_USER u");
|
||||
StringBuilder sb = new StringBuilder("select c.COM_ID_C, c.COM_CONTENT_C, c.COM_CREATEDATE_D, u.USE_USERNAME_C, u.USE_EMAIL_C from T_COMMENT c, T_USER u");
|
||||
sb.append(" where c.COM_IDDOC_C = :documentId and c.COM_IDUSER_C = u.USE_ID_C and c.COM_DELETEDATE_D is null ");
|
||||
sb.append(" order by c.COM_CREATEDATE_D asc ");
|
||||
Query q = em.createNativeQuery(sb.toString());
|
||||
@@ -106,6 +106,7 @@ public class CommentDao {
|
||||
commentDto.setContent((String) o[i++]);
|
||||
commentDto.setCreateTimestamp(((Timestamp) o[i++]).getTime());
|
||||
commentDto.setCreatorName((String) o[i++]);
|
||||
commentDto.setCreatorEmail((String) o[i++]);
|
||||
commentDtoList.add(commentDto);
|
||||
}
|
||||
return commentDtoList;
|
||||
|
||||
@@ -19,6 +19,11 @@ public class CommentDto {
|
||||
*/
|
||||
private String creatorName;
|
||||
|
||||
/**
|
||||
* Creator email.
|
||||
*/
|
||||
private String creatorEmail;
|
||||
|
||||
/**
|
||||
* Content.
|
||||
*/
|
||||
@@ -44,6 +49,14 @@ public class CommentDto {
|
||||
public void setCreatorName(String creatorName) {
|
||||
this.creatorName = creatorName;
|
||||
}
|
||||
|
||||
public String getCreatorEmail() {
|
||||
return creatorEmail;
|
||||
}
|
||||
|
||||
public void setCreatorEmail(String creatorEmail) {
|
||||
this.creatorEmail = creatorEmail;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
|
||||
@@ -11,6 +11,8 @@ import javax.imageio.ImageWriteParam;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.hash.Hashing;
|
||||
import com.sismics.util.mime.MimeType;
|
||||
|
||||
/**
|
||||
@@ -62,4 +64,21 @@ public class ImageUtil {
|
||||
public static boolean isImage(String mimeType) {
|
||||
return mimeType.equals(MimeType.IMAGE_GIF) || mimeType.equals(MimeType.IMAGE_PNG) || mimeType.equals(MimeType.IMAGE_JPEG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute Gravatar hash.
|
||||
* See https://en.gravatar.com/site/implement/hash/.
|
||||
*
|
||||
* @param email
|
||||
* @return Gravatar hash
|
||||
*/
|
||||
public static String computeGravatar(String email) {
|
||||
if (email == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Hashing.md5().hashString(
|
||||
email.trim().toLowerCase(), Charsets.UTF_8)
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
||||
17
docs-core/src/test/java/com/sismics/util/TestImageUtil.java
Normal file
17
docs-core/src/test/java/com/sismics/util/TestImageUtil.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package com.sismics.util;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Test of the image utilities.
|
||||
*
|
||||
* @author bgamard
|
||||
*/
|
||||
public class TestImageUtil {
|
||||
|
||||
@Test
|
||||
public void computeGravatarTest() throws Exception {
|
||||
Assert.assertEquals("0bc83cb571cd1c50ba6f3e8a78ef1346", ImageUtil.computeGravatar("MyEmailAddress@example.com "));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user