Social service - More REST API resoruces
This commit is contained in:
parent
0551ee95f3
commit
a55ba31d9a
2
pom.xml
2
pom.xml
|
@ -6,7 +6,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.gcube.tools</groupId>
|
<groupId>org.gcube.tools</groupId>
|
||||||
<artifactId>maven-parent</artifactId>
|
<artifactId>maven-parent</artifactId>
|
||||||
<version>1.2.0</version>
|
<version>1.1.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<groupId>org.gcube.portal</groupId>
|
<groupId>org.gcube.portal</groupId>
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package org.gcube.portal.social.networking.ws.methods.v2;
|
package org.gcube.portal.social.networking.ws.methods.v2;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
@ -16,12 +15,10 @@ import javax.ws.rs.POST;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.QueryParam;
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.GenericType;
|
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import javax.ws.rs.core.Response.Status;
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
|
||||||
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
||||||
import org.gcube.common.authorization.library.utils.Caller;
|
import org.gcube.common.authorization.library.utils.Caller;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
|
@ -52,8 +49,8 @@ import com.webcohesion.enunciate.metadata.rs.StatusCodes;
|
||||||
*/
|
*/
|
||||||
@Path("2/comments")
|
@Path("2/comments")
|
||||||
@RequestHeaders ({
|
@RequestHeaders ({
|
||||||
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
||||||
@RequestHeader( name = "Content-Type", description = "application/json")
|
@RequestHeader( name = "Content-Type", description = "application/json")
|
||||||
})
|
})
|
||||||
public class Comments {
|
public class Comments {
|
||||||
|
|
||||||
|
@ -62,20 +59,20 @@ public class Comments {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Retrieve the list of comments belonging to the post id (key) of the token in the related context
|
* Retrieve the list of comments belonging to the post id (key) of the token in the related context
|
||||||
* @param key the key as in the POST JSON representation
|
* @param key the key as in the POST JSON representation
|
||||||
* @pathExample /get-comments-by-post-id?key=9ea137e9-6606-45ff-a1a2-94d4e8760583
|
* @pathExample /get-comments-by-post-id?key=9ea137e9-6606-45ff-a1a2-94d4e8760583
|
||||||
* @return the list of comments belonging to the post identified by the key in the context identified by the token
|
* @return the list of comments belonging to the post identified by the key in the context identified by the token
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@Path("get-comments-by-post-id")
|
@Path("get-comments-by-post-id")
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 200, condition = "The list of comments is put into the 'result' field"),
|
@ResponseCode ( code = 200, condition = "The list of comments is put into the 'result' field"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response getAllCommentsByPostId(
|
public Response getAllCommentsByPostId(
|
||||||
@NotNull
|
@NotNull
|
||||||
@QueryParam("key")
|
@QueryParam("key")
|
||||||
String key) {
|
String key) {
|
||||||
|
|
||||||
ResponseBean responseBean = new ResponseBean();
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
@ -108,8 +105,8 @@ public class Comments {
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@Path("get-comments-user")
|
@Path("get-comments-user")
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 200, condition = "The list of comments is put into the 'result' field"),
|
@ResponseCode ( code = 200, condition = "The list of comments is put into the 'result' field"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response getCommentsUser() {
|
public Response getCommentsUser() {
|
||||||
|
|
||||||
|
@ -143,10 +140,10 @@ public class Comments {
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@Path("get-comments-user-by-time")
|
@Path("get-comments-user-by-time")
|
||||||
public Response getCommentsUserByTime(
|
public Response getCommentsUserByTime(
|
||||||
@QueryParam("time")
|
@QueryParam("time")
|
||||||
@Min(value = 0, message="time cannot be negative")
|
@Min(value = 0, message="time cannot be negative")
|
||||||
long timeInMillis
|
long timeInMillis
|
||||||
) throws ValidationException{
|
) throws ValidationException{
|
||||||
|
|
||||||
ResponseBean responseBean = new ResponseBean();
|
ResponseBean responseBean = new ResponseBean();
|
||||||
Status status = Status.OK;
|
Status status = Status.OK;
|
||||||
|
@ -182,12 +179,12 @@ public class Comments {
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 201, condition = "Successfull created, the new comment is reported in the 'result' field of the returned object"),
|
@ResponseCode ( code = 201, condition = "Successfull created, the new comment is reported in the 'result' field of the returned object"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response writeComment(
|
public Response writeComment(
|
||||||
@NotNull(message="Comment to write is missing")
|
@NotNull(message="Comment to write is missing")
|
||||||
@Valid
|
@Valid
|
||||||
CommentInputBean comment) throws ValidationException {
|
CommentInputBean comment) throws ValidationException {
|
||||||
Caller caller = AuthorizationProvider.instance.get();
|
Caller caller = AuthorizationProvider.instance.get();
|
||||||
String username = caller.getClient().getId();
|
String username = caller.getClient().getId();
|
||||||
|
@ -223,7 +220,7 @@ public class Comments {
|
||||||
responseBean.setSuccess(false);
|
responseBean.setSuccess(false);
|
||||||
status = Status.INTERNAL_SERVER_ERROR;
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
return Response.status(status).entity(responseBean).build();
|
return Response.status(status).entity(responseBean).build();
|
||||||
}
|
}
|
||||||
catch(Exception e) {
|
catch(Exception e) {
|
||||||
logger.error("Unable to write comment", e);
|
logger.error("Unable to write comment", e);
|
||||||
responseBean.setMessage("Could not reach the DB to write the comment, something went wrong");
|
responseBean.setMessage("Could not reach the DB to write the comment, something went wrong");
|
||||||
|
@ -235,14 +232,16 @@ public class Comments {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//lib api
|
//lib api
|
||||||
@POST
|
@POST
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@Path("add-comment-lib")
|
@Path("add-comment-lib")
|
||||||
public Response addCommentLib(@NotNull(message="Comment to write is missing")
|
public Response addCommentLib(@NotNull(message="Comment to write is missing")
|
||||||
@Valid
|
@Valid
|
||||||
Comment comment)throws ValidationException {
|
Comment comment)throws ValidationException {
|
||||||
ResponseBean responseBean = new ResponseBean();
|
ResponseBean responseBean = new ResponseBean();
|
||||||
Status status = Status.OK;
|
Status status = Status.OK;
|
||||||
try {
|
try {
|
||||||
|
@ -396,4 +395,6 @@ public class Comments {
|
||||||
}
|
}
|
||||||
return Response.status(status).entity(responseBean).build();
|
return Response.status(status).entity(responseBean).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package org.gcube.portal.social.networking.ws.methods.v2;
|
package org.gcube.portal.social.networking.ws.methods.v2;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -10,18 +8,14 @@ import javax.validation.ValidationException;
|
||||||
import javax.validation.constraints.Min;
|
import javax.validation.constraints.Min;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.*;
|
||||||
import javax.ws.rs.core.GenericType;
|
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import javax.ws.rs.core.Response.Status;
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
|
||||||
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
||||||
import org.gcube.common.authorization.library.utils.Caller;
|
import org.gcube.common.authorization.library.utils.Caller;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.portal.databook.server.DatabookStore;
|
import org.gcube.portal.databook.server.DatabookStore;
|
||||||
import org.gcube.portal.databook.shared.Comment;
|
|
||||||
import org.gcube.portal.databook.shared.Feed;
|
|
||||||
import org.gcube.portal.databook.shared.Post;
|
import org.gcube.portal.databook.shared.Post;
|
||||||
import org.gcube.portal.social.networking.liferay.ws.GroupManagerWSBuilder;
|
import org.gcube.portal.social.networking.liferay.ws.GroupManagerWSBuilder;
|
||||||
import org.gcube.portal.social.networking.ws.outputs.ResponseBean;
|
import org.gcube.portal.social.networking.ws.outputs.ResponseBean;
|
||||||
|
@ -39,9 +33,9 @@ import com.webcohesion.enunciate.metadata.rs.StatusCodes;
|
||||||
*/
|
*/
|
||||||
@Path("2/hashtags")
|
@Path("2/hashtags")
|
||||||
@RequestHeaders ({
|
@RequestHeaders ({
|
||||||
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
||||||
@RequestHeader( name = "Content-Type", description = "application/json")
|
@RequestHeader( name = "Content-Type", description = "application/json")
|
||||||
})
|
})
|
||||||
public class HashTags {
|
public class HashTags {
|
||||||
|
|
||||||
// Logger
|
// Logger
|
||||||
|
@ -51,8 +45,8 @@ public class HashTags {
|
||||||
@Path("get-hashtags-and-occurrences/")
|
@Path("get-hashtags-and-occurrences/")
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 200, condition = "Hashtags and occurrences retrieved, reported in the 'result' field of the returned object"),
|
@ResponseCode ( code = 200, condition = "Hashtags and occurrences retrieved, reported in the 'result' field of the returned object"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
/**
|
/**
|
||||||
* @return hashtags in the context bound to the auth token
|
* @return hashtags in the context bound to the auth token
|
||||||
|
@ -103,7 +97,7 @@ public class HashTags {
|
||||||
@NotNull(message="hashtag to save is missing")
|
@NotNull(message="hashtag to save is missing")
|
||||||
@Valid
|
@Valid
|
||||||
List<String> hashtags
|
List<String> hashtags
|
||||||
) throws ValidationException{
|
) throws ValidationException {
|
||||||
ResponseBean responseBean = new ResponseBean();
|
ResponseBean responseBean = new ResponseBean();
|
||||||
Status status = Status.OK;
|
Status status = Status.OK;
|
||||||
try{
|
try{
|
||||||
|
@ -281,6 +275,7 @@ public class HashTags {
|
||||||
@QueryParam("hashtag")
|
@QueryParam("hashtag")
|
||||||
String hashtag
|
String hashtag
|
||||||
) throws ValidationException {
|
) throws ValidationException {
|
||||||
|
hashtag = "#" + hashtag;
|
||||||
|
|
||||||
ResponseBean responseBean = new ResponseBean();
|
ResponseBean responseBean = new ResponseBean();
|
||||||
Status status = Status.OK;
|
Status status = Status.OK;
|
||||||
|
@ -300,4 +295,5 @@ public class HashTags {
|
||||||
}
|
}
|
||||||
return Response.status(status).entity(responseBean).build();
|
return Response.status(status).entity(responseBean).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,9 +41,9 @@ public class Invites {
|
||||||
@QueryParam("email")
|
@QueryParam("email")
|
||||||
String email
|
String email
|
||||||
) throws ValidationException{
|
) throws ValidationException{
|
||||||
ResponseBean responseBean = new ResponseBean();
|
ResponseBean responseBean = new ResponseBean();
|
||||||
Status status = Status.OK;
|
Status status = Status.OK;
|
||||||
String inv = null;
|
String inv = null;
|
||||||
|
|
||||||
try{
|
try{
|
||||||
logger.info("Retrieving invite for vre " + vreid);
|
logger.info("Retrieving invite for vre " + vreid);
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
package org.gcube.portal.social.networking.ws.methods.v2;
|
package org.gcube.portal.social.networking.ws.methods.v2;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import javax.validation.ValidationException;
|
import javax.validation.ValidationException;
|
||||||
import javax.validation.constraints.Min;
|
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
|
@ -14,16 +12,13 @@ import javax.ws.rs.POST;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.QueryParam;
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.GenericType;
|
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import javax.ws.rs.core.Response.Status;
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
|
||||||
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
||||||
import org.gcube.common.authorization.library.utils.Caller;
|
import org.gcube.common.authorization.library.utils.Caller;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.portal.databook.shared.Comment;
|
|
||||||
import org.gcube.portal.databook.shared.Like;
|
import org.gcube.portal.databook.shared.Like;
|
||||||
import org.gcube.portal.social.networking.ws.inputs.LikeInputBean;
|
import org.gcube.portal.social.networking.ws.inputs.LikeInputBean;
|
||||||
import org.gcube.portal.social.networking.ws.inputs.PostId;
|
import org.gcube.portal.social.networking.ws.inputs.PostId;
|
||||||
|
@ -43,8 +38,8 @@ import com.webcohesion.enunciate.metadata.rs.StatusCodes;
|
||||||
*/
|
*/
|
||||||
@Path("2/likes")
|
@Path("2/likes")
|
||||||
@RequestHeaders ({
|
@RequestHeaders ({
|
||||||
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
||||||
@RequestHeader( name = "Content-Type", description = "application/json")
|
@RequestHeader( name = "Content-Type", description = "application/json")
|
||||||
})
|
})
|
||||||
public class Likes {
|
public class Likes {
|
||||||
|
|
||||||
|
@ -53,20 +48,20 @@ public class Likes {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Retrieve the list of likes belonging to the post id (key) of the token in the related context
|
* Retrieve the list of likes belonging to the post id (key) of the token in the related context
|
||||||
* @param key the key as in the POST JSON representation
|
* @param key the key as in the POST JSON representation
|
||||||
* @pathExample /get-likes-by-post-id?key=9ea137e9-6606-45ff-a1a2-94d4e8760583
|
* @pathExample /get-likes-by-post-id?key=9ea137e9-6606-45ff-a1a2-94d4e8760583
|
||||||
* @return the list of likes belonging to the post identified by the key in the context identified by the token
|
* @return the list of likes belonging to the post identified by the key in the context identified by the token
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@Path("get-likes-by-post-id")
|
@Path("get-likes-by-post-id")
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 200, condition = "The list of likes is put into the 'result' field"),
|
@ResponseCode ( code = 200, condition = "The list of likes is put into the 'result' field"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response getAllLikesByPostId(
|
public Response getAllLikesByPostId(
|
||||||
@NotNull
|
@NotNull
|
||||||
@QueryParam("key")
|
@QueryParam("key")
|
||||||
String key) {
|
String key) {
|
||||||
|
|
||||||
ResponseBean responseBean = new ResponseBean();
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
@ -93,8 +88,8 @@ public class Likes {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new like to a post in the context of the token
|
* Create a new like to a post in the context of the token
|
||||||
* @param post The post id to be liked
|
* @param postid The post id to be liked
|
||||||
* @return true if everything is OK
|
* @return true if everything is OK
|
||||||
* @throws ValidationException
|
* @throws ValidationException
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
|
@ -102,12 +97,12 @@ public class Likes {
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 201, condition = "Successful created, the like operation result is reported in the 'result' field of the returned object"),
|
@ResponseCode ( code = 201, condition = "Successful created, the like operation result is reported in the 'result' field of the returned object"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response like(
|
public Response like(
|
||||||
@NotNull(message="Post to like is missing")
|
@NotNull(message="Post to like is missing")
|
||||||
@Valid
|
@Valid
|
||||||
PostId post) throws ValidationException {
|
PostId post) throws ValidationException {
|
||||||
Caller caller = AuthorizationProvider.instance.get();
|
Caller caller = AuthorizationProvider.instance.get();
|
||||||
String username = caller.getClient().getId();
|
String username = caller.getClient().getId();
|
||||||
|
@ -130,10 +125,10 @@ public class Likes {
|
||||||
responseBean.setSuccess(true);
|
responseBean.setSuccess(true);
|
||||||
return Response.status(status).entity(responseBean).build();
|
return Response.status(status).entity(responseBean).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unlike to a post in the context of the token
|
* Unlike to a post in the context of the token
|
||||||
* @param likeInputBean The post id to be liked
|
* @param postid The post id to be liked
|
||||||
* @return true if everything is OK
|
* @return true if everything is OK
|
||||||
* @throws ValidationException
|
* @throws ValidationException
|
||||||
*/
|
*/
|
||||||
|
@ -142,12 +137,12 @@ public class Likes {
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 201, condition = "The unlike operation result is reported in the 'result' field of the returned object"),
|
@ResponseCode ( code = 201, condition = "The unlike operation result is reported in the 'result' field of the returned object"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response unlike(
|
public Response unlike(
|
||||||
@NotNull(message="Post to unlike is missing")
|
@NotNull(message="Post to unlike is missing")
|
||||||
@Valid
|
@Valid
|
||||||
LikeInputBean likeInputBean) throws ValidationException {
|
LikeInputBean likeInputBean) throws ValidationException {
|
||||||
Caller caller = AuthorizationProvider.instance.get();
|
Caller caller = AuthorizationProvider.instance.get();
|
||||||
String username = caller.getClient().getId();
|
String username = caller.getClient().getId();
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
package org.gcube.portal.social.networking.ws.methods.v2;
|
package org.gcube.portal.social.networking.ws.methods.v2;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import javax.validation.ValidationException;
|
import javax.validation.ValidationException;
|
||||||
|
@ -14,12 +17,10 @@ import javax.ws.rs.POST;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.QueryParam;
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.GenericType;
|
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import javax.ws.rs.core.Response.Status;
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
|
||||||
import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager;
|
import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager;
|
||||||
import org.gcube.applicationsupportlayer.social.NotificationsManager;
|
import org.gcube.applicationsupportlayer.social.NotificationsManager;
|
||||||
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite;
|
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite;
|
||||||
|
@ -30,7 +31,10 @@ import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
import org.gcube.common.authorization.library.utils.Caller;
|
import org.gcube.common.authorization.library.utils.Caller;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.common.scope.impl.ScopeBean;
|
import org.gcube.common.scope.impl.ScopeBean;
|
||||||
import org.gcube.portal.databook.shared.*;
|
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.databook.shared.RunningJob;
|
||||||
import org.gcube.portal.notifications.bean.GenericItemBean;
|
import org.gcube.portal.notifications.bean.GenericItemBean;
|
||||||
import org.gcube.portal.notifications.thread.JobStatusNotificationThread;
|
import org.gcube.portal.notifications.thread.JobStatusNotificationThread;
|
||||||
import org.gcube.portal.social.networking.caches.SocialNetworkingSiteFinder;
|
import org.gcube.portal.social.networking.caches.SocialNetworkingSiteFinder;
|
||||||
|
@ -77,8 +81,8 @@ import com.webcohesion.enunciate.metadata.rs.StatusCodes;
|
||||||
*/
|
*/
|
||||||
@Path("2/notifications")
|
@Path("2/notifications")
|
||||||
@RequestHeaders ({
|
@RequestHeaders ({
|
||||||
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
||||||
@RequestHeader( name = "Content-Type", description = "application/json")
|
@RequestHeader( name = "Content-Type", description = "application/json")
|
||||||
})
|
})
|
||||||
public class Notifications {
|
public class Notifications {
|
||||||
|
|
||||||
|
@ -97,15 +101,15 @@ public class Notifications {
|
||||||
@Path("get-range-notifications/")
|
@Path("get-range-notifications/")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 200, condition = "Notifications retrieved and reported in the 'result' field of the returned object"),
|
@ResponseCode ( code = 200, condition = "Notifications retrieved and reported in the 'result' field of the returned object"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response getRangeNotifications(
|
public Response getRangeNotifications(
|
||||||
@DefaultValue("1") @QueryParam("from") @Min(value=1, message="from must be greater or equal to 1")
|
@DefaultValue("1") @QueryParam("from") @Min(value=1, message="from must be greater or equal to 1")
|
||||||
int from,
|
int from,
|
||||||
@DefaultValue("10") @QueryParam("quantity") @Min(value=0, message="quantity must be greater or equal to 0")
|
@DefaultValue("10") @QueryParam("quantity") @Min(value=0, message="quantity must be greater or equal to 0")
|
||||||
int quantity
|
int quantity
|
||||||
) throws ValidationException{
|
) throws ValidationException{
|
||||||
|
|
||||||
Caller caller = AuthorizationProvider.instance.get();
|
Caller caller = AuthorizationProvider.instance.get();
|
||||||
String username = caller.getClient().getId();
|
String username = caller.getClient().getId();
|
||||||
|
@ -138,19 +142,19 @@ public class Notifications {
|
||||||
* @responseExample application/json { "success": true, "message": null "result": true }
|
* @responseExample application/json { "success": true, "message": null "result": true }
|
||||||
* @param username the username you want to check
|
* @param username the username you want to check
|
||||||
* @return true if the notification for the user are disabled (Catalogue and Workspace ones)
|
* @return true if the notification for the user are disabled (Catalogue and Workspace ones)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("is-user-disabled/")
|
@Path("is-user-disabled/")
|
||||||
|
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 200, condition = "true if the notification for the username given as query param are disabled (Catalogue and Workspace ones), false otherwise"),
|
@ResponseCode ( code = 200, condition = "true if the notification for the username given as query param are disabled (Catalogue and Workspace ones), false otherwise"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
@AuthorizationControl(allowedRoles={INFRASTRUCTURE_MANAGER_ROLE}, exception=AuthException.class)
|
@AuthorizationControl(allowedRoles={INFRASTRUCTURE_MANAGER_ROLE}, exception=AuthException.class)
|
||||||
public Response isUserDisabled(
|
public Response isUserDisabled(
|
||||||
@QueryParam("username") @NotNull(message="username cannot be null")
|
@QueryParam("username") @NotNull(message="username cannot be null")
|
||||||
String username) throws ValidationException{
|
String username) throws ValidationException{
|
||||||
ResponseBean responseBean = new ResponseBean();
|
ResponseBean responseBean = new ResponseBean();
|
||||||
Status status = Status.OK;
|
Status status = Status.OK;
|
||||||
|
@ -185,8 +189,8 @@ public class Notifications {
|
||||||
// })
|
// })
|
||||||
// @AuthorizationControl(allowedRoles={INFRASTRUCTURE_MANAGER_ROLE}, exception=AuthException.class)
|
// @AuthorizationControl(allowedRoles={INFRASTRUCTURE_MANAGER_ROLE}, exception=AuthException.class)
|
||||||
// public Response setUserNotifications(
|
// public Response setUserNotifications(
|
||||||
// @NotNull(message="input is missing")
|
// @NotNull(message="input is missing")
|
||||||
// @Valid
|
// @Valid
|
||||||
// UserSetNotificationBean setting) throws ValidationException{
|
// UserSetNotificationBean setting) throws ValidationException{
|
||||||
//
|
//
|
||||||
// Caller caller = AuthorizationProvider.instance.get();
|
// Caller caller = AuthorizationProvider.instance.get();
|
||||||
|
@ -219,10 +223,10 @@ public class Notifications {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* @deprecated
|
||||||
* @param usernameToCheck
|
* @param usernameToCheck
|
||||||
* @return true if notification are enabled for this user
|
* @return true if notification are enabled for this user
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
private boolean isNotificationEnabled(String usernameToCheck) throws IOException {
|
private boolean isNotificationEnabled(String usernameToCheck) throws IOException {
|
||||||
// MemcachedClient entries = new DistributedCacheClient().getMemcachedClient();
|
// MemcachedClient entries = new DistributedCacheClient().getMemcachedClient();
|
||||||
|
@ -235,12 +239,12 @@ public class Notifications {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// /**
|
// /**
|
||||||
// *
|
// *
|
||||||
// * @param username the user you want to disable or enable notifications (max 29 days)
|
// * @param username the user you want to disable or enable notifications (max 29 days)
|
||||||
// * @param callerId the username or clientid of the operation executor
|
// * @param callerId the username or clientid of the operation executor
|
||||||
// * @param disable true if you want to disable the notifications for this user
|
// * @param disable true if you want to disable the notifications for this user
|
||||||
// * @return true if the operation was performed
|
// * @return true if the operation was performed
|
||||||
// * @throws IOException
|
// * @throws IOException
|
||||||
// */
|
// */
|
||||||
// private Boolean setUserNotificationsOnOff(String username, boolean disable, String callerId) throws IOException {
|
// private Boolean setUserNotificationsOnOff(String username, boolean disable, String callerId) throws IOException {
|
||||||
// MemcachedClient entries = new DistributedCacheClient().getMemcachedClient();
|
// MemcachedClient entries = new DistributedCacheClient().getMemcachedClient();
|
||||||
|
@ -273,12 +277,12 @@ public class Notifications {
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 200, condition = "Notification is sent correctly"),
|
@ResponseCode ( code = 200, condition = "Notification is sent correctly"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response notifyJobStatus(
|
public Response notifyJobStatus(
|
||||||
@NotNull(message="input is missing")
|
@NotNull(message="input is missing")
|
||||||
@Valid
|
@Valid
|
||||||
JobNotificationBean job) throws ValidationException{
|
JobNotificationBean job) throws ValidationException{
|
||||||
|
|
||||||
Caller caller = AuthorizationProvider.instance.get();
|
Caller caller = AuthorizationProvider.instance.get();
|
||||||
|
@ -329,12 +333,12 @@ public class Notifications {
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 200, condition = "Catalogue Notification is sent correctly"),
|
@ResponseCode ( code = 200, condition = "Catalogue Notification is sent correctly"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response catalogue(
|
public Response catalogue(
|
||||||
@NotNull(message="input is missing")
|
@NotNull(message="input is missing")
|
||||||
@Valid
|
@Valid
|
||||||
CatalogueEvent event) throws ValidationException, UserManagementSystemException, UserRetrievalFault{
|
CatalogueEvent event) throws ValidationException, UserManagementSystemException, UserRetrievalFault{
|
||||||
|
|
||||||
Caller caller = AuthorizationProvider.instance.get();
|
Caller caller = AuthorizationProvider.instance.get();
|
||||||
|
@ -350,14 +354,14 @@ public class Notifications {
|
||||||
SecurityTokenProvider.instance.set(LiferayJSONWsCredentials.getSingleton().getNotifierUserToken());
|
SecurityTokenProvider.instance.set(LiferayJSONWsCredentials.getSingleton().getNotifierUserToken());
|
||||||
username = jarvis.getUsername();
|
username = jarvis.getUsername();
|
||||||
fullName = caller.getClient().getId().replace("service-account-", ""); // the actual name of the IAM Client
|
fullName = caller.getClient().getId().replace("service-account-", ""); // the actual name of the IAM Client
|
||||||
senderUser = um.getUserByUsername(username);
|
senderUser = um.getUserByUsername(username);
|
||||||
user = new SocialNetworkingUser(senderUser.getUsername(), senderUser.getEmail(), fullName, senderUser.getUserAvatarURL());
|
user = new SocialNetworkingUser(senderUser.getUsername(), senderUser.getEmail(), fullName, senderUser.getUserAvatarURL());
|
||||||
}else{
|
}else{
|
||||||
username = caller.getClient().getId();
|
username = caller.getClient().getId();
|
||||||
senderUser = um.getUserByUsername(username);
|
senderUser = um.getUserByUsername(username);
|
||||||
user = new SocialNetworkingUser(senderUser.getUsername(), senderUser.getEmail(), senderUser.getFullname(), senderUser.getUserAvatarURL());
|
user = new SocialNetworkingUser(senderUser.getUsername(), senderUser.getEmail(), senderUser.getFullname(), senderUser.getUserAvatarURL());
|
||||||
}
|
}
|
||||||
|
|
||||||
String context = ScopeProvider.instance.get();
|
String context = ScopeProvider.instance.get();
|
||||||
|
|
||||||
logger.debug("catalogue notifications from user = " + username);
|
logger.debug("catalogue notifications from user = " + username);
|
||||||
|
@ -367,9 +371,9 @@ public class Notifications {
|
||||||
try {
|
try {
|
||||||
logger.debug("catalogue notifications type is " + event.getType());
|
logger.debug("catalogue notifications type is " + event.getType());
|
||||||
SocialNetworkingSite site = SocialNetworkingSiteFinder.getSocialNetworkingSiteFromScope(context);
|
SocialNetworkingSite site = SocialNetworkingSiteFinder.getSocialNetworkingSiteFromScope(context);
|
||||||
|
|
||||||
|
|
||||||
NotificationsManager nm = new ApplicationNotificationsManager(UserManagerWSBuilder.getInstance().getUserManager(), site, context, user);
|
NotificationsManager nm = new ApplicationNotificationsManager(UserManagerWSBuilder.getInstance().getUserManager(), site, context, user);
|
||||||
|
|
||||||
String[] idsToNotify = event.getIdsToNotify();
|
String[] idsToNotify = event.getIdsToNotify();
|
||||||
if (! event.idsAsGroup()) {
|
if (! event.idsAsGroup()) {
|
||||||
|
@ -378,7 +382,7 @@ public class Notifications {
|
||||||
if (isNotificationEnabled(userIdToNotify)) {
|
if (isNotificationEnabled(userIdToNotify)) {
|
||||||
String username2Notify = null;
|
String username2Notify = null;
|
||||||
try {
|
try {
|
||||||
username2Notify = um.getUserByUsername(userIdToNotify).getUsername();
|
username2Notify = um.getUserByUsername(userIdToNotify).getUsername();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
status = Status.BAD_REQUEST;
|
status = Status.BAD_REQUEST;
|
||||||
|
@ -388,14 +392,14 @@ public class Notifications {
|
||||||
return Response.status(status).entity(responseBean).build();
|
return Response.status(status).entity(responseBean).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
deliveryResult =
|
deliveryResult =
|
||||||
nm.notifyCatalogueEvent(
|
nm.notifyCatalogueEvent(
|
||||||
CatalogueEventTypeMapper.getType(event.getType()),
|
CatalogueEventTypeMapper.getType(event.getType()),
|
||||||
username2Notify,
|
username2Notify,
|
||||||
event.getItemId(),
|
event.getItemId(),
|
||||||
event.getNotifyText(),
|
event.getNotifyText(),
|
||||||
event.getItemURL());
|
event.getItemURL());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Log.info("Notification disabled (admin) for user "+userIdToNotify + " will not notify");
|
Log.info("Notification disabled (admin) for user "+userIdToNotify + " will not notify");
|
||||||
}
|
}
|
||||||
|
@ -416,20 +420,20 @@ public class Notifications {
|
||||||
String[] userIdsToNotify = getUsernamesByContext(scope).toArray(new String[0]); //resolve the members
|
String[] userIdsToNotify = getUsernamesByContext(scope).toArray(new String[0]); //resolve the members
|
||||||
for (int j = 0; j < userIdsToNotify.length; j++) {
|
for (int j = 0; j < userIdsToNotify.length; j++) {
|
||||||
String userIdToNotify = userIdsToNotify[j];
|
String userIdToNotify = userIdsToNotify[j];
|
||||||
if (isNotificationEnabled(userIdToNotify)) {
|
if (isNotificationEnabled(userIdToNotify)) {
|
||||||
deliveryResult =
|
deliveryResult =
|
||||||
nm.notifyCatalogueEvent(
|
nm.notifyCatalogueEvent(
|
||||||
CatalogueEventTypeMapper.getType(event.getType()),
|
CatalogueEventTypeMapper.getType(event.getType()),
|
||||||
userIdToNotify,
|
userIdToNotify,
|
||||||
event.getItemId(),
|
event.getItemId(),
|
||||||
event.getNotifyText(),
|
event.getNotifyText(),
|
||||||
event.getItemURL());
|
event.getItemURL());
|
||||||
} else {
|
} else {
|
||||||
Log.info("Notification disabled (admin) for user "+userIdToNotify + " will not notify");
|
Log.info("Notification disabled (admin) for user "+userIdToNotify + " will not notify");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(IllegalArgumentException e) {
|
catch(IllegalArgumentException e) {
|
||||||
status = Status.BAD_REQUEST;
|
status = Status.BAD_REQUEST;
|
||||||
logger.error("Context not valid", e);
|
logger.error("Context not valid", e);
|
||||||
|
@ -469,12 +473,12 @@ public class Notifications {
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 200, condition = "Workspace Notification is sent correctly"),
|
@ResponseCode ( code = 200, condition = "Workspace Notification is sent correctly"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response workspace(
|
public Response workspace(
|
||||||
@NotNull(message="input is missing")
|
@NotNull(message="input is missing")
|
||||||
@Valid
|
@Valid
|
||||||
WorkspaceEvent event) throws ValidationException{
|
WorkspaceEvent event) throws ValidationException{
|
||||||
|
|
||||||
Caller caller = AuthorizationProvider.instance.get();
|
Caller caller = AuthorizationProvider.instance.get();
|
||||||
|
@ -498,23 +502,23 @@ public class Notifications {
|
||||||
SecurityTokenProvider.instance.set(LiferayJSONWsCredentials.getSingleton().getNotifierUserToken());
|
SecurityTokenProvider.instance.set(LiferayJSONWsCredentials.getSingleton().getNotifierUserToken());
|
||||||
username = jarvis.getUsername();
|
username = jarvis.getUsername();
|
||||||
fullName = caller.getClient().getId().replace("service-account-", ""); // the actual name of the IAM Client
|
fullName = caller.getClient().getId().replace("service-account-", ""); // the actual name of the IAM Client
|
||||||
senderUser = um.getUserByUsername(username);
|
senderUser = um.getUserByUsername(username);
|
||||||
user = new SocialNetworkingUser(senderUser.getUsername(), senderUser.getEmail(), fullName, senderUser.getUserAvatarURL());
|
user = new SocialNetworkingUser(senderUser.getUsername(), senderUser.getEmail(), fullName, senderUser.getUserAvatarURL());
|
||||||
}else{
|
}else{
|
||||||
username = caller.getClient().getId();
|
username = caller.getClient().getId();
|
||||||
senderUser = um.getUserByUsername(username);
|
senderUser = um.getUserByUsername(username);
|
||||||
user = new SocialNetworkingUser(senderUser.getUsername(), senderUser.getEmail(), senderUser.getFullname(), senderUser.getUserAvatarURL());
|
user = new SocialNetworkingUser(senderUser.getUsername(), senderUser.getEmail(), senderUser.getFullname(), senderUser.getUserAvatarURL());
|
||||||
}
|
}
|
||||||
NotificationsManager nm = new ApplicationNotificationsManager(UserManagerWSBuilder.getInstance().getUserManager(), site, context, user);
|
NotificationsManager nm = new ApplicationNotificationsManager(UserManagerWSBuilder.getInstance().getUserManager(), site, context, user);
|
||||||
|
|
||||||
String[] idsToNotify = event.getIdsToNotify();
|
String[] idsToNotify = event.getIdsToNotify();
|
||||||
if (! event.idsAsGroup()) {
|
if (! event.idsAsGroup()) {
|
||||||
for (int i = 0; i < idsToNotify.length; i++) {
|
for (int i = 0; i < idsToNotify.length; i++) {
|
||||||
String userIdToNotify = idsToNotify[i];
|
String userIdToNotify = idsToNotify[i];
|
||||||
if (isNotificationEnabled(userIdToNotify)) {
|
if (isNotificationEnabled(userIdToNotify)) {
|
||||||
String username2Notify = "";
|
String username2Notify = "";
|
||||||
try {
|
try {
|
||||||
username2Notify = um.getUserByUsername(userIdToNotify).getUsername();
|
username2Notify = um.getUserByUsername(userIdToNotify).getUsername();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
status = Status.NOT_ACCEPTABLE;
|
status = Status.NOT_ACCEPTABLE;
|
||||||
|
@ -544,14 +548,14 @@ public class Notifications {
|
||||||
String[] userIdsToNotify = getUsernamesByContext(scope).toArray(new String[0]); //resolve the members
|
String[] userIdsToNotify = getUsernamesByContext(scope).toArray(new String[0]); //resolve the members
|
||||||
for (int j = 0; j < userIdsToNotify.length; j++) {
|
for (int j = 0; j < userIdsToNotify.length; j++) {
|
||||||
String userIdToNotify = userIdsToNotify[j];
|
String userIdToNotify = userIdsToNotify[j];
|
||||||
if (isNotificationEnabled(userIdToNotify))
|
if (isNotificationEnabled(userIdToNotify))
|
||||||
deliveryResult = notifyWorkspaceEvent(event, nm, userIdToNotify);
|
deliveryResult = notifyWorkspaceEvent(event, nm, userIdToNotify);
|
||||||
else {
|
else {
|
||||||
Log.info("Notification disabled (admin) for user "+userIdToNotify + " will not notify");
|
Log.info("Notification disabled (admin) for user "+userIdToNotify + " will not notify");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(IllegalArgumentException e) {
|
catch(IllegalArgumentException e) {
|
||||||
status = Status.BAD_REQUEST;
|
status = Status.BAD_REQUEST;
|
||||||
logger.error("Context not valid", e);
|
logger.error("Context not valid", e);
|
||||||
|
@ -580,7 +584,7 @@ public class Notifications {
|
||||||
return Response.status(status).entity(responseBean).build();
|
return Response.status(status).entity(responseBean).build();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param event
|
* @param event
|
||||||
* @param nm
|
* @param nm
|
||||||
* @param idToNotify
|
* @param idToNotify
|
||||||
|
@ -589,49 +593,49 @@ public class Notifications {
|
||||||
private boolean notifyWorkspaceEvent(WorkspaceEvent event, NotificationsManager nm, String idToNotify) {
|
private boolean notifyWorkspaceEvent(WorkspaceEvent event, NotificationsManager nm, String idToNotify) {
|
||||||
try {
|
try {
|
||||||
switch (event.getType()) {
|
switch (event.getType()) {
|
||||||
case ITEM_NEW: {
|
case ITEM_NEW: {
|
||||||
AddedItemEvent itemBean = (AddedItemEvent) event;
|
AddedItemEvent itemBean = (AddedItemEvent) event;
|
||||||
return nm.notifyAddedItem(idToNotify, WorkspaceItemMapper.getFileItem(itemBean.getItem()), WorkspaceItemMapper.getSharedFolder(itemBean.getItem().getParent()));
|
return nm.notifyAddedItem(idToNotify, WorkspaceItemMapper.getFileItem(itemBean.getItem()), WorkspaceItemMapper.getSharedFolder(itemBean.getItem().getParent()));
|
||||||
}
|
}
|
||||||
case ITEM_UPDATE: {
|
case ITEM_UPDATE: {
|
||||||
UpdatedItemEvent itemBean = (UpdatedItemEvent) event;
|
UpdatedItemEvent itemBean = (UpdatedItemEvent) event;
|
||||||
return nm.notifyUpdatedItem(idToNotify, WorkspaceItemMapper.getFileItem(itemBean.getItem()), WorkspaceItemMapper.getSharedFolder(itemBean.getItem().getParent()));
|
return nm.notifyUpdatedItem(idToNotify, WorkspaceItemMapper.getFileItem(itemBean.getItem()), WorkspaceItemMapper.getSharedFolder(itemBean.getItem().getParent()));
|
||||||
}
|
}
|
||||||
case ITEM_DELETE: {
|
case ITEM_DELETE: {
|
||||||
DeletedItemEvent itemBean = (DeletedItemEvent) event;
|
DeletedItemEvent itemBean = (DeletedItemEvent) event;
|
||||||
return nm.notifyRemovedItem(idToNotify, itemBean.getItemName(), WorkspaceItemMapper.getSharedFolder(itemBean.getFolder()));
|
return nm.notifyRemovedItem(idToNotify, itemBean.getItemName(), WorkspaceItemMapper.getSharedFolder(itemBean.getFolder()));
|
||||||
}
|
}
|
||||||
case FOLDER_SHARE: {
|
case FOLDER_SHARE: {
|
||||||
SharedFolderEvent itemBean = (SharedFolderEvent) event;
|
SharedFolderEvent itemBean = (SharedFolderEvent) event;
|
||||||
return nm.notifyFolderSharing(idToNotify, WorkspaceItemMapper.getSharedFolder(itemBean.getFolder()));
|
return nm.notifyFolderSharing(idToNotify, WorkspaceItemMapper.getSharedFolder(itemBean.getFolder()));
|
||||||
}
|
}
|
||||||
case FOLDER_UNSHARE: {
|
case FOLDER_UNSHARE: {
|
||||||
UnsharedFolderEvent itemBean = (UnsharedFolderEvent) event;
|
UnsharedFolderEvent itemBean = (UnsharedFolderEvent) event;
|
||||||
return nm.notifyFolderUnsharing(idToNotify, itemBean.getUnsharedFolderId(), itemBean.getUnsharedFolderName());
|
return nm.notifyFolderUnsharing(idToNotify, itemBean.getUnsharedFolderId(), itemBean.getUnsharedFolderName());
|
||||||
}
|
}
|
||||||
case FOLDER_RENAME: {
|
case FOLDER_RENAME: {
|
||||||
RenamedFolderEvent itemBean = (RenamedFolderEvent) event;
|
RenamedFolderEvent itemBean = (RenamedFolderEvent) event;
|
||||||
return nm.notifyFolderRenaming(idToNotify, itemBean.getPreviousName(), itemBean.getNewName(), itemBean.getRenamedFolderId());
|
return nm.notifyFolderRenaming(idToNotify, itemBean.getPreviousName(), itemBean.getNewName(), itemBean.getRenamedFolderId());
|
||||||
}
|
}
|
||||||
case FOLDER_ADMIN_UPGRADE: {
|
case FOLDER_ADMIN_UPGRADE: {
|
||||||
FolderAdminUpgradeEvent itemBean = (FolderAdminUpgradeEvent) event;
|
FolderAdminUpgradeEvent itemBean = (FolderAdminUpgradeEvent) event;
|
||||||
return nm.notifyAdministratorUpgrade(idToNotify, WorkspaceItemMapper.getSharedFolder(itemBean.getFolder()));
|
return nm.notifyAdministratorUpgrade(idToNotify, WorkspaceItemMapper.getSharedFolder(itemBean.getFolder()));
|
||||||
}
|
}
|
||||||
case FOLDER_ADMIN_DOWNGRADE: {
|
case FOLDER_ADMIN_DOWNGRADE: {
|
||||||
FolderAdminDowngradeEvent itemBean = (FolderAdminDowngradeEvent) event;
|
FolderAdminDowngradeEvent itemBean = (FolderAdminDowngradeEvent) event;
|
||||||
return nm.notifyAdministratorDowngrade(idToNotify, WorkspaceItemMapper.getSharedFolder(itemBean.getFolder()));
|
return nm.notifyAdministratorDowngrade(idToNotify, WorkspaceItemMapper.getSharedFolder(itemBean.getFolder()));
|
||||||
}
|
}
|
||||||
case FOLDER_ADDEDUSER: {
|
case FOLDER_ADDEDUSER: {
|
||||||
FolderAddedUserEvent itemBean = (FolderAddedUserEvent) event;
|
FolderAddedUserEvent itemBean = (FolderAddedUserEvent) event;
|
||||||
UserManager userManager = UserManagerWSBuilder.getInstance().getUserManager();
|
UserManager userManager = UserManagerWSBuilder.getInstance().getUserManager();
|
||||||
return nm.notifyFolderAddedUsers(idToNotify, WorkspaceItemMapper.getSharedFolder(itemBean.getFolder()), itemBean.getNewAddedUserIds(), userManager);
|
return nm.notifyFolderAddedUsers(idToNotify, WorkspaceItemMapper.getSharedFolder(itemBean.getFolder()), itemBean.getNewAddedUserIds(), userManager);
|
||||||
}
|
}
|
||||||
case FOLDER_REMOVEDUSER: {
|
case FOLDER_REMOVEDUSER: {
|
||||||
FolderRemovedUserEvent itemBean = (FolderRemovedUserEvent) event;
|
FolderRemovedUserEvent itemBean = (FolderRemovedUserEvent) event;
|
||||||
return nm.notifyFolderRemovedUser(idToNotify, WorkspaceItemMapper.getSharedFolder(itemBean.getFolder()));
|
return nm.notifyFolderRemovedUser(idToNotify, WorkspaceItemMapper.getSharedFolder(itemBean.getFolder()));
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch(Exception e){
|
} catch(Exception e){
|
||||||
logger.error("Unable to send job notification", e);
|
logger.error("Unable to send job notification", e);
|
||||||
|
@ -640,7 +644,7 @@ public class Notifications {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param context
|
* @param context
|
||||||
* @return
|
* @return
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
|
@ -672,6 +676,7 @@ public class Notifications {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//library api
|
//library api
|
||||||
@POST
|
@POST
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@ -970,4 +975,5 @@ public class Notifications {
|
||||||
}
|
}
|
||||||
return Response.status(status).entity(responseBean).build();
|
return Response.status(status).entity(responseBean).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package org.gcube.portal.social.networking.ws.methods.v2;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -17,12 +16,10 @@ import javax.ws.rs.POST;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.QueryParam;
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.GenericType;
|
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import javax.ws.rs.core.Response.Status;
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
|
||||||
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
||||||
import org.gcube.common.authorization.library.utils.Caller;
|
import org.gcube.common.authorization.library.utils.Caller;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
|
@ -32,7 +29,6 @@ import org.gcube.portal.databook.shared.ex.ColumnNameNotFoundException;
|
||||||
import org.gcube.portal.databook.shared.ex.FeedIDNotFoundException;
|
import org.gcube.portal.databook.shared.ex.FeedIDNotFoundException;
|
||||||
import org.gcube.portal.databook.shared.ex.FeedTypeNotFoundException;
|
import org.gcube.portal.databook.shared.ex.FeedTypeNotFoundException;
|
||||||
import org.gcube.portal.databook.shared.ex.PrivacyLevelTypeNotFoundException;
|
import org.gcube.portal.databook.shared.ex.PrivacyLevelTypeNotFoundException;
|
||||||
import org.gcube.portal.social.networking.ws.inputs.PostId;
|
|
||||||
import org.gcube.portal.social.networking.ws.inputs.PostInputBean;
|
import org.gcube.portal.social.networking.ws.inputs.PostInputBean;
|
||||||
import org.gcube.portal.social.networking.ws.outputs.ResponseBean;
|
import org.gcube.portal.social.networking.ws.outputs.ResponseBean;
|
||||||
import org.gcube.portal.social.networking.ws.utils.CassandraConnection;
|
import org.gcube.portal.social.networking.ws.utils.CassandraConnection;
|
||||||
|
@ -51,14 +47,14 @@ import com.webcohesion.enunciate.metadata.rs.StatusCodes;
|
||||||
*/
|
*/
|
||||||
@Path("2/posts")
|
@Path("2/posts")
|
||||||
@RequestHeaders ({
|
@RequestHeaders ({
|
||||||
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
||||||
@RequestHeader( name = "Content-Type", description = "application/json")
|
@RequestHeader( name = "Content-Type", description = "application/json")
|
||||||
})
|
})
|
||||||
public class Posts {
|
public class Posts {
|
||||||
|
|
||||||
// Logger
|
// Logger
|
||||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(Posts.class);
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(Posts.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve posts of the auth token's owner, and allow to filter them by time"
|
* Retrieve posts of the auth token's owner, and allow to filter them by time"
|
||||||
* @param timeInMillis The reference time since when retrieving posts
|
* @param timeInMillis The reference time since when retrieving posts
|
||||||
|
@ -69,13 +65,13 @@ public class Posts {
|
||||||
@Path("get-posts-user-since/")
|
@Path("get-posts-user-since/")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 200, condition = "Successful retrieval of posts, reported in the 'result' field of the returned object"),
|
@ResponseCode ( code = 200, condition = "Successful retrieval of posts, reported in the 'result' field of the returned object"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response getRecentPostsByUserAndDate(
|
public Response getRecentPostsByUserAndDate(
|
||||||
@QueryParam("time") @Min(value = 0, message="time cannot be negative")
|
@QueryParam("time") @Min(value = 0, message="time cannot be negative")
|
||||||
long timeInMillis
|
long timeInMillis
|
||||||
) throws ValidationException{
|
) throws ValidationException{
|
||||||
|
|
||||||
ResponseBean responseBean = new ResponseBean();
|
ResponseBean responseBean = new ResponseBean();
|
||||||
Status status = Status.OK;
|
Status status = Status.OK;
|
||||||
|
@ -102,8 +98,8 @@ public class Posts {
|
||||||
|
|
||||||
return Response.status(status).entity(responseBean).build();
|
return Response.status(status).entity(responseBean).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve all user's posts
|
* Retrieve all user's posts
|
||||||
* @return all posts of the auth token's owner in the context identified by the token
|
* @return all posts of the auth token's owner in the context identified by the token
|
||||||
|
@ -112,8 +108,8 @@ public class Posts {
|
||||||
@Path("get-posts-user/")
|
@Path("get-posts-user/")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 200, condition = "Successful retrieval of posts, reported in the 'result' field of the returned object"),
|
@ResponseCode ( code = 200, condition = "Successful retrieval of posts, reported in the 'result' field of the returned object"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response getAllPostsByUser() {
|
public Response getAllPostsByUser() {
|
||||||
|
|
||||||
|
@ -140,7 +136,7 @@ public class Posts {
|
||||||
|
|
||||||
return Response.status(status).entity(responseBean).build();
|
return Response.status(status).entity(responseBean).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a post by id
|
* Retrieve a post by id
|
||||||
* @return the post if the post id belongs to a post in the context identified by the token
|
* @return the post if the post id belongs to a post in the context identified by the token
|
||||||
|
@ -149,18 +145,18 @@ public class Posts {
|
||||||
@Path("get-post/")
|
@Path("get-post/")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 200, condition = "Successful retrieval of posts, reported in the 'result' field of the returned object"),
|
@ResponseCode ( code = 200, condition = "Successful retrieval of posts, reported in the 'result' field of the returned object"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response getPost(@QueryParam("id") String id) {
|
public Response getPost(@QueryParam("id") String id) {
|
||||||
String context = ScopeProvider.instance.get();
|
String context = ScopeProvider.instance.get();
|
||||||
Caller caller = AuthorizationProvider.instance.get();
|
Caller caller = AuthorizationProvider.instance.get();
|
||||||
ResponseBean responseBean = new ResponseBean();
|
ResponseBean responseBean = new ResponseBean();
|
||||||
Status status = Status.OK;
|
Status status = Status.OK;
|
||||||
List<Post> posts = new ArrayList<>();
|
List<Post> posts = new ArrayList<>();
|
||||||
try{
|
try{
|
||||||
logger.debug("Retrieving post with id " + id);
|
logger.debug("Retrieving post with id " + id);
|
||||||
try {
|
try {
|
||||||
posts.add(CassandraConnection.getInstance().getDatabookStore().readPost(id));
|
posts.add(CassandraConnection.getInstance().getDatabookStore().readPost(id));
|
||||||
} catch(FeedIDNotFoundException e){
|
} catch(FeedIDNotFoundException e){
|
||||||
responseBean.setMessage("The post with id " + id + " does not exist in context " + context);
|
responseBean.setMessage("The post with id " + id + " does not exist in context " + context);
|
||||||
|
@ -187,7 +183,7 @@ public class Posts {
|
||||||
|
|
||||||
return Response.status(status).entity(responseBean).build();
|
return Response.status(status).entity(responseBean).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a given quantity of latest user's posts
|
* Retrieve a given quantity of latest user's posts
|
||||||
* @param quantity the number of latest post to get
|
* @param quantity the number of latest post to get
|
||||||
|
@ -199,13 +195,13 @@ public class Posts {
|
||||||
@Path("get-posts-user-quantity/")
|
@Path("get-posts-user-quantity/")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 200, condition = "Successful retrieval of posts, reported in the 'result' field of the returned object"),
|
@ResponseCode ( code = 200, condition = "Successful retrieval of posts, reported in the 'result' field of the returned object"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response getQuantityPostsByUser(
|
public Response getQuantityPostsByUser(
|
||||||
@DefaultValue("10")
|
@DefaultValue("10")
|
||||||
@QueryParam("quantity")
|
@QueryParam("quantity")
|
||||||
@Min(value=0, message="quantity cannot be negative")
|
@Min(value=0, message="quantity cannot be negative")
|
||||||
int quantity) throws ValidationException{
|
int quantity) throws ValidationException{
|
||||||
|
|
||||||
Caller caller = AuthorizationProvider.instance.get();
|
Caller caller = AuthorizationProvider.instance.get();
|
||||||
|
@ -241,7 +237,7 @@ public class Posts {
|
||||||
}
|
}
|
||||||
return Response.status(status).entity(responseBean).build();
|
return Response.status(status).entity(responseBean).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new user post having as owner the auth token's owner
|
* Create a new user post having as owner the auth token's owner
|
||||||
* @param post The post to be written
|
* @param post The post to be written
|
||||||
|
@ -253,12 +249,12 @@ public class Posts {
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 201, condition = "Successfull created, the new post is reported in the 'result' field of the returned object"),
|
@ResponseCode ( code = 201, condition = "Successfull created, the new post is reported in the 'result' field of the returned object"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response writePostUser(
|
public Response writePostUser(
|
||||||
@NotNull(message="Post to write is missing")
|
@NotNull(message="Post to write is missing")
|
||||||
@Valid
|
@Valid
|
||||||
PostInputBean post) throws ValidationException{
|
PostInputBean post) throws ValidationException{
|
||||||
|
|
||||||
logger.debug("Request of writing a feed coming from user " + post);
|
logger.debug("Request of writing a feed coming from user " + post);
|
||||||
|
@ -288,15 +284,15 @@ public class Posts {
|
||||||
logger.debug("Trying to share user post...");
|
logger.debug("Trying to share user post...");
|
||||||
Post res = SocialUtils.shareUserUpdate(
|
Post res = SocialUtils.shareUserUpdate(
|
||||||
username,
|
username,
|
||||||
postText,
|
postText,
|
||||||
context,
|
context,
|
||||||
previewTitle,
|
previewTitle,
|
||||||
previewDescription,
|
previewDescription,
|
||||||
previewHost,
|
previewHost,
|
||||||
previewUrl,
|
previewUrl,
|
||||||
httpImageUrl,
|
httpImageUrl,
|
||||||
enableNotification
|
enableNotification
|
||||||
);
|
);
|
||||||
|
|
||||||
if(res != null){
|
if(res != null){
|
||||||
logger.debug("Post correctly written by user " + username);
|
logger.debug("Post correctly written by user " + username);
|
||||||
|
@ -313,7 +309,7 @@ public class Posts {
|
||||||
return Response.status(status).entity(responseBean).build();
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the application's posts
|
* Retrieve the application's posts
|
||||||
* @return the application (IAM Client) posts belonging to the token's owner (i.e., an application)"
|
* @return the application (IAM Client) posts belonging to the token's owner (i.e., an application)"
|
||||||
|
@ -322,9 +318,9 @@ public class Posts {
|
||||||
@Path("get-posts-app/")
|
@Path("get-posts-app/")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 200, condition = "Successfull created, the new post is reported in the 'result' field of the returned object"),
|
@ResponseCode ( code = 200, condition = "Successfull created, the new post is reported in the 'result' field of the returned object"),
|
||||||
@ResponseCode ( code = 403, condition = "\"There is no application profile with such token"),
|
@ResponseCode ( code = 403, condition = "\"There is no application profile with such token"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response getAllPostsByApp() {
|
public Response getAllPostsByApp() {
|
||||||
|
|
||||||
|
@ -364,7 +360,7 @@ public class Posts {
|
||||||
|
|
||||||
return Response.status(status).entity(responseBean).build();
|
return Response.status(status).entity(responseBean).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new application post having as owner-application the token's owner (the IAM Client), note that the application must be registered on the Information System
|
* Create a new application post having as owner-application the token's owner (the IAM Client), note that the application must be registered on the Information System
|
||||||
* @param post The post to be written
|
* @param post The post to be written
|
||||||
|
@ -375,13 +371,13 @@ public class Posts {
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 200, condition = "Successfull created, the new post is reported in the 'result' field of the returned object"),
|
@ResponseCode ( code = 200, condition = "Successfull created, the new post is reported in the 'result' field of the returned object"),
|
||||||
@ResponseCode ( code = 403, condition = "\"There is no application profile with such token"),
|
@ResponseCode ( code = 403, condition = "\"There is no application profile with such token"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response writePostApp(
|
public Response writePostApp(
|
||||||
@NotNull(message="Post to write is null")
|
@NotNull(message="Post to write is null")
|
||||||
@Valid
|
@Valid
|
||||||
PostInputBean post){
|
PostInputBean post){
|
||||||
|
|
||||||
Caller caller = AuthorizationProvider.instance.get();
|
Caller caller = AuthorizationProvider.instance.get();
|
||||||
|
@ -419,15 +415,15 @@ public class Posts {
|
||||||
|
|
||||||
// write post + notification if it is the case
|
// write post + notification if it is the case
|
||||||
Post written = SocialUtils.shareApplicationUpdate(
|
Post written = SocialUtils.shareApplicationUpdate(
|
||||||
postText,
|
postText,
|
||||||
params,
|
params,
|
||||||
previewTitle,
|
previewTitle,
|
||||||
previewDescription,
|
previewDescription,
|
||||||
httpImageUrl,
|
httpImageUrl,
|
||||||
appProfile,
|
appProfile,
|
||||||
caller,
|
caller,
|
||||||
enableNotification
|
enableNotification
|
||||||
);
|
);
|
||||||
|
|
||||||
if(written != null){
|
if(written != null){
|
||||||
responseBean.setResult(written);
|
responseBean.setResult(written);
|
||||||
|
@ -443,15 +439,15 @@ public class Posts {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return all the posts in the context bound to the auth token
|
* @return all the posts in the context bound to the auth token
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("get-posts-vre/")
|
@Path("get-posts-vre/")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 201, condition = "Sccessfull retrieved posts, they are reported in the 'result' field of the returned object"),
|
@ResponseCode ( code = 201, condition = "Sccessfull retrieved posts, they are reported in the 'result' field of the returned object"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response getAllPostsByVRE() {
|
public Response getAllPostsByVRE() {
|
||||||
|
|
||||||
|
@ -478,28 +474,28 @@ public class Posts {
|
||||||
/**
|
/**
|
||||||
* return the most recent posts for this vre up to quantity param and the last index of the posts in the timeline
|
* return the most recent posts for this vre up to quantity param and the last index of the posts in the timeline
|
||||||
* lastReturnedPostTimelineIndex is useful to know from where to start the range the next time you ask, because there are deletions
|
* lastReturnedPostTimelineIndex is useful to know from where to start the range the next time you ask, because there are deletions
|
||||||
*
|
*
|
||||||
* @param from the range start (most recent feeds for this vre) has to be greater than 0
|
* @param from the range start (most recent feeds for this vre) has to be greater than 0
|
||||||
* @param quantity the number of most recent feeds for this vre starting from "from" param
|
* @param quantity the number of most recent feeds for this vre starting from "from" param
|
||||||
* @pathExample /get-recent-posts-vre-by-range?from=1&quantity=10
|
* @pathExample /get-recent-posts-vre-by-range?from=1&quantity=10
|
||||||
* @return a <class>RangePosts</class> containing of most recent feeds for this vre
|
* @return a <class>RangePosts</class> containing of most recent feeds for this vre
|
||||||
* @throws FeedTypeNotFoundException
|
* @throws FeedTypeNotFoundException
|
||||||
* @throws PrivacyLevelTypeNotFoundException
|
* @throws PrivacyLevelTypeNotFoundException
|
||||||
* @throws ColumnNameNotFoundException
|
* @throws ColumnNameNotFoundException
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("get-recent-posts-vre-by-range/")
|
@Path("get-recent-posts-vre-by-range/")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 201, condition = "Sccessfull retrieved posts, they are reported in the 'result' field of the returned object"),
|
@ResponseCode ( code = 201, condition = "Sccessfull retrieved posts, they are reported in the 'result' field of the returned object"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response getRecentPostsByVREAndRange(
|
public Response getRecentPostsByVREAndRange(
|
||||||
@QueryParam("from")
|
@QueryParam("from")
|
||||||
@Min(value=1, message="from cannot be negative")
|
@Min(value=1, message="from cannot be negative")
|
||||||
int from,
|
int from,
|
||||||
@QueryParam("quantity")
|
@QueryParam("quantity")
|
||||||
@Min(value=1, message="quantity cannot be negative")
|
@Min(value=1, message="quantity cannot be negative")
|
||||||
int quantity) throws ValidationException {
|
int quantity) throws ValidationException {
|
||||||
|
|
||||||
String context = ScopeProvider.instance.get();
|
String context = ScopeProvider.instance.get();
|
||||||
|
@ -533,12 +529,12 @@ public class Posts {
|
||||||
@Path("get-posts-by-hashtag/")
|
@Path("get-posts-by-hashtag/")
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 201, condition = "Sccessfull retrieved posts, they are reported in the 'result' field of the returned object"),
|
@ResponseCode ( code = 201, condition = "Sccessfull retrieved posts, they are reported in the 'result' field of the returned object"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response getPostsByHashTags(
|
public Response getPostsByHashTags(
|
||||||
@QueryParam("hashtag")
|
@QueryParam("hashtag")
|
||||||
@NotNull(message="hashtag cannot be missing")
|
@NotNull(message="hashtag cannot be missing")
|
||||||
String hashtag) throws ValidationException {
|
String hashtag) throws ValidationException {
|
||||||
|
|
||||||
Caller caller = AuthorizationProvider.instance.get();
|
Caller caller = AuthorizationProvider.instance.get();
|
||||||
|
@ -560,7 +556,7 @@ public class Posts {
|
||||||
}
|
}
|
||||||
return Response.status(status).entity(responseBean).build();
|
return Response.status(status).entity(responseBean).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve ids (UUID) of the liked posts by the user
|
* Retrieve ids (UUID) of the liked posts by the user
|
||||||
* @return ids (UUID) of the liked posts by the user in the context bound to the auth token
|
* @return ids (UUID) of the liked posts by the user in the context bound to the auth token
|
||||||
|
@ -569,8 +565,8 @@ public class Posts {
|
||||||
@Path("get-id-liked-posts/")
|
@Path("get-id-liked-posts/")
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 201, condition = "Sccessfull retrieved ids, they are reported in the 'result' field of the returned object"),
|
@ResponseCode ( code = 201, condition = "Sccessfull retrieved ids, they are reported in the 'result' field of the returned object"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response getAllLikedPostIdsByUser() {
|
public Response getAllLikedPostIdsByUser() {
|
||||||
|
|
||||||
|
@ -599,7 +595,7 @@ public class Posts {
|
||||||
|
|
||||||
return Response.status(status).entity(responseBean).build();
|
return Response.status(status).entity(responseBean).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve posts liked by the user
|
* Retrieve posts liked by the user
|
||||||
* @param limit The maximum number of posts to be retrieved
|
* @param limit The maximum number of posts to be retrieved
|
||||||
|
@ -610,13 +606,13 @@ public class Posts {
|
||||||
@Path("get-liked-posts/")
|
@Path("get-liked-posts/")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 200, condition = "Successfull retrieved posts, they are reported in the 'result' field of the returned object"),
|
@ResponseCode ( code = 200, condition = "Successfull retrieved posts, they are reported in the 'result' field of the returned object"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response getAllLikedPostsByUser(
|
public Response getAllLikedPostsByUser(
|
||||||
@DefaultValue("10")
|
@DefaultValue("10")
|
||||||
@QueryParam("limit")
|
@QueryParam("limit")
|
||||||
@Min(message="limit cannot be negative", value = 0)
|
@Min(message="limit cannot be negative", value = 0)
|
||||||
int limit) throws ValidationException{
|
int limit) throws ValidationException{
|
||||||
|
|
||||||
Caller caller = AuthorizationProvider.instance.get();
|
Caller caller = AuthorizationProvider.instance.get();
|
||||||
|
@ -646,6 +642,7 @@ public class Posts {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//library api
|
//library api
|
||||||
@POST
|
@POST
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@ -883,7 +880,7 @@ public class Posts {
|
||||||
public Response getAllPostsByAppLib(
|
public Response getAllPostsByAppLib(
|
||||||
@QueryParam("appid")
|
@QueryParam("appid")
|
||||||
String appid
|
String appid
|
||||||
) throws ValidationException{
|
) throws ValidationException{
|
||||||
ResponseBean responseBean = new ResponseBean();
|
ResponseBean responseBean = new ResponseBean();
|
||||||
Status status = Status.OK;
|
Status status = Status.OK;
|
||||||
try{
|
try{
|
||||||
|
@ -980,7 +977,7 @@ public class Posts {
|
||||||
public Response getAllPostsByVRELib(
|
public Response getAllPostsByVRELib(
|
||||||
@QueryParam("vreid")
|
@QueryParam("vreid")
|
||||||
String vreid
|
String vreid
|
||||||
) throws ValidationException{
|
) throws ValidationException{
|
||||||
ResponseBean responseBean = new ResponseBean();
|
ResponseBean responseBean = new ResponseBean();
|
||||||
Status status = Status.OK;
|
Status status = Status.OK;
|
||||||
try{
|
try{
|
||||||
|
|
Loading…
Reference in New Issue