fixed postid param

This commit is contained in:
Massimiliano Assante 2023-02-09 15:09:38 +01:00
parent 735bb8149b
commit 2ebd2b7f8f
3 changed files with 52 additions and 20 deletions

View File

@ -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 + "]";
}
}

View File

@ -1,12 +1,10 @@
package org.gcube.portal.social.networking.ws.methods.v2; package org.gcube.portal.social.networking.ws.methods.v2;
import java.util.Date;
import java.util.List; import java.util.List;
import javax.validation.Valid; import javax.validation.Valid;
import javax.validation.ValidationException; import javax.validation.ValidationException;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.GET; 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.provider.AuthorizationProvider;
import org.gcube.common.authorization.library.utils.Caller; import org.gcube.common.authorization.library.utils.Caller;
import org.gcube.common.scope.api.ScopeProvider; 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.Like;
import org.gcube.portal.databook.shared.ex.FeedIDNotFoundException; import org.gcube.portal.social.networking.ws.inputs.PostId;
import org.gcube.portal.social.networking.ws.inputs.CommentInputBean;
import org.gcube.portal.social.networking.ws.outputs.ResponseBean; 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.CassandraConnection;
import org.gcube.portal.social.networking.ws.utils.ErrorMessages; 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.gcube.portal.social.networking.ws.utils.SocialUtils;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -107,18 +102,18 @@ public class Likes {
public Response like( public Response like(
@NotNull(message="Post to like is missing") @NotNull(message="Post to like is missing")
@Valid @Valid
String postId) throws ValidationException { PostId postId) throws ValidationException {
Caller caller = AuthorizationProvider.instance.get(); Caller caller = AuthorizationProvider.instance.get();
String username = caller.getClient().getId(); String username = caller.getClient().getId();
logger.debug("Request of like coming from user " + username); logger.debug("Request of like coming from user " + username);
String context = ScopeProvider.instance.get(); String context = ScopeProvider.instance.get();
ResponseBean responseBean = new ResponseBean(); ResponseBean responseBean = new ResponseBean();
Status status = Status.OK; Status status = Status.OK;
boolean likeResultOperation = SocialUtils.like(username, postId, context); boolean likeResultOperation = SocialUtils.like(username, postId.getPostId(), context);
if (likeResultOperation) if (likeResultOperation)
logger.info("Added like OK to postId " + postId); logger.info("Added like OK to postId " + postId.getPostId());
else { 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.setMessage("Unable to like, something went wrong please see server log");
responseBean.setSuccess(false); responseBean.setSuccess(false);
status = Status.INTERNAL_SERVER_ERROR; status = Status.INTERNAL_SERVER_ERROR;
@ -147,17 +142,17 @@ public class Likes {
public Response unlike( public Response unlike(
@NotNull(message="Post to unlike is missing") @NotNull(message="Post to unlike is missing")
@Valid @Valid
String postId) throws ValidationException { PostId postId) throws ValidationException {
Caller caller = AuthorizationProvider.instance.get(); Caller caller = AuthorizationProvider.instance.get();
String username = caller.getClient().getId(); String username = caller.getClient().getId();
logger.debug("Request of unlike coming from user " + username); logger.debug("Request of unlike coming from user " + username);
ResponseBean responseBean = new ResponseBean(); ResponseBean responseBean = new ResponseBean();
Status status = Status.OK; Status status = Status.OK;
boolean likeResultOperation = SocialUtils.unlike(username, postId); boolean likeResultOperation = SocialUtils.unlike(username, postId.getPostId());
if (likeResultOperation) if (likeResultOperation)
logger.info("Unlike OK to postId " + postId); logger.info("Unlike OK to postId " + postId.getPostId());
else { 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.setMessage("Unable to unlike, something went wrong please see server log");
responseBean.setSuccess(false); responseBean.setSuccess(false);
status = Status.INTERNAL_SERVER_ERROR; status = Status.INTERNAL_SERVER_ERROR;

View File

@ -15,9 +15,6 @@ import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.UUID; 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.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; 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.ex.ApplicationProfileNotFoundException;
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite; import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite;
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingUser; 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.authorization.library.utils.Caller;
import org.gcube.common.resources.gcore.utils.XPathHelper; import org.gcube.common.resources.gcore.utils.XPathHelper;
import org.gcube.common.scope.api.ScopeProvider; 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.caches.SocialNetworkingSiteFinder;
import org.gcube.portal.social.networking.liferay.ws.GroupManagerWSBuilder; import org.gcube.portal.social.networking.liferay.ws.GroupManagerWSBuilder;
import org.gcube.portal.social.networking.liferay.ws.UserManagerWSBuilder; 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.portlets.widgets.pickitem.shared.ItemBean;
import org.gcube.resources.discovery.client.api.DiscoveryClient; import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.Query; import org.gcube.resources.discovery.client.queries.api.Query;
@ -674,10 +669,11 @@ public class SocialUtils {
new Date(), postid, user.getFullname(), user.getUserAvatarURL()); new Date(), postid, user.getFullname(), user.getUserAvatarURL());
Post thePost = null; Post thePost = null;
try { try {
logger.info("Attempting to read post with id: " +postid);
thePost = CassandraConnection.getInstance().getDatabookStore().readPost(postid); thePost = CassandraConnection.getInstance().getDatabookStore().readPost(postid);
likeCommitResult = CassandraConnection.getInstance().getDatabookStore().like(toLike); likeCommitResult = CassandraConnection.getInstance().getDatabookStore().like(toLike);
} catch (Exception e) { } 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; return false;
} }
//if the like was correctly delivered notify the user who made the post //if the like was correctly delivered notify the user who made the post