Added support for SendTo

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/message-conversations@169229 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2018-06-14 16:42:21 +00:00
parent d6a28f356a
commit 3cd5a30c1b
12 changed files with 144 additions and 35 deletions

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/messages-2.0.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<classpathentry kind="src" output="target/messages-2.1.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.0.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<classpathentry excluding="**" kind="src" output="target/messages-2.1.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
@ -22,7 +22,7 @@
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/messages-2.0.0-SNAPSHOT/WEB-INF/classes" path="target/generated-sources/gwt">
<classpathentry kind="src" output="target/messages-2.1.0-SNAPSHOT/WEB-INF/classes" path="target/generated-sources/gwt">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
@ -35,5 +35,5 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/messages-2.0.0-SNAPSHOT/WEB-INF/classes"/>
<classpathentry kind="output" path="target/messages-2.1.0-SNAPSHOT/WEB-INF/classes"/>
</classpath>

View File

@ -8,6 +8,9 @@
<dependent-module archiveName="workspace-explorer-2.0.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/workspace-explorer-TRUNK-1.5.0-SNAPSHOT/workspace-explorer-TRUNK-1.5.0-SNAPSHOT">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="storagehub-icons-library-1.0.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/storagehub-icons-library/storagehub-icons-library">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="client-context-library-1.0.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/client-context-library/client-context-library">
<dependency-type>uses</dependency-type>
</dependent-module>

View File

@ -1,7 +1,8 @@
<ReleaseNotes>
<Changeset component="org.gcube.portlets-user.messages.2-0-0"
date="2018-05-23">
<Changeset component="org.gcube.portlets-user.messages.2-1-0"
date="2018-06-14">
<Change>Updated Workspace Explorer dependency</Change>
<Change>Added support for SendTo</Change>
</Changeset>
<Changeset component="org.gcube.portlets-user.messages.2-0-0"
date="2017-09-21">

View File

@ -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);
}-*/;
}

View File

@ -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 <code>onModuleLoad()</code>.
* @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;
}
}
}

View File

@ -16,6 +16,7 @@ public interface MessageService extends RemoteService {
ArrayList<ConvMessage> getMessages(boolean sent);
ConvMessage getMessageById(String messageId, boolean sent);
CurrUserAndPortalUsersWrapper getWorkspaceUsers();
ArrayList<WSUser> getUsersInfo(String[] usernames);
ArrayList<WSUser> searchUsers(String keyword);
boolean sendToById(ArrayList<String> recipientIds, ArrayList<String> listAttachmentsId, String subject, String body);
boolean deleteMessageById(String messageId, boolean sent);

View File

@ -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<Widget, ApplicationView> {
@ -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<ArrayList<ConvMessage>>() {
@Override
@ -134,11 +144,13 @@ public class ApplicationView extends Composite {
public void onSuccess(ArrayList<ConvMessage> 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<MessageUserModel> recipients = Arrays.asList(new MessageUserModel(0, "you", "You", ""));

View File

@ -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<ArrayList<WSUser>>() {
@Override
public void onFailure(Throwable caught) {
}
@Override
public void onSuccess(ArrayList<WSUser> result) {
for (WSUser user : result) {
acModal.addItem(new UserSuggestion(user));
}
}
});
}
public void setIsReply(ConvMessage msg) {
acModal.addItem(new UserSuggestion(

View File

@ -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<WSUser> getUsersInfo(String[] usernames) {
ArrayList<WSUser> 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<String> recipientIds, ArrayList<String> listAttachmentsId, String subject, String body) {
PortalContext pContext = PortalContext.getConfiguration();
@ -521,4 +540,5 @@ public class ConvServiceImpl extends RemoteServiceServlet implements MessageServ
}

View File

@ -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
*/

View File

@ -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"%>
<portlet:defineObjects />
<%
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);
%>
<script type="application/javascript">
@ -28,7 +41,8 @@ window.addEventListener('DOMContentLoaded', function(e) {
</script>
<iframe id="myIframe" src='<%=strURL%>' width="100%" marginwidth="0"
marginheight="0" frameborder="0" scrolling="no" style=" overflow-x: hidden; "> </iframe>
marginheight="0" frameborder="0" scrolling="no"
style="overflow-x: hidden;"> </iframe>
<!-- iFrame resize handler -->
<script type="text/javascript">

View File

@ -6,6 +6,7 @@
<portlet-name>MessageConv</portlet-name>
<layout-cacheable>false</layout-cacheable>
<instanceable>false</instanceable>
<requires-namespaced-parameters>false</requires-namespaced-parameters>
<ajaxable>false</ajaxable>
<header-portlet-css>/MessageConversations.css</header-portlet-css>
</portlet>