show error message when there is a connection problem issue

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/message-conversations@154652 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2017-09-27 12:43:48 +00:00
parent 652d1d5acc
commit 740bb2b707
4 changed files with 102 additions and 86 deletions

View File

@ -3,8 +3,6 @@ package org.gcube.portets.user.message_conversations.client;
import org.gcube.portets.user.message_conversations.client.ui.ApplicationView; import org.gcube.portets.user.message_conversations.client.ui.ApplicationView;
import com.google.gwt.core.client.EntryPoint; import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.RootPanel;
/** /**
@ -13,28 +11,14 @@ import com.google.gwt.user.client.ui.RootPanel;
public class MessageConversations implements EntryPoint { public class MessageConversations implements EntryPoint {
public static final String DIV_CONTAINER_ID = "create-users-container"; public static final String DIV_CONTAINER_ID = "create-users-container";
public static final String ARTIFACT_ID = "messages"; public static final String ARTIFACT_ID = "messages";
/**
* Create a remote service proxy to talk to the server-side Greeting service.
*/
private final MessageServiceAsync convService = GWT.create(MessageService.class);
private ApplicationView ap; private ApplicationView ap;
/** /**
* This is the entry point method. * This is the entry point method.
*/ */
public void onModuleLoad() { public void onModuleLoad() {
((ServiceDefTarget) convService).setServiceEntryPoint(Utils.getServiceEntryPoint());
ap = new ApplicationView(); ap = new ApplicationView();
RootPanel.get(DIV_CONTAINER_ID).add(ap); RootPanel.get(DIV_CONTAINER_ID).add(ap);
ap.readUserMessages(false);
} }
} }

View File

@ -115,6 +115,7 @@ public class ApplicationView extends Composite {
forward.setTooltip("Forward"); forward.setTooltip("Forward");
forward.setTooltipPosition(Position.LEFT); forward.setTooltipPosition(Position.LEFT);
} }
readUserMessages(false);
} }
/** /**
@ -140,12 +141,18 @@ public class ApplicationView extends Composite {
messageLoader.setVisible(false); messageLoader.setVisible(false);
} }
} else { } else {
RootPanel.get("create-users-container").add(new HTML("It is impossible to read your messages at this time. " showErrorOccurred();
+ "This could be a server error, please try to reload the page"));
} }
} }
}); });
} }
private void showErrorOccurred() {
messagesCollection.clear();
messagesLoader.setVisible(false);
messageLoader.setVisible(false);
hideSidePanel();
writeErrorMessage();
}
/** /**
* *
* @param messages * @param messages
@ -375,4 +382,20 @@ public class ApplicationView extends Composite {
totalMessages++; totalMessages++;
updateBadge(false); updateBadge(false);
} }
private void writeErrorMessage() {
MessagesResources images = GWT.create(MessagesResources.class);
List<MessageUserModel> recipients = Arrays.asList(new MessageUserModel(0, "you", "You", ""));
@SuppressWarnings("deprecation")
MessageUserModel sender = new MessageUserModel(0, "jarvis", "D4Science Team", images.d4scienceTeam().getURL(), "", "");
ConvMessage welcomeMessage = new ConvMessage("0", "An error occurred!", sender, recipients , new Date(), MessagesResources.ERROR_MESSAGE, true, false);
FAB.setVisible(false);
displayMessage.showMessage(welcomeMessage);
welcomeMessage.setContent(MessagesResources.ERROR_MESSAGE.substring(0, 102)+ " ...");
MessageItem item = new MessageItem(welcomeMessage, messagesCollection, this, false);
item.hideMessageMenu();
messagesCollection.add(item);
totalMessages++;
updateBadge(false);
}
} }

View File

@ -5,15 +5,18 @@ import com.google.gwt.resources.client.ImageResource;
public interface MessagesResources extends ClientBundle { public interface MessagesResources extends ClientBundle {
public static final String WELCOME_MESSAGE = "Welcome to your Messages.\nMessages lets you stay connected, organized, and productive at work, at home, and everywhere in between. "+ public static final String WELCOME_MESSAGE = "Welcome to your Messages.\nMessages lets you stay connected, organized, and productive at work, at home, and everywhere in between. "+
"Also, you can easily attach very large files to your messages from Workspace." + "Also, you can easily attach very large files to your messages from Workspace." +
"\n\nThis message will automatically be deleted as soon you'll receive another one."; "\n\nThis message will automatically be deleted as soon you'll receive another one.";
public static final String ERROR_MESSAGE = "We are very sorry, it is impossible to read your messages at the moment.\n\nThis could be either a networking problem or an error on the server."
+ " Please try to reload this page, if the error persists report the issue.";
@Source("group.png") @Source("group.png")
ImageResource group(); ImageResource group();
@Source("user.png") @Source("user.png")
ImageResource user(); ImageResource user();
@Source("d4science.png") @Source("d4science.png")
ImageResource d4scienceTeam(); ImageResource d4scienceTeam();
} }

View File

@ -121,73 +121,79 @@ public class ConvServiceImpl extends RemoteServiceServlet implements MessageServ
e.printStackTrace(); e.printStackTrace();
return null; return null;
} }
List<WorkspaceMessage> listMessages = null;
try {
listMessages = (sent) ?
workspace.getWorkspaceMessageManager().getSentMessages() : workspace.getWorkspaceMessageManager().getReceivedMessages();
} catch (Exception e) {
_log.error("Could not read messages of " + user.getFullname());
return null;
}
_log.debug("Got messages of " + user.getFullname() + " how many? " + listMessages.size());
//the messages are returned from the oldest to the new one, so we reverse them
Collections.reverse(listMessages);
LiferayUserManager um = new LiferayUserManager();
List<WorkspaceMessage> listMessages = (sent) ? for (WorkspaceMessage m : listMessages) {
workspace.getWorkspaceMessageManager().getSentMessages() : workspace.getWorkspaceMessageManager().getReceivedMessages(); String previewBody = m.getBody().length() > 80 ? m.getBody().substring(0, 79) + " ..." : m.getBody();
_log.debug("Got messages of " + user.getFullname() + " how many? " + listMessages.size()); MessageUserModel mu = null;
//the messages are returned from the oldest to the new one, so we reverse them GCubeUser sender = null;
Collections.reverse(listMessages); try {
LiferayUserManager um = new LiferayUserManager(); if (sent) {
if (m.getAddresses().size() < 2) {
GCubeUser recipient = um.getUserByUsername(m.getAddresses().get(0));
mu = new MessageUserModel(recipient.getUserId(), recipient.getUsername(), recipient.getFullname(), recipient.getUserAvatarURL(), "", "");
} else {
//we have at least 2 recipients
GCubeUser recipient1 = um.getUserByUsername(m.getAddresses().get(0));
GCubeUser recipient2 = um.getUserByUsername(m.getAddresses().get(1));
String label2Display = recipient1.getFirstName() + " & " + recipient2.getFirstName();
if (m.getAddresses().size() > 2)
label2Display += " & ...";
mu = new MessageUserModel(recipient1.getUserId(), recipient1.getUsername(), label2Display, null, "", "");
for (WorkspaceMessage m : listMessages) {
String previewBody = m.getBody().length() > 80 ? m.getBody().substring(0, 79) + " ..." : m.getBody();
MessageUserModel mu = null;
GCubeUser sender = null;
try {
if (sent) {
if (m.getAddresses().size() < 2) {
GCubeUser recipient = um.getUserByUsername(m.getAddresses().get(0));
mu = new MessageUserModel(recipient.getUserId(), recipient.getUsername(), recipient.getFullname(), recipient.getUserAvatarURL(), "", "");
} else {
//we have at least 2 recipients
GCubeUser recipient1 = um.getUserByUsername(m.getAddresses().get(0));
GCubeUser recipient2 = um.getUserByUsername(m.getAddresses().get(1));
String label2Display = recipient1.getFirstName() + " & " + recipient2.getFirstName();
if (m.getAddresses().size() > 2)
label2Display += " & ...";
mu = new MessageUserModel(recipient1.getUserId(), recipient1.getUsername(), label2Display, null, "", "");
}
} else { //received message
sender = um.getUserByUsername(m.getSender().getPortalLogin());
mu = new MessageUserModel(sender.getUserId(), sender.getUsername(), sender.getFullname(), sender.getUserAvatarURL(), "", "");
}
} catch (Exception ex) {
if (!sent) {
mu = new MessageUserModel(m.getSender().getPortalLogin());
} else {
mu = new MessageUserModel(m.getAddresses().get(0));
}
}
boolean hasAttachments = !m.getAttachmentsIds().isEmpty();
if (!sent) { //received messages
toReturn.add(new ConvMessage(
m.getId(),
m.getSubject(),
mu,
new Date(m.getSendTime().getTimeInMillis()),
previewBody,
m.isRead(),
hasAttachments));
} else { //sent messages
ArrayList<MessageUserModel> recipients = new ArrayList<>();
for (String rec : m.getAddresses()) {
recipients.add(new MessageUserModel(rec));
}
toReturn.add(new ConvMessage(
m.getId(),
m.getSubject(),
mu,
recipients,
new Date(m.getSendTime().getTimeInMillis()),
previewBody,
m.isRead(),
hasAttachments));
} }
} else { //received message
sender = um.getUserByUsername(m.getSender().getPortalLogin());
mu = new MessageUserModel(sender.getUserId(), sender.getUsername(), sender.getFullname(), sender.getUserAvatarURL(), "", "");
} }
} catch (Exception ex) {
if (!sent) {
mu = new MessageUserModel(m.getSender().getPortalLogin());
} else {
mu = new MessageUserModel(m.getAddresses().get(0));
}
}
boolean hasAttachments = !m.getAttachmentsIds().isEmpty();
if (!sent) { //received messages
toReturn.add(new ConvMessage(
m.getId(),
m.getSubject(),
mu,
new Date(m.getSendTime().getTimeInMillis()),
previewBody,
m.isRead(),
hasAttachments));
} else { //sent messages
ArrayList<MessageUserModel> recipients = new ArrayList<>();
for (String rec : m.getAddresses()) {
recipients.add(new MessageUserModel(rec));
}
toReturn.add(new ConvMessage(
m.getId(),
m.getSubject(),
mu,
recipients,
new Date(m.getSendTime().getTimeInMillis()),
previewBody,
m.isRead(),
hasAttachments));
}
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return null;
} }
_log.trace("get All Messages Received "); _log.trace("get All Messages Received ");
return toReturn; return toReturn;
@ -204,8 +210,8 @@ public class ConvServiceImpl extends RemoteServiceServlet implements MessageServ
Workspace workspace = manager.getHome().getWorkspace(); Workspace workspace = manager.getHome().getWorkspace();
WorkspaceMessage m = (sent) ? WorkspaceMessage m = (sent) ?
workspace.getWorkspaceMessageManager().getSentMessage(messageId): workspace.getWorkspaceMessageManager().getReceivedMessage(messageId); workspace.getWorkspaceMessageManager().getSentMessage(messageId): workspace.getWorkspaceMessageManager().getReceivedMessage(messageId);
m.setStatus(false); m.setStatus(false);
return true; return true;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return false; return false;