fixed unlike method
This commit is contained in:
parent
2ebd2b7f8f
commit
8b58a29d9f
|
@ -0,0 +1,60 @@
|
|||
package org.gcube.portal.social.networking.ws.inputs;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
|
||||
/**
|
||||
* Like Bean object
|
||||
*/
|
||||
public class LikeInputBean {
|
||||
|
||||
@JsonProperty("likeid")
|
||||
@NotNull(message="likeid cannot be null")
|
||||
@Size(message="likeid cannot be empty", min=1)
|
||||
private String likeid;
|
||||
|
||||
@JsonProperty("postid")
|
||||
@NotNull(message="postid cannot be null")
|
||||
@Size(message="postid cannot be empty", min=1)
|
||||
private String postid;
|
||||
|
||||
public LikeInputBean() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param likeid
|
||||
* @param postid
|
||||
*/
|
||||
public LikeInputBean(String likeid, String postid) {
|
||||
super();
|
||||
this.likeid = likeid;
|
||||
this.postid = postid;
|
||||
}
|
||||
|
||||
public String getLikeid() {
|
||||
return likeid;
|
||||
}
|
||||
|
||||
public void setLikeid(String likeid) {
|
||||
this.likeid = likeid;
|
||||
}
|
||||
|
||||
public String getPostid() {
|
||||
return postid;
|
||||
}
|
||||
|
||||
public void setPostid(String postid) {
|
||||
this.postid = postid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LikeInputBean [likeid=" + likeid + ", postid=" + postid + "]";
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -7,35 +7,37 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
|||
|
||||
|
||||
/**
|
||||
* Post id object
|
||||
* Application id object
|
||||
|
||||
*/
|
||||
//@ApiModel(description="An object containing the app_id field", value="Application")
|
||||
public class PostId {
|
||||
|
||||
@JsonProperty("postid")
|
||||
@NotNull(message="postid cannot be null")
|
||||
@Size(message="postid cannot be empty", min=1)
|
||||
private String postid;
|
||||
@JsonProperty("postId")
|
||||
@NotNull(message="postId cannot be null")
|
||||
@Size(message="postId cannot be empty", min=1)
|
||||
private String postId;
|
||||
|
||||
public PostId() {
|
||||
super();
|
||||
}
|
||||
|
||||
public PostId(String postid) {
|
||||
public PostId(String postId) {
|
||||
super();
|
||||
this.postid = postid;
|
||||
this.postId = postId;
|
||||
}
|
||||
|
||||
public String getPostId() {
|
||||
return postid;
|
||||
return postId;
|
||||
}
|
||||
|
||||
public void setPostId(String postid) {
|
||||
this.postid = postid;
|
||||
public void setPostId(String postId) {
|
||||
this.postId = postId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PostId [postid=" + postid + "]";
|
||||
return "PostId [postId=" + postId + "]";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
|||
import org.gcube.common.authorization.library.utils.Caller;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.portal.databook.shared.Like;
|
||||
import org.gcube.portal.social.networking.ws.inputs.LikeInputBean;
|
||||
import org.gcube.portal.social.networking.ws.inputs.PostId;
|
||||
import org.gcube.portal.social.networking.ws.outputs.ResponseBean;
|
||||
import org.gcube.portal.social.networking.ws.utils.CassandraConnection;
|
||||
|
@ -102,18 +103,18 @@ public class Likes {
|
|||
public Response like(
|
||||
@NotNull(message="Post to like is missing")
|
||||
@Valid
|
||||
PostId postId) throws ValidationException {
|
||||
PostId post) throws ValidationException {
|
||||
Caller caller = AuthorizationProvider.instance.get();
|
||||
String username = caller.getClient().getId();
|
||||
logger.debug("Request of like coming from user " + username);
|
||||
String context = ScopeProvider.instance.get();
|
||||
ResponseBean responseBean = new ResponseBean();
|
||||
Status status = Status.OK;
|
||||
boolean likeResultOperation = SocialUtils.like(username, postId.getPostId(), context);
|
||||
boolean likeResultOperation = SocialUtils.like(username, post.getPostId(), context);
|
||||
if (likeResultOperation)
|
||||
logger.info("Added like OK to postId " + postId.getPostId());
|
||||
logger.info("Added like OK to postId " + post.getPostId());
|
||||
else {
|
||||
logger.error("Unable to like this post"+ postId.getPostId());
|
||||
logger.error("Unable to like this post"+ post.getPostId());
|
||||
responseBean.setMessage("Unable to like, something went wrong please see server log");
|
||||
responseBean.setSuccess(false);
|
||||
status = Status.INTERNAL_SERVER_ERROR;
|
||||
|
@ -142,17 +143,17 @@ public class Likes {
|
|||
public Response unlike(
|
||||
@NotNull(message="Post to unlike is missing")
|
||||
@Valid
|
||||
PostId postId) throws ValidationException {
|
||||
LikeInputBean likeInputBean) throws ValidationException {
|
||||
Caller caller = AuthorizationProvider.instance.get();
|
||||
String username = caller.getClient().getId();
|
||||
logger.debug("Request of unlike coming from user " + username);
|
||||
ResponseBean responseBean = new ResponseBean();
|
||||
Status status = Status.OK;
|
||||
boolean likeResultOperation = SocialUtils.unlike(username, postId.getPostId());
|
||||
boolean likeResultOperation = SocialUtils.unlike(username, likeInputBean.getLikeid(), likeInputBean.getPostid());
|
||||
if (likeResultOperation)
|
||||
logger.info("Unlike OK to postId " + postId.getPostId());
|
||||
logger.info("Unlike OK to postId " + likeInputBean.getPostid());
|
||||
else {
|
||||
logger.error("Unable to unlike this post"+ postId.getPostId());
|
||||
logger.error("Unable to unlike this post"+ likeInputBean.getPostid());
|
||||
responseBean.setMessage("Unable to unlike, something went wrong please see server log");
|
||||
responseBean.setSuccess(false);
|
||||
status = Status.INTERNAL_SERVER_ERROR;
|
||||
|
|
|
@ -698,7 +698,7 @@ public class SocialUtils {
|
|||
return likeCommitResult && resultNotifyLike;
|
||||
}
|
||||
|
||||
public static boolean unlike(String username, String postid) {
|
||||
public static boolean unlike(String username, String likeid, String postid) {
|
||||
boolean unlikeCommitResult = false;
|
||||
// retrieve user information
|
||||
GCubeUser user;
|
||||
|
@ -713,7 +713,7 @@ public class SocialUtils {
|
|||
String thumbnailURL = user.getUserAvatarURL();
|
||||
try {
|
||||
|
||||
unlikeCommitResult = CassandraConnection.getInstance().getDatabookStore().unlike(username, fullName, thumbnailURL);
|
||||
unlikeCommitResult = CassandraConnection.getInstance().getDatabookStore().unlike(username, likeid, postid);
|
||||
} catch (Exception e) {
|
||||
logger.error("Post not Found for this like ot could not unlike the post " + e.getMessage());
|
||||
return false;
|
||||
|
|
Loading…
Reference in New Issue