diff --git a/pom.xml b/pom.xml index 634417f..22d3ed7 100644 --- a/pom.xml +++ b/pom.xml @@ -72,9 +72,16 @@ ${gwtVersion} provided + - org.gcube.portal - social-networking-library + org.gcube.social-networking + social-service-model + [1.2.0-SNAPSHOT, 2.0.0) + + + org.gcube.social-networking + social-service-client + [2.0.0-SNAPSHOT, 3.0.0) provided diff --git a/src/main/java/org/gcube/portlets/user/topics/server/TopicServiceImpl.java b/src/main/java/org/gcube/portlets/user/topics/server/TopicServiceImpl.java index 6c1dade..343660f 100644 --- a/src/main/java/org/gcube/portlets/user/topics/server/TopicServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/topics/server/TopicServiceImpl.java @@ -12,10 +12,9 @@ import java.util.Set; import org.apache.commons.codec.binary.Base64; import org.gcube.common.portal.PortalContext; -import org.gcube.portal.databook.client.GCubeSocialNetworking; -import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl; -import org.gcube.portal.databook.server.DatabookStore; -import org.gcube.portal.databook.shared.Feed; +import org.gcube.social_networking.social_networking_client_library.LibClient; +import org.gcube.social_networking.socialnetworking.model.client.GCubeSocialNetworking; +import org.gcube.social_networking.socialnetworking.model.shared.Post; import org.gcube.portlets.user.topics.client.TopicService; import org.gcube.portlets.user.topics.shared.HashTagOccAndWeight; import org.gcube.portlets.user.topics.shared.HashtagsWrapper; @@ -43,7 +42,7 @@ public class TopicServiceImpl extends RemoteServiceServlet implements TopicServi private static final double FRESHNESS_FACTOR = 0.4; private static final double NORMALIZED_SCORE_FACTOR = 0.6; - private DatabookStore store; + private LibClient libClient; private GroupManager gm; private UserManager um; @@ -51,7 +50,11 @@ public class TopicServiceImpl extends RemoteServiceServlet implements TopicServi * connect to cassandra at startup */ public void init() { - store = new DBCassandraAstyanaxImpl(); + try { + libClient = new LibClient(); + } catch (Exception e) { + throw new RuntimeException(e); + } gm = new LiferayGroupManager(); um = new LiferayUserManager(); } @@ -59,9 +62,9 @@ public class TopicServiceImpl extends RemoteServiceServlet implements TopicServi /** * close connection to cassandra at shutdown */ - public void destroy() { + /*public void destroy() { store.closeConnection(); - } + }*/ /** @@ -107,7 +110,7 @@ public class TopicServiceImpl extends RemoteServiceServlet implements TopicServi for (String context : contexts) { - Map hashtagsAndOccurrenceInScope = store.getVREHashtagsWithOccurrenceFilteredByTime(context, referenceTime.getTimeInMillis()); + Map hashtagsAndOccurrenceInScope = libClient.getVREHashtagsWithOccurrenceFilteredByTimeLib(context, referenceTime.getTimeInMillis()); // merge the values if needed for (String hashtag : hashtagsAndOccurrenceInScope.keySet()) { @@ -136,7 +139,7 @@ public class TopicServiceImpl extends RemoteServiceServlet implements TopicServi else { logger.debug("****** retrieving hashtags for scope " + currentScope); - hashtagsAndOccurrences = store.getVREHashtagsWithOccurrenceFilteredByTime(currentScope, referenceTime.getTimeInMillis()); + hashtagsAndOccurrences = libClient.getVREHashtagsWithOccurrenceFilteredByTimeLib(currentScope, referenceTime.getTimeInMillis()); } // now we need to evaluate score for each element @@ -173,7 +176,7 @@ public class TopicServiceImpl extends RemoteServiceServlet implements TopicServi /** * Evaluate the weight for each element as w = 0.6 * s + 0.4 * f * where s is the score: a normalized value given by counter_i / counter_max - * f is the freshness: evaluated taking into account the most recent feed containing that hashtag into the window w (that is, the period taken into account) + * f is the freshness: evaluated taking into account the most recent post containing that hashtag into the window w (that is, the period taken into account) * @param hashtags * @param hashtagsInVres (present if vreid is null) * @param window size @@ -210,24 +213,24 @@ public class TopicServiceImpl extends RemoteServiceServlet implements TopicServi // create the weight for each entry as: // w = NORMALIZED_SCORE_FACTOR * normalized_score + FRESHNESS_FACTOR * freshness - // freshness is evaluated as (window_size - latest_feed_for_hashtag_in_window_month)/window_size + // freshness is evaluated as (window_size - latest_post_for_hashtag_in_window_month)/window_size for(Entry entry : hashtags.entrySet()){ // first part of the weight double weight = NORMALIZED_SCORE_FACTOR * normalized.get(entry.getKey()); - List mostRecentFeedForHashtag = null; + List mostRecentPostForHashtag = null; // we are in the simplest case.. the hashtag belongs (or the request comes) from a single vre if(hashtagsInVres == null){ try{ - mostRecentFeedForHashtag = store.getVREFeedsByHashtag(vreId, entry.getKey()); + mostRecentPostForHashtag = libClient.getVREPostsByHashtagLib(vreId, entry.getKey()); }catch(Exception e){ - logger.error("Unable to retrieve the most recent feeds for hashtag " + entry.getKey() + " in " + vreId); + logger.error("Unable to retrieve the most recent posts for hashtag " + entry.getKey() + " in " + vreId); // put a weight of zero for this hashtag weights.put(entry.getKey(), 0.0); @@ -240,41 +243,41 @@ public class TopicServiceImpl extends RemoteServiceServlet implements TopicServi List vres = hashtagsInVres.get(entry.getKey()); // init list - mostRecentFeedForHashtag = new ArrayList(); + mostRecentPostForHashtag = new ArrayList(); - List feedsForVre; + List postsForVre; for (String vre : vres) { try{ - feedsForVre = store.getVREFeedsByHashtag(vre, entry.getKey()); + postsForVre = libClient.getVREPostsByHashtagLib(vre, entry.getKey()); }catch(Exception e){ - logger.error("Unable to retrieve the most recent feeds for hashtag " + entry.getKey() + " in " + vreId); + logger.error("Unable to retrieve the most recent posts for hashtag " + entry.getKey() + " in " + vreId); continue; } // add to the list - mostRecentFeedForHashtag.addAll(feedsForVre); + mostRecentPostForHashtag.addAll(postsForVre); } - // check if there is at least a feed or it is empty - if(mostRecentFeedForHashtag.isEmpty()){ + // check if there is at least a post or it is empty + if(mostRecentPostForHashtag.isEmpty()){ // put a weight of zero for this hashtag weights.put(entry.getKey(), 0.0); continue; } } - // retrieve the most recent one among these feeds - Collections.sort(mostRecentFeedForHashtag, Collections.reverseOrder()); + // retrieve the most recent one among these posts + Collections.sort(mostRecentPostForHashtag, Collections.reverseOrder()); - // get month of the last recent feed for this hashtag - Calendar monstRecentFeedForHashTagTime = Calendar.getInstance(); - monstRecentFeedForHashTagTime.setTimeInMillis(mostRecentFeedForHashtag.get(0).getTime().getTime()); + // get month of the last recent post for this hashtag + Calendar monstRecentPostForHashTagTime = Calendar.getInstance(); + monstRecentPostForHashTagTime.setTimeInMillis(mostRecentPostForHashtag.get(0).getTime().getTime()); - int sub = currentMonth - monstRecentFeedForHashTagTime.get(Calendar.MONTH); + int sub = currentMonth - monstRecentPostForHashTagTime.get(Calendar.MONTH); int value = sub >= 0? sub : 12 - Math.abs(sub); double freshness = 1.0 - (double)(value) / (double)(windowSize); logger.debug("freshness is " + freshness + " for hashtag " + entry.getKey() + - " because the last feed has month " + monstRecentFeedForHashTagTime.get(Calendar.MONTH)); + " because the last post has month " + monstRecentPostForHashTagTime.get(Calendar.MONTH)); // update the weight weight += FRESHNESS_FACTOR * freshness; diff --git a/src/main/resources/org/gcube/portlets/user/topics/TopTopics.gwt.xml b/src/main/resources/org/gcube/portlets/user/topics/TopTopics.gwt.xml index d89802f..c549e28 100644 --- a/src/main/resources/org/gcube/portlets/user/topics/TopTopics.gwt.xml +++ b/src/main/resources/org/gcube/portlets/user/topics/TopTopics.gwt.xml @@ -9,7 +9,7 @@ - +