From 9a4add44ecbd32dea6ac3d30fd81ae1ac82e3dbc Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sun, 15 Oct 2017 05:37:18 +0300 Subject: api: ImagesService --- juick-core/src/main/java/com/juick/Attachment.java | 58 ++++++++++++++++++++++ juick-core/src/main/java/com/juick/Message.java | 50 ++++--------------- juick-core/src/main/java/com/juick/Photo.java | 2 + .../com/juick/formatters/PlainTextFormatter.java | 2 +- .../src/test/java/com/juick/MessageTest.java | 25 ---------- 5 files changed, 70 insertions(+), 67 deletions(-) create mode 100644 juick-core/src/main/java/com/juick/Attachment.java (limited to 'juick-core') diff --git a/juick-core/src/main/java/com/juick/Attachment.java b/juick-core/src/main/java/com/juick/Attachment.java new file mode 100644 index 00000000..76f2995a --- /dev/null +++ b/juick-core/src/main/java/com/juick/Attachment.java @@ -0,0 +1,58 @@ +package com.juick; + +public class Attachment { + private String url; + private Integer height; + private Integer width; + private Attachment small; + private Attachment medium; + private Attachment thumbnail; + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public Integer getHeight() { + return height; + } + + public void setHeight(Integer height) { + this.height = height; + } + + public Integer getWidth() { + return width; + } + + public void setWidth(Integer width) { + this.width = width; + } + + public Attachment getSmall() { + return small; + } + + public void setSmall(Attachment small) { + this.small = small; + } + + public Attachment getMedium() { + return medium; + } + + public void setMedium(Attachment medium) { + this.medium = medium; + } + + public Attachment getThumbnail() { + return thumbnail; + } + + public void setThumbnail(Attachment thumbnail) { + this.thumbnail = thumbnail; + } +} diff --git a/juick-core/src/main/java/com/juick/Message.java b/juick-core/src/main/java/com/juick/Message.java index 25463c46..8f903e1f 100644 --- a/juick-core/src/main/java/com/juick/Message.java +++ b/juick-core/src/main/java/com/juick/Message.java @@ -27,16 +27,13 @@ import org.apache.commons.lang3.builder.ToStringBuilder; import javax.xml.bind.annotation.*; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import java.time.Instant; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; -import java.util.TreeSet; +import java.util.*; /** * @author Ugnich Anton */ @XmlRootElement(name = "juick", namespace = "http://juick.com/message") -@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER) +@XmlAccessorType() public class Message implements Comparable { private int mid = 0; private int rid = 0; @@ -67,6 +64,8 @@ public class Message implements Comparable { private String attachmentType; @XmlTransient private Photo photo; + @XmlTransient + private Attachment attachment; public String Video = null; public Place Place = null; private int likes; @@ -158,25 +157,6 @@ public class Message implements Comparable { } } - @JsonIgnore - public String getAttachmentURL() { - if (attachmentType != null) { - StringBuilder builder = new StringBuilder(); - - builder.append("http://i.juick.com/"); - builder.append(attachmentType.equals("mp4") ? "video" : "photos-1024"); - builder.append("/").append(getMid()); - - if (getRid() > 0) - builder.append("-").append(getRid()); - - builder.append(".").append(attachmentType); - - return builder.toString(); - } - return null; - } - @JsonIgnore public String getTagsString() { StringBuilder builder = new StringBuilder(); @@ -352,22 +332,10 @@ public class Message implements Comparable { this.repliesBy = repliesBy; } - @JsonProperty("photo") - @XmlTransient - public Photo getPhotoURLs() { - if (StringUtils.isNotBlank(attachmentType)) { - Photo photo = new Photo(); - if (rid > 0) { - photo.setSmall(String.format("https://i.juick.com/photos-512/%d-%d.%s", mid, rid, attachmentType)); - photo.setMedium(String.format("https://i.juick.com/photos-1024/%d-%d.%s", mid, rid, attachmentType)); - photo.setThumbnail(String.format("https://i.juick.com/ps/%d-%d.%s", mid, rid, attachmentType)); - } else { - photo.setSmall(String.format("https://i.juick.com/photos-512/%d.%s", mid, attachmentType)); - photo.setMedium(String.format("https://i.juick.com/photos-1024/%d.%s", mid, attachmentType)); - photo.setThumbnail(String.format("https://i.juick.com/ps/%d.%s", mid, attachmentType)); - } - return photo; - } - return null; + public Attachment getAttachment() { + return attachment; + } + public void setAttachment(Attachment attachment) { + this.attachment = attachment; } } diff --git a/juick-core/src/main/java/com/juick/Photo.java b/juick-core/src/main/java/com/juick/Photo.java index af20fc88..06299610 100644 --- a/juick-core/src/main/java/com/juick/Photo.java +++ b/juick-core/src/main/java/com/juick/Photo.java @@ -20,6 +20,8 @@ package com.juick; /** * Created by vitalyster on 30.11.2016. */ +// used for compatibility +@Deprecated public class Photo { private String small; private String medium; diff --git a/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java b/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java index c62e0134..06ae8a0a 100644 --- a/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java +++ b/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java @@ -39,7 +39,7 @@ public class PlainTextFormatter { sb.append(title).append(jmsg.getUser().getName()).append(":\n") .append(subtitle).append("\n").append(jmsg.getText()).append("\n"); if (jmsg.getPhoto() != null) { - sb.append(jmsg.getAttachmentURL()); + sb.append(jmsg.getAttachment().getMedium().getUrl()); } return sb.toString(); } diff --git a/juick-core/src/test/java/com/juick/MessageTest.java b/juick-core/src/test/java/com/juick/MessageTest.java index b420edfa..3bdac9be 100644 --- a/juick-core/src/test/java/com/juick/MessageTest.java +++ b/juick-core/src/test/java/com/juick/MessageTest.java @@ -127,31 +127,6 @@ public class MessageTest { assertThat(message2.compareTo(message1), equalTo(1)); } - @Test - public void attachmentURLShouldBeReturnCorrectResult() throws Exception { - Message message1 = new Message(); - - assertThat(message1.getAttachmentURL(), nullValue()); - - message1.setAttachmentType("jpeg"); - - assertThat(message1.getAttachmentURL(), equalTo("http://i.juick.com/photos-1024/0.jpeg")); - - message1.setRid(1); - - assertThat(message1.getAttachmentURL(), equalTo("http://i.juick.com/photos-1024/0-1.jpeg")); - - Message message2 = new Message(); - - message2.setAttachmentType("mp4"); - - assertThat(message2.getAttachmentURL(), equalTo("http://i.juick.com/video/0.mp4")); - - message2.setRid(1); - - assertThat(message2.getAttachmentURL(), equalTo("http://i.juick.com/video/0-1.mp4")); - } - @Test public void tagsStringShouldBeEmptyIfNoTags() throws Exception { Message message = new Message(); -- cgit v1.2.3