diff --git a/src/main/java/org/gcube/portal/social/networking/ws/lib/Comments.java b/src/main/java/org/gcube/portal/social/networking/ws/lib/Comments.java new file mode 100644 index 0000000..8e5ecb2 --- /dev/null +++ b/src/main/java/org/gcube/portal/social/networking/ws/lib/Comments.java @@ -0,0 +1,201 @@ +package org.gcube.portal.social.networking.ws.lib; + + +import com.webcohesion.enunciate.metadata.Ignore; +import com.webcohesion.enunciate.metadata.rs.RequestHeader; +import com.webcohesion.enunciate.metadata.rs.RequestHeaders; +import com.webcohesion.enunciate.metadata.rs.ResponseCode; +import com.webcohesion.enunciate.metadata.rs.StatusCodes; +import org.gcube.portal.databook.shared.Comment; +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.slf4j.LoggerFactory; + +import javax.validation.Valid; +import javax.validation.ValidationException; +import javax.validation.constraints.Min; +import javax.validation.constraints.NotNull; +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; +import java.util.List; + +/** + * REST interface for the social networking library (comments). + * @author Ahmed Ibrahim ISTI-CNR + */ +@Path("lib/comments") +@RequestHeaders ({ + @RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"), + @RequestHeader( name = "Content-Type", description = "application/json") +}) +@Ignore +public class Comments { + + // Logger + private static final org.slf4j.Logger logger = LoggerFactory.getLogger(Comments.class); + + //lib api + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("add-comment-lib") + public Response addCommentLib(@NotNull(message="Comment to write is missing") + @Valid + Comment comment)throws ValidationException { + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try { + logger.info("Writing comment with commentid " + comment.getKey()); + boolean result = CassandraConnection.getInstance().getDatabookStore().addComment(comment); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(result); + } catch (Exception e) { + logger.error("Unable to write comment.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("read-comment-by-id-lib") + public Response readCommentByIdLib(@QueryParam("commentid") + String commentid)throws ValidationException{ + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + logger.info("Getting comment with commentid " + commentid); + Comment result = CassandraConnection.getInstance().getDatabookStore().readCommentById(commentid); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(true); + }catch(Exception e){ + logger.error("Unable to find comment.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("get-comments-by-post-id-lib") + @StatusCodes ({ + @ResponseCode ( code = 200, condition = "The list of comments is put into the 'result' field"), + @ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT) + }) + public Response getAllCommentsByPostIdLib( + @NotNull + @QueryParam("postid") + String postid) { + + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + List comments = null; + + try{ + logger.info("Retrieving comments for postid " + postid); + comments = CassandraConnection.getInstance().getDatabookStore().getAllCommentByPost(postid); + responseBean.setResult(comments); + responseBean.setSuccess(true); + }catch(Exception e){ + logger.error("Unable to retrieve such comments.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + + return Response.status(status).entity(responseBean).build(); + } + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("get-recent-comments-by-user-and-date-lib") + public Response getRecentCommentsByUserAndDateLib( + @QueryParam("time") + @Min(value = 0, message="time cannot be negative") + long timeInMillis, + @QueryParam("username") + String username + ) throws ValidationException{ + + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + List comments = null; + + try{ + logger.info("Retrieving comments for user id " + username); + comments = CassandraConnection.getInstance().getDatabookStore().getRecentCommentsByUserAndDate(username, timeInMillis); + responseBean.setResult(comments); + responseBean.setMessage(""); + responseBean.setSuccess(true); + }catch(Exception e){ + logger.error("Unable to retrieve such comments.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("edit-comment-lib") + public Response editCommentLib( + @NotNull(message="Comment to edit is missing") + @Valid + Comment comment + ) throws ValidationException{ + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + logger.info("Writing comment with commentid " + comment.getKey()); + boolean result = CassandraConnection.getInstance().getDatabookStore().editComment(comment); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(result); + }catch(Exception e){ + logger.error("Unable to write comment.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("delete-comment-lib") + public Response deleteCommentLib( + @QueryParam("commentid") + String commentid, + @QueryParam("postid") + String postid + ) throws ValidationException{ + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + logger.info("deleting comment with commentid " + commentid); + boolean result = CassandraConnection.getInstance().getDatabookStore().deleteComment(commentid, postid); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(result); + }catch(Exception e){ + logger.error("Unable to delete comment.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } +} diff --git a/src/main/java/org/gcube/portal/social/networking/ws/lib/HashTags.java b/src/main/java/org/gcube/portal/social/networking/ws/lib/HashTags.java new file mode 100644 index 0000000..9dc7046 --- /dev/null +++ b/src/main/java/org/gcube/portal/social/networking/ws/lib/HashTags.java @@ -0,0 +1,249 @@ +package org.gcube.portal.social.networking.ws.lib; + +import com.webcohesion.enunciate.metadata.Ignore; +import com.webcohesion.enunciate.metadata.rs.RequestHeader; +import com.webcohesion.enunciate.metadata.rs.RequestHeaders; +import org.gcube.portal.databook.shared.Post; +import org.gcube.portal.social.networking.ws.outputs.ResponseBean; +import org.gcube.portal.social.networking.ws.utils.CassandraConnection; +import org.slf4j.LoggerFactory; + +import javax.validation.Valid; +import javax.validation.ValidationException; +import javax.validation.constraints.Min; +import javax.validation.constraints.NotNull; +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; +import java.util.List; +import java.util.Map; + +/** + * REST interface for the social networking library (hash tags). + * @author Ahmed Ibrahim ISTI-CNR + */ +@Path("lib/hashtags") +@RequestHeaders ({ + @RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"), + @RequestHeader( name = "Content-Type", description = "application/json") +}) +@Ignore +public class HashTags { + + // Logger + private static final org.slf4j.Logger logger = LoggerFactory.getLogger(HashTags.class); + + //lib api + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("save-hashtag-lib") + public Response saveHashTagsLib( + @QueryParam("feedid") + String feedid, + @QueryParam("vreid") + String vreid, + @NotNull(message="hashtag to save is missing") + @Valid + List hashtags + ) throws ValidationException { + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + logger.info("Saving hashtags " ); + boolean result = CassandraConnection.getInstance().getDatabookStore().saveHashTags(feedid,vreid,hashtags); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(result); + }catch(Exception e){ + logger.error("Unable to save hashtags.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("delete-hashtag-lib") + public Response deleteHashTagsLib( + @QueryParam("feedid") + String feedid, + @QueryParam("vreid") + String vreid, + @NotNull(message="hashtag to delete is missing") + @Valid + List hashtags + ) throws ValidationException{ + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + logger.info("deleting hashtags " ); + boolean result = CassandraConnection.getInstance().getDatabookStore().deleteHashTags(feedid,vreid,hashtags); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(result); + }catch(Exception e){ + logger.error("Unable to delete hashtags.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("save-hashtag-comment-lib") + public Response saveHashTagsCommentLib( + @QueryParam("commentid") + String commentid, + @QueryParam("vreid") + String vreid, + @NotNull(message="hashtag to save is missing") + @Valid + List hashtags + ) throws ValidationException{ + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + logger.info("Saving hashtags comments " ); + boolean result = CassandraConnection.getInstance().getDatabookStore().saveHashTagsComment(commentid,vreid,hashtags); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(result); + }catch(Exception e){ + logger.error("Unable to save hashtags comments.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("delete-hashtag-comment-lib") + public Response deleteHashTagsCommentLib( + @QueryParam("commentid") + String commentid, + @QueryParam("vreid") + String vreid, + @NotNull(message="hashtag to delete is missing") + @Valid + List hashtags + ) throws ValidationException{ + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + logger.info("deleting hashtags " ); + boolean result = CassandraConnection.getInstance().getDatabookStore().deleteHashTagsComment(commentid,vreid,hashtags); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(result); + }catch(Exception e){ + logger.error("Unable to delete hashtags.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("get-vre-hashtags-occurrences-lib") + public Response getVREHashtagsWithOccurrenceLib( + @QueryParam("vreid") + String vreid + ) throws ValidationException { + + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + Map hashtags = null; + + try{ + logger.info("getting vre hashtags occurrences " + vreid); + hashtags = CassandraConnection.getInstance().getDatabookStore().getVREHashtagsWithOccurrence(vreid); + responseBean.setResult(hashtags); + responseBean.setMessage(""); + responseBean.setSuccess(true); + }catch(Exception e){ + logger.error("Unable to retrieve such comments.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("get-vre-hashtags-occurrences-time-lib") + public Response getVREHashtagsWithOccurrenceFilteredByTimeLib( + @QueryParam("vreid") + String vreid, + @QueryParam("time") + @Min(value = 0, message="time cannot be negative") + long timestamp + ) throws ValidationException { + + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + Map hashtags = null; + + try{ + logger.info("getting vre hashtags occurrences " + vreid); + hashtags = CassandraConnection.getInstance().getDatabookStore().getVREHashtagsWithOccurrenceFilteredByTime(vreid, timestamp); + responseBean.setResult(hashtags); + responseBean.setMessage(""); + responseBean.setSuccess(true); + }catch(Exception e){ + logger.error("Unable to retrieve such comments.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("get-vre-post-by-hashtag-lib") + public Response getVREFeedsByHashtagLib( + @QueryParam("vreid") + String vreid, + @QueryParam("hashtag") + String hashtag + ) throws ValidationException { + hashtag = "#" + hashtag; + + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + List posts = null; + + try{ + logger.info("getting vre hashtags occurrences " + vreid); + posts = CassandraConnection.getInstance().getDatabookStore().getVREPostsByHashtag(vreid, hashtag); + responseBean.setResult(posts); + responseBean.setMessage(""); + responseBean.setSuccess(true); + }catch(Exception e){ + logger.error("Unable to retrieve such comments.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + +} diff --git a/src/main/java/org/gcube/portal/social/networking/ws/methods/v2/Invites.java b/src/main/java/org/gcube/portal/social/networking/ws/lib/Invites.java similarity index 95% rename from src/main/java/org/gcube/portal/social/networking/ws/methods/v2/Invites.java rename to src/main/java/org/gcube/portal/social/networking/ws/lib/Invites.java index c89a861..c9e0afe 100644 --- a/src/main/java/org/gcube/portal/social/networking/ws/methods/v2/Invites.java +++ b/src/main/java/org/gcube/portal/social/networking/ws/lib/Invites.java @@ -1,6 +1,14 @@ -package org.gcube.portal.social.networking.ws.methods.v2; +package org.gcube.portal.social.networking.ws.lib; -import java.util.List; +import com.webcohesion.enunciate.metadata.Ignore; +import com.webcohesion.enunciate.metadata.rs.RequestHeader; +import com.webcohesion.enunciate.metadata.rs.RequestHeaders; +import org.gcube.portal.databook.shared.Invite; +import org.gcube.portal.databook.shared.InviteOperationResult; +import org.gcube.portal.databook.shared.InviteStatus; +import org.gcube.portal.social.networking.ws.outputs.ResponseBean; +import org.gcube.portal.social.networking.ws.utils.CassandraConnection; +import org.slf4j.LoggerFactory; import javax.validation.Valid; import javax.validation.ValidationException; @@ -9,25 +17,19 @@ import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; - -import org.gcube.portal.databook.shared.*; -import org.gcube.portal.social.networking.ws.utils.CassandraConnection; -import org.gcube.portal.social.networking.ws.outputs.ResponseBean; -import org.slf4j.LoggerFactory; - -import com.webcohesion.enunciate.metadata.rs.RequestHeader; -import com.webcohesion.enunciate.metadata.rs.RequestHeaders; +import java.util.List; /** * REST interface for the social networking library (hash tags). * @author Ahmed Ibrahim ISTI-CNR */ -@Path("2/invites") +@Path("lib/invites") @RequestHeaders ({ @RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"), @RequestHeader( name = "Content-Type", description = "application/json") }) +@Ignore public class Invites { // Logger diff --git a/src/main/java/org/gcube/portal/social/networking/ws/lib/Likes.java b/src/main/java/org/gcube/portal/social/networking/ws/lib/Likes.java new file mode 100644 index 0000000..2169323 --- /dev/null +++ b/src/main/java/org/gcube/portal/social/networking/ws/lib/Likes.java @@ -0,0 +1,147 @@ +package org.gcube.portal.social.networking.ws.lib; + + +import com.webcohesion.enunciate.metadata.Ignore; +import com.webcohesion.enunciate.metadata.rs.RequestHeader; +import com.webcohesion.enunciate.metadata.rs.RequestHeaders; +import org.gcube.portal.databook.shared.Like; +import org.gcube.portal.social.networking.ws.outputs.ResponseBean; +import org.gcube.portal.social.networking.ws.utils.CassandraConnection; +import org.slf4j.LoggerFactory; + +import javax.validation.Valid; +import javax.validation.ValidationException; +import javax.validation.constraints.NotNull; +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; +import java.util.List; + +/** + * REST interface for the social networking library (likes). + * @author Ahmed Ibrahim ISTI-CNR + */ +@Path("lib/likes") +@RequestHeaders ({ + @RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"), + @RequestHeader( name = "Content-Type", description = "application/json") +}) +@Ignore +public class Likes { + + // Logger + private static final org.slf4j.Logger logger = LoggerFactory.getLogger(Likes.class); + + //library api + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("like-lib") + public Response likeLib( + @NotNull(message="like to add is missing") + @Valid + Like like + ) throws ValidationException{ + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + logger.info("Writing like with likeid " + like.getKey()); + boolean result = CassandraConnection.getInstance().getDatabookStore().like(like); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(result); + }catch(Exception e){ + logger.error("Unable to write comment.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("unlike-lib") + public Response unlikeLib( + @QueryParam("userid") + String userid, + @QueryParam("likeid") + String likeid, + @QueryParam("feedid") + String feedid + ) throws ValidationException{ + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + logger.info("Writing unlike with likeid " + likeid); + boolean result = CassandraConnection.getInstance().getDatabookStore().unlike(userid,likeid,feedid); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(result); + }catch(Exception e){ + logger.error("Unable to write comment.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("get-all-liked-posts-by-user-lib") + public Response getAllLikedPostIdsByUserLib( + @QueryParam("userid") + String userid + ) throws ValidationException{ + + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + List likes = null; + + try{ + logger.info("Retrieving likes for user id " + userid); + likes = CassandraConnection.getInstance().getDatabookStore().getAllLikedPostIdsByUser(userid); + responseBean.setResult(likes); + responseBean.setMessage(""); + responseBean.setSuccess(true); + }catch(Exception e){ + logger.error("Unable to retrieve such likes.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("get-all-likes-by-post-lib") + public Response getAllLikesByPostLib( + @QueryParam("postid") + String postid + ) throws ValidationException{ + + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + List likes = null; + + try{ + logger.info("Retrieving likes for post id " + postid); + likes = CassandraConnection.getInstance().getDatabookStore().getAllLikesByPost(postid); + responseBean.setResult(likes); + responseBean.setMessage(""); + responseBean.setSuccess(true); + }catch(Exception e){ + logger.error("Unable to retrieve such likes.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } +} diff --git a/src/main/java/org/gcube/portal/social/networking/ws/lib/Notifications.java b/src/main/java/org/gcube/portal/social/networking/ws/lib/Notifications.java new file mode 100644 index 0000000..d719dd2 --- /dev/null +++ b/src/main/java/org/gcube/portal/social/networking/ws/lib/Notifications.java @@ -0,0 +1,338 @@ +package org.gcube.portal.social.networking.ws.lib; + +import com.webcohesion.enunciate.metadata.Ignore; +import com.webcohesion.enunciate.metadata.rs.RequestHeader; +import com.webcohesion.enunciate.metadata.rs.RequestHeaders; +import org.gcube.portal.databook.shared.Notification; +import org.gcube.portal.databook.shared.NotificationChannelType; +import org.gcube.portal.databook.shared.NotificationType; +import org.gcube.portal.social.networking.ws.outputs.ResponseBean; +import org.gcube.portal.social.networking.ws.utils.CassandraConnection; +import org.slf4j.LoggerFactory; + +import javax.validation.Valid; +import javax.validation.ValidationException; +import javax.validation.constraints.NotNull; +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; +import java.util.List; +import java.util.Map; + +/** + * REST interface for the social networking library (notifications). + * @author Ahmed Ibrahim ISTI-CNR + */ +@Path("lib/notifications") +@RequestHeaders ({ + @RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"), + @RequestHeader( name = "Content-Type", description = "application/json") +}) +@Ignore +public class Notifications { + + // Logger + private static final org.slf4j.Logger logger = LoggerFactory.getLogger(Notifications.class); + private static final String INFRASTRUCTURE_MANAGER_ROLE = "Infrastructure-Manager"; + + //library api + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("save-notification-lib") + public Response saveNotificationLib( + @NotNull(message="notification to add is missing") + @Valid + Notification not + ) throws ValidationException{ + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + boolean result = CassandraConnection.getInstance().getDatabookStore().saveNotification(not); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(result); + }catch(Exception e){ + logger.error("Unable to write comment.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("read-notification-lib") + public Response readNotificationLib( + @QueryParam("notid") + String notid + ) throws ValidationException{ + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + Notification result = CassandraConnection.getInstance().getDatabookStore().readNotification(notid); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(true); + }catch(Exception e){ + logger.error("Unable to write comment.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("set-notification-read-lib") + public Response setNotificationReadLib( + @QueryParam("notid") + String notid + ) throws ValidationException{ + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + boolean result = CassandraConnection.getInstance().getDatabookStore().setNotificationRead(notid); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(result); + }catch(Exception e){ + logger.error("Unable to write comment.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("get-all-notifications-user") + public Response getAllNotificationByUserLib( + @QueryParam("userid") + String userid, + @QueryParam("limit") + int limit + ) throws ValidationException{ + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + List result = CassandraConnection.getInstance().getDatabookStore().getAllNotificationByUser(userid,limit); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(true); + }catch(Exception e){ + logger.error("Unable to write comment.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("get-unread-notifications-user") + public Response getUnreadNotificationsByUserLib( + @QueryParam("userid") + String userid + ) throws ValidationException{ + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + List result = CassandraConnection.getInstance().getDatabookStore().getUnreadNotificationsByUser(userid); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(true); + }catch(Exception e){ + logger.error("Unable to write comment.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("get-range-notifications-user") + public Response getRangeNotificationsByUserLib( + @QueryParam("userid") + String userid, + @QueryParam("from") + int from, + @QueryParam("quantity") + int quantity + ) throws ValidationException{ + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + List result = CassandraConnection.getInstance().getDatabookStore().getRangeNotificationsByUser(userid,from, quantity); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(true); + }catch(Exception e){ + logger.error("Unable to write comment.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("set-all-notification-read-lib") + public Response setAllNotificationReadByUserLib( + @QueryParam("userid") + String userid + ) throws ValidationException{ + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + boolean result = CassandraConnection.getInstance().getDatabookStore().setAllNotificationReadByUser(userid); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(result); + }catch(Exception e){ + logger.error("Unable to write comment.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("check-unread-notification-lib") + public Response checkUnreadNotificationsLib( + @QueryParam("userid") + String userid + ) throws ValidationException{ + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + boolean result = CassandraConnection.getInstance().getDatabookStore().checkUnreadNotifications(userid); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(true); + }catch(Exception e){ + logger.error("Unable to write comment.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("check-unread-messages-notification-lib") + public Response checkUnreadMessagesNotificationsLib( + @QueryParam("userid") + String userid + ) throws ValidationException{ + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + boolean result = CassandraConnection.getInstance().getDatabookStore().checkUnreadMessagesNotifications(userid); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(true); + }catch(Exception e){ + logger.error("Unable to write comment.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("get-user-notification-channels-lib") + public Response getUserNotificationChannelsLib( + @QueryParam("userid") + String userid, + @NotNull(message="attachment to add is missing") + @Valid + NotificationType notificationType + ) throws ValidationException{ + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + List result = CassandraConnection.getInstance().getDatabookStore().getUserNotificationChannels(userid,notificationType); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(true); + }catch(Exception e){ + logger.error("Unable to write comment.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("set-notification-preference-lib") + public Response setUserNotificationPreferencesLib( + @QueryParam("userid") + String userid, + @NotNull(message="attachment to add is missing") + @Valid + Map enabledChannels + ) throws ValidationException{ + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + boolean result = CassandraConnection.getInstance().getDatabookStore().setUserNotificationPreferences(userid,enabledChannels); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(true); + }catch(Exception e){ + logger.error("Unable to write comment.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("get-notification-preference-lib") + public Response getUserNotificationPreferencesLib( + @QueryParam("userid") + String userid + ) throws ValidationException{ + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + Map result = CassandraConnection.getInstance().getDatabookStore().getUserNotificationPreferences(userid); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(true); + }catch(Exception e){ + logger.error("Unable to write comment.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + +} diff --git a/src/main/java/org/gcube/portal/social/networking/ws/lib/Posts.java b/src/main/java/org/gcube/portal/social/networking/ws/lib/Posts.java new file mode 100644 index 0000000..7530adb --- /dev/null +++ b/src/main/java/org/gcube/portal/social/networking/ws/lib/Posts.java @@ -0,0 +1,485 @@ +package org.gcube.portal.social.networking.ws.lib; + + +import com.webcohesion.enunciate.metadata.Ignore; +import com.webcohesion.enunciate.metadata.rs.RequestHeader; +import com.webcohesion.enunciate.metadata.rs.RequestHeaders; +import org.gcube.portal.databook.shared.*; +import org.gcube.portal.social.networking.ws.outputs.ResponseBean; +import org.gcube.portal.social.networking.ws.utils.CassandraConnection; +import org.slf4j.LoggerFactory; + +import javax.validation.Valid; +import javax.validation.ValidationException; +import javax.validation.constraints.NotNull; +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; +import java.util.List; + +/** + * REST interface for the social networking library (posts). + * @author Ahmed Ibrahim ISTI-CNR + */ +@Path("lib/posts") +@RequestHeaders ({ + @RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"), + @RequestHeader( name = "Content-Type", description = "application/json") +}) +@Ignore +public class Posts { + + // Logger + private static final org.slf4j.Logger logger = LoggerFactory.getLogger(Posts.class); + + //library api + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("save-user-post-lib") + public Response saveUserPostLib( + @NotNull(message="post to add is missing") + @Valid + Post post + ) throws ValidationException{ + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + boolean result = CassandraConnection.getInstance().getDatabookStore().saveUserPost(post); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(result); + }catch(Exception e){ + logger.error("Unable to write comment.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("save-user-post-attachments-lib") + public Response saveUserPostLib( + @NotNull(message="post to add is missing") + @Valid + PostWithAttachment postWithAttachment + ) throws ValidationException{ + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + Post post = postWithAttachment.getPost(); + logger.info("Post is " + post); + List attachments = postWithAttachment.getAttachments(); + logger.info("Attachments are " + attachments); + boolean result = CassandraConnection.getInstance().getDatabookStore().saveUserPost(post,attachments); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(result); + }catch(Exception e){ + logger.error("Unable to write comment.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("save-app-post-attachments-lib") + public Response saveAppPostLib( + @NotNull(message="post to add is missing") + @Valid + PostWithAttachment postWithAttachment + ) throws ValidationException{ + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + Post post = postWithAttachment.getPost(); + List attachments = postWithAttachment.getAttachments(); + boolean result = CassandraConnection.getInstance().getDatabookStore().saveAppPost(post,attachments); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(result); + }catch(Exception e){ + logger.error("Unable to write comment.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("save-app-post-lib") + public Response saveAppPostLib( + @NotNull(message="post to add is missing") + @Valid + Post post + ) throws ValidationException{ + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + boolean result = CassandraConnection.getInstance().getDatabookStore().saveAppPost(post); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(result); + }catch(Exception e){ + logger.error("Unable to write comment.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("save-post-to-vretimeline-lib") + public Response savePostToVRETimelineLib( + @QueryParam("postid") + String postid, + @QueryParam("vreid") + String vreid + ) throws ValidationException{ + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + boolean result = CassandraConnection.getInstance().getDatabookStore().savePostToVRETimeline(postid, vreid); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(result); + }catch(Exception e){ + logger.error("Unable to write comment.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("read-post-lib") + public Response readPostLib( + @QueryParam("postid") + String postid + ) throws ValidationException{ + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + Post result = CassandraConnection.getInstance().getDatabookStore().readPost(postid); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(true); + }catch(Exception e){ + logger.error("Unable to write comment.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("get-recent-posts-by-user-date-lib") + public Response getRecentPostsByUserAndDateLib( + @QueryParam("userid") + String userid, + @QueryParam("time") + long timeinmillis + ) throws ValidationException{ + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + List result = CassandraConnection.getInstance().getDatabookStore().getRecentPostsByUserAndDate(userid, timeinmillis); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(true); + }catch(Exception e){ + logger.error("Unable to write comment.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("delete-post-lib") + public Response deletePostLib( + @QueryParam("postid") + String postid + ) throws ValidationException{ + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + boolean result = CassandraConnection.getInstance().getDatabookStore().deletePost(postid); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(result); + }catch(Exception e){ + logger.error("Unable to write comment.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("get-all-posts-by-user-lib") + public Response getAllPostsByUserLib( + @QueryParam("userid") + String userid + ) throws ValidationException{ + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + List result = CassandraConnection.getInstance().getDatabookStore().getAllPostsByUser(userid); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(true); + }catch(Exception e){ + logger.error("Unable to write comment.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("get-all-posts-by-app-lib") + public Response getAllPostsByAppLib( + @QueryParam("appid") + String appid + ) throws ValidationException{ + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + List result = CassandraConnection.getInstance().getDatabookStore().getAllPostsByApp(appid); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(true); + }catch(Exception e){ + logger.error("Unable to write comment.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("get-recent-commented-posts-by-user-lib") + public Response getRecentCommentedPostsByUserAndDateLib( + @QueryParam("userid") + String userid, + @QueryParam("time") + long timeinmillis + ) throws ValidationException{ + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + List result = CassandraConnection.getInstance().getDatabookStore().getRecentCommentedPostsByUserAndDate(userid, timeinmillis); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(true); + }catch(Exception e){ + logger.error("Unable to write comment.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("get-portal-privacy-level-posts-lib") + public Response getAllPortalPrivacyLevelPostsLib() throws ValidationException{ + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + List result = CassandraConnection.getInstance().getDatabookStore().getAllPortalPrivacyLevelPosts(); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(true); + }catch(Exception e){ + logger.error("Unable to write comment.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("get-recent-posts-by-user-lib") + public Response getRecentPostsByUserLib( + @QueryParam("userid") + String userid, + @QueryParam("quantity") + int quantity + ) throws ValidationException{ + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + List result = CassandraConnection.getInstance().getDatabookStore().getRecentPostsByUser(userid, quantity); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(true); + }catch(Exception e){ + logger.error("Unable to write comment.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("get-all-posts-by-vre-lib") + public Response getAllPostsByVRELib( + @QueryParam("vreid") + String vreid + ) throws ValidationException{ + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + List result = CassandraConnection.getInstance().getDatabookStore().getAllPostsByVRE(vreid); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(true); + }catch(Exception e){ + logger.error("Unable to write comment.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("get-recent-posts-by-vre-lib") + public Response getRecentPostsByVRELib( + @QueryParam("vreid") + String vreid, + @QueryParam("quantity") + int quantity + ) throws ValidationException{ + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + List result = CassandraConnection.getInstance().getDatabookStore().getRecentPostsByVRE(vreid, quantity); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(true); + }catch(Exception e){ + logger.error("Unable to write comment.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("get-recent-posts-by-vre-range-lib") + public Response getRecentPostsByVREAndRangeLib( + @QueryParam("vreid") + String vreid, + @QueryParam("from") + int from, + @QueryParam("quantity") + int quantity + ) throws ValidationException{ + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + RangePosts result = CassandraConnection.getInstance().getDatabookStore().getRecentPostsByVREAndRange(vreid, from, quantity); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(true); + }catch(Exception e){ + logger.error("Unable to write comment.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("get-attachment-by-postid-lib") + public Response getAttachmentsByFeedIdLib( + @QueryParam("postid") + String postid + ) throws ValidationException{ + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + List result = CassandraConnection.getInstance().getDatabookStore().getAttachmentsByFeedId(postid); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(true); + }catch(Exception e){ + logger.error("Unable to write comment.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } + + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("get-all-vre-ids-lib") + public Response getAllVREIdsLib() throws ValidationException{ + ResponseBean responseBean = new ResponseBean(); + Status status = Status.OK; + try{ + List result = CassandraConnection.getInstance().getDatabookStore().getAllVREIds(); + responseBean.setResult(result); + responseBean.setMessage(""); + responseBean.setSuccess(true); + }catch(Exception e){ + logger.error("Unable to write comment.", e); + responseBean.setMessage(e.getMessage()); + responseBean.setSuccess(false); + status = Status.INTERNAL_SERVER_ERROR; + } + return Response.status(status).entity(responseBean).build(); + } +} diff --git a/src/main/java/org/gcube/portal/social/networking/ws/methods/v2/Comments.java b/src/main/java/org/gcube/portal/social/networking/ws/methods/v2/Comments.java index addca86..a32fe06 100644 --- a/src/main/java/org/gcube/portal/social/networking/ws/methods/v2/Comments.java +++ b/src/main/java/org/gcube/portal/social/networking/ws/methods/v2/Comments.java @@ -230,172 +230,4 @@ public class Comments { return Response.status(status).entity(responseBean).build(); } } - - - - - - //lib api - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("add-comment-lib") - public Response addCommentLib(@NotNull(message="Comment to write is missing") - @Valid - Comment comment)throws ValidationException { - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try { - logger.info("Writing comment with commentid " + comment.getKey()); - boolean result = CassandraConnection.getInstance().getDatabookStore().addComment(comment); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(result); - } catch (Exception e) { - logger.error("Unable to write comment.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - @GET - @Produces(MediaType.APPLICATION_JSON) - @Path("read-comment-by-id-lib") - public Response readCommentByIdLib(@QueryParam("commentid") - String commentid)throws ValidationException{ - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - logger.info("Getting comment with commentid " + commentid); - Comment result = CassandraConnection.getInstance().getDatabookStore().readCommentById(commentid); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(true); - }catch(Exception e){ - logger.error("Unable to find comment.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - @GET - @Produces(MediaType.APPLICATION_JSON) - @Path("get-comments-by-post-id-lib") - @StatusCodes ({ - @ResponseCode ( code = 200, condition = "The list of comments is put into the 'result' field"), - @ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT) - }) - public Response getAllCommentsByPostIdLib( - @NotNull - @QueryParam("postid") - String postid) { - - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - List comments = null; - - try{ - logger.info("Retrieving comments for postid " + postid); - comments = CassandraConnection.getInstance().getDatabookStore().getAllCommentByPost(postid); - responseBean.setResult(comments); - responseBean.setSuccess(true); - }catch(Exception e){ - logger.error("Unable to retrieve such comments.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - - return Response.status(status).entity(responseBean).build(); - } - - @GET - @Produces(MediaType.APPLICATION_JSON) - @Path("get-recent-comments-by-user-and-date-lib") - public Response getRecentCommentsByUserAndDateLib( - @QueryParam("time") - @Min(value = 0, message="time cannot be negative") - long timeInMillis, - @QueryParam("username") - String username - ) throws ValidationException{ - - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - List comments = null; - - try{ - logger.info("Retrieving comments for user id " + username); - comments = CassandraConnection.getInstance().getDatabookStore().getRecentCommentsByUserAndDate(username, timeInMillis); - responseBean.setResult(comments); - responseBean.setMessage(""); - responseBean.setSuccess(true); - }catch(Exception e){ - logger.error("Unable to retrieve such comments.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("edit-comment-lib") - public Response editCommentLib( - @NotNull(message="Comment to edit is missing") - @Valid - Comment comment - ) throws ValidationException{ - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - logger.info("Writing comment with commentid " + comment.getKey()); - boolean result = CassandraConnection.getInstance().getDatabookStore().editComment(comment); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(result); - }catch(Exception e){ - logger.error("Unable to write comment.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("delete-comment-lib") - public Response deleteCommentLib( - @QueryParam("commentid") - String commentid, - @QueryParam("postid") - String postid - ) throws ValidationException{ - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - logger.info("deleting comment with commentid " + commentid); - boolean result = CassandraConnection.getInstance().getDatabookStore().deleteComment(commentid, postid); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(result); - }catch(Exception e){ - logger.error("Unable to delete comment.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - } diff --git a/src/main/java/org/gcube/portal/social/networking/ws/methods/v2/HashTags.java b/src/main/java/org/gcube/portal/social/networking/ws/methods/v2/HashTags.java index bd07b86..944fa17 100644 --- a/src/main/java/org/gcube/portal/social/networking/ws/methods/v2/HashTags.java +++ b/src/main/java/org/gcube/portal/social/networking/ws/methods/v2/HashTags.java @@ -81,220 +81,4 @@ public class HashTags { return Response.status(status).entity(responseBean).build(); } - - - - - //lib api - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("save-hashtag-lib") - public Response saveHashTagsLib( - @QueryParam("feedid") - String feedid, - @QueryParam("vreid") - String vreid, - @NotNull(message="hashtag to save is missing") - @Valid - List hashtags - ) throws ValidationException { - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - logger.info("Saving hashtags " ); - boolean result = CassandraConnection.getInstance().getDatabookStore().saveHashTags(feedid,vreid,hashtags); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(result); - }catch(Exception e){ - logger.error("Unable to save hashtags.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("delete-hashtag-lib") - public Response deleteHashTagsLib( - @QueryParam("feedid") - String feedid, - @QueryParam("vreid") - String vreid, - @NotNull(message="hashtag to delete is missing") - @Valid - List hashtags - ) throws ValidationException{ - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - logger.info("deleting hashtags " ); - boolean result = CassandraConnection.getInstance().getDatabookStore().deleteHashTags(feedid,vreid,hashtags); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(result); - }catch(Exception e){ - logger.error("Unable to delete hashtags.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("save-hashtag-comment-lib") - public Response saveHashTagsCommentLib( - @QueryParam("commentid") - String commentid, - @QueryParam("vreid") - String vreid, - @NotNull(message="hashtag to save is missing") - @Valid - List hashtags - ) throws ValidationException{ - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - logger.info("Saving hashtags comments " ); - boolean result = CassandraConnection.getInstance().getDatabookStore().saveHashTagsComment(commentid,vreid,hashtags); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(result); - }catch(Exception e){ - logger.error("Unable to save hashtags comments.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("delete-hashtag-comment-lib") - public Response deleteHashTagsCommentLib( - @QueryParam("commentid") - String commentid, - @QueryParam("vreid") - String vreid, - @NotNull(message="hashtag to delete is missing") - @Valid - List hashtags - ) throws ValidationException{ - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - logger.info("deleting hashtags " ); - boolean result = CassandraConnection.getInstance().getDatabookStore().deleteHashTagsComment(commentid,vreid,hashtags); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(result); - }catch(Exception e){ - logger.error("Unable to delete hashtags.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - - @GET - @Produces(MediaType.APPLICATION_JSON) - @Path("get-vre-hashtags-occurrences-lib") - public Response getVREHashtagsWithOccurrenceLib( - @QueryParam("vreid") - String vreid - ) throws ValidationException { - - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - Map hashtags = null; - - try{ - logger.info("getting vre hashtags occurrences " + vreid); - hashtags = CassandraConnection.getInstance().getDatabookStore().getVREHashtagsWithOccurrence(vreid); - responseBean.setResult(hashtags); - responseBean.setMessage(""); - responseBean.setSuccess(true); - }catch(Exception e){ - logger.error("Unable to retrieve such comments.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - - @GET - @Produces(MediaType.APPLICATION_JSON) - @Path("get-vre-hashtags-occurrences-time-lib") - public Response getVREHashtagsWithOccurrenceFilteredByTimeLib( - @QueryParam("vreid") - String vreid, - @QueryParam("time") - @Min(value = 0, message="time cannot be negative") - long timestamp - ) throws ValidationException { - - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - Map hashtags = null; - - try{ - logger.info("getting vre hashtags occurrences " + vreid); - hashtags = CassandraConnection.getInstance().getDatabookStore().getVREHashtagsWithOccurrenceFilteredByTime(vreid, timestamp); - responseBean.setResult(hashtags); - responseBean.setMessage(""); - responseBean.setSuccess(true); - }catch(Exception e){ - logger.error("Unable to retrieve such comments.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - @GET - @Produces(MediaType.APPLICATION_JSON) - @Path("get-vre-post-by-hashtag-lib") - public Response getVREFeedsByHashtagLib( - @QueryParam("vreid") - String vreid, - @QueryParam("hashtag") - String hashtag - ) throws ValidationException { - hashtag = "#" + hashtag; - - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - List posts = null; - - try{ - logger.info("getting vre hashtags occurrences " + vreid); - posts = CassandraConnection.getInstance().getDatabookStore().getVREPostsByHashtag(vreid, hashtag); - responseBean.setResult(posts); - responseBean.setMessage(""); - responseBean.setSuccess(true); - }catch(Exception e){ - logger.error("Unable to retrieve such comments.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - } diff --git a/src/main/java/org/gcube/portal/social/networking/ws/methods/v2/Likes.java b/src/main/java/org/gcube/portal/social/networking/ws/methods/v2/Likes.java index a3fc120..5f83228 100644 --- a/src/main/java/org/gcube/portal/social/networking/ws/methods/v2/Likes.java +++ b/src/main/java/org/gcube/portal/social/networking/ws/methods/v2/Likes.java @@ -165,119 +165,4 @@ public class Likes { responseBean.setSuccess(true); return Response.status(status).entity(responseBean).build(); } - - - - - //library api - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("like-lib") - public Response likeLib( - @NotNull(message="like to add is missing") - @Valid - Like like - ) throws ValidationException{ - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - logger.info("Writing like with likeid " + like.getKey()); - boolean result = CassandraConnection.getInstance().getDatabookStore().like(like); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(result); - }catch(Exception e){ - logger.error("Unable to write comment.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("unlike-lib") - public Response unlikeLib( - @QueryParam("userid") - String userid, - @QueryParam("likeid") - String likeid, - @QueryParam("feedid") - String feedid - ) throws ValidationException{ - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - logger.info("Writing unlike with likeid " + likeid); - boolean result = CassandraConnection.getInstance().getDatabookStore().unlike(userid,likeid,feedid); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(result); - }catch(Exception e){ - logger.error("Unable to write comment.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - - @GET - @Produces(MediaType.APPLICATION_JSON) - @Path("get-all-liked-posts-by-user-lib") - public Response getAllLikedPostIdsByUserLib( - @QueryParam("userid") - String userid - ) throws ValidationException{ - - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - List likes = null; - - try{ - logger.info("Retrieving likes for user id " + userid); - likes = CassandraConnection.getInstance().getDatabookStore().getAllLikedPostIdsByUser(userid); - responseBean.setResult(likes); - responseBean.setMessage(""); - responseBean.setSuccess(true); - }catch(Exception e){ - logger.error("Unable to retrieve such likes.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - - @GET - @Produces(MediaType.APPLICATION_JSON) - @Path("get-all-likes-by-post-lib") - public Response getAllLikesByPostLib( - @QueryParam("postid") - String postid - ) throws ValidationException{ - - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - List likes = null; - - try{ - logger.info("Retrieving likes for post id " + postid); - likes = CassandraConnection.getInstance().getDatabookStore().getAllLikesByPost(postid); - responseBean.setResult(likes); - responseBean.setMessage(""); - responseBean.setSuccess(true); - }catch(Exception e){ - logger.error("Unable to retrieve such likes.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } } diff --git a/src/main/java/org/gcube/portal/social/networking/ws/methods/v2/Notifications.java b/src/main/java/org/gcube/portal/social/networking/ws/methods/v2/Notifications.java index 599abbb..3fb0b49 100644 --- a/src/main/java/org/gcube/portal/social/networking/ws/methods/v2/Notifications.java +++ b/src/main/java/org/gcube/portal/social/networking/ws/methods/v2/Notifications.java @@ -674,307 +674,4 @@ public class Notifications { } return usernames; } - - - - - //library api - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("save-notification-lib") - public Response saveNotificationLib( - @NotNull(message="notification to add is missing") - @Valid - Notification not - ) throws ValidationException{ - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - boolean result = CassandraConnection.getInstance().getDatabookStore().saveNotification(not); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(result); - }catch(Exception e){ - logger.error("Unable to write comment.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - @GET - @Produces(MediaType.APPLICATION_JSON) - @Path("read-notification-lib") - public Response readNotificationLib( - @QueryParam("notid") - String notid - ) throws ValidationException{ - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - Notification result = CassandraConnection.getInstance().getDatabookStore().readNotification(notid); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(true); - }catch(Exception e){ - logger.error("Unable to write comment.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("set-notification-read-lib") - public Response setNotificationReadLib( - @QueryParam("notid") - String notid - ) throws ValidationException{ - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - boolean result = CassandraConnection.getInstance().getDatabookStore().setNotificationRead(notid); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(result); - }catch(Exception e){ - logger.error("Unable to write comment.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - @GET - @Produces(MediaType.APPLICATION_JSON) - @Path("get-all-notifications-user") - public Response getAllNotificationByUserLib( - @QueryParam("userid") - String userid, - @QueryParam("limit") - int limit - ) throws ValidationException{ - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - List result = CassandraConnection.getInstance().getDatabookStore().getAllNotificationByUser(userid,limit); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(true); - }catch(Exception e){ - logger.error("Unable to write comment.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - @GET - @Produces(MediaType.APPLICATION_JSON) - @Path("get-unread-notifications-user") - public Response getUnreadNotificationsByUserLib( - @QueryParam("userid") - String userid - ) throws ValidationException{ - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - List result = CassandraConnection.getInstance().getDatabookStore().getUnreadNotificationsByUser(userid); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(true); - }catch(Exception e){ - logger.error("Unable to write comment.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - @GET - @Produces(MediaType.APPLICATION_JSON) - @Path("get-range-notifications-user") - public Response getRangeNotificationsByUserLib( - @QueryParam("userid") - String userid, - @QueryParam("from") - int from, - @QueryParam("quantity") - int quantity - ) throws ValidationException{ - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - List result = CassandraConnection.getInstance().getDatabookStore().getRangeNotificationsByUser(userid,from, quantity); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(true); - }catch(Exception e){ - logger.error("Unable to write comment.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("set-all-notification-read-lib") - public Response setAllNotificationReadByUserLib( - @QueryParam("userid") - String userid - ) throws ValidationException{ - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - boolean result = CassandraConnection.getInstance().getDatabookStore().setAllNotificationReadByUser(userid); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(result); - }catch(Exception e){ - logger.error("Unable to write comment.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("check-unread-notification-lib") - public Response checkUnreadNotificationsLib( - @QueryParam("userid") - String userid - ) throws ValidationException{ - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - boolean result = CassandraConnection.getInstance().getDatabookStore().checkUnreadNotifications(userid); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(true); - }catch(Exception e){ - logger.error("Unable to write comment.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("check-unread-messages-notification-lib") - public Response checkUnreadMessagesNotificationsLib( - @QueryParam("userid") - String userid - ) throws ValidationException{ - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - boolean result = CassandraConnection.getInstance().getDatabookStore().checkUnreadMessagesNotifications(userid); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(true); - }catch(Exception e){ - logger.error("Unable to write comment.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("get-user-notification-channels-lib") - public Response getUserNotificationChannelsLib( - @QueryParam("userid") - String userid, - @NotNull(message="attachment to add is missing") - @Valid - NotificationType notificationType - ) throws ValidationException{ - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - List result = CassandraConnection.getInstance().getDatabookStore().getUserNotificationChannels(userid,notificationType); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(true); - }catch(Exception e){ - logger.error("Unable to write comment.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("set-notification-preference-lib") - public Response setUserNotificationPreferencesLib( - @QueryParam("userid") - String userid, - @NotNull(message="attachment to add is missing") - @Valid - Map enabledChannels - ) throws ValidationException{ - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - boolean result = CassandraConnection.getInstance().getDatabookStore().setUserNotificationPreferences(userid,enabledChannels); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(true); - }catch(Exception e){ - logger.error("Unable to write comment.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - - @GET - @Produces(MediaType.APPLICATION_JSON) - @Path("get-notification-preference-lib") - public Response getUserNotificationPreferencesLib( - @QueryParam("userid") - String userid - ) throws ValidationException{ - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - Map result = CassandraConnection.getInstance().getDatabookStore().getUserNotificationPreferences(userid); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(true); - }catch(Exception e){ - logger.error("Unable to write comment.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - } diff --git a/src/main/java/org/gcube/portal/social/networking/ws/methods/v2/Posts.java b/src/main/java/org/gcube/portal/social/networking/ws/methods/v2/Posts.java index 21290f4..a3dbacc 100644 --- a/src/main/java/org/gcube/portal/social/networking/ws/methods/v2/Posts.java +++ b/src/main/java/org/gcube/portal/social/networking/ws/methods/v2/Posts.java @@ -19,6 +19,7 @@ import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; +import org.gcube.portal.databook.shared.PostWithAttachment; import org.gcube.common.authorization.library.provider.AuthorizationProvider; import org.gcube.common.authorization.library.utils.Caller; @@ -639,456 +640,4 @@ public class Posts { } return Response.status(status).entity(responseBean).build(); } - - - - - - //library api - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("save-user-post-lib") - public Response saveUserPostLib( - @NotNull(message="post to add is missing") - @Valid - Post post - ) throws ValidationException{ - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - boolean result = CassandraConnection.getInstance().getDatabookStore().saveUserPost(post); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(result); - }catch(Exception e){ - logger.error("Unable to write comment.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("save-user-post-attachments-lib") - public Response saveUserPostLib( - @NotNull(message="post to add is missing") - @Valid - Map> obj - ) throws ValidationException{ - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - Post post = obj.keySet().iterator().next(); - List attachments = obj.get(post); - boolean result = CassandraConnection.getInstance().getDatabookStore().saveUserPost(post,attachments); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(result); - }catch(Exception e){ - logger.error("Unable to write comment.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("save-app-post-attachments-lib") - public Response saveAppPostLib( - @NotNull(message="post to add is missing") - @Valid - Map> obj - ) throws ValidationException{ - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - Post post = obj.keySet().iterator().next(); - List attachments = obj.get(post); - boolean result = CassandraConnection.getInstance().getDatabookStore().saveAppPost(post,attachments); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(result); - }catch(Exception e){ - logger.error("Unable to write comment.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("save-app-post-lib") - public Response saveAppPostLib( - @NotNull(message="post to add is missing") - @Valid - Post post - ) throws ValidationException{ - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - boolean result = CassandraConnection.getInstance().getDatabookStore().saveAppPost(post); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(result); - }catch(Exception e){ - logger.error("Unable to write comment.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("save-post-to-vretimeline-lib") - public Response savePostToVRETimelineLib( - @QueryParam("postid") - String postid, - @QueryParam("vreid") - String vreid - ) throws ValidationException{ - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - boolean result = CassandraConnection.getInstance().getDatabookStore().savePostToVRETimeline(postid, vreid); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(result); - }catch(Exception e){ - logger.error("Unable to write comment.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - - @GET - @Produces(MediaType.APPLICATION_JSON) - @Path("read-post-lib") - public Response readPostLib( - @QueryParam("postid") - String postid - ) throws ValidationException{ - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - Post result = CassandraConnection.getInstance().getDatabookStore().readPost(postid); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(true); - }catch(Exception e){ - logger.error("Unable to write comment.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - - @GET - @Produces(MediaType.APPLICATION_JSON) - @Path("get-recent-posts-by-user-date-lib") - public Response getRecentPostsByUserAndDateLib( - @QueryParam("userid") - String userid, - @QueryParam("time") - long timeinmillis - ) throws ValidationException{ - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - List result = CassandraConnection.getInstance().getDatabookStore().getRecentPostsByUserAndDate(userid, timeinmillis); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(true); - }catch(Exception e){ - logger.error("Unable to write comment.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("delete-post-lib") - public Response deletePostLib( - @QueryParam("postid") - String postid - ) throws ValidationException{ - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - boolean result = CassandraConnection.getInstance().getDatabookStore().deletePost(postid); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(result); - }catch(Exception e){ - logger.error("Unable to write comment.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - - @GET - @Produces(MediaType.APPLICATION_JSON) - @Path("get-all-posts-by-user-lib") - public Response getAllPostsByUserLib( - @QueryParam("userid") - String userid - ) throws ValidationException{ - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - List result = CassandraConnection.getInstance().getDatabookStore().getAllPostsByUser(userid); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(true); - }catch(Exception e){ - logger.error("Unable to write comment.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - - @GET - @Produces(MediaType.APPLICATION_JSON) - @Path("get-all-posts-by-app-lib") - public Response getAllPostsByAppLib( - @QueryParam("appid") - String appid - ) throws ValidationException{ - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - List result = CassandraConnection.getInstance().getDatabookStore().getAllPostsByApp(appid); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(true); - }catch(Exception e){ - logger.error("Unable to write comment.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - - @GET - @Produces(MediaType.APPLICATION_JSON) - @Path("get-recent-commented-posts-by-user-lib") - public Response getRecentCommentedPostsByUserAndDateLib( - @QueryParam("userid") - String userid, - @QueryParam("time") - long timeinmillis - ) throws ValidationException{ - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - List result = CassandraConnection.getInstance().getDatabookStore().getRecentCommentedPostsByUserAndDate(userid, timeinmillis); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(true); - }catch(Exception e){ - logger.error("Unable to write comment.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - - - @GET - @Produces(MediaType.APPLICATION_JSON) - @Path("get-portal-privacy-level-posts-lib") - public Response getAllPortalPrivacyLevelPostsLib() throws ValidationException{ - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - List result = CassandraConnection.getInstance().getDatabookStore().getAllPortalPrivacyLevelPosts(); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(true); - }catch(Exception e){ - logger.error("Unable to write comment.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - - @GET - @Produces(MediaType.APPLICATION_JSON) - @Path("get-recent-posts-by-user-lib") - public Response getRecentPostsByUserLib( - @QueryParam("userid") - String userid, - @QueryParam("quantity") - int quantity - ) throws ValidationException{ - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - List result = CassandraConnection.getInstance().getDatabookStore().getRecentPostsByUser(userid, quantity); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(true); - }catch(Exception e){ - logger.error("Unable to write comment.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - @GET - @Produces(MediaType.APPLICATION_JSON) - @Path("get-all-posts-by-vre-lib") - public Response getAllPostsByVRELib( - @QueryParam("vreid") - String vreid - ) throws ValidationException{ - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - List result = CassandraConnection.getInstance().getDatabookStore().getAllPostsByVRE(vreid); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(true); - }catch(Exception e){ - logger.error("Unable to write comment.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - @GET - @Produces(MediaType.APPLICATION_JSON) - @Path("get-recent-posts-by-vre-lib") - public Response getRecentPostsByVRELib( - @QueryParam("vreid") - String vreid, - @QueryParam("quantity") - int quantity - ) throws ValidationException{ - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - List result = CassandraConnection.getInstance().getDatabookStore().getRecentPostsByVRE(vreid, quantity); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(true); - }catch(Exception e){ - logger.error("Unable to write comment.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - @GET - @Produces(MediaType.APPLICATION_JSON) - @Path("get-recent-posts-by-vre-range-lib") - public Response getRecentPostsByVREAndRangeLib( - @QueryParam("vreid") - String vreid, - @QueryParam("from") - int from, - @QueryParam("quantity") - int quantity - ) throws ValidationException{ - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - RangePosts result = CassandraConnection.getInstance().getDatabookStore().getRecentPostsByVREAndRange(vreid, from, quantity); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(true); - }catch(Exception e){ - logger.error("Unable to write comment.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - - @GET - @Produces(MediaType.APPLICATION_JSON) - @Path("get-attachment-by-postid-lib") - public Response getAttachmentsByFeedIdLib( - @QueryParam("postid") - String postid - ) throws ValidationException{ - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - List result = CassandraConnection.getInstance().getDatabookStore().getAttachmentsByFeedId(postid); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(true); - }catch(Exception e){ - logger.error("Unable to write comment.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } - - - @GET - @Produces(MediaType.APPLICATION_JSON) - @Path("get-all-vre-ids-lib") - public Response getAllVREIdsLib() throws ValidationException{ - ResponseBean responseBean = new ResponseBean(); - Status status = Status.OK; - try{ - List result = CassandraConnection.getInstance().getDatabookStore().getAllVREIds(); - responseBean.setResult(result); - responseBean.setMessage(""); - responseBean.setSuccess(true); - }catch(Exception e){ - logger.error("Unable to write comment.", e); - responseBean.setMessage(e.getMessage()); - responseBean.setSuccess(false); - status = Status.INTERNAL_SERVER_ERROR; - } - return Response.status(status).entity(responseBean).build(); - } }