minor fix
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/top-topics@132181 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
6ec05b2040
commit
0107f8843f
|
@ -11,6 +11,7 @@ import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.codec.binary.Base64;
|
import org.apache.commons.codec.binary.Base64;
|
||||||
import org.gcube.application.framework.core.session.ASLSession;
|
import org.gcube.application.framework.core.session.ASLSession;
|
||||||
|
@ -39,9 +40,10 @@ import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class TopicServiceImpl extends RemoteServiceServlet implements TopicService {
|
public class TopicServiceImpl extends RemoteServiceServlet implements TopicService {
|
||||||
private static final Logger _log = LoggerFactory.getLogger(TopicServiceImpl.class);
|
private static final Logger logger = LoggerFactory.getLogger(TopicServiceImpl.class);
|
||||||
|
|
||||||
public static final String TEST_USER = "test.user";
|
public static final String TEST_USER = "test.user";
|
||||||
|
private static final String TEST_SCOPE = "/gcube/devsec/devVRE";
|
||||||
private static final int WINDOW_SIZE_IN_MONTHS = 6; // it must not exceed 12
|
private static final int WINDOW_SIZE_IN_MONTHS = 6; // it must not exceed 12
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -70,12 +72,13 @@ public class TopicServiceImpl extends RemoteServiceServlet implements TopicServi
|
||||||
String sessionID = this.getThreadLocalRequest().getSession().getId();
|
String sessionID = this.getThreadLocalRequest().getSession().getId();
|
||||||
String user = (String) this.getThreadLocalRequest().getSession().getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
|
String user = (String) this.getThreadLocalRequest().getSession().getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
_log.warn("USER IS NULL setting test.user and Running OUTSIDE PORTAL");
|
logger.warn("USER IS NULL setting test.user and Running OUTSIDE PORTAL");
|
||||||
user = getDevelopmentUser();
|
user = getDevelopmentUser();
|
||||||
SessionManager.getInstance().getASLSession(sessionID, user).setScope("/gcube/devsec/devVRE");
|
SessionManager.getInstance().getASLSession(sessionID, user).setScope(TEST_SCOPE);
|
||||||
}
|
}
|
||||||
return SessionManager.getInstance().getASLSession(sessionID, user);
|
return SessionManager.getInstance().getASLSession(sessionID, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* when packaging test will fail if the user is not set to test.user
|
* when packaging test will fail if the user is not set to test.user
|
||||||
* @return .
|
* @return .
|
||||||
|
@ -93,10 +96,16 @@ public class TopicServiceImpl extends RemoteServiceServlet implements TopicServi
|
||||||
public HashtagsWrapper getHashtags() {
|
public HashtagsWrapper getHashtags() {
|
||||||
ArrayList<String> hashtagsChart = new ArrayList<String>();
|
ArrayList<String> hashtagsChart = new ArrayList<String>();
|
||||||
ASLSession session = getASLSession();
|
ASLSession session = getASLSession();
|
||||||
|
|
||||||
String userName = session.getUsername();
|
String userName = session.getUsername();
|
||||||
boolean isInfrastructure = isInfrastructureScope();
|
|
||||||
String currentScope = session.getScope();
|
String currentScope = session.getScope();
|
||||||
|
boolean isInfrastructure = isInfrastructureScope();
|
||||||
|
|
||||||
|
//in case the portal is restarted and you have the social home open it will get test.user (no callback to set session info)
|
||||||
|
//this check just return nothing if that happens
|
||||||
|
if (userName.compareTo(TEST_USER) == 0) {
|
||||||
|
logger.debug("Found " + userName + " returning nothing");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
long timestampStart = System.currentTimeMillis();
|
long timestampStart = System.currentTimeMillis();
|
||||||
|
|
||||||
|
@ -107,20 +116,14 @@ public class TopicServiceImpl extends RemoteServiceServlet implements TopicServi
|
||||||
|
|
||||||
// print it
|
// print it
|
||||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
_log.debug("Reference time for trending topics is " + format.format(referenceTime.getTime()));
|
logger.debug("Reference time for trending topics is " + format.format(referenceTime.getTime()));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
//in case the portal is restarted and you have the social home open it will get test.user (no callback to set session info)
|
|
||||||
//this check just return nothing if that happens
|
|
||||||
if (userName.compareTo("test.user") == 0) {
|
|
||||||
_log.debug("Found " + userName + " returning nothing");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
ArrayList<HashTagAndOccurrence> toSort = new ArrayList<HashTagAndOccurrence>();
|
ArrayList<HashTagAndOccurrence> toSort = new ArrayList<HashTagAndOccurrence>();
|
||||||
|
|
||||||
if (isInfrastructure) {
|
if (isInfrastructure) {
|
||||||
_log.debug("****** retrieving hashtags for user VREs");
|
logger.debug("****** retrieving hashtags for user VREs and site");
|
||||||
|
|
||||||
// different vres could have a same hashtag, we need to merge them
|
// different vres could have a same hashtag, we need to merge them
|
||||||
Map<String, Integer> hashtags = new HashMap<String, Integer>();
|
Map<String, Integer> hashtags = new HashMap<String, Integer>();
|
||||||
|
@ -134,39 +137,44 @@ public class TopicServiceImpl extends RemoteServiceServlet implements TopicServi
|
||||||
UserManager um = new LiferayUserManager();
|
UserManager um = new LiferayUserManager();
|
||||||
GCubeUser user = um.getUserByUsername(userName);
|
GCubeUser user = um.getUserByUsername(userName);
|
||||||
|
|
||||||
List<GCubeGroup> groups = gm.listGroupsByUser(user.getUserId());
|
Set<GCubeGroup> vresInPortal = gm.listGroupsByUserAndSite(user.getUserId(), getThreadLocalRequest().getServerName());
|
||||||
for (GCubeGroup group : groups) {
|
logger.debug("Contexts in this site are per user " + vresInPortal);
|
||||||
if (gm.isVRE(group.getGroupId())) {
|
|
||||||
String vreid = gm.getInfrastructureScope(group.getGroupId()); //get the scope
|
|
||||||
Map<String, Integer> map = store.getVREHashtagsWithOccurrenceFilteredByTime(vreid, referenceTime.getTimeInMillis());
|
|
||||||
|
|
||||||
// merge the values if needed
|
List<String> contexts = new ArrayList<String>();
|
||||||
for (String hashtag : map.keySet()) {
|
|
||||||
|
|
||||||
if(hashtags.containsKey(hashtag)){
|
// get the scopes associated with such groups
|
||||||
|
for (GCubeGroup gCubeGroup : vresInPortal) {
|
||||||
|
contexts.add(gm.getInfrastructureScope(gCubeGroup.getGroupId()));
|
||||||
|
}
|
||||||
|
|
||||||
int currentValue = hashtags.get(hashtag);
|
for (String context : contexts) {
|
||||||
int newValue = currentValue + map.get(hashtag);
|
Map<String, Integer> map = store.getVREHashtagsWithOccurrenceFilteredByTime(context, referenceTime.getTimeInMillis());
|
||||||
|
|
||||||
// remove and re-add
|
// merge the values if needed
|
||||||
hashtags.remove(hashtag);
|
for (String hashtag : map.keySet()) {
|
||||||
hashtags.put(hashtag, newValue);
|
|
||||||
|
|
||||||
// get the current list of vres in which the hashtag is present and add this new one
|
if(hashtags.containsKey(hashtag)){
|
||||||
List<String> vres = hashtagsInVres.get(hashtag);
|
|
||||||
vres.add(vreid);
|
|
||||||
hashtagsInVres.remove(hashtag);
|
|
||||||
hashtagsInVres.put(hashtag, vres);
|
|
||||||
|
|
||||||
}else{
|
int currentValue = hashtags.get(hashtag);
|
||||||
|
int newValue = currentValue + map.get(hashtag);
|
||||||
|
|
||||||
hashtags.put(hashtag, map.get(hashtag));
|
// remove and re-add
|
||||||
|
hashtags.remove(hashtag);
|
||||||
|
hashtags.put(hashtag, newValue);
|
||||||
|
|
||||||
// put in the hashmap hashtagsInVres too
|
// get the current list of vres in which the hashtag is present and add this new one
|
||||||
List<String> vres = new ArrayList<String>();
|
List<String> vres = hashtagsInVres.get(hashtag);
|
||||||
vres.add(vreid);
|
vres.add(context);
|
||||||
hashtagsInVres.put(hashtag, vres);
|
hashtagsInVres.put(hashtag, vres);
|
||||||
}
|
|
||||||
|
}else{
|
||||||
|
|
||||||
|
hashtags.put(hashtag, map.get(hashtag));
|
||||||
|
|
||||||
|
// put in the hashmap hashtagsInVres too
|
||||||
|
List<String> vres = new ArrayList<String>();
|
||||||
|
vres.add(context);
|
||||||
|
hashtagsInVres.put(hashtag, vres);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -181,24 +189,22 @@ public class TopicServiceImpl extends RemoteServiceServlet implements TopicServi
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//else must be in a VRE scope
|
logger.debug("****** retrieving hashtags for scope " + currentScope);
|
||||||
String scope = session.getScope();
|
Map<String, Integer> hashtags = store.getVREHashtagsWithOccurrenceFilteredByTime(currentScope, referenceTime.getTimeInMillis());
|
||||||
_log.debug("****** retrieving hashtags for scope " + scope);
|
|
||||||
Map<String, Integer> hashtags = store.getVREHashtagsWithOccurrenceFilteredByTime(scope, referenceTime.getTimeInMillis());
|
|
||||||
// now we need to evaluate the weight for each element
|
// now we need to evaluate the weight for each element
|
||||||
Map<String, Double> weights = evaluateWeight(hashtags, WINDOW_SIZE_IN_MONTHS, currentMonth, referenceTime, scope, null);
|
Map<String, Double> weights = evaluateWeight(hashtags, WINDOW_SIZE_IN_MONTHS, currentMonth, referenceTime, currentScope, null);
|
||||||
for (String hashtag : hashtags.keySet()) {
|
for (String hashtag : hashtags.keySet()) {
|
||||||
toSort.add(new HashTagAndOccurrence(hashtag, hashtags.get(hashtag), weights.get(hashtag)));
|
toSort.add(new HashTagAndOccurrence(hashtag, hashtags.get(hashtag), weights.get(hashtag)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_log.debug("Number of topics retrieved is " + toSort.size());
|
logger.debug("Number of topics retrieved is " + toSort.size());
|
||||||
|
|
||||||
Collections.sort(toSort); // sort for weight
|
Collections.sort(toSort); // sort for weight
|
||||||
|
|
||||||
for (HashTagAndOccurrence wrapper : toSort) {
|
for (HashTagAndOccurrence wrapper : toSort) {
|
||||||
|
|
||||||
_log.debug("Entry is " + wrapper.toString() + " with weight " + wrapper.getWeight());
|
logger.debug("Entry is " + wrapper.toString() + " with weight " + wrapper.getWeight());
|
||||||
|
|
||||||
String hashtag = wrapper.getHashtag();
|
String hashtag = wrapper.getHashtag();
|
||||||
|
|
||||||
|
@ -210,12 +216,12 @@ public class TopicServiceImpl extends RemoteServiceServlet implements TopicServi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
e.printStackTrace();
|
logger.error("Error while retrieving hashtags ", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
long timestampEnd = System.currentTimeMillis() - timestampStart;
|
long timestampEnd = System.currentTimeMillis() - timestampStart;
|
||||||
_log.debug("Overall time to retrieve hastags is " + timestampEnd + "ms");
|
logger.debug("Overall time to retrieve hastags is " + timestampEnd + "ms");
|
||||||
|
|
||||||
return new HashtagsWrapper(isInfrastructure, hashtagsChart);
|
return new HashtagsWrapper(isInfrastructure, hashtagsChart);
|
||||||
}
|
}
|
||||||
|
@ -273,7 +279,7 @@ public class TopicServiceImpl extends RemoteServiceServlet implements TopicServi
|
||||||
|
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
|
|
||||||
_log.error("Unable to retrieve the most recent feeds for hashtag " + entry.getKey() + " in " + vreId);
|
logger.error("Unable to retrieve the most recent feeds for hashtag " + entry.getKey() + " in " + vreId);
|
||||||
|
|
||||||
// put a weight of zero for this hashtag
|
// put a weight of zero for this hashtag
|
||||||
weights.put(entry.getKey(), 0.0);
|
weights.put(entry.getKey(), 0.0);
|
||||||
|
@ -293,7 +299,7 @@ public class TopicServiceImpl extends RemoteServiceServlet implements TopicServi
|
||||||
try{
|
try{
|
||||||
feedsForVre = store.getVREFeedsByHashtag(vre, entry.getKey());
|
feedsForVre = store.getVREFeedsByHashtag(vre, entry.getKey());
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
_log.error("Unable to retrieve the most recent feeds for hashtag " + entry.getKey() + " in " + vreId);
|
logger.error("Unable to retrieve the most recent feeds for hashtag " + entry.getKey() + " in " + vreId);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,7 +325,7 @@ public class TopicServiceImpl extends RemoteServiceServlet implements TopicServi
|
||||||
int sub = currentMonth - monstRecentFeedForHashTagTime.get(Calendar.MONTH);
|
int sub = currentMonth - monstRecentFeedForHashTagTime.get(Calendar.MONTH);
|
||||||
int value = sub >= 0? sub : 12 - Math.abs(sub);
|
int value = sub >= 0? sub : 12 - Math.abs(sub);
|
||||||
double freshness = 1.0 - (double)(value) / (double)(windowSize);
|
double freshness = 1.0 - (double)(value) / (double)(windowSize);
|
||||||
_log.debug("freshness is " + freshness + " for hashtag " + entry.getKey() +
|
logger.debug("freshness is " + freshness + " for hashtag " + entry.getKey() +
|
||||||
" because the last feed has month " + monstRecentFeedForHashTagTime.get(Calendar.MONTH));
|
" because the last feed has month " + monstRecentFeedForHashTagTime.get(Calendar.MONTH));
|
||||||
|
|
||||||
// update the weight
|
// update the weight
|
||||||
|
@ -333,7 +339,7 @@ public class TopicServiceImpl extends RemoteServiceServlet implements TopicServi
|
||||||
Map<String, Double> scoredListSorted = sortByWeight(weights);
|
Map<String, Double> scoredListSorted = sortByWeight(weights);
|
||||||
for(Entry<String, Double> entry : scoredListSorted.entrySet()){
|
for(Entry<String, Double> entry : scoredListSorted.entrySet()){
|
||||||
|
|
||||||
_log.debug("[hashtag=" + entry.getKey() + " , weight=" + entry.getValue() + "]");
|
logger.debug("[hashtag=" + entry.getKey() + " , weight=" + entry.getValue() + "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
return weights;
|
return weights;
|
||||||
|
@ -378,7 +384,7 @@ public class TopicServiceImpl extends RemoteServiceServlet implements TopicServi
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
_log.error("NullPointerException in isInfrastructureScope returning false");
|
logger.error("NullPointerException in isInfrastructureScope returning false");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
package org.gcube.portlets.user.topics.shared;
|
package org.gcube.portlets.user.topics.shared;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bean class for hashtag and its occurrence number
|
||||||
|
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||||
|
*/
|
||||||
public class HashTagAndOccurrence implements Comparable<HashTagAndOccurrence>{
|
public class HashTagAndOccurrence implements Comparable<HashTagAndOccurrence>{
|
||||||
private String hashtag;
|
private String hashtag;
|
||||||
private Integer occurrence;
|
private Integer occurrence;
|
||||||
|
|
Loading…
Reference in New Issue