From e0674f99c3888393f048c087fc509f9d1b73e9ba Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Fri, 25 Mar 2016 10:47:56 +0000 Subject: [PATCH] works like a charm git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portlets/user/join-vre@126288 82a268e6-3cf1-43bd-a215-b396298e98cf --- .settings/org.eclipse.wst.common.component | 3 + .../portlets/user/joinvre/client/JoinVRE.java | 5 +- .../joinvre/client/ui/AccessVREDialog.java | 7 +- .../client/ui/AccessViaInviteDialog.java | 36 +++++- .../joinvre/server/EmailNotification.java | 106 ------------------ .../user/joinvre/server/JoinServiceImpl.java | 35 ++---- .../user/joinvre/server/LoginServiceUtil.java | 74 ++++++------ .../server/portlet/JoinVREPortlet.java | 6 +- .../portlets/user/joinvre/JoinVRE.gwt.xml | 2 +- 9 files changed, 80 insertions(+), 194 deletions(-) delete mode 100644 src/main/java/org/gcube/portlets/user/joinvre/server/EmailNotification.java diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 2ff775f..1b65ee8 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -4,6 +4,9 @@ + + uses + diff --git a/src/main/java/org/gcube/portlets/user/joinvre/client/JoinVRE.java b/src/main/java/org/gcube/portlets/user/joinvre/client/JoinVRE.java index 0e0a565..95365f8 100644 --- a/src/main/java/org/gcube/portlets/user/joinvre/client/JoinVRE.java +++ b/src/main/java/org/gcube/portlets/user/joinvre/client/JoinVRE.java @@ -30,10 +30,7 @@ public class JoinVRE implements EntryPoint { private void checkIsReferral() { logger.log(Level.INFO,"checkIsReferral()"); if (getSiteLiferayId() == null) { - ResponsivePanel rp = null; - rp = displayVREs(); -// //TODO: REMOVE -// checkInvitation(new VRE(), 1, rp); + displayVREs(); } else { Long vreId = -1L; diff --git a/src/main/java/org/gcube/portlets/user/joinvre/client/ui/AccessVREDialog.java b/src/main/java/org/gcube/portlets/user/joinvre/client/ui/AccessVREDialog.java index 107d7fd..78c6183 100644 --- a/src/main/java/org/gcube/portlets/user/joinvre/client/ui/AccessVREDialog.java +++ b/src/main/java/org/gcube/portlets/user/joinvre/client/ui/AccessVREDialog.java @@ -20,6 +20,7 @@ import com.google.gwt.user.client.ui.Widget; public class AccessVREDialog extends Composite { private final JoinServiceAsync joinService = GWT.create(JoinService.class); + private final static boolean IS_INVITATION = false; private static AccessVREDialogUiBinder uiBinder = GWT .create(AccessVREDialogUiBinder.class); @@ -30,7 +31,7 @@ public class AccessVREDialog extends Composite { @UiField Button confirmRequest; @UiField HelpBlock helpBlock; @UiField Icon loading; - private boolean isInvitation = false; + VRE myVRE = null; public AccessVREDialog(final VRE vre) { initWidget(uiBinder.createAndBindUi(this)); @@ -43,7 +44,7 @@ public class AccessVREDialog extends Composite { } public void show() { - String headerText = isInvitation ? "Invitation to " + myVRE.getName() : "Join request for " + myVRE.getName(); + String headerText = "Join VRE request for " + myVRE.getName(); m.setTitle(headerText); m.show(); } @@ -56,7 +57,7 @@ public class AccessVREDialog extends Composite { void confirm(ClickEvent e) { helpBlock.setText("Registering to " + myVRE.getName() + " please wait ... "); loading.setVisible(true); - joinService.registerUser(myVRE.getinfraScope(), myVRE.getId(), isInvitation, new AsyncCallback() { + joinService.registerUser(myVRE.getinfraScope(), myVRE.getId(), IS_INVITATION, new AsyncCallback() { @Override public void onSuccess(Boolean result) { diff --git a/src/main/java/org/gcube/portlets/user/joinvre/client/ui/AccessViaInviteDialog.java b/src/main/java/org/gcube/portlets/user/joinvre/client/ui/AccessViaInviteDialog.java index 8b1be69..7854798 100644 --- a/src/main/java/org/gcube/portlets/user/joinvre/client/ui/AccessViaInviteDialog.java +++ b/src/main/java/org/gcube/portlets/user/joinvre/client/ui/AccessViaInviteDialog.java @@ -1,26 +1,29 @@ package org.gcube.portlets.user.joinvre.client.ui; -import org.gcube.portal.databook.shared.Invite; import org.gcube.portal.databook.shared.UserInfo; import org.gcube.portlets.user.joinvre.client.JoinService; import org.gcube.portlets.user.joinvre.client.JoinServiceAsync; import org.gcube.portlets.user.joinvre.shared.VRE; +import com.github.gwtbootstrap.client.ui.Button; import com.github.gwtbootstrap.client.ui.HelpBlock; import com.github.gwtbootstrap.client.ui.Icon; import com.github.gwtbootstrap.client.ui.Image; import com.github.gwtbootstrap.client.ui.Modal; +import com.github.gwtbootstrap.client.ui.constants.ButtonType; import com.google.gwt.core.client.GWT; +import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; -import com.github.gwtbootstrap.client.ui.Button; -import com.github.gwtbootstrap.client.ui.constants.ButtonType; +import com.google.gwt.uibinder.client.UiHandler; +import com.google.gwt.user.client.Window.Location; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.Widget; public class AccessViaInviteDialog extends Composite { private final JoinServiceAsync joinService = GWT.create(JoinService.class); + private final static boolean IS_INVITATION = true; private static AccessViaInviteDialogUiBinder uiBinder = GWT.create(AccessViaInviteDialogUiBinder.class); interface AccessViaInviteDialogUiBinder extends @@ -45,8 +48,9 @@ public class AccessViaInviteDialog extends Composite { joinService.readInvite(inviteId, new AsyncCallback() { @Override public void onSuccess(UserInfo invitingUser) { - helpBlock.setText("You have been invited by " +invitingUser.getFullName()); + helpBlock.setText("You have been invited by " +invitingUser.getFullName() + ", to accept the invite, please click on the accept invite button below."); avatarImage.setUrl(invitingUser.getAvatarId()); + avatarImage.setVisible(true); confirmRequest.setType(ButtonType.PRIMARY); confirmRequest.setEnabled(true); loading.removeFromParent(); @@ -65,6 +69,28 @@ public class AccessViaInviteDialog extends Composite { m.setTitle(headerText); m.show(); } - + @UiHandler("close") + void handleClick(ClickEvent e) { + m.hide(); + } + @UiHandler("confirmRequest") + void confirm(ClickEvent e) { + helpBlock.setText("Registering to " + myVRE.getName() + " please wait ... "); + loading.setVisible(true); + joinService.registerUser(myVRE.getinfraScope(), myVRE.getId(), IS_INVITATION, new AsyncCallback() { + + @Override + public void onSuccess(Boolean result) { + Location.assign(myVRE.getFriendlyURL()); + } + + @Override + public void onFailure(Throwable caught) { + confirmRequest.removeFromParent(); + m.setTitle("An error occurred! Your request has not been sent"); + helpBlock.setText("An email with the cause of the error has been sent to the support team, we'll be back to you shortly."); + } + }); + } } diff --git a/src/main/java/org/gcube/portlets/user/joinvre/server/EmailNotification.java b/src/main/java/org/gcube/portlets/user/joinvre/server/EmailNotification.java deleted file mode 100644 index 62e6651..0000000 --- a/src/main/java/org/gcube/portlets/user/joinvre/server/EmailNotification.java +++ /dev/null @@ -1,106 +0,0 @@ -package org.gcube.portlets.user.joinvre.server; - -import java.util.Date; -import java.util.Properties; - -import javax.mail.Address; -import javax.mail.Message; -import javax.mail.Session; -import javax.mail.Transport; -import javax.mail.internet.InternetAddress; -import javax.mail.internet.MimeMessage; - -import org.gcube.common.portal.PortalContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -/** - * A class for sending email - * - * @author M. Assante - * - */ -public class EmailNotification { - private static final String SENDER_EMAIL = "notificationSenderEmail"; - private static final String GATEWAY_NAME = "portalinstancename"; - /** - * The sender of the email - */ - private String emailSender; - - /** - * The recipients of the email - */ - private String emailrecipients[]; - - /** - * Email's subject - */ - private String emailSubject; - - /** - * Email's body message - */ - private String emailBody; - - private String portalName; - - /** Logger */ - private static Logger _log = LoggerFactory.getLogger(EmailNotification.class); - - /** - * Class's constructor - * - * @param sender - * @param recipients - * @param subject - * @param body - */ - public EmailNotification(String sender, String recipients[], String subject, String body) { - this.emailSender = PortalContext.getConfiguration().getSenderEmail(); - this.emailrecipients = recipients; - this.emailSubject = subject; - this.emailBody = body; - this.portalName = PortalContext.getConfiguration().getGatewayName(); - } - - public void sendEmail() { - Properties props = System.getProperties(); - String mailServiceHost = "localhost"; - props.put("mail.smtp.host", mailServiceHost); - String mailServicePort = "25"; - props.put("mail.smtp.port", mailServicePort); - Session session = Session.getDefaultInstance(props, null); - session.setDebug(true); - Message mimeMessage = new MimeMessage(session); - - try { - // EMAIL SENDER - Address from = new InternetAddress(emailSender, portalName); - mimeMessage.setHeader("Content-Type", "text/html; charset=UTF-8"); - mimeMessage.setFrom(from); - - // EMAIL RECIPIENTS - for (int i=0; iDear manager of "+ scope +",
this email message was automatically generated by " + portalbasicurl +" to inform you that "); - body.append("

"); - body.append("

"); - body.append(""+name + " " + lastname +" has self registered to the following environment: "); - body.append("

"); - body.append("" + scope+""); - body.append("
"); - body.append("
"); - body.append("Username: " + username); - body.append("
"); - body.append("e-mail: " + currUser.getEmail()); - body.append("

"); - body.append("

"); - body.append("
" + portalbasicurl); - body.append("

"); - body.append("

"); - body.append("WARNING / LEGAL TEXT: This message is intended only for the use of the individual or entity to which it is addressed and may contain"+ - " information which is privileged, confidential, proprietary, or exempt from disclosure under applicable law. " + - "If you are not the intended recipient or the person responsible for delivering the message to the intended recipient, you are strictly prohibited from disclosing, distributing, copying, or in any way using this message."); - body.append("

"); + body.append("

").append("

") + .append(""+name + " " + lastname +" has self registered to the following environment: ") + .append("

") + .append("" + scope+"") + .append("
") + .append("
") + .append("Username: " + username) + .append("
") + .append("e-mail: " + currUser.getEmail()) + .append("

") + .append("

") + .append("
" + portalbasicurl) + .append("

"); String[] allMails = new String[adminEmails.size()]; adminEmails.toArray(allMails); - EmailNotification mailToAdmin = new EmailNotification("no-reply@d4science.org", allMails , "[" + gatewayName + "] - Self Registration", body.toString()); + EmailNotification mailToAdmin = new EmailNotification(allMails , "[" + gatewayName + "] - Self Registration", body.toString()); mailToAdmin.sendEmail(); } @@ -202,31 +196,27 @@ public class LoginServiceUtil { StringBuffer body = new StringBuffer(); body.append("

Dear manager of "+ scope +",
this email message was automatically generated by " + portalbasicurl +" to inform you that "); - body.append("

"); - body.append("

"); - body.append(""+name + " " + lastname +" has accepted an invitation to the following environment: "); - body.append("

"); - body.append("" + scope+""); - body.append("
"); - body.append("
"); - body.append("Username: " + username); - body.append("
"); - body.append("e-mail: " + currUser.getEmail()); - body.append("

"); - body.append("

"); - body.append("The invitation was sent by " + invite.getSenderFullName() +" (" + invite.getSenderUserId()+") on " + invite.getTime()+""); - body.append("

"); - body.append("

"); - body.append("WARNING / LEGAL TEXT: This message is intended only for the use of the individual or entity to which it is addressed and may contain"+ - " information which is privileged, confidential, proprietary, or exempt from disclosure under applicable law. " + - "If you are not the intended recipient or the person responsible for delivering the message to the intended recipient, you are strictly prohibited from disclosing, distributing, copying, or in any way using this message."); - body.append("

"); + body.append("

") + .append("

") + .append(""+name + " " + lastname +" has accepted an invitation to the following environment: ") + .append("

") + .append("" + scope+"") + .append("
") + .append("
") + .append("Username: " + username) + .append("
") + .append("e-mail: " + currUser.getEmail()) + .append("

") + .append("

") + .append("The invitation was sent by " + invite.getSenderFullName() +" (" + invite.getSenderUserId()+") on " + invite.getTime()+"") + .append("

"); + String[] allMails = new String[adminEmails.size()]; adminEmails.toArray(allMails); - EmailNotification mailToAdmin = new EmailNotification("no-reply@d4science.org", allMails , "[" + gatewayName + "] - Accepted Invitation", body.toString()); + EmailNotification mailToAdmin = new EmailNotification(allMails , "[" + gatewayName + "] - Accepted Invitation", body.toString()); mailToAdmin.sendEmail(); } diff --git a/src/main/java/org/gcube/portlets/user/joinvre/server/portlet/JoinVREPortlet.java b/src/main/java/org/gcube/portlets/user/joinvre/server/portlet/JoinVREPortlet.java index c826eeb..00f20ba 100644 --- a/src/main/java/org/gcube/portlets/user/joinvre/server/portlet/JoinVREPortlet.java +++ b/src/main/java/org/gcube/portlets/user/joinvre/server/portlet/JoinVREPortlet.java @@ -20,16 +20,12 @@ import com.liferay.portal.theme.ThemeDisplay; /** * @author Massimiliano Assante, ISTI-CNR - massimiliano.assante@isti.cnr.it - * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ */ public class JoinVREPortlet extends GenericPortlet { private static Log _log = LogFactoryUtil.getLog(JoinVREPortlet.class); - public void doView(RenderRequest request, RenderResponse response) - throws PortletException, IOException { - _log.info("************************* Rendering JoinVRE Portlet"); - + public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { response.setContentType("text/html"); try { ScopeHelper.setContext(request); diff --git a/src/main/resources/org/gcube/portlets/user/joinvre/JoinVRE.gwt.xml b/src/main/resources/org/gcube/portlets/user/joinvre/JoinVRE.gwt.xml index c738758..973f3dd 100644 --- a/src/main/resources/org/gcube/portlets/user/joinvre/JoinVRE.gwt.xml +++ b/src/main/resources/org/gcube/portlets/user/joinvre/JoinVRE.gwt.xml @@ -6,7 +6,7 @@ - +