solved bug:

-right panel slow down when the message were more then 1000
This commit is contained in:
lucio.lelii 2021-04-13 18:50:15 +02:00
parent f9911cbdc6
commit 1c3d93ebba
12 changed files with 543 additions and 84 deletions

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/messages-2.4.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<classpathentry kind="src" output="target/messages-2.5.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/messages-2.4.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<classpathentry excluding="**" kind="src" output="target/messages-2.5.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
@ -22,13 +22,13 @@
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/messages-2.4.0-SNAPSHOT/WEB-INF/classes" path="target/generated-sources/gwt">
<classpathentry kind="src" output="target/messages-2.5.0-SNAPSHOT/WEB-INF/classes" path="target/generated-sources/gwt">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="com.gwtplugins.gwt.eclipse.core.GWT_CONTAINER/gwt-2.8.1"/>
<classpathentry kind="con" path="com.gwtplugins.gwt.eclipse.core.GWT_CONTAINER"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
@ -36,22 +36,5 @@
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="/Users/massi/portal/distro/GWT SDK/gwt-2.8.2/gwt-user.jar">
<attributes>
<attribute name="javadoc_location" value="file:/Users/massi/portal/distro/GWT%20SDK/gwt-2.8.2/doc/javadoc/"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="/Users/massi/portal/distro/GWT SDK/gwt-2.8.2/gwt-codeserver.jar">
<attributes>
<attribute name="javadoc_location" value="file:/Users/massi/portal/distro/GWT%20SDK/gwt-2.8.2/doc/javadoc/"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="/Users/massi/portal/distro/GWT SDK/gwt-2.8.2/gwt-dev.jar">
<attributes>
<attribute name="javadoc_location" value="file:/Users/massi/portal/distro/GWT%20SDK/gwt-2.8.2/doc/javadoc/"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="/Users/massi/portal/distro/GWT SDK/gwt-2.8.2/validation-api-1.0.0.GA-sources.jar"/>
<classpathentry kind="lib" path="/Users/massi/portal/distro/GWT SDK/gwt-2.8.2/validation-api-1.0.0.GA.jar" sourcepath="/Users/massi/portal/distro/GWT SDK/gwt-2.8.2/validation-api-1.0.0.GA-sources.jar"/>
<classpathentry kind="output" path="target/messages-2.4.0-SNAPSHOT/WEB-INF/classes"/>
<classpathentry kind="output" path="target/messages-2.5.0-SNAPSHOT/WEB-INF/classes"/>
</classpath>

View File

@ -3,7 +3,9 @@ org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8

View File

@ -1,11 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="messages">
<wb-module deploy-name="messages-2.5.0-SNAPSHOT">
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/target/generated-sources/gwt"/>
<property name="java-output-path" value="/message-conversations/target/message-conversations-0.0.1-SNAPSHOT/WEB-INF/classes"/>
<property name="context-root" value="messages"/>
</wb-module>
</project-modules>

View File

@ -55,7 +55,6 @@ import gwt.material.design.client.constants.IconType;
import gwt.material.design.client.constants.Position;
import gwt.material.design.client.ui.MaterialAnchorButton;
import gwt.material.design.client.ui.MaterialBadge;
import gwt.material.design.client.ui.MaterialCollection;
import gwt.material.design.client.ui.MaterialFAB;
import gwt.material.design.client.ui.MaterialLink;
import gwt.material.design.client.ui.MaterialProgress;
@ -88,10 +87,12 @@ public class ApplicationView extends Composite {
@UiField MaterialFAB FAB;
@UiField MaterialLink menu, newMessage, switcher;
@UiField MaterialAnchorButton replyAll, reply, forward;
@UiField MaterialCollection messagesCollection;
@UiField MaterialProgress messageLoader, messagesLoader;
@UiField MaterialBadge badge;
@UiField ShowMorePagerPanel pagerPanel;
MyMaterialCollection<ConvMessage> messagesCollection;
private ConvMessage currentSelected;
private DisplayMessage displayMessage;
private WriteMessage newMessageDisplay;
@ -160,7 +161,6 @@ public class ApplicationView extends Composite {
});
}
private void showErrorOccurred() {
messagesCollection.clear();
messagesLoader.setVisible(false);
messageLoader.setVisible(false);
hideSidePanel();
@ -172,18 +172,21 @@ public class ApplicationView extends Composite {
* @param sent
*/
public void showMessages(ArrayList<ConvMessage> messages, boolean sent) {
messagesCollection.clear();
messagesLoader.setVisible(false);
messagesCollection.setVisible(true);
int scrollerHeight = Window.getClientHeight() - 100;
scrollerPanel.setHeight(scrollerHeight+"px");
scrollerPanel.setHeight(scrollerHeight+"px");
pagerPanel.setHeight(scrollerHeight+"px");
GWT.log("message returned are "+messages.size());
messagesCollection= new MyMaterialCollection<>(messages, c -> new MessageItem(c, messagesCollection, this, sent));
messagesCollection.init();
pagerPanel.setDisplay(messagesCollection);
for (ConvMessage convMessage : messages) {
messagesCollection.add(new MessageItem(convMessage, messagesCollection, this, sent));
if (! (sent || convMessage.isRead()))
unreadMessages++;
totalMessages++;
}
if (messages.size() > 0) {
GWT.log("message returned are "+messages.size());
MessageItem first = (MessageItem) messagesCollection.getChildrenList().get(0);
first.setSelected(true);
} else {
@ -247,7 +250,6 @@ public class ApplicationView extends Composite {
}
private void displayMessage(String messageId, final boolean sent) {
messageLoader.setColor(Utils.getRandomColor());
messageLoader.setVisible(true);
scrollerPanel.clear();
convService.getMessageById(messageId, toggleSwitch, new AsyncCallback<ConvMessage>() {

View File

@ -1,7 +1,9 @@
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui' xmlns:m="urn:import:gwt.material.design.client.ui"
xmlns:g='urn:import:com.google.gwt.user.client.ui'
xmlns:m="urn:import:gwt.material.design.client.ui"
xmlns:ma="urn:import:gwt.material.design.addins.client"
xmlns:mc="urn:import:org.gcube.portets.user.message_conversations.client.autocomplete">
xmlns:mc="urn:import:org.gcube.portets.user.message_conversations.client.autocomplete"
xmlns:my="urn:import:org.gcube.portets.user.message_conversations.client.ui">
<ui:style>
.animation {
@ -41,42 +43,47 @@
<g:HTMLPanel ui:field="htmlPanel">
<!-- TOP BAR -->
<m:MaterialHeader ui:field="header">
<m:MaterialNavBar ui:field="navBar" layoutPosition="FIXED"
addStyleNames="{style.topBar}" height="60" backgroundColor="WHITE">
<m:MaterialNavSection float="LEFT" showOn="SHOW_ON_MED_DOWN">
<m:MaterialLink iconType="MENU" iconColor="LIGHT_BLUE_DARKEN_2"
paddingLeft="25" waves="DEFAULT" ui:field="menu" hideOn="HIDE_ON_MED_DOWN" />
<m:MaterialLink iconType="INBOX" textColor="LIGHT_BLUE_DARKEN_2"
ui:field="switcher" waves="DEFAULT" paddingLeft="25">
<m:MaterialBadge text="22 unread" backgroundColor="LIGHT_BLUE_DARKEN_2"
textColor="WHITE" circle="false" ui:field="badge" visible="false"
<m:MaterialNavBar ui:field="navBar"
layoutPosition="FIXED" addStyleNames="{style.topBar}" height="60"
backgroundColor="WHITE">
<m:MaterialNavSection float="LEFT"
showOn="SHOW_ON_MED_DOWN">
<m:MaterialLink iconType="MENU"
iconColor="LIGHT_BLUE_DARKEN_2" paddingLeft="25" waves="DEFAULT"
ui:field="menu" hideOn="HIDE_ON_MED_DOWN" />
<m:MaterialLink iconType="INBOX"
textColor="LIGHT_BLUE_DARKEN_2" ui:field="switcher"
waves="DEFAULT" paddingLeft="25">
<m:MaterialBadge text="22 unread"
backgroundColor="LIGHT_BLUE_DARKEN_2" textColor="WHITE"
circle="false" ui:field="badge" visible="false"
hideOn="HIDE_ON_MED_DOWN" />
</m:MaterialLink>
<m:MaterialLink ui:field="newMessage" text="New"
showOn="SHOW_ON_MED_DOWN" iconType="MESSAGE" textColor="LIGHT_BLUE_DARKEN_2"
waves="LIGHT" />
showOn="SHOW_ON_MED_DOWN" iconType="MESSAGE"
textColor="LIGHT_BLUE_DARKEN_2" waves="LIGHT" />
</m:MaterialNavSection>
</m:MaterialNavBar>
</m:MaterialHeader>
<!-- SIDE PANEL -->
<m:MaterialRow ui:field="rightPanel" overflow="AUTO"
depth="995" grid="l3 m3 s12" padding="0" backgroundColor="WHITE"
height="100%" layoutPosition="FIXED" top="60" left="0" width="350px"
<m:MaterialRow ui:field="rightPanel" depth="995"
grid="l3 m3 s12" padding="0" backgroundColor="WHITE" height="90%"
layoutPosition="FIXED" top="60" left="0" width="350px"
addStyleNames="{style.animation} {style.borderRight}">
<m:MaterialProgress type="INDETERMINATE" ui:field="messagesLoader"
color="BLUE" />
<m:MaterialCollection ui:field="messagesCollection"
addStyleNames="{style.marginTop}" visible="false">
</m:MaterialCollection>
<m:MaterialProgress type="INDETERMINATE"
ui:field="messagesLoader" color="BLUE" />
<my:ShowMorePagerPanel ui:field="pagerPanel"
addStyleNames="{style.marginTop}">
</my:ShowMorePagerPanel>
</m:MaterialRow>
<!-- MAIN WINDOW -->
<m:MaterialContainer fontSize="0.8em">
<m:MaterialRow layoutPosition="RELATIVE" grid="l8 s12 m12"
top="65">
<m:MaterialRow layoutPosition="RELATIVE"
grid="l8 s12 m12" top="65">
<m:MaterialProgress type="INDETERMINATE"
ui:field="messageLoader" color="TEAL" />
<g:ScrollPanel height="600px" ui:field="scrollerPanel"
@ -86,16 +93,20 @@
<!-- FAB -->
<m:MaterialFAB ui:field="FAB">
<m:MaterialButton type="FLOATING" backgroundColor="RED"
iconType="REPLY" size="LARGE" />
<m:MaterialButton type="FLOATING"
backgroundColor="RED" iconType="REPLY" size="LARGE" />
<m:MaterialFABList>
<m:MaterialAnchorButton type="FLOATING"
waves="LIGHT" backgroundColor="BLUE" ui:field="forward" iconType="FORWARD" />
waves="LIGHT" backgroundColor="BLUE" ui:field="forward"
iconType="FORWARD" />
<m:MaterialAnchorButton type="FLOATING"
waves="LIGHT" backgroundColor="AMBER" ui:field="replyAll" iconType="REPLY_ALL" />
waves="LIGHT" backgroundColor="AMBER" ui:field="replyAll"
iconType="REPLY_ALL" />
<m:MaterialAnchorButton type="FLOATING"
waves="LIGHT" backgroundColor="TEAL" ui:field="reply" iconType="REPLY" />
waves="LIGHT" backgroundColor="TEAL" ui:field="reply"
iconType="REPLY" />
</m:MaterialFABList>
</m:MaterialFAB>
</g:HTMLPanel>
</ui:UiBinder>

View File

@ -0,0 +1,113 @@
package org.gcube.portets.user.message_conversations.client.ui;
import java.util.ArrayList;
import java.util.function.Function;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.view.client.HasRows;
import com.google.gwt.view.client.Range;
import com.google.gwt.view.client.RangeChangeEvent.Handler;
import gwt.material.design.client.ui.MaterialCollection;
public class MyMaterialCollection<T> extends MaterialCollection implements HasRows {
private final int DEFAULT_LENGTH= 20;
private boolean init_called = false;
ArrayList<T> objects = new ArrayList<>();
Function<T, Widget> converter;
public MyMaterialCollection(ArrayList<T> objects, Function<T, Widget> function) {
this.objects = objects;
this.converter = function;
}
int start=0;
int length=DEFAULT_LENGTH;
public void init(){
if (init_called) GWT.log("init already called");
else {
init_called = true;
onRangeChanged();
}
}
private void onRangeChanged() {
int widgetCountIndex = super.getWidgetCount()-1;
int index = widgetCountIndex-1>start ? widgetCountIndex: start;
int finish = length>objects.size()? objects.size():length ;
for (int i =index; i<finish; i++) {
super.add(converter.apply(objects.get(i)));
}
}
public void add(Widget widget) {}
@Override
public HandlerRegistration addRangeChangeHandler(Handler handler) {
return new MyHandlerRegistration();
}
@Override
public HandlerRegistration addRowCountChangeHandler(
com.google.gwt.view.client.RowCountChangeEvent.Handler handler) {
return new MyHandlerRegistration();
}
@Override
public int getRowCount() {
GWT.log("get row count");
return objects.size();
}
@Override
public Range getVisibleRange() {
GWT.log("get visible range");
return new Range(start, length);
}
@Override
public boolean isRowCountExact() {
GWT.log("is row exact");
return true;
}
@Override
public void setRowCount(int count) {
GWT.log("set row count");
}
@Override
public void setRowCount(int count, boolean isExact) {
GWT.log("set row count ex");
}
@Override
public void setVisibleRange(int start, int length) {
this.start = start;
this.length = length;
onRangeChanged();
}
@Override
public void setVisibleRange(Range range) {
this.setVisibleRange(range.getStart(), range.getLength());
}
class MyHandlerRegistration implements HandlerRegistration{
@Override
public void removeHandler() {
GWT.log("handler removed");
}
}
}

View File

@ -0,0 +1,106 @@
package org.gcube.portets.user.message_conversations.client.ui;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ScrollEvent;
import com.google.gwt.event.dom.client.ScrollHandler;
import com.google.gwt.user.cellview.client.AbstractPager;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.view.client.HasRows;
/**
* A scrolling pager that automatically increases the range every time the
* scroll bar reaches the bottom.
*/
public class ShowMorePagerPanel extends AbstractPager {
/**
* The default increment size.
*/
private static final int DEFAULT_INCREMENT = 20;
/**
* The increment size.
*/
private int incrementSize = DEFAULT_INCREMENT;
/**
* The last scroll position.
*/
private int lastScrollPos = 0;
/**
* The scrollable panel.
*/
private final ScrollPanel scrollable = new ScrollPanel();
/**
* Construct a new {@link ShowMorePagerPanel}.
*/
public ShowMorePagerPanel() {
initWidget(scrollable);
// Do not let the scrollable take tab focus.
scrollable.getElement().setTabIndex(-1);
// Handle scroll events.
scrollable.addScrollHandler(new ScrollHandler() {
public void onScroll(ScrollEvent event) {
// If scrolling up, ignore the event.
int oldScrollPos = lastScrollPos;
lastScrollPos = scrollable.getVerticalScrollPosition();
if (oldScrollPos >= lastScrollPos) {
return;
}
HasRows display = getDisplay();
if (display == null) {
return;
}
int maxScrollTop = scrollable.getWidget().getOffsetHeight()
- scrollable.getOffsetHeight();
if (lastScrollPos >= maxScrollTop) {
// We are near the end, so increase the page size.
int newPageSize = Math.min(
display.getVisibleRange().getLength() + incrementSize,
display.getRowCount());
display.setVisibleRange(0, newPageSize);
}
}
});
}
/**
* Get the number of rows by which the range is increased when the scrollbar
* reaches the bottom.
*
* @return the increment size
*/
public int getIncrementSize() {
return incrementSize;
}
@Override
public void setDisplay(HasRows display) {
assert display instanceof Widget : "display must extend Widget";
scrollable.setWidget((Widget) display);
scrollable.scrollToTop();
super.setDisplay(display);
}
/**
* Set the number of rows by which the range is increased when the scrollbar
* reaches the bottom.
*
* @param incrementSize the incremental number of rows
*/
public void setIncrementSize(int incrementSize) {
GWT.log("increment of "+ incrementSize);
this.incrementSize = incrementSize;
}
@Override
protected void onRangeOrRowCountChanged() {
GWT.log("range changed ...");
}
}

View File

@ -0,0 +1,79 @@
package org.gcube.portets.user.message_conversations.server;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import org.gcube.portets.user.message_conversations.client.MessageService;
import org.gcube.portets.user.message_conversations.shared.ConvMessage;
import org.gcube.portets.user.message_conversations.shared.CurrUserAndPortalUsersWrapper;
import org.gcube.portets.user.message_conversations.shared.WSUser;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
@SuppressWarnings("serial")
public class ConvService extends RemoteServiceServlet implements MessageService, HttpServletRetriever {
MessageService delegate;
public void init() {
delegate = new ConvServiceImpl(this);
}
@Override
public ArrayList<ConvMessage> getMessages(boolean sent) {
return delegate.getMessages(sent);
}
@Override
public ConvMessage getMessageById(String messageId, boolean sent) {
return delegate.getMessageById(messageId, sent);
}
@Override
public CurrUserAndPortalUsersWrapper getWorkspaceUsers() {
return delegate.getWorkspaceUsers();
}
@Override
public ArrayList<WSUser> getUsersInfo(String[] usernames) {
return delegate.getUsersInfo(usernames);
}
@Override
public ArrayList<WSUser> searchUsers(String keyword) {
return delegate.searchUsers(keyword);
}
@Override
public boolean sendToById(ArrayList<String> recipientIds, ArrayList<String> listAttachmentsId, String subject,
String body) {
return delegate.sendToById(recipientIds, listAttachmentsId, subject, body);
}
@Override
public boolean deleteMessageById(String messageId, boolean sent) {
return delegate.deleteMessageById(messageId, sent);
}
@Override
public String getAttachmentDownloadURL(String itemId) {
return delegate.getAttachmentDownloadURL(itemId);
}
@Override
public boolean saveAttachmentToWorkspaceFolder(String itemId, String destinationFolderId) {
return delegate.saveAttachmentToWorkspaceFolder(itemId, destinationFolderId);
}
@Override
public boolean markMessageUnread(String messageId, boolean sent) {
return delegate.markMessageUnread(messageId, sent);
}
@Override
public HttpServletRequest getRequest() {
return getThreadLocalRequest();
}
}

View File

@ -37,7 +37,6 @@ import org.gcube.vomanagement.usermanagement.util.ManagementUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.model.User;
@ -47,16 +46,18 @@ import com.liferay.portal.util.PortalUtil;
/**
* @author Massimiliano Assante, CNR-ISTI
*/
@SuppressWarnings("serial")
public class ConvServiceImpl extends RemoteServiceServlet implements MessageService {
public class ConvServiceImpl implements MessageService {
private static final Logger _log = LoggerFactory.getLogger(ConvServiceImpl.class);
private PortalContext pContext;
private UserManager um;
public void init() {
private HttpServletRetriever requestRetriever;
ConvServiceImpl(HttpServletRetriever servletRetriever) {
um = new LiferayUserManager();
pContext = PortalContext.getConfiguration();
requestRetriever= servletRetriever;
}
/**
*
@ -89,7 +90,7 @@ public class ConvServiceImpl extends RemoteServiceServlet implements MessageServ
return null;
}
} else {
return pContext.getCurrentUser(getThreadLocalRequest());
return pContext.getCurrentUser(requestRetriever.getRequest());
}
}
@ -97,10 +98,10 @@ public class ConvServiceImpl extends RemoteServiceServlet implements MessageServ
public ArrayList<ConvMessage> getMessages(boolean sent) {
ArrayList<ConvMessage> toReturn = new ArrayList<>();
try {
GCubeUser user = getCurrentUser(getThreadLocalRequest());
GCubeUser user = getCurrentUser(requestRetriever.getRequest());
pContext = PortalContext.getConfiguration();
_log.debug("*** Reading user = " +user.getFullname());
String scope = pContext.getCurrentScope(getThreadLocalRequest());
String scope = pContext.getCurrentScope(requestRetriever.getRequest());
ScopeProvider.instance.set(scope);
String token = pContext.getCurrentUserToken(scope, user.getUserId());
SecurityTokenProvider.instance.set(token);
@ -186,8 +187,8 @@ public class ConvServiceImpl extends RemoteServiceServlet implements MessageServ
@Override
public boolean markMessageUnread(String messageId, boolean sent) {
GCubeUser user = getCurrentUser(getThreadLocalRequest());
String scope = pContext.getCurrentScope(getThreadLocalRequest());
GCubeUser user = getCurrentUser(requestRetriever.getRequest());
String scope = pContext.getCurrentScope(requestRetriever.getRequest());
SecurityTokenProvider.instance.set(pContext.getCurrentUserToken(scope, user.getUserId()));
try {
MessageManagerClient client = AbstractPlugin.messages().build();
@ -203,9 +204,9 @@ public class ConvServiceImpl extends RemoteServiceServlet implements MessageServ
public ConvMessage getMessageById(String messageId, boolean sent) {
ConvMessage toReturn = null;
try {
GCubeUser user = getCurrentUser(getThreadLocalRequest());
GCubeUser user = getCurrentUser(requestRetriever.getRequest());
_log.debug("*** Reading user from liferay session = " +user.getFullname());
String scope = pContext.getCurrentScope(getThreadLocalRequest());
String scope = pContext.getCurrentScope(requestRetriever.getRequest());
SecurityTokenProvider.instance.set(pContext.getCurrentUserToken(scope, user.getUserId()));
LiferayUserManager um = new LiferayUserManager();
MessageManagerClient client = AbstractPlugin.messages().build();
@ -262,8 +263,8 @@ public class ConvServiceImpl extends RemoteServiceServlet implements MessageServ
@Override
public String getAttachmentDownloadURL(String itemId) {
GCubeUser user = getCurrentUser(getThreadLocalRequest());
String scope = pContext.getCurrentScope(getThreadLocalRequest());
GCubeUser user = getCurrentUser(requestRetriever.getRequest());
String scope = pContext.getCurrentScope(requestRetriever.getRequest());
SecurityTokenProvider.instance.set(pContext.getCurrentUserToken(scope, user.getUserId()));
_log.info("getAttachmentDownloadURL for user "+user.getUsername() + " file id="+itemId);
try {
@ -278,8 +279,8 @@ public class ConvServiceImpl extends RemoteServiceServlet implements MessageServ
}
@Override
public boolean saveAttachmentToWorkspaceFolder(String itemId, String destinationFolderId) {
GCubeUser user = getCurrentUser(getThreadLocalRequest());
String scope = pContext.getCurrentScope(getThreadLocalRequest());
GCubeUser user = getCurrentUser(requestRetriever.getRequest());
String scope = pContext.getCurrentScope(requestRetriever.getRequest());
SecurityTokenProvider.instance.set(pContext.getCurrentUserToken(scope, user.getUserId()));
try {
StorageHubClient shc = new StorageHubClient();
@ -294,9 +295,9 @@ public class ConvServiceImpl extends RemoteServiceServlet implements MessageServ
@Override
public boolean deleteMessageById(String messageId, boolean sent) {
GCubeUser user = getCurrentUser(getThreadLocalRequest());
GCubeUser user = getCurrentUser(requestRetriever.getRequest());
_log.debug("deleteMessageById reading user from liferay session = " +user.getFullname() + " m id = " + messageId);
String scope = pContext.getCurrentScope(getThreadLocalRequest());
String scope = pContext.getCurrentScope(requestRetriever.getRequest());
SecurityTokenProvider.instance.set(pContext.getCurrentUserToken(scope, user.getUserId()));
try {
MessageManagerClient client = AbstractPlugin.messages().build();
@ -313,7 +314,7 @@ public class ConvServiceImpl extends RemoteServiceServlet implements MessageServ
public ArrayList<WSUser> searchUsers(String keyword) {
ArrayList<WSUser> toReturn = new ArrayList<>();
if (isWithinPortal()) {
long gatewayGroupId = pContext.getCurrentGroupId(this.getThreadLocalRequest());
long gatewayGroupId = pContext.getCurrentGroupId(this.requestRetriever.getRequest());
try {
_log.debug("Searching " + keyword);
List<GCubeUser> users = um.searchUsersByGroup(keyword, gatewayGroupId);
@ -357,7 +358,7 @@ public class ConvServiceImpl extends RemoteServiceServlet implements MessageServ
@Override
public boolean sendToById(ArrayList<String> recipientIds, ArrayList<String> listAttachmentsId, String subject, String body) {
PortalContext pContext = PortalContext.getConfiguration();
GCubeUser currentUser = pContext.getCurrentUser(getThreadLocalRequest());
GCubeUser currentUser = pContext.getCurrentUser(requestRetriever.getRequest());
MessageManagerClient client = AbstractPlugin.messages().build();
try {
_log.info("Sending message to: " + recipientIds.toString());
@ -375,7 +376,7 @@ public class ConvServiceImpl extends RemoteServiceServlet implements MessageServ
List<GenericItemBean> recipients = getUsersbyUserId(recipientIds);
NotificationsManager nm = new ApplicationNotificationsManager(new SocialNetworkingSite(getThreadLocalRequest()), pContext.getCurrentScope(getThreadLocalRequest()),
NotificationsManager nm = new ApplicationNotificationsManager(new SocialNetworkingSite(requestRetriever.getRequest()), pContext.getCurrentScope(requestRetriever.getRequest()),
new SocialNetworkingUser(
currentUser.getUsername(),
currentUser.getEmail(),
@ -472,7 +473,7 @@ public class ConvServiceImpl extends RemoteServiceServlet implements MessageServ
public CurrUserAndPortalUsersWrapper getWorkspaceUsers() {
PortalContext pContext = PortalContext.getConfiguration();
GCubeUser currentUser = pContext.getCurrentUser(getThreadLocalRequest());
GCubeUser currentUser = pContext.getCurrentUser(requestRetriever.getRequest());
_log.debug("trying to get WorkspaceUsers ..");
WSUser currUser = null;
ArrayList<WSUser> portalUsers = new ArrayList<WSUser>();

View File

@ -0,0 +1,144 @@
package org.gcube.portets.user.message_conversations.server;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.gcube.portets.user.message_conversations.client.MessageService;
import org.gcube.portets.user.message_conversations.shared.ConvMessage;
import org.gcube.portets.user.message_conversations.shared.CurrUserAndPortalUsersWrapper;
import org.gcube.portets.user.message_conversations.shared.MessageUserModel;
import org.gcube.portets.user.message_conversations.shared.WSUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class FakeConvServiceImpl implements MessageService{
private static final Logger _log = LoggerFactory.getLogger(FakeConvServiceImpl.class);
ArrayList<ConvMessage> receivedMessages;
ArrayList<ConvMessage> sentMessages;
Map<String,ConvMessage> receivedMessagesMap = new HashMap<>();
Map<String,ConvMessage> sentMessagesMap = new HashMap<>();
final int messageReceivedNumberToTest = 200;
final int messageSentNumberToTest = 11;
public FakeConvServiceImpl() {
Calendar cal = Calendar.getInstance();
MessageUserModel mu = new MessageUserModel("andrea.rossi");
List<MessageUserModel> recipients = Arrays.asList(new MessageUserModel("lucio.lelii"));
String prefix ="received";
receivedMessages = new ArrayList<>();
for (int i =0; i<messageReceivedNumberToTest; i++) {
String id = "id-"+prefix+i;
ConvMessage msg= new ConvMessage(id, prefix+i, mu, recipients, new Date(cal.getTimeInMillis()), prefix+i, false, false);
receivedMessages.add(msg);
receivedMessagesMap.put(id, msg);
}
prefix ="sent";
sentMessages = new ArrayList<>();
for (int i =0; i<messageSentNumberToTest; i++) {
String id = "id-"+prefix+i;
ConvMessage msg= new ConvMessage(id, prefix+i, mu, recipients, new Date(cal.getTimeInMillis()), prefix+i, false, false);
sentMessages.add(msg);
sentMessagesMap.put(id, msg);
}
}
@Override
public ArrayList<ConvMessage> getMessages(boolean sent) {
if (sent) {
_log.info("sent messages call with sent {}",sent);
return new ArrayList<>(sentMessages);
}
else {
_log.info("received messages call with sent {}",sent);
return new ArrayList<>(receivedMessages);
}
}
@Override
public ConvMessage getMessageById(String messageId, boolean sent) {
_log.info("get messageById called with id {} and sent {}", messageId,sent );
ConvMessage msg;
if (sent)
msg = sentMessagesMap.get(messageId);
else msg = receivedMessagesMap.get(messageId);
msg.setRead(true);
return msg;
}
@Override
public CurrUserAndPortalUsersWrapper getWorkspaceUsers() {
_log.debug("trying to get WorkspaceUsers ..");
WSUser currUser = new WSUser("andrea.rossi", "andrea.rossi", "Andrea Rossi", "m.assante@gmail.com");
ArrayList<WSUser> portalUsers = new ArrayList<WSUser>();
for (int i = 0; i < 10; i++) {
portalUsers.add(new WSUser(""+i, "username"+i, "userGetFullname()"+i, "user.getEmail()"+i));
}
CurrUserAndPortalUsersWrapper toReturn = new CurrUserAndPortalUsersWrapper(currUser, portalUsers);
return toReturn;
}
@Override
public ArrayList<WSUser> getUsersInfo(String[] usernames) {
return new ArrayList<>(Arrays.asList(new WSUser("andrea.rossi", "andrea.rossi", "Andrea Rossi", "m.assante@gmail.com")));
}
@Override
public ArrayList<WSUser> searchUsers(String keyword) {
return new ArrayList<>(Arrays.asList(new WSUser("andrea.rossi", "andrea.rossi", "Andrea Rossi", "m.assante@gmail.com")));
}
@Override
public boolean sendToById(ArrayList<String> recipientIds, ArrayList<String> listAttachmentsId, String subject,
String body) {
_log.info("email sent");
return true;
}
@Override
public boolean deleteMessageById(String messageId, boolean sent) {
_log.info("message deleted");
return true;
}
@Override
public String getAttachmentDownloadURL(String itemId) {
return "www.google.it";
}
@Override
public boolean saveAttachmentToWorkspaceFolder(String itemId, String destinationFolderId) {
_log.info("attachment saved");
return true;
}
@Override
public boolean markMessageUnread(String messageId, boolean sent) {
_log.info("message marked");
return true;
}
}

View File

@ -0,0 +1,8 @@
package org.gcube.portets.user.message_conversations.server;
import javax.servlet.http.HttpServletRequest;
public interface HttpServletRetriever {
HttpServletRequest getRequest();
}

View File

@ -7,7 +7,7 @@
<!-- Servlets -->
<servlet>
<servlet-name>convServlet</servlet-name>
<servlet-class>org.gcube.portets.user.message_conversations.server.ConvServiceImpl</servlet-class>
<servlet-class>org.gcube.portets.user.message_conversations.server.ConvService</servlet-class>
</servlet>
<servlet-mapping>
@ -20,7 +20,7 @@
<servlet-class>com.liferay.portal.kernel.servlet.PortalDelegateServlet</servlet-class>
<init-param>
<param-name>servlet-class</param-name>
<param-value>org.gcube.portets.user.message_conversations.server.ConvServiceImpl</param-value>
<param-value>org.gcube.portets.user.message_conversations.server.ConvService</param-value>
</init-param>
<init-param>
<param-name>sub-context</param-name>