added refreshing time in prop file
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/news-feed@72932 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
76dd55c325
commit
ae51ecbc94
|
@ -6,7 +6,6 @@
|
|||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="target/generated-sources/gwt"/>
|
||||
<classpathentry including="**/*.java" kind="src" output="src/main/webapp/WEB-INF/classes" path="src/main/resources"/>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#Tue Apr 02 16:01:09 CEST 2013
|
||||
#Thu Apr 04 16:40:07 CEST 2013
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<faceted-project>
|
||||
<fixed facet="wst.jsdt.web"/>
|
||||
<installed facet="jst.web" version="2.3"/>
|
||||
<installed facet="wst.jsdt.web" version="1.0"/>
|
||||
<installed facet="jst.web" version="2.5"/>
|
||||
<installed facet="java" version="1.6"/>
|
||||
</faceted-project>
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.gcube.portal.databook.shared.Comment;
|
|||
import org.gcube.portal.databook.shared.Like;
|
||||
import org.gcube.portal.databook.shared.UserInfo;
|
||||
import org.gcube.portlets.user.newsfeed.shared.EnhancedFeed;
|
||||
import org.gcube.portlets.user.newsfeed.shared.UserSettings;
|
||||
|
||||
import com.google.gwt.user.client.rpc.RemoteService;
|
||||
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
|
||||
|
@ -37,5 +38,5 @@ public interface NewsService extends RemoteService {
|
|||
|
||||
ArrayList<Comment> getAllCommentsByFeed(String feedid);
|
||||
|
||||
UserInfo getUserInfo();
|
||||
UserSettings getUserSettings();
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.gcube.portal.databook.shared.Comment;
|
|||
import org.gcube.portal.databook.shared.Like;
|
||||
import org.gcube.portal.databook.shared.UserInfo;
|
||||
import org.gcube.portlets.user.newsfeed.shared.EnhancedFeed;
|
||||
import org.gcube.portlets.user.newsfeed.shared.UserSettings;
|
||||
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
|
||||
|
@ -27,7 +28,7 @@ public interface NewsServiceAsync {
|
|||
|
||||
void getOnlyMyUserFeeds(AsyncCallback<ArrayList<EnhancedFeed>> callback);
|
||||
|
||||
void getUserInfo(AsyncCallback<UserInfo> callback);
|
||||
void getUserSettings(AsyncCallback<UserSettings> callback);
|
||||
|
||||
void comment(String feedid, String text, String feedOwnerId,
|
||||
AsyncCallback<Comment> callback);
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.gcube.portlets.user.newsfeed.client.templates.FilterPanel;
|
|||
import org.gcube.portlets.user.newsfeed.client.templates.SingleComment;
|
||||
import org.gcube.portlets.user.newsfeed.client.templates.TweetTemplate;
|
||||
import org.gcube.portlets.user.newsfeed.shared.EnhancedFeed;
|
||||
import org.gcube.portlets.user.newsfeed.shared.UserSettings;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.core.client.RunAsyncCallback;
|
||||
|
@ -73,13 +74,12 @@ public class NewsFeedPanel extends Composite {
|
|||
public static final String COMMENT_LABEL = "Reply";
|
||||
public static final String MESSAGE_LABEL = "Message";
|
||||
|
||||
public static final int delayMillis = 300000; //5 minutes
|
||||
private int delayMillis = 300000; //5 minutes by default
|
||||
|
||||
private boolean isFirstTweet = false;
|
||||
|
||||
private Image loadingImage;
|
||||
private UserInfo myUserInfo;
|
||||
|
||||
private FilterType currentFilter;
|
||||
private Timer feedsTimer;
|
||||
/**
|
||||
|
@ -176,15 +176,16 @@ public class NewsFeedPanel extends Composite {
|
|||
loadingImage = new Image(loading);
|
||||
newsPanel.add(loadingImage);
|
||||
|
||||
newsService.getUserInfo(new AsyncCallback<UserInfo>() {
|
||||
newsService.getUserSettings(new AsyncCallback<UserSettings>() {
|
||||
@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("<div class=\"nofeed-message\">" +
|
||||
"Ops! There were problems while retrieving your feeds!. <br> " +
|
||||
"Looks like we are not able to communicate with the infrastructure, (or your session expired)<br> please try again in a short while or refresh the page.</div>"));
|
||||
"Looks like we are not able to communicate with the infrastructure,<br> (or your session expired)<br> please try again in a short while or refresh the page.</div>"));
|
||||
stopTimer();
|
||||
}
|
||||
|
||||
|
|
|
@ -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<UserInfo>() {
|
||||
service.getUserSettings(new AsyncCallback<UserSettings>() {
|
||||
@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<UserInfo>() {
|
||||
service.getUserSettings(new AsyncCallback<UserSettings>() {
|
||||
@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<UserInfo>() {
|
||||
service.getUserSettings(new AsyncCallback<UserSettings>() {
|
||||
@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
|
||||
|
|
|
@ -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<String, Long> portraitIdCache;
|
||||
|
||||
public void init() {
|
||||
store = new DBCassandraAstyanaxImpl();
|
||||
portraitIdCache = new HashMap<String, Long>();
|
||||
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<EnhancedFeed> 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<String> likedFeeds = (ArrayList<String>) 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 + "]";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
# Defines the News Feed refreshing time in minutes
|
||||
REFRESH_TIME = 5
|
Loading…
Reference in New Issue