() {
@Override
public void onFailure(Throwable caught) {
}
@Override
- public void onSuccess(UserInfo result) {
- myUserInfo = result;
- if (result.getUsername().equals("test.user")) {
+ public void onSuccess(UserSettings result) {
+ myUserInfo = result.getUserInfo();
+ delayMillis = result.getRefreshingTimeInMillis();
+ if (result.getUserInfo().getUsername().equals("test.user")) {
Window.alert("Your session has expired, please log out and login again");
}
else {
@@ -438,7 +439,7 @@ public class NewsFeedPanel extends Composite {
newsPanel.clear();
newsPanel.add(new HTML("" +
"Ops! There were problems while retrieving your feeds!.
" +
- "Looks like we are not able to communicate with the infrastructure, (or your session expired)
please try again in a short while or refresh the page.
"));
+ "Looks like we are not able to communicate with the infrastructure,
(or your session expired)
please try again in a short while or refresh the page."));
stopTimer();
}
diff --git a/src/main/java/org/gcube/portlets/user/newsfeed/client/templates/FilterPanel.java b/src/main/java/org/gcube/portlets/user/newsfeed/client/templates/FilterPanel.java
index cc30d0a..9a4f9dd 100644
--- a/src/main/java/org/gcube/portlets/user/newsfeed/client/templates/FilterPanel.java
+++ b/src/main/java/org/gcube/portlets/user/newsfeed/client/templates/FilterPanel.java
@@ -4,6 +4,7 @@ import org.gcube.portal.databook.shared.UserInfo;
import org.gcube.portlets.user.newsfeed.client.FilterType;
import org.gcube.portlets.user.newsfeed.client.NewsServiceAsync;
import org.gcube.portlets.user.newsfeed.client.panels.NewsFeedPanel;
+import org.gcube.portlets.user.newsfeed.shared.UserSettings;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Cursor;
@@ -87,15 +88,15 @@ public class FilterPanel extends Composite {
onlyme.removeStyleName("filter-selected");
favoritesLink.setStyleName("filter-selected");
caller.setCurrentFilter(FilterType.LIKEDFEEDS);
- service.getUserInfo(new AsyncCallback() {
+ service.getUserSettings(new AsyncCallback() {
@Override
public void onFailure(Throwable caught) {
Window.alert(ERROR_MESSAGE);
}
@Override
- public void onSuccess(UserInfo result) {
- if (result.getUsername().equals("test.user")) {
+ public void onSuccess(UserSettings result) {
+ if (result.getUserInfo().getUsername().equals("test.user")) {
Window.alert(SESSION_EXPIRED);
}
else
@@ -110,15 +111,15 @@ public class FilterPanel extends Composite {
favoritesLink.removeStyleName("filter-selected");
allUpdatesLink.setStyleName("filter-selected");
caller.setCurrentFilter(FilterType.ALL_UPDATES);
- service.getUserInfo(new AsyncCallback() {
+ service.getUserSettings(new AsyncCallback() {
@Override
public void onFailure(Throwable caught) {
Window.alert(ERROR_MESSAGE);
}
@Override
- public void onSuccess(UserInfo result) {
- if (result.getUsername().equals("test.user")) {
+ public void onSuccess(UserSettings result) {
+ if (result.getUserInfo().getUsername().equals("test.user")) {
Window.alert(SESSION_EXPIRED);
}
else
@@ -133,15 +134,15 @@ public class FilterPanel extends Composite {
favoritesLink.removeStyleName("filter-selected");
onlyme.setStyleName("filter-selected");
caller.setCurrentFilter(FilterType.MINE);
- service.getUserInfo(new AsyncCallback() {
+ service.getUserSettings(new AsyncCallback() {
@Override
public void onFailure(Throwable caught) {
Window.alert(ERROR_MESSAGE);
}
@Override
- public void onSuccess(UserInfo result) {
- if (result.getUsername().equals("test.user")) {
+ public void onSuccess(UserSettings result) {
+ if (result.getUserInfo().getUsername().equals("test.user")) {
Window.alert(SESSION_EXPIRED);
}
else
diff --git a/src/main/java/org/gcube/portlets/user/newsfeed/server/NewsServiceImpl.java b/src/main/java/org/gcube/portlets/user/newsfeed/server/NewsServiceImpl.java
index 61b92e6..eac8401 100644
--- a/src/main/java/org/gcube/portlets/user/newsfeed/server/NewsServiceImpl.java
+++ b/src/main/java/org/gcube/portlets/user/newsfeed/server/NewsServiceImpl.java
@@ -1,10 +1,14 @@
package org.gcube.portlets.user.newsfeed.server;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
+import java.util.Properties;
import java.util.UUID;
import org.gcube.application.framework.core.session.ASLSession;
@@ -26,6 +30,7 @@ import org.gcube.portal.databook.shared.ex.FeedTypeNotFoundException;
import org.gcube.portal.databook.shared.ex.PrivacyLevelTypeNotFoundException;
import org.gcube.portlets.user.newsfeed.client.NewsService;
import org.gcube.portlets.user.newsfeed.shared.EnhancedFeed;
+import org.gcube.portlets.user.newsfeed.shared.UserSettings;
import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayGroupManager;
@@ -63,13 +68,8 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
private final static int MAX_FEEDS_NO = 20;
-
- //this is the cache for the user portraitsId that change among portals, the cache avoids to continuosly ask the LR DB the portraitID;
- private HashMap portraitIdCache;
-
public void init() {
- store = new DBCassandraAstyanaxImpl();
- portraitIdCache = new HashMap();
+ store = new DBCassandraAstyanaxImpl();
}
public void destroy() {
@@ -106,9 +106,11 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
else {
//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)
+ if (userName.compareTo("test.user") == 0) {
+ _log.debug("Found " + userName + " returning nothing");
return null;
-
+ }
+
_log.info("****** retrieving feeds for user: " + userName);
User currUser = OrganizationsUtil.validateUser(userName);
@@ -218,8 +220,8 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
}
return null;
}
-
-
+
+
/**
@@ -280,7 +282,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
}
return enhanceFeeds(userFeeds);
}
-
+
@Override
public ArrayList getOnlyLikedFeeds() {
String userName = getASLSession().getUsername();
@@ -297,7 +299,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
@Override
public boolean like(String feedid, String feedText, String feedOwnerId) {
boolean likeCommitResult = false;
- UserInfo user = getUserInfo();
+ UserInfo user = getUserSettings().getUserInfo();
Like toLike = new Like(UUID.randomUUID().toString(), user.getUsername(),
new Date(), feedid, user.getFullName(), user.getAvatarId());
try {
@@ -311,8 +313,8 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
if (likeCommitResult) {
//if the user who liked this post is not the user who posted it notify the poster user (Feed owner)
if (! user.getUsername().equals(feedOwnerId)) {
- NotificationsManager nm = new ApplicationNotificationsManager(getASLSession());
- boolean nResult = nm.notifyLikedFeed(feedOwnerId, feedid, escapeHtml(feedText));
+ NotificationsManager nm = new ApplicationNotificationsManager(getASLSession());
+ boolean nResult = nm.notifyLikedFeed(feedOwnerId, feedid, escapeHtml(feedText));
_log.trace("Like Notification added? " + nResult);
}
}
@@ -327,7 +329,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
public Comment comment(String feedid, String commentText, String feedOwnerId) {
boolean commentCommitResult = false;
_log.trace("Trying to add this comment " + commentText);
- UserInfo user = getUserInfo();
+ UserInfo user = getUserSettings().getUserInfo();
Comment comment = new Comment(UUID.randomUUID().toString(), user.getUsername(),
new Date(), feedid, escapeHtml(commentText), user.getFullName(), user.getAvatarId());
try {
@@ -348,7 +350,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
}
//if there are other users who liked this post they get notified too, asynchronously with this thread
Thread thread = new Thread(new NotificationsThread(commentText, nm, getAllLikesByFeed(feedid)));
- thread.start();
+ thread.start();
}
return comment;
}
@@ -368,10 +370,10 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
//sort the Feeds
Collections.sort(toEnhance, Collections.reverseOrder());
ArrayList likedFeeds = (ArrayList) store.getAllLikedFeedIdsByUser(getASLSession().getUsername());
-// System.out.println("Liked Feed for " + username);
-// for (String liked : likedFeeds) {
-// System.out.println(liked);
-// }
+ // System.out.println("Liked Feed for " + username);
+ // for (String liked : likedFeeds) {
+ // System.out.println(liked);
+ // }
for (Feed feed : toEnhance) {
feed.setDescription(replaceAmpersand(feed.getDescription()));
@@ -435,25 +437,20 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
return "";
}
StringBuilder thumbnailURL = new StringBuilder("/image/user_male_portrait?img_id=");
-// if (portraitIdCache.containsKey(screenName))
-// return thumbnailURL.append(portraitIdCache.get(screenName)).toString();
-// else {
- User user = null;
- try {
- user = UserLocalServiceUtil.getUserByScreenName(OrganizationsUtil.getCompany().getCompanyId(), screenName);
-// portraitIdCache.put(screenName, user.getPortraitId());
- } catch (PortalException e) {
- e.printStackTrace();
- } catch (SystemException e) {
- e.printStackTrace();
- }
- return thumbnailURL.append(user.getPortraitId()).toString();
-// }
+ User user = null;
+ try {
+ user = UserLocalServiceUtil.getUserByScreenName(OrganizationsUtil.getCompany().getCompanyId(), screenName);
+ } catch (PortalException e) {
+ e.printStackTrace();
+ } catch (SystemException e) {
+ e.printStackTrace();
+ }
+ return thumbnailURL.append(user.getPortraitId()).toString();
}
@Override
- public UserInfo getUserInfo() {
+ public UserSettings getUserSettings() {
if (getUserFromSession() != null)
return getUserFromSession();
try {
@@ -469,19 +466,22 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
email = user.getEmailAddress();
ThemeDisplay themeDisplay = (ThemeDisplay) this.getThreadLocalRequest().getSession().getAttribute(WebKeys.THEME_DISPLAY);
String accountURL = themeDisplay.getURLMyAccount().toString();
- UserInfo toReturn = new UserInfo(username, fullName, thumbnailURL, user.getEmailAddress(), accountURL, true, false, null);
+
+ UserInfo userInfo = new UserInfo(username, fullName, thumbnailURL, user.getEmailAddress(), accountURL, true, false, null);
+ UserSettings toReturn = new UserSettings(userInfo, getFeedsRefreshTimeInMillis());
setUserInSession(toReturn);
return toReturn;
}
else {
_log.info("Returning test USER");
- return new UserInfo(getASLSession().getUsername(), fullName, thumbnailURL, email, "fakeAccountUrl", true, false, null);
+ UserInfo user = new UserInfo(getASLSession().getUsername(), fullName, thumbnailURL, email, "fakeAccountUrl", true, false, null);
+ return new UserSettings(user, getFeedsRefreshTimeInMillis());
}
} catch (Exception e) {
e.printStackTrace();
}
- return new UserInfo();
+ return new UserSettings();
}
@Override
@@ -525,11 +525,11 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
}
}
- private UserInfo getUserFromSession() {
- return (UserInfo) getASLSession().getAttribute(UserInfo.USER_INFO_ATTR);
+ private UserSettings getUserFromSession() {
+ return (UserSettings) getASLSession().getAttribute(UserInfo.USER_INFO_ATTR);
}
- private void setUserInSession(UserInfo user) {
+ private void setUserInSession(UserSettings user) {
getASLSession().setAttribute(UserInfo.USER_INFO_ATTR, user);
}
/**
@@ -558,7 +558,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
@Override
public Comment editComment(Comment toEdit) {
- UserInfo user = getUserInfo();
+ UserInfo user = getUserSettings().getUserInfo();
Comment edited = new Comment(toEdit.getKey(), toEdit.getUserid(),
new Date(), toEdit.getFeedid(), escapeHtml(toEdit.getText()), user.getFullName(), user.getAvatarId());
try {
@@ -626,4 +626,36 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
return true;
return false;
}
+ /**
+ * read from the property the refreshing time
+ * @return the refreshingTime in milliseconds
+ */
+ private int getFeedsRefreshTimeInMillis() {
+ Properties props = new Properties();
+ int toReturn = 0;
+ int minutes = 0;
+ try {
+ String propertyfile = this.getThreadLocalRequest().getServletPath()+"conf/settings.properties";
+ File propsFile = new File(propertyfile);
+ FileInputStream fis = new FileInputStream(propsFile);
+ props.load( fis);
+
+ minutes = Integer.parseInt(props.getProperty("REFRESH_TIME"));
+ toReturn = minutes*60*1000;
+ }
+ //catch exception in case properties file does not exist
+ catch(IOException e) {
+ toReturn = 300000; //5 minutes
+ _log.error("settings.properties file not found under conf dir, returning 5 minutes");
+ return toReturn;
+ }
+ //catch exception in case the property value isNot a Number
+ catch (ClassCastException ex) {
+ toReturn = 300000; //5 minutes
+ _log.error("REFRESH_TIME must be a number (in minutes) returning 5 minutes");
+ return toReturn;
+ }
+ _log.debug("Returning REFRESH_TIME in millis: " + toReturn + " minutes: " + minutes);
+ return toReturn;
+ }
}
diff --git a/src/main/java/org/gcube/portlets/user/newsfeed/shared/UserSettings.java b/src/main/java/org/gcube/portlets/user/newsfeed/shared/UserSettings.java
new file mode 100644
index 0000000..d5833ae
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/newsfeed/shared/UserSettings.java
@@ -0,0 +1,37 @@
+package org.gcube.portlets.user.newsfeed.shared;
+
+import java.io.Serializable;
+
+import org.gcube.portal.databook.shared.UserInfo;
+
+@SuppressWarnings("serial")
+public class UserSettings implements Serializable {
+ private UserInfo userInfo;
+ private int refreshingTimeInMillis;
+ public UserSettings() {
+ super();
+ // TODO Auto-generated constructor stub
+ }
+ public UserSettings(UserInfo userInfo, int refreshingTimeInMillis) {
+ super();
+ this.userInfo = userInfo;
+ this.refreshingTimeInMillis = refreshingTimeInMillis;
+ }
+ public UserInfo getUserInfo() {
+ return userInfo;
+ }
+ public void setUserInfo(UserInfo userInfo) {
+ this.userInfo = userInfo;
+ }
+ public int getRefreshingTimeInMillis() {
+ return refreshingTimeInMillis;
+ }
+ public void setRefreshingTimeInMillis(int refreshingTimeInMillis) {
+ this.refreshingTimeInMillis = refreshingTimeInMillis;
+ }
+ @Override
+ public String toString() {
+ return "UserSettings [userInfo=" + userInfo
+ + ", refreshingTimeInMillis=" + refreshingTimeInMillis + "]";
+ }
+}
diff --git a/src/main/webapp/conf/settings.properties b/src/main/webapp/conf/settings.properties
new file mode 100644
index 0000000..af56cad
--- /dev/null
+++ b/src/main/webapp/conf/settings.properties
@@ -0,0 +1,2 @@
+# Defines the News Feed refreshing time in minutes
+REFRESH_TIME = 5
\ No newline at end of file