fix on method get user post quantity
This commit is contained in:
parent
8470bb032b
commit
c726b73f1f
1
pom.xml
1
pom.xml
|
@ -16,7 +16,6 @@
|
|||
<name>social-networking-library-ws</name>
|
||||
<description>Rest interface for the social networking library.</description>
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<enunciate.version>2.14.0</enunciate.version>
|
||||
<jackson.version>2.8.11</jackson.version>
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.gcube.common.scope.api.ScopeProvider;
|
|||
import org.gcube.portal.databook.server.DatabookStore;
|
||||
import org.gcube.portal.databook.shared.ApplicationProfile;
|
||||
import org.gcube.portal.databook.shared.Feed;
|
||||
import org.gcube.portal.databook.shared.Post;
|
||||
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.utils.CassandraConnection;
|
||||
|
@ -74,19 +75,19 @@ public class Posts {
|
|||
Caller caller = AuthorizationProvider.instance.get();
|
||||
String context = ScopeProvider.instance.get();
|
||||
String username = caller.getClient().getId();
|
||||
List<Feed> feeds = null;
|
||||
List<Post> posts = null;
|
||||
|
||||
try{
|
||||
logger.info("Retrieving feeds for user id " + username + " and reference time " + timeInMillis);
|
||||
feeds = CassandraConnection.getInstance().getDatabookStore().getRecentFeedsByUserAndDate(username, timeInMillis);
|
||||
Filters.filterFeedsPerContext(feeds, context);
|
||||
Filters.hideSensitiveInformation(feeds, caller.getClient().getId());
|
||||
responseBean.setResult(feeds);
|
||||
logger.info("Retrieving post for user id " + username + " and reference time " + timeInMillis);
|
||||
posts = CassandraConnection.getInstance().getDatabookStore().getRecentPostsByUserAndDate(username, timeInMillis);
|
||||
Filters.filterPostsPerContext(posts, context);
|
||||
Filters.hideSensitiveInformation(posts, caller.getClient().getId());
|
||||
responseBean.setResult(posts);
|
||||
responseBean.setMessage("");
|
||||
responseBean.setSuccess(true);
|
||||
|
||||
}catch(Exception e){
|
||||
logger.error("Unable to retrieve such feeds.", e);
|
||||
logger.error("Unable to retrieve such posts.", e);
|
||||
responseBean.setMessage(e.getMessage());
|
||||
responseBean.setSuccess(false);
|
||||
status = Status.INTERNAL_SERVER_ERROR;
|
||||
|
@ -113,13 +114,13 @@ public class Posts {
|
|||
String context = ScopeProvider.instance.get();
|
||||
ResponseBean responseBean = new ResponseBean();
|
||||
Status status = Status.OK;
|
||||
List<Feed> feeds = null;
|
||||
List<Post> posts = null;
|
||||
try{
|
||||
logger.debug("Retrieving feeds for user with id " + username);
|
||||
feeds = CassandraConnection.getInstance().getDatabookStore().getAllFeedsByUser(username);
|
||||
Filters.filterFeedsPerContext(feeds, context);
|
||||
Filters.hideSensitiveInformation(feeds, caller.getClient().getId());
|
||||
responseBean.setResult(feeds);
|
||||
logger.debug("Retrieving posts for user with id " + username);
|
||||
posts = CassandraConnection.getInstance().getDatabookStore().getAllPostsByUser(username);
|
||||
Filters.filterPostsPerContext(posts, context);
|
||||
Filters.hideSensitiveInformation(posts, caller.getClient().getId());
|
||||
responseBean.setResult(posts);
|
||||
responseBean.setMessage("");
|
||||
responseBean.setSuccess(true);
|
||||
}catch(Exception e){
|
||||
|
@ -157,7 +158,7 @@ public class Posts {
|
|||
ResponseBean responseBean = new ResponseBean();
|
||||
Status status = Status.OK;
|
||||
|
||||
List<Feed> feeds = new ArrayList<Feed>();
|
||||
List<Post> posts = new ArrayList<>();
|
||||
|
||||
// if quantity is zero, just return an empty list
|
||||
if(quantity == 0){
|
||||
|
@ -165,15 +166,19 @@ public class Posts {
|
|||
return Response.status(status).entity(responseBean).build();
|
||||
}
|
||||
try{
|
||||
logger.debug("Retrieving last " + quantity + " feeds made by user " + username);
|
||||
feeds = CassandraConnection.getInstance().getDatabookStore().getRecentFeedsByUser(username, -1);
|
||||
Filters.filterFeedsPerContext(feeds, context);
|
||||
feeds = feeds.subList(0, quantity);
|
||||
Filters.hideSensitiveInformation(feeds, caller.getClient().getId());
|
||||
responseBean.setResult(feeds);
|
||||
logger.debug("getRecentPostsByUser first, posts made by user " + username);
|
||||
posts = CassandraConnection.getInstance().getDatabookStore().getAllPostsByUser(username);
|
||||
if (posts != null)
|
||||
logger.debug("got " + posts.size() + " posts");
|
||||
logger.debug("Retrieving last " + quantity + " posts made by user " + username + " in context = "+context);
|
||||
Filters.filterPostsPerContext(posts, context);
|
||||
quantity = (quantity > posts.size()) ? posts.size() : quantity;
|
||||
posts = posts.subList(0, quantity);
|
||||
Filters.hideSensitiveInformation(posts, caller.getClient().getId());
|
||||
responseBean.setResult(posts);
|
||||
responseBean.setSuccess(true);
|
||||
}catch(Exception e){
|
||||
logger.error("Unable to retrieve such feeds.", e);
|
||||
logger.error("Unable to retrieve such posts.", e);
|
||||
responseBean.setMessage(e.getMessage());
|
||||
responseBean.setSuccess(false);
|
||||
status = Status.INTERNAL_SERVER_ERROR;
|
||||
|
@ -224,7 +229,7 @@ public class Posts {
|
|||
|
||||
|
||||
// try to share
|
||||
logger.debug("Trying to share user feed...");
|
||||
logger.debug("Trying to share user post...");
|
||||
Feed res = SocialUtils.shareUserUpdate(
|
||||
username,
|
||||
postText,
|
||||
|
@ -286,9 +291,9 @@ public class Posts {
|
|||
}
|
||||
try{
|
||||
|
||||
logger.debug("Retrieving feeds for app with id " + appId);
|
||||
List<Feed> feeds = CassandraConnection.getInstance().getDatabookStore().getAllFeedsByApp(appId);
|
||||
Filters.filterFeedsPerContext(feeds, context);
|
||||
logger.debug("Retrieving posts for app with id " + appId);
|
||||
List<Post> feeds = CassandraConnection.getInstance().getDatabookStore().getAllPostsByApp(appId);
|
||||
Filters.filterPostsPerContext(feeds, context);
|
||||
responseBean.setSuccess(true);
|
||||
responseBean.setResult(feeds);
|
||||
|
||||
|
@ -343,7 +348,7 @@ public class Posts {
|
|||
}
|
||||
|
||||
// parse
|
||||
String feedText = post.getText();
|
||||
String postText = post.getText();
|
||||
String previewTitle = post.getPreviewtitle();
|
||||
String previewDescription = post.getPreviewdescription();
|
||||
String httpImageUrl = post.getHttpimageurl();
|
||||
|
@ -358,7 +363,7 @@ public class Posts {
|
|||
|
||||
// write feed + notification if it is the case
|
||||
Feed written = SocialUtils.shareApplicationUpdate(
|
||||
feedText,
|
||||
postText,
|
||||
params,
|
||||
previewTitle,
|
||||
previewDescription,
|
||||
|
@ -394,18 +399,18 @@ public class Posts {
|
|||
*/
|
||||
public Response getAllPostsByVRE() {
|
||||
|
||||
String scope = ScopeProvider.instance.get();
|
||||
String context = ScopeProvider.instance.get();
|
||||
Caller caller = AuthorizationProvider.instance.get();
|
||||
logger.debug("Retrieving all posts coming from vre = " + scope);
|
||||
logger.debug("Retrieving all posts coming from vre = " + context);
|
||||
ResponseBean responseBean = new ResponseBean();
|
||||
Status status = Status.OK;
|
||||
try{
|
||||
List<Feed> feeds = CassandraConnection.getInstance().getDatabookStore().getAllFeedsByVRE(scope);
|
||||
Filters.hideSensitiveInformation(feeds, caller.getClient().getId());
|
||||
responseBean.setResult(feeds);
|
||||
List<Post> posts = CassandraConnection.getInstance().getDatabookStore().getAllPostsByVRE(context);
|
||||
Filters.hideSensitiveInformation(posts, caller.getClient().getId());
|
||||
responseBean.setResult(posts);
|
||||
responseBean.setSuccess(true);
|
||||
}catch(Exception e){
|
||||
logger.error("Unable to retrieve feeds for vre = " + scope, e);
|
||||
logger.error("Unable to retrieve posts for vre = " + context, e);
|
||||
status = Status.INTERNAL_SERVER_ERROR;
|
||||
responseBean.setMessage(e.toString());
|
||||
responseBean.setSuccess(false);
|
||||
|
@ -440,9 +445,9 @@ public class Posts {
|
|||
logger.info("User " + username + " has requested posts containing hashtag " + hashtag + " in context " + context);
|
||||
try{
|
||||
DatabookStore datastore = CassandraConnection.getInstance().getDatabookStore();
|
||||
List<Feed> feeds = datastore.getVREFeedsByHashtag(context, hashtag);
|
||||
Filters.hideSensitiveInformation(feeds, caller.getClient().getId());
|
||||
responseBean.setResult(feeds);
|
||||
List<Post> posts = datastore.getVREPostsByHashtag(context, hashtag);
|
||||
Filters.hideSensitiveInformation(posts, caller.getClient().getId());
|
||||
responseBean.setResult(posts);
|
||||
responseBean.setSuccess(true);
|
||||
|
||||
}catch(Exception e){
|
||||
|
@ -468,21 +473,21 @@ public class Posts {
|
|||
Caller caller = AuthorizationProvider.instance.get();
|
||||
String username = caller.getClient().getId();
|
||||
String context = ScopeProvider.instance.get();
|
||||
logger.debug("Retrieving all liked feeds for user with id " + username + " in context " + context);
|
||||
logger.debug("Retrieving all liked posts for user with id " + username + " in context " + context);
|
||||
|
||||
List<String> retrievedLikedFeedsIds = null;
|
||||
List<String> retrievedLikedPostsIds = null;
|
||||
ResponseBean responseBean = new ResponseBean();
|
||||
Status status = Status.OK;
|
||||
try{
|
||||
|
||||
DatabookStore datastore = CassandraConnection.getInstance().getDatabookStore();
|
||||
retrievedLikedFeedsIds = datastore.getAllLikedFeedIdsByUser(username);
|
||||
Filters.filterFeedsPerContextById(retrievedLikedFeedsIds, context);
|
||||
responseBean.setResult(retrievedLikedFeedsIds);
|
||||
retrievedLikedPostsIds = datastore.getAllLikedPostIdsByUser(username);
|
||||
Filters.filterFeedsPerContextById(retrievedLikedPostsIds, context);
|
||||
responseBean.setResult(retrievedLikedPostsIds);
|
||||
responseBean.setSuccess(true);
|
||||
logger.debug("Ids of liked feeds by " + username + " retrieved");
|
||||
logger.debug("Ids of liked posts by " + username + " retrieved");
|
||||
}catch(Exception e){
|
||||
logger.error("Unable to read such ids of liked feeds.", e);
|
||||
logger.error("Unable to read such ids of liked Posts.", e);
|
||||
responseBean.setMessage(e.getMessage());
|
||||
responseBean.setSuccess(false);
|
||||
status = Status.INTERNAL_SERVER_ERROR;
|
||||
|
@ -513,20 +518,20 @@ public class Posts {
|
|||
Caller caller = AuthorizationProvider.instance.get();
|
||||
String username = caller.getClient().getId();
|
||||
String context = ScopeProvider.instance.get();
|
||||
List<Feed> retrievedLikedFeeds = null;
|
||||
List<Post> retrievedLikedPosts = null;
|
||||
ResponseBean responseBean = new ResponseBean();
|
||||
Status status = Status.OK;
|
||||
|
||||
try{
|
||||
logger.debug("Retrieving " + limit + " liked feeds for user with id " + username + " in context " + context);
|
||||
retrievedLikedFeeds = CassandraConnection.getInstance().getDatabookStore().getAllLikedFeedsByUser(username, limit);
|
||||
Filters.filterFeedsPerContext(retrievedLikedFeeds, context);
|
||||
Filters.hideSensitiveInformation(retrievedLikedFeeds, caller.getClient().getId());
|
||||
responseBean.setResult(retrievedLikedFeeds);
|
||||
logger.debug("Retrieving " + limit + " liked posts for user with id " + username + " in context " + context);
|
||||
retrievedLikedPosts = CassandraConnection.getInstance().getDatabookStore().getAllLikedPostsByUser(username, limit);
|
||||
Filters.filterPostsPerContext(retrievedLikedPosts, context);
|
||||
Filters.hideSensitiveInformation(retrievedLikedPosts, caller.getClient().getId());
|
||||
responseBean.setResult(retrievedLikedPosts);
|
||||
responseBean.setSuccess(true);
|
||||
logger.debug("Liked feeds by " + username + " retrieved");
|
||||
logger.debug("Liked posts by " + username + " retrieved");
|
||||
}catch(Exception e){
|
||||
logger.error("Unable to read such liked feeds.", e);
|
||||
logger.error("Unable to read such liked posts.", e);
|
||||
responseBean.setMessage(e.getMessage());
|
||||
responseBean.setSuccess(false);
|
||||
status = Status.INTERNAL_SERVER_ERROR;
|
||||
|
|
Loading…
Reference in New Issue