" +
+ askManagersOption.clear();
+ askManagersOption.add(new HTML("
" +
"Sorry, looks like something is broken with the server connection
" +
"Please check your connection and try refresh this page.
"));
}
});
- initWidget(mainPanel);
messageManagers.addClickHandler(new ClickHandler() {
@Override
@@ -95,7 +140,7 @@ public class VREManagersPanel extends Composite {
for (UserInfo user : managers) {
listToLogin.add(user.getUsername());
}
-
+
GWT.runAsync(new RunAsyncCallback() {
@Override
public void onSuccess() {
@@ -107,14 +152,96 @@ public class VREManagersPanel extends Composite {
});
}
});
+
+ service.isLeaveButtonAvailable(Location.getHref(), new AsyncCallback
() {
+
+ @Override
+ public void onSuccess(Boolean result) {
+ leaveVREOption.clear();
+ leaveVREOption.setHorizontalAlignment(HasAlignment.ALIGN_LEFT);
+ if(!result)
+ addLeaveVREButton();
+
+ }
+
+ @Override
+ public void onFailure(Throwable caught) {
+ leaveVREOption.clear();
+ }
+ });
}
+ private void addLeaveVREButton(){
- private void showLoader() {
- mainPanel.clear();
- mainPanel.setWidth("100%");
- mainPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER);
- mainPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
- mainPanel.add(loadingImage);
+ // add leave VRE button
+ leaveVreButton.addClickHandler(new ClickHandler() {
+
+ @Override
+ public void onClick(ClickEvent event) {
+
+ // show alert block
+ alertBlockOnLeave.setVisible(true);
+
+ }
+ });
+
+ // Add Cancel and Confirm Leave buttons
+ Span cancel = new Span("Cancel");
+ Span confirmLeave = new Span("Confirm Leave");
+ cancel.setStyleName("cancel-leave-button");
+ confirmLeave.setStyleName("cancel-leave-button");
+
+ // add to main panel
+ alertBlockOnLeave.setHTML(leaveAlertMessage + "
");
+ alertBlockOnLeave.add(cancel);
+ alertBlockOnLeave.add(new Label(" or "));
+ alertBlockOnLeave.add(confirmLeave);
+ alertBlockOnLeave.setType(AlertType.WARNING);
+ alertBlockOnLeave.setHeading("WARNING!");
+ alertBlockOnLeave.setClose(false);
+ alertBlockOnLeave.setVisible(false);
+ leaveVREOption.add(alertBlockOnLeave);
+ leaveVREOption.add(leaveVreButton);
+
+ // add handlers
+ cancel.addClickHandler(new ClickHandler() {
+
+ @Override
+ public void onClick(ClickEvent event) {
+
+ // just hide alertBlock
+ alertBlockOnLeave.setVisible(false);
+ }
+ });
+
+ confirmLeave.addClickHandler(new ClickHandler() {
+
+ @Override
+ public void onClick(ClickEvent event){
+ service.removeUserFromVRE(new AsyncCallback() {
+ @Override
+ public void onSuccess(String result) {
+ if (result != null)
+ Location.assign(result);
+ else
+ CheckSession.showLogoutDialog();
+
+ }
+ @Override
+ public void onFailure(Throwable caught) {
+ Window.alert("We're sorry we couldn't reach the server, try again later ... " + caught.getMessage());
+ }
+ });
+
+ }
+ });
+ }
+
+ private void showLoader(VerticalPanel panel) {
+ panel.clear();
+ panel.setWidth("100%");
+ panel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER);
+ panel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
+ panel.add(loadingImage);
}
}
diff --git a/src/main/java/org/gcube/portlets/user/questions/server/QuestionsServiceImpl.java b/src/main/java/org/gcube/portlets/user/questions/server/QuestionsServiceImpl.java
index 081858e..0975704 100644
--- a/src/main/java/org/gcube/portlets/user/questions/server/QuestionsServiceImpl.java
+++ b/src/main/java/org/gcube/portlets/user/questions/server/QuestionsServiceImpl.java
@@ -3,24 +3,26 @@ package org.gcube.portlets.user.questions.server;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.apache.commons.codec.binary.Base64;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager;
-import org.gcube.portal.custom.communitymanager.OrganizationsUtil;
+import org.gcube.common.portal.PortalContext;
+import org.gcube.common.portal.mailing.EmailNotification;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.gcube.portal.databook.client.GCubeSocialNetworking;
import org.gcube.portal.databook.shared.UserInfo;
+import org.gcube.portlets.user.gcubewidgets.server.ScopeServiceImpl;
import org.gcube.portlets.user.questions.client.QuestionsService;
import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.UserManager;
-import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
-import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
-import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayGroupManager;
-import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayUserManager;
-import org.gcube.vomanagement.usermanagement.model.RoleModel;
-import org.gcube.vomanagement.usermanagement.model.UserModel;
+import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
+import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
+import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
+import org.gcube.vomanagement.usermanagement.model.GCubeRole;
+import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -70,24 +72,24 @@ public class QuestionsServiceImpl extends RemoteServiceServlet implements Questi
if (isWithinPortal()) {
_log.trace("Asking user and roles ...");
UserManager userM = new LiferayUserManager();
- HashMap> usersAndRoles = null;
+ Map> usersAndRoles = null;
try {
usersAndRoles = userM.listUsersAndRolesByGroup(getCurrentGroupID());
} catch (Exception e) {
e.printStackTrace();
}
- Set users = usersAndRoles.keySet();
- for (UserModel usr:users) {
- List roles = usersAndRoles.get(usr);
+ Set users = usersAndRoles.keySet();
+ for (GCubeUser usr:users) {
+ List roles = usersAndRoles.get(usr);
for (int i = 0; i < roles.size(); i++) {
if (roles.get(i).getRoleName().equals("VRE-Manager")) {
- String username = usr.getScreenName();
+ String username = usr.getUsername();
_log.trace("Found Manager ... " + username);
String fullName = usr.getFullname();
String thumbnailURL = "images/Avatar_default.png";
try {
- com.liferay.portal.model.User user = UserLocalServiceUtil.getUserByScreenName(OrganizationsUtil.getCompany().getCompanyId(), username);
- thumbnailURL = user.isMale() ? "/image/user_male_portrait?img_id="+user.getPortraitId() : "/image/user_female_portrait?img_id="+user.getPortraitId();
+ GCubeUser user = userM.getUserByUsername(username);
+ thumbnailURL = user.getUserAvatarURL();
HashMap vreNames = new HashMap();
String headline = user.getJobTitle();
UserInfo userInfo = new UserInfo(username, fullName, thumbnailURL, headline, getUserProfileLink(username), user.isMale(), false, vreNames);
@@ -110,6 +112,58 @@ public class QuestionsServiceImpl extends RemoteServiceServlet implements Questi
return toReturn;
}
+ /**
+ *@return the redirect url if everything goes ok, null otherwise
+ */
+ @Override
+ public String removeUserFromVRE() {
+ String username = getASLSession().getUsername();
+ if (username.compareTo("test.user") == 0)
+ return null;
+ _log.debug("Going to remove user from the current Group: " + getCurrentGroupID() + ". Username is: " + username);
+ UserManager userM = new LiferayUserManager();
+ try {
+ userM.dismissUserFromGroup(getCurrentGroupID(), userM.getUserId(username));
+ sendUserUnregisteredNotification(username, getASLSession().getScope(),
+ PortalContext.getConfiguration().getGatewayURL(getThreadLocalRequest()),
+ PortalContext.getConfiguration().getGatewayName(getThreadLocalRequest()));
+ return "/";
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+ @Override
+ public boolean isLeaveButtonAvailable(String portalURL) {
+
+ if(isWithinPortal()){
+ String friendlyURL = ScopeServiceImpl.extractOrgFriendlyURL(portalURL);
+ GroupManager gm = new LiferayGroupManager();
+ GCubeGroup currSite = null;
+ try {
+ List groups = gm.listGroups();
+ for (GCubeGroup g : groups) {
+ if (g.getFriendlyURL().compareTo(friendlyURL) == 0) {
+ long groupId = g.getGroupId();
+ String scopeToSet = gm.getInfrastructureScope(groupId);
+ getASLSession().setScope(scopeToSet);
+ _log.info("GOT Selected Research Environment: " + scopeToSet);
+ currSite = g;
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ Boolean isMandatory = false;
+ try{
+ isMandatory = (Boolean) gm.readCustomAttr(currSite.getGroupId(), org.gcube.vomanagement.usermanagement.model.CustomAttributeKeys.MANDATORY.getKeyName());
+ }catch(Exception e){
+ _log.error("Unable to evaluate if the leave button can be added for the current group " + currSite.getGroupName(), e);
+ }
+ _log.debug("Is Leave button available in vre " + currSite.getGroupName() + " ? " + isMandatory);
+ return isMandatory;
+ }else return true;
+ }
/**
*
* @return true if you're running into the portal, false if in development
@@ -131,22 +185,99 @@ public class QuestionsServiceImpl extends RemoteServiceServlet implements Questi
* @throws Exception
* @throws CurrentGroupRetrievalException
*/
- private String getCurrentGroupID() throws Exception {
+ private long getCurrentGroupID(){
GroupManager groupM = new LiferayGroupManager();
ASLSession session = getASLSession();
_log.debug("The current group NAME is --> " + session.getGroupName());
try {
return groupM.getGroupId(session.getGroupName());
- } catch (GroupRetrievalFault e) {
+ } catch (Exception e) {
e.printStackTrace();
}
- return null;
+ return 0;
}
-
+
private String getUserProfileLink(String username) {
return "profile?"+ new String(Base64.encodeBase64(GCubeSocialNetworking.USER_PROFILE_OID.getBytes()))+"="+new String(Base64.encodeBase64(username.getBytes()));
}
-
+ /**
+ *
+ * @param scope .
+ * @param optionalMessage .
+ */
+ public void sendUserUnregisteredNotification(String username, String scope, String portalbasicurl, String gatewayName) {
+ ArrayList adminEmails = getAdministratorsEmails(scope);
+ UserManager um = new LiferayUserManager();
+ GCubeUser currUser = null;
+ try {
+ currUser = um.getUserByUsername(username);
+ } catch (Exception e) {
+ }
+ String name = currUser.getFirstName();
+ String lastname = currUser.getLastName();
+
+ 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 left 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("
");
+
+ String[] allMails = new String[adminEmails.size()];
+
+ adminEmails.toArray(allMails);
+
+ EmailNotification mailToAdmin = new EmailNotification(allMails , "Unregistration from VRE", body.toString(), getThreadLocalRequest());
+
+ mailToAdmin.sendEmail();
+ }
+
+ protected static ArrayList getAdministratorsEmails(String scope) {
+ LiferayUserManager userManager = new LiferayUserManager();
+ LiferayGroupManager groupManager = new LiferayGroupManager();
+ long groupId = -1;
+ try {
+ List allGroups = groupManager.listGroups();
+ _log.debug("Number of groups retrieved: " + allGroups.size());
+ for (int i = 0; i < allGroups.size(); i++) {
+ long grId = allGroups.get(i).getGroupId();
+ String groupScope = groupManager.getInfrastructureScope(grId);
+ _log.debug("Comparing: " + groupScope + " " + scope);
+ if (groupScope.equals(scope)) {
+ groupId = allGroups.get(i).getGroupId();
+ break;
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ Map> usersAndRoles = null;
+ try {
+ usersAndRoles = userManager.listUsersAndRolesByGroup(groupId);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ Set users = usersAndRoles.keySet();
+ ArrayList adminEmailsList = new ArrayList();
+ for (GCubeUser usr:users) {
+ List roles = usersAndRoles.get(usr);
+ for (int i = 0; i < roles.size(); i++) {
+ if (roles.get(i).getRoleName().equals("VO-Admin") || roles.get(i).getRoleName().equals("VRE-Manager")) {
+ adminEmailsList.add(usr.getEmail());
+ _log.debug("Admin: " + usr.getFullname());
+ break;
+ }
+ }
+ }
+ return adminEmailsList;
+ }
}
diff --git a/src/main/webapp/Questions.css b/src/main/webapp/Questions.css
index 0cf141c..4d37119 100644
--- a/src/main/webapp/Questions.css
+++ b/src/main/webapp/Questions.css
@@ -8,11 +8,6 @@
.questions-frame {
padding: 10px;
- background-color: #FFF;
- border-radius: 6px !important;
- -moz-border-radius: 6px !important;
- -webkit-border-radius: 6px !important;
- border: 1px solid #DBDBDB;
}
.manager-user-photo {
@@ -49,7 +44,7 @@ a.manager-person-link {
line-height: 18px;
}
-a.manager-person-link,a.manager-person-link:visited {
+a.manager-person-link, a.manager-person-link:visited {
cursor: pointer;
cursor: hand;
font-size: 16x;
@@ -63,7 +58,6 @@ a.manager-person-link:hover {
text-decoration: underline;
}
-
.manager-headline {
font-size: 13px;
color: #444444;
@@ -74,4 +68,14 @@ a.manager-person-link:hover {
.manager-institution {
font-size: 11px;
color: #444444;
+}
+
+.cancel-leave-button {
+ font-weight: bold;
+}
+
+.cancel-leave-button:hover {
+ cursor: pointer;
+ cursor: hand;
+ text-decoration: underline;
}
\ No newline at end of file
diff --git a/src/main/webapp/WEB-INF/liferay-display.xml b/src/main/webapp/WEB-INF/liferay-display.xml
index 64928ca..6b84f14 100644
--- a/src/main/webapp/WEB-INF/liferay-display.xml
+++ b/src/main/webapp/WEB-INF/liferay-display.xml
@@ -1,8 +1,8 @@
-
+
-
+
\ No newline at end of file
diff --git a/src/main/webapp/WEB-INF/liferay-plugin-package.properties b/src/main/webapp/WEB-INF/liferay-plugin-package.properties
index 621b168..366e090 100644
--- a/src/main/webapp/WEB-INF/liferay-plugin-package.properties
+++ b/src/main/webapp/WEB-INF/liferay-plugin-package.properties
@@ -1,4 +1,4 @@
-name=VREManagers
+name=VRESettings
module-group-id=liferay
module-incremental-version=1
tags=
@@ -6,4 +6,4 @@ short-description=
change-log=
page-url=http://www.d4science.org
author=D4Science.org
-licenses=EUPL
\ No newline at end of file
+licenses=EUPL
diff --git a/src/main/webapp/WEB-INF/liferay-portlet.xml b/src/main/webapp/WEB-INF/liferay-portlet.xml
index ea33f62..107e1f0 100644
--- a/src/main/webapp/WEB-INF/liferay-portlet.xml
+++ b/src/main/webapp/WEB-INF/liferay-portlet.xml
@@ -1,9 +1,8 @@
-
-
+
- VREManagers
+ VRESettings
false
false
false
diff --git a/src/main/webapp/WEB-INF/portlet.xml b/src/main/webapp/WEB-INF/portlet.xml
index c7ba5b7..8b78220 100644
--- a/src/main/webapp/WEB-INF/portlet.xml
+++ b/src/main/webapp/WEB-INF/portlet.xml
@@ -7,8 +7,8 @@
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
>
- VREManagers
- VRE Managers
+ VRESettings
+ VRE Settings
org.gcube.portlets.user.questions.server.portlet.VREManagersPortlet
view-jsp
@@ -19,9 +19,9 @@
text/html
- Questions? Ask the Managers
- VRE Managers
- VRE Managers
+ Settings
+ Settings
+ vre settings
administrator
diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml
index 2d97450..fb69927 100644
--- a/src/main/webapp/WEB-INF/web.xml
+++ b/src/main/webapp/WEB-INF/web.xml
@@ -1,9 +1,8 @@
-
-
-
+