fixed postid param
This commit is contained in:
parent
735bb8149b
commit
2ebd2b7f8f
|
@ -0,0 +1,41 @@
|
|||
package org.gcube.portal.social.networking.ws.inputs;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
|
||||
/**
|
||||
* Post 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;
|
||||
|
||||
public PostId() {
|
||||
super();
|
||||
}
|
||||
|
||||
public PostId(String postid) {
|
||||
super();
|
||||
this.postid = postid;
|
||||
}
|
||||
|
||||
public String getPostId() {
|
||||
return postid;
|
||||
}
|
||||
|
||||
public void setPostId(String postid) {
|
||||
this.postid = postid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PostId [postid=" + postid + "]";
|
||||
}
|
||||
}
|
|
@ -1,12 +1,10 @@
|
|||
package org.gcube.portal.social.networking.ws.methods.v2;
|
||||
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.ValidationException;
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
|
@ -21,14 +19,11 @@ import javax.ws.rs.core.Response.Status;
|
|||
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.Comment;
|
||||
import org.gcube.portal.databook.shared.Like;
|
||||
import org.gcube.portal.databook.shared.ex.FeedIDNotFoundException;
|
||||
import org.gcube.portal.social.networking.ws.inputs.CommentInputBean;
|
||||
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;
|
||||
import org.gcube.portal.social.networking.ws.utils.ErrorMessages;
|
||||
import org.gcube.portal.social.networking.ws.utils.Filters;
|
||||
import org.gcube.portal.social.networking.ws.utils.SocialUtils;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -107,18 +102,18 @@ public class Likes {
|
|||
public Response like(
|
||||
@NotNull(message="Post to like is missing")
|
||||
@Valid
|
||||
String postId) throws ValidationException {
|
||||
PostId postId) 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, context);
|
||||
boolean likeResultOperation = SocialUtils.like(username, postId.getPostId(), context);
|
||||
if (likeResultOperation)
|
||||
logger.info("Added like OK to postId " + postId);
|
||||
logger.info("Added like OK to postId " + postId.getPostId());
|
||||
else {
|
||||
logger.error("Unable to like this post"+ postId);
|
||||
logger.error("Unable to like this post"+ postId.getPostId());
|
||||
responseBean.setMessage("Unable to like, something went wrong please see server log");
|
||||
responseBean.setSuccess(false);
|
||||
status = Status.INTERNAL_SERVER_ERROR;
|
||||
|
@ -147,17 +142,17 @@ public class Likes {
|
|||
public Response unlike(
|
||||
@NotNull(message="Post to unlike is missing")
|
||||
@Valid
|
||||
String postId) throws ValidationException {
|
||||
PostId postId) 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);
|
||||
boolean likeResultOperation = SocialUtils.unlike(username, postId.getPostId());
|
||||
if (likeResultOperation)
|
||||
logger.info("Unlike OK to postId " + postId);
|
||||
logger.info("Unlike OK to postId " + postId.getPostId());
|
||||
else {
|
||||
logger.error("Unable to unlike this post"+ postId);
|
||||
logger.error("Unable to unlike this post"+ postId.getPostId());
|
||||
responseBean.setMessage("Unable to unlike, something went wrong please see server log");
|
||||
responseBean.setSuccess(false);
|
||||
status = Status.INTERNAL_SERVER_ERROR;
|
||||
|
|
|
@ -15,9 +15,6 @@ import java.util.Map.Entry;
|
|||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
|
@ -26,7 +23,6 @@ import org.gcube.applicationsupportlayer.social.NotificationsManager;
|
|||
import org.gcube.applicationsupportlayer.social.ex.ApplicationProfileNotFoundException;
|
||||
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite;
|
||||
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingUser;
|
||||
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
||||
import org.gcube.common.authorization.library.utils.Caller;
|
||||
import org.gcube.common.resources.gcore.utils.XPathHelper;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
|
@ -46,7 +42,6 @@ import org.gcube.portal.notifications.thread.PostNotificationsThread;
|
|||
import org.gcube.portal.social.networking.caches.SocialNetworkingSiteFinder;
|
||||
import org.gcube.portal.social.networking.liferay.ws.GroupManagerWSBuilder;
|
||||
import org.gcube.portal.social.networking.liferay.ws.UserManagerWSBuilder;
|
||||
import org.gcube.portal.social.networking.ws.outputs.ResponseBean;
|
||||
import org.gcube.portlets.widgets.pickitem.shared.ItemBean;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.queries.api.Query;
|
||||
|
@ -674,10 +669,11 @@ public class SocialUtils {
|
|||
new Date(), postid, user.getFullname(), user.getUserAvatarURL());
|
||||
Post thePost = null;
|
||||
try {
|
||||
logger.info("Attempting to read post with id: " +postid);
|
||||
thePost = CassandraConnection.getInstance().getDatabookStore().readPost(postid);
|
||||
likeCommitResult = CassandraConnection.getInstance().getDatabookStore().like(toLike);
|
||||
} catch (Exception e) {
|
||||
logger.error("Post not Found for this like ot could not like the post " + e.getMessage());
|
||||
logger.error("Post not found for this like ot could not like the post " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
//if the like was correctly delivered notify the user who made the post
|
||||
|
|
Loading…
Reference in New Issue