added comment support

This commit is contained in:
bancika
2016-10-27 13:07:23 +02:00
parent 0da4375857
commit d1279ccc9a
5 changed files with 145 additions and 2 deletions
@@ -0,0 +1,98 @@
package org.diylc.plugins.cloud.model;
public class CommentEntity {
private int id;
private int userId;
private String username;
private String comment;
private String postedAt;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public String getDate() {
return postedAt;
}
public void setDate(String date) {
this.postedAt = date;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((comment == null) ? 0 : comment.hashCode());
result = prime * result + ((postedAt == null) ? 0 : postedAt.hashCode());
result = prime * result + id;
result = prime * result + userId;
result = prime * result + ((username == null) ? 0 : username.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
CommentEntity other = (CommentEntity) obj;
if (comment == null) {
if (other.comment != null)
return false;
} else if (!comment.equals(other.comment))
return false;
if (postedAt == null) {
if (other.postedAt != null)
return false;
} else if (!postedAt.equals(other.postedAt))
return false;
if (id != other.id)
return false;
if (userId != other.userId)
return false;
if (username == null) {
if (other.username != null)
return false;
} else if (!username.equals(other.username))
return false;
return true;
}
@Override
public String toString() {
return "CommentEntity [id=" + id + ", username=" + username + ", date=" + postedAt + "]";
}
}
@@ -133,4 +133,13 @@ public interface IServiceAPI {
* @return a {@link List} of available sortings.
*/
List<String> getSortings();
/**
* Returns all available comments for the given projectId.
*
* @param projectId
* @return string with error message if the error occurred or a list of {@link CommentEntity}
* objects.
*/
Object getComments(@ParamName("projectId") int projectId);
}
@@ -12,6 +12,7 @@ import java.util.List;
import org.apache.log4j.Logger;
import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.plugins.cloud.model.CommentEntity;
import org.diylc.plugins.cloud.model.IServiceAPI;
import org.diylc.plugins.cloud.model.ProjectEntity;
import org.diylc.plugins.cloud.model.UserEntity;
@@ -254,6 +255,24 @@ public class CloudPresenter {
}
}
public List<CommentEntity> GetComments(int projectId) throws CloudException {
try {
Object res = service.getComments(projectId);
if (res == null)
throw new CloudException("Failed to retreive search results.");
if (res instanceof String)
throw new CloudException(res.toString());
if (res instanceof List<?>) {
@SuppressWarnings("unchecked")
List<CommentEntity> comments = (List<CommentEntity>) res;
return comments;
}
throw new CloudException("Unexpected server response received for comments: " + res.getClass().getName());
} catch (Exception e) {
throw new CloudException(e);
}
}
private String getMachineId() {
if (machineId == null) {
try {