diff --git a/.classpath b/.classpath index 0b062bc..cefd118 100644 --- a/.classpath +++ b/.classpath @@ -1,12 +1,12 @@ - + - + @@ -22,7 +22,7 @@ - + @@ -35,5 +35,5 @@ - + diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 2f37318..29adda4 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -8,6 +8,9 @@ uses + + uses + uses diff --git a/distro/changelog.xml b/distro/changelog.xml index 33fcd2a..63c4429 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -1,7 +1,8 @@ - + Updated Workspace Explorer dependency + Added support for SendTo diff --git a/src/main/java/org/gcube/portets/user/message_conversations/client/Encoder.java b/src/main/java/org/gcube/portets/user/message_conversations/client/Encoder.java new file mode 100644 index 0000000..ca5909c --- /dev/null +++ b/src/main/java/org/gcube/portets/user/message_conversations/client/Encoder.java @@ -0,0 +1,15 @@ +package org.gcube.portets.user.message_conversations.client; +/** + * simply encode base64 strings + * @author massi + * + */ +public class Encoder { + public static native String encode(String toEncode) /*-{ + return btoa(toEncode); + }-*/; + + public static native String decode(String toDecode) /*-{ + return atob(toDecode); +}-*/; +} diff --git a/src/main/java/org/gcube/portets/user/message_conversations/client/MessageConversations.java b/src/main/java/org/gcube/portets/user/message_conversations/client/MessageConversations.java index ae0fa44..02974ea 100644 --- a/src/main/java/org/gcube/portets/user/message_conversations/client/MessageConversations.java +++ b/src/main/java/org/gcube/portets/user/message_conversations/client/MessageConversations.java @@ -3,22 +3,50 @@ package org.gcube.portets.user.message_conversations.client; import org.gcube.portets.user.message_conversations.client.ui.ApplicationView; import com.google.gwt.core.client.EntryPoint; +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.RootPanel; /** - * Entry point classes define onModuleLoad(). + * @author Massimiliano Assante, CNR-ISTI */ public class MessageConversations implements EntryPoint { public static final String DIV_CONTAINER_ID = "create-users-container"; public static final String ARTIFACT_ID = "messages"; - + public static final String USER_PROFILE_OID = "userIdentificationParameter"; private ApplicationView ap; /** * This is the entry point method. */ public void onModuleLoad() { - ap = new ApplicationView(); + String[] usernamesToSendTo = getUserToShowId(); + //we check whether there exists usernames to send to in the params, if not regular Messages else we show the new message panel to send the message to the users passed + ap = (usernamesToSendTo != null && usernamesToSendTo.length > 0) ? + new ApplicationView(usernamesToSendTo) : new ApplicationView(); RootPanel.get(DIV_CONTAINER_ID).add(ap); } + + /** + * decode the usernames from the location param (the list of usernames decoded should be comma separated e.g. username1,username2) + * @return the decoded (base64) userid + */ + public static String[] getUserToShowId() { + String encodedOid = Encoder.encode(USER_PROFILE_OID); + if (Window.Location.getParameter(encodedOid) == null) + return null; + try { + String encodedUsernames = Window.Location.getParameter(encodedOid); + String decodedUserNames = Encoder.decode(encodedUsernames); + if (decodedUserNames.contains(",")) + return decodedUserNames.split(","); + else { + String[] usernames = {decodedUserNames}; + return usernames; + } + } catch (Exception e) { + GWT.log("Something wring in parsing username list"); + return null; + } + } } diff --git a/src/main/java/org/gcube/portets/user/message_conversations/client/MessageService.java b/src/main/java/org/gcube/portets/user/message_conversations/client/MessageService.java index 5eaad2e..fd822f3 100644 --- a/src/main/java/org/gcube/portets/user/message_conversations/client/MessageService.java +++ b/src/main/java/org/gcube/portets/user/message_conversations/client/MessageService.java @@ -16,6 +16,7 @@ public interface MessageService extends RemoteService { ArrayList getMessages(boolean sent); ConvMessage getMessageById(String messageId, boolean sent); CurrUserAndPortalUsersWrapper getWorkspaceUsers(); + ArrayList getUsersInfo(String[] usernames); ArrayList searchUsers(String keyword); boolean sendToById(ArrayList recipientIds, ArrayList listAttachmentsId, String subject, String body); boolean deleteMessageById(String messageId, boolean sent); diff --git a/src/main/java/org/gcube/portets/user/message_conversations/client/ui/ApplicationView.java b/src/main/java/org/gcube/portets/user/message_conversations/client/ui/ApplicationView.java index c0bbccc..921b741 100755 --- a/src/main/java/org/gcube/portets/user/message_conversations/client/ui/ApplicationView.java +++ b/src/main/java/org/gcube/portets/user/message_conversations/client/ui/ApplicationView.java @@ -63,7 +63,9 @@ import gwt.material.design.client.ui.MaterialRow; import gwt.material.design.client.ui.MaterialToast; import gwt.material.design.client.ui.animate.MaterialAnimation; import gwt.material.design.client.ui.animate.Transition; - +/** + * @author Massimiliano Assante, CNR-ISTI + */ public class ApplicationView extends Composite { interface Binder extends UiBinder { @@ -92,9 +94,9 @@ public class ApplicationView extends Composite { private ConvMessage currentSelected; private DisplayMessage displayMessage; private WriteMessage newMessageDisplay; + private boolean isSendTo = false; - - public ApplicationView() { + public ApplicationView(String... sendToUserNames) { initWidget(uiBinder.createAndBindUi(this)); ((ServiceDefTarget) convService).setServiceEntryPoint(Utils.getServiceEntryPoint()); displayMessage = new DisplayMessage(convService, this); @@ -115,14 +117,22 @@ public class ApplicationView extends Composite { forward.setTooltip("Forward"); forward.setTooltipPosition(Position.LEFT); } - readUserMessages(false); + + String[] usernamesToSendTo = sendToUserNames; + if (usernamesToSendTo != null && usernamesToSendTo.length > 0) { + prepareNewMessageForSendTo(usernamesToSendTo); + isSendTo = true; + messageLoader.setVisible(false); + } + readUserMessages(false, isSendTo); + } /** * * @param sent */ - public void readUserMessages(final boolean sent) { + public void readUserMessages(final boolean sent, boolean isSendTo) { messagesLoader.setVisible(true); convService.getMessages(sent, new AsyncCallback>() { @Override @@ -134,11 +144,13 @@ public class ApplicationView extends Composite { public void onSuccess(ArrayList messages) { if (messages != null) { showMessages(messages, sent); - if (messages.size() > 0) - readUserMessage(messages.get(0).getId(), sent); - else { - writeWelcomeMessage(); - messageLoader.setVisible(false); + if (!isSendTo) { + if (messages.size() > 0) + readUserMessage(messages.get(0).getId(), sent); + else { + writeWelcomeMessage(); + messageLoader.setVisible(false); + } } } else { showErrorOccurred(); @@ -279,7 +291,7 @@ public class ApplicationView extends Composite { switcher.setIconType(IconType.INBOX); } toggleSwitch = ! toggleSwitch; - readUserMessages(toggleSwitch); + readUserMessages(toggleSwitch, false); } @UiHandler("menu") @@ -302,6 +314,12 @@ public class ApplicationView extends Composite { hideSidePanel(); } + private void prepareNewMessageForSendTo(String[] usernamesToSendTo) { + newMessageDisplay = new WriteMessage(convService, this); + newMessageDisplay.setNewMessageForSendTo(usernamesToSendTo); + displayNewOrReplyMessage(); + } + @UiHandler("newMessage") void onNewMessage(ClickEvent e) { newMessageDisplay = new WriteMessage(convService, this); @@ -382,7 +400,7 @@ public class ApplicationView extends Composite { totalMessages++; updateBadge(false); } - + private void writeErrorMessage() { MessagesResources images = GWT.create(MessagesResources.class); List recipients = Arrays.asList(new MessageUserModel(0, "you", "You", "")); diff --git a/src/main/java/org/gcube/portets/user/message_conversations/client/ui/WriteMessage.java b/src/main/java/org/gcube/portets/user/message_conversations/client/ui/WriteMessage.java index 1b83dca..db4fa5c 100644 --- a/src/main/java/org/gcube/portets/user/message_conversations/client/ui/WriteMessage.java +++ b/src/main/java/org/gcube/portets/user/message_conversations/client/ui/WriteMessage.java @@ -44,7 +44,9 @@ import gwt.material.design.client.ui.MaterialPreLoader; import gwt.material.design.client.ui.MaterialRow; import gwt.material.design.client.ui.MaterialTextArea; import gwt.material.design.client.ui.MaterialTextBox; - +/** + * @author Massimiliano Assante, CNR-ISTI + */ public class WriteMessage extends Composite { private static MessageWindowUiBinder uiBinder = GWT.create(MessageWindowUiBinder.class); @@ -79,6 +81,21 @@ public class WriteMessage extends Composite { MaterialPanel getMainPanel() { return mainPanel; } + + public void setNewMessageForSendTo(String[] usernames) { + GWT.log("her add the users"); + convService.getUsersInfo(usernames, new AsyncCallback>() { + @Override + public void onFailure(Throwable caught) { + } + @Override + public void onSuccess(ArrayList result) { + for (WSUser user : result) { + acModal.addItem(new UserSuggestion(user)); + } + } + }); + } public void setIsReply(ConvMessage msg) { acModal.addItem(new UserSuggestion( diff --git a/src/main/java/org/gcube/portets/user/message_conversations/server/ConvServiceImpl.java b/src/main/java/org/gcube/portets/user/message_conversations/server/ConvServiceImpl.java index 224a2e3..56de4d3 100644 --- a/src/main/java/org/gcube/portets/user/message_conversations/server/ConvServiceImpl.java +++ b/src/main/java/org/gcube/portets/user/message_conversations/server/ConvServiceImpl.java @@ -53,7 +53,7 @@ import com.liferay.portal.service.GroupLocalServiceUtil; import com.liferay.portal.service.UserLocalServiceUtil; import com.liferay.portal.util.PortalUtil; /** - * The server side implementation of the RPC service. + * @author Massimiliano Assante, CNR-ISTI */ @SuppressWarnings("serial") public class ConvServiceImpl extends RemoteServiceServlet implements MessageService { @@ -362,6 +362,25 @@ public class ConvServiceImpl extends RemoteServiceServlet implements MessageServ return toReturn; } + @Override + public ArrayList getUsersInfo(String[] usernames) { + ArrayList toReturn = new ArrayList<>(); + if (isWithinPortal()) { + try { + for (String username : usernames) { + User user = UserLocalServiceUtil.getUserByScreenName(ManagementUtils.getCompany().getCompanyId(), username); + toReturn.add(new WSUser(""+user.getUserId(), user.getScreenName(), user.getFullName(), extractDomainFromEmail(user.getEmailAddress()))); + } + } catch (SystemException | PortalException e) { + e.printStackTrace(); + } + } else { //development + toReturn.add(new WSUser("andrea.rossi", "andrea.rossi", "Andrea Rossi", "rossi@gmail.com")); + toReturn.add(new WSUser("ginoi", "gino", "Gino Pino", "gino@hotmail.com")); + } + return toReturn; + } + @Override public boolean sendToById(ArrayList recipientIds, ArrayList listAttachmentsId, String subject, String body) { PortalContext pContext = PortalContext.getConfiguration(); @@ -521,4 +540,5 @@ public class ConvServiceImpl extends RemoteServiceServlet implements MessageServ + } diff --git a/src/main/java/org/gcube/portets/user/message_conversations/server/portlet/MessagesPortlet.java b/src/main/java/org/gcube/portets/user/message_conversations/server/portlet/MessagesPortlet.java index e8fb074..0f4986a 100644 --- a/src/main/java/org/gcube/portets/user/message_conversations/server/portlet/MessagesPortlet.java +++ b/src/main/java/org/gcube/portets/user/message_conversations/server/portlet/MessagesPortlet.java @@ -11,16 +11,7 @@ import javax.portlet.PortletRequestDispatcher; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; - -/** - * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * - */ public class MessagesPortlet extends GenericPortlet { - - - /** * JSP folder name */ diff --git a/src/main/webapp/WEB-INF/jsp/Messages_view.jsp b/src/main/webapp/WEB-INF/jsp/Messages_view.jsp index 94ba7eb..9f9f031 100644 --- a/src/main/webapp/WEB-INF/jsp/Messages_view.jsp +++ b/src/main/webapp/WEB-INF/jsp/Messages_view.jsp @@ -1,18 +1,31 @@ - + <%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%> <%@ page import="org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager"%> <%@ page import="org.gcube.common.authorization.library.provider.UserInfo"%> <%@ page import="org.gcube.common.portal.PortalContext"%> +<%@ page import="com.liferay.portal.util.PortalUtil"%> +<%@ page import="javax.servlet.http.HttpServletRequest"%> + <% + String USER_PROFILE_OID = "userIdentificationParameter"; + String encoded_USER_PROFILE_OID = "dXNlcklkZW50aWZpY2F0aW9uUGFyYW1ldGVy"; //for simplicity we add the encoded version of the param above + String additionalParameter = ""; + + HttpServletRequest r = PortalUtil.getHttpServletRequest(renderRequest); + + if (PortalUtil.getOriginalServletRequest(r).getParameter(encoded_USER_PROFILE_OID) != null) { + additionalParameter = "&"+encoded_USER_PROFILE_OID+"="+PortalUtil.getOriginalServletRequest(r).getParameter(encoded_USER_PROFILE_OID); + System.out.println("found additional parameter ... " + additionalParameter); + } long groupId = com.liferay.portal.util.PortalUtil.getScopeGroupId(request); long userId = com.liferay.portal.util.PortalUtil.getUser(request).getUserId(); String strURL = response.encodeURL( - request.getContextPath() + "/MessageConversations.html?gid=" + groupId + "&uid=" + userId); + request.getContextPath() + "/MessageConversations.html?gid=" + groupId + "&uid=" + userId + additionalParameter); %> + marginheight="0" frameborder="0" scrolling="no" + style="overflow-x: hidden;">