Portlet's name changed to Settings. It now contains also the leave group option (if available)

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/questions@128511 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-05-06 16:12:32 +00:00
parent 9397eb4fe6
commit dd3300fb24
15 changed files with 358 additions and 83 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" output="target/questions-1.2.0-SNAPSHOT/WEB-INF/classes" path="src/main/java"> <classpathentry kind="src" output="target/questions-2.0.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes> <attributes>
<attribute name="optional" value="true"/> <attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
@ -31,5 +31,5 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="output" path="target/questions-1.2.0-SNAPSHOT/WEB-INF/classes"/> <classpathentry kind="output" path="target/questions-2.0.0-SNAPSHOT/WEB-INF/classes"/>
</classpath> </classpath>

View File

@ -1,5 +1,5 @@
eclipse.preferences.version=1 eclipse.preferences.version=1
jarsExcludedFromWebInfLib= jarsExcludedFromWebInfLib=
lastWarOutDir=/Users/massi/Documents/workspace/questions/target/questions-1.0.0-SNAPSHOT lastWarOutDir=/home/costantino/workspace/questions/target/questions-2.0.0-SNAPSHOT
warSrcDir=src/main/webapp warSrcDir=src/main/webapp
warSrcDirIsOutput=false warSrcDirIsOutput=false

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<faceted-project> <faceted-project>
<fixed facet="wst.jsdt.web"/> <fixed facet="wst.jsdt.web"/>
<installed facet="jst.web" version="2.3"/> <installed facet="jst.web" version="3.0"/>
<installed facet="wst.jsdt.web" version="1.0"/> <installed facet="wst.jsdt.web" version="1.0"/>
<installed facet="java" version="1.7"/> <installed facet="java" version="1.7"/>
<installed facet="liferay.portlet" version="6.0"/> <installed facet="liferay.portlet" version="6.0"/>

20
pom.xml
View File

@ -13,7 +13,7 @@
<groupId>org.gcube.portlets.user</groupId> <groupId>org.gcube.portlets.user</groupId>
<artifactId>questions</artifactId> <artifactId>questions</artifactId>
<packaging>war</packaging> <packaging>war</packaging>
<version>1.2.0-SNAPSHOT</version> <version>2.0.0-SNAPSHOT</version>
<name>gCube Questions Ask Managers Portlet</name> <name>gCube Questions Ask Managers Portlet</name>
<description> <description>
gCube Questions Ask Managers Portlet gCube Questions Ask Managers Portlet
@ -27,6 +27,7 @@
<!-- Convenience property to set the GWT version --> <!-- Convenience property to set the GWT version -->
<gwtVersion>2.7.0</gwtVersion> <gwtVersion>2.7.0</gwtVersion>
<distroDirectory>distro</distroDirectory> <distroDirectory>distro</distroDirectory>
<liferay.version>6.2.5</liferay.version>
<maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target> <maven.compiler.target>1.7</maven.compiler.target>
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory> <webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
@ -72,17 +73,24 @@
<dependency> <dependency>
<groupId>org.gcube.portlets.user</groupId> <groupId>org.gcube.portlets.user</groupId>
<artifactId>gcube-widgets</artifactId> <artifactId>gcube-widgets</artifactId>
<scope>provided</scope> <version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
<scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.gcube.portal</groupId> <groupId>org.gcube.portal</groupId>
<artifactId>custom-portal-handler</artifactId> <artifactId>custom-portal-handler</artifactId>
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>commons-io</groupId> <groupId>commons-io</groupId>
<artifactId>commons-io</artifactId> <artifactId>commons-io</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.gcube.common.portal</groupId>
<artifactId>portal-manager</artifactId>
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
</dependency>
<dependency> <dependency>
<groupId>org.gcube.core</groupId> <groupId>org.gcube.core</groupId>
<artifactId>common-encryption</artifactId> <artifactId>common-encryption</artifactId>
@ -130,7 +138,7 @@
<dependency> <dependency>
<groupId>org.gcube.portlets.widgets</groupId> <groupId>org.gcube.portlets.widgets</groupId>
<artifactId>wsmail-widget</artifactId> <artifactId>wsmail-widget</artifactId>
<version>[1.4.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version> <version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
@ -139,6 +147,11 @@
<version>[2.13.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version> <version>[2.13.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>session-checker</artifactId>
<version>[1.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
</dependency>
<dependency> <dependency>
<groupId>org.apache.httpcomponents</groupId> <groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId> <artifactId>httpclient</artifactId>
@ -147,6 +160,7 @@
<dependency> <dependency>
<groupId>com.liferay.portal</groupId> <groupId>com.liferay.portal</groupId>
<artifactId>portal-service</artifactId> <artifactId>portal-service</artifactId>
<version>${liferay.version}</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -7,8 +7,6 @@ import com.google.gwt.user.client.ui.RootPanel;
* Entry point classes define <code>onModuleLoad()</code>. * Entry point classes define <code>onModuleLoad()</code>.
*/ */
public class Questions implements EntryPoint { public class Questions implements EntryPoint {
public void onModuleLoad() { public void onModuleLoad() {
RootPanel.get("questionsManagersDiv").add(new VREManagersPanel()); RootPanel.get("questionsManagersDiv").add(new VREManagersPanel());
} }

View File

@ -13,4 +13,6 @@ import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
@RemoteServiceRelativePath("greet") @RemoteServiceRelativePath("greet")
public interface QuestionsService extends RemoteService { public interface QuestionsService extends RemoteService {
ArrayList<UserInfo> getManagers(); ArrayList<UserInfo> getManagers();
String removeUserFromVRE();
boolean isLeaveButtonAvailable(String currentUrl);
} }

View File

@ -7,7 +7,8 @@ import org.gcube.portal.databook.shared.UserInfo;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
public interface QuestionsServiceAsync { public interface QuestionsServiceAsync {
void getManagers(AsyncCallback<ArrayList<UserInfo>> callback); void getManagers(AsyncCallback<ArrayList<UserInfo>> callback);
void removeUserFromVRE(AsyncCallback<String> callback);
void isLeaveButtonAvailable(String currentUrl,
AsyncCallback<Boolean> callback);
} }

View File

@ -4,68 +4,113 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.gcube.portal.databook.shared.UserInfo; import org.gcube.portal.databook.shared.UserInfo;
import org.gcube.portlets.user.gcubewidgets.client.elements.Span;
import org.gcube.portlets.user.questions.client.resources.Images; import org.gcube.portlets.user.questions.client.resources.Images;
import org.gcube.portlets.user.questions.client.ui.DisplayBadge; import org.gcube.portlets.user.questions.client.ui.DisplayBadge;
import org.gcube.portlets.widgets.sessionchecker.client.CheckSession;
import org.gcube.portlets.widgets.wsmail.client.forms.MailForm; import org.gcube.portlets.widgets.wsmail.client.forms.MailForm;
import com.github.gwtbootstrap.client.ui.AlertBlock;
import com.github.gwtbootstrap.client.ui.Button; import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.Label;
import com.github.gwtbootstrap.client.ui.constants.AlertType;
import com.github.gwtbootstrap.client.ui.constants.ButtonType;
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.RunAsyncCallback; import com.google.gwt.core.client.RunAsyncCallback;
import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window; import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.Window.Location;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasAlignment; import com.google.gwt.user.client.ui.HasAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment; import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image; import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.SimplePanel; import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.VerticalPanel; import com.google.gwt.user.client.ui.VerticalPanel;
public class VREManagersPanel extends Composite { public class VREManagersPanel extends Composite {
private final QuestionsServiceAsync service = GWT.create(QuestionsService.class); private final QuestionsServiceAsync service = GWT.create(QuestionsService.class);
public static final String DISPLAY_NAME = "Questions? Ask the managers";
private Image loadingImage; private Image loadingImage;
private Image postToImage; private Image postToImage;
private Button messageManagers = new Button(); private Button messageManagers = new Button();
private Button leaveVreButton = new Button("Leave Group");
private AlertBlock alertBlockOnLeave = new AlertBlock();
private static final String leaveAlertMessage = "Are you sure you want to leave this group? "
+ "By leaving this group you will no longer receive updates and lose the workspace folder related to the group.";
// main panel
private VerticalPanel mainPanel = new VerticalPanel(); private VerticalPanel mainPanel = new VerticalPanel();
// panel for Questions? Ask the managers option
private VerticalPanel askManagersOption = new VerticalPanel();
// panel for leave group option
private VerticalPanel leaveVREOption = new VerticalPanel();
// list of managers
private ArrayList<UserInfo> managers; private ArrayList<UserInfo> managers;
public VREManagersPanel() { public VREManagersPanel() {
super(); super();
initWidget(mainPanel);
Images images = GWT.create(Images.class); Images images = GWT.create(Images.class);
loadingImage = new Image(images.membersLoader().getSafeUri()); loadingImage = new Image(images.membersLoader().getSafeUri());
postToImage = new Image(images.postToIcon().getSafeUri()); postToImage = new Image(images.postToIcon().getSafeUri());
mainPanel.add(loadingImage); // add options subpanels to the main one
showLoader(); mainPanel.add(askManagersOption); // this is always present ...
// more options label to show the other ones (if present)
final Button showMoreOptions = new Button("Show more options ...");
showMoreOptions.setType(ButtonType.LINK);
// handler
showMoreOptions.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// hide the button itself
showMoreOptions.setVisible(false);
// show other options
leaveVREOption.setVisible(true);
}
});
mainPanel.add(showMoreOptions);
mainPanel.add(leaveVREOption);
// hide options but askManagersOption
leaveVREOption.setVisible(false);
// show loaders for the panels
showLoader(askManagersOption);
showLoader(leaveVREOption);
service.getManagers(new AsyncCallback<ArrayList<UserInfo>>() { service.getManagers(new AsyncCallback<ArrayList<UserInfo>>() {
@Override @Override
public void onSuccess(ArrayList<UserInfo> users) { public void onSuccess(ArrayList<UserInfo> users) {
askManagersOption.clear();
managers = users; managers = users;
mainPanel.clear(); askManagersOption.setHorizontalAlignment(HasAlignment.ALIGN_LEFT);
mainPanel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT); askManagersOption.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
mainPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP); askManagersOption.setStyleName("questions-frame");
mainPanel.setStyleName("questions-frame");
HTML name = new HTML(DISPLAY_NAME);
name.setStyleName("questions-title");
HorizontalPanel hp = new HorizontalPanel();
hp.add(name);
postToImage.setStyleName("manager-post-image"); postToImage.setStyleName("manager-post-image");
postToImage.setTitle("Message privately to the Managers"); postToImage.setTitle("Message privately to the Managers");
// hp.add(postToImage);
mainPanel.add(hp);
if (users == null || users.isEmpty()) { if (users == null || users.isEmpty()) {
mainPanel.add(new HTML("<div class=\"frame\" style=\"font-size: 16px;\">Ops, something went wrong. Please <a href=\"javascript: location.reload();\">reload<a/> this page.</div>")); askManagersOption.add(new HTML("<div class=\"frame\" style=\"font-size: 16px;\">Ops, something went wrong. Please <a href=\"javascript: location.reload();\">reload<a/> this page.</div>"));
} else { } else {
for (int i = 0; i < users.size(); i++) { for (int i = 0; i < users.size(); i++) {
mainPanel.add(new DisplayBadge(users.get(i))); askManagersOption.add(new DisplayBadge(users.get(i)));
} }
if (users.size() > 1) if (users.size() > 1)
messageManagers.setText("Message managers"); messageManagers.setText("Message managers");
@ -75,18 +120,18 @@ public class VREManagersPanel extends Composite {
SimplePanel bPanel = new SimplePanel(); SimplePanel bPanel = new SimplePanel();
bPanel.setStyleName("manager-action"); bPanel.setStyleName("manager-action");
bPanel.setWidget(messageManagers); bPanel.setWidget(messageManagers);
mainPanel.add(bPanel); askManagersOption.add(bPanel);
} }
@Override @Override
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
mainPanel.add(new HTML("<div class=\"nofeed-message\">" + askManagersOption.clear();
askManagersOption.add(new HTML("<div class=\"nofeed-message\">" +
"Sorry, looks like something is broken with the server connection<br> " + "Sorry, looks like something is broken with the server connection<br> " +
"Please check your connection and try refresh this page.</div>")); "Please check your connection and try refresh this page.</div>"));
} }
}); });
initWidget(mainPanel);
messageManagers.addClickHandler(new ClickHandler() { messageManagers.addClickHandler(new ClickHandler() {
@Override @Override
@ -95,7 +140,7 @@ public class VREManagersPanel extends Composite {
for (UserInfo user : managers) { for (UserInfo user : managers) {
listToLogin.add(user.getUsername()); listToLogin.add(user.getUsername());
} }
GWT.runAsync(new RunAsyncCallback() { GWT.runAsync(new RunAsyncCallback() {
@Override @Override
public void onSuccess() { public void onSuccess() {
@ -107,14 +152,96 @@ public class VREManagersPanel extends Composite {
}); });
} }
}); });
service.isLeaveButtonAvailable(Location.getHref(), new AsyncCallback<Boolean>() {
@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() { // add leave VRE button
mainPanel.clear(); leaveVreButton.addClickHandler(new ClickHandler() {
mainPanel.setWidth("100%");
mainPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER); @Override
mainPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); public void onClick(ClickEvent event) {
mainPanel.add(loadingImage);
// 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 + "<br><br>");
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<String>() {
@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);
} }
} }

View File

@ -3,24 +3,26 @@ package org.gcube.portlets.user.questions.server;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.gcube.application.framework.core.session.ASLSession; import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager; 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.custom.scopemanager.scopehelper.ScopeHelper;
import org.gcube.portal.databook.client.GCubeSocialNetworking; import org.gcube.portal.databook.client.GCubeSocialNetworking;
import org.gcube.portal.databook.shared.UserInfo; 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.portlets.user.questions.client.QuestionsService;
import org.gcube.vomanagement.usermanagement.GroupManager; import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.UserManager; import org.gcube.vomanagement.usermanagement.UserManager;
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayGroupManager; import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayUserManager; import org.gcube.vomanagement.usermanagement.model.GCubeRole;
import org.gcube.vomanagement.usermanagement.model.RoleModel; import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.gcube.vomanagement.usermanagement.model.UserModel;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -70,24 +72,24 @@ public class QuestionsServiceImpl extends RemoteServiceServlet implements Questi
if (isWithinPortal()) { if (isWithinPortal()) {
_log.trace("Asking user and roles ..."); _log.trace("Asking user and roles ...");
UserManager userM = new LiferayUserManager(); UserManager userM = new LiferayUserManager();
HashMap<UserModel, List<RoleModel>> usersAndRoles = null; Map<GCubeUser, List<GCubeRole>> usersAndRoles = null;
try { try {
usersAndRoles = userM.listUsersAndRolesByGroup(getCurrentGroupID()); usersAndRoles = userM.listUsersAndRolesByGroup(getCurrentGroupID());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
Set<UserModel> users = usersAndRoles.keySet(); Set<GCubeUser> users = usersAndRoles.keySet();
for (UserModel usr:users) { for (GCubeUser usr:users) {
List<RoleModel> roles = usersAndRoles.get(usr); List<GCubeRole> roles = usersAndRoles.get(usr);
for (int i = 0; i < roles.size(); i++) { for (int i = 0; i < roles.size(); i++) {
if (roles.get(i).getRoleName().equals("VRE-Manager")) { if (roles.get(i).getRoleName().equals("VRE-Manager")) {
String username = usr.getScreenName(); String username = usr.getUsername();
_log.trace("Found Manager ... " + username); _log.trace("Found Manager ... " + username);
String fullName = usr.getFullname(); String fullName = usr.getFullname();
String thumbnailURL = "images/Avatar_default.png"; String thumbnailURL = "images/Avatar_default.png";
try { try {
com.liferay.portal.model.User user = UserLocalServiceUtil.getUserByScreenName(OrganizationsUtil.getCompany().getCompanyId(), username); GCubeUser user = userM.getUserByUsername(username);
thumbnailURL = user.isMale() ? "/image/user_male_portrait?img_id="+user.getPortraitId() : "/image/user_female_portrait?img_id="+user.getPortraitId(); thumbnailURL = user.getUserAvatarURL();
HashMap<String, String> vreNames = new HashMap<String, String>(); HashMap<String, String> vreNames = new HashMap<String, String>();
String headline = user.getJobTitle(); String headline = user.getJobTitle();
UserInfo userInfo = new UserInfo(username, fullName, thumbnailURL, headline, getUserProfileLink(username), user.isMale(), false, vreNames); 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 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<GCubeGroup> 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 * @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 Exception
* @throws CurrentGroupRetrievalException * @throws CurrentGroupRetrievalException
*/ */
private String getCurrentGroupID() throws Exception { private long getCurrentGroupID(){
GroupManager groupM = new LiferayGroupManager(); GroupManager groupM = new LiferayGroupManager();
ASLSession session = getASLSession(); ASLSession session = getASLSession();
_log.debug("The current group NAME is --> " + session.getGroupName()); _log.debug("The current group NAME is --> " + session.getGroupName());
try { try {
return groupM.getGroupId(session.getGroupName()); return groupM.getGroupId(session.getGroupName());
} catch (GroupRetrievalFault e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return null; return 0;
} }
private String getUserProfileLink(String username) { private String getUserProfileLink(String username) {
return "profile?"+ new String(Base64.encodeBase64(GCubeSocialNetworking.USER_PROFILE_OID.getBytes()))+"="+new String(Base64.encodeBase64(username.getBytes())); 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<String> 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("<p>Dear manager of "+ scope +",<br />this email message was automatically generated by " + portalbasicurl +" to inform you that ");
body.append("</p>");
body.append("<p>");
body.append("<b>"+name + " " + lastname +"</b> has left the following environment: ");
body.append("<br /><br />");
body.append("<b>" + scope+"</b>");
body.append("<br />");
body.append("<br />");
body.append("<b>Username: </b>" + username);
body.append("<br />");
body.append("<b>e-mail: </b>" + currUser.getEmail());
body.append("</p>");
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<String> getAdministratorsEmails(String scope) {
LiferayUserManager userManager = new LiferayUserManager();
LiferayGroupManager groupManager = new LiferayGroupManager();
long groupId = -1;
try {
List<GCubeGroup> 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<GCubeUser, List<GCubeRole>> usersAndRoles = null;
try {
usersAndRoles = userManager.listUsersAndRolesByGroup(groupId);
} catch (Exception e) {
e.printStackTrace();
}
Set<GCubeUser> users = usersAndRoles.keySet();
ArrayList<String> adminEmailsList = new ArrayList<String>();
for (GCubeUser usr:users) {
List<GCubeRole> 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;
}
} }

View File

@ -8,11 +8,6 @@
.questions-frame { .questions-frame {
padding: 10px; 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 { .manager-user-photo {
@ -49,7 +44,7 @@ a.manager-person-link {
line-height: 18px; line-height: 18px;
} }
a.manager-person-link,a.manager-person-link:visited { a.manager-person-link, a.manager-person-link:visited {
cursor: pointer; cursor: pointer;
cursor: hand; cursor: hand;
font-size: 16x; font-size: 16x;
@ -63,7 +58,6 @@ a.manager-person-link:hover {
text-decoration: underline; text-decoration: underline;
} }
.manager-headline { .manager-headline {
font-size: 13px; font-size: 13px;
color: #444444; color: #444444;
@ -74,4 +68,14 @@ a.manager-person-link:hover {
.manager-institution { .manager-institution {
font-size: 11px; font-size: 11px;
color: #444444; color: #444444;
}
.cancel-leave-button {
font-weight: bold;
}
.cancel-leave-button:hover {
cursor: pointer;
cursor: hand;
text-decoration: underline;
} }

View File

@ -1,8 +1,8 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<!DOCTYPE display PUBLIC "-//Liferay//DTD Display 6.0.0//EN" "http://www.liferay.com/dtd/liferay-display_6_0_0.dtd"> <!DOCTYPE display PUBLIC "-//Liferay//DTD Display 6.2.0//EN" "http://www.liferay.com/dtd/liferay-display_6_2_0.dtd">
<display> <display>
<category name="gCube Social Apps"> <category name="gCube Social Apps">
<portlet id="VREManagers" /> <portlet id="VRESettings" />
</category> </category>
</display> </display>

View File

@ -1,4 +1,4 @@
name=VREManagers name=VRESettings
module-group-id=liferay module-group-id=liferay
module-incremental-version=1 module-incremental-version=1
tags= tags=
@ -6,4 +6,4 @@ short-description=
change-log= change-log=
page-url=http://www.d4science.org page-url=http://www.d4science.org
author=D4Science.org author=D4Science.org
licenses=EUPL licenses=EUPL

View File

@ -1,9 +1,8 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<!DOCTYPE liferay-portlet-app PUBLIC "-//Liferay//DTD Portlet Application 5.2.0//EN" "http://www.liferay.com/dtd/liferay-portlet-app_6_0_0.dtd"> <!DOCTYPE liferay-portlet-app PUBLIC "-//Liferay//DTD Portlet Application 6.2.0//EN" "http://www.liferay.com/dtd/liferay-portlet-app_6_2_0.dtd">
<liferay-portlet-app> <liferay-portlet-app>
<portlet> <portlet>
<portlet-name>VREManagers</portlet-name> <portlet-name>VRESettings</portlet-name>
<layout-cacheable>false</layout-cacheable> <layout-cacheable>false</layout-cacheable>
<instanceable>false</instanceable> <instanceable>false</instanceable>
<ajaxable>false</ajaxable> <ajaxable>false</ajaxable>

View File

@ -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" 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"
> >
<portlet> <portlet>
<portlet-name>VREManagers</portlet-name> <portlet-name>VRESettings</portlet-name>
<display-name>VRE Managers</display-name> <display-name>VRE Settings</display-name>
<portlet-class>org.gcube.portlets.user.questions.server.portlet.VREManagersPortlet</portlet-class> <portlet-class>org.gcube.portlets.user.questions.server.portlet.VREManagersPortlet</portlet-class>
<init-param> <init-param>
<name>view-jsp</name> <name>view-jsp</name>
@ -19,9 +19,9 @@
<mime-type>text/html</mime-type> <mime-type>text/html</mime-type>
</supports> </supports>
<portlet-info> <portlet-info>
<title>Questions? Ask the Managers</title> <title>Settings</title>
<short-title>VRE Managers</short-title> <short-title>Settings</short-title>
<keywords>VRE Managers</keywords> <keywords>vre settings</keywords>
</portlet-info> </portlet-info>
<security-role-ref> <security-role-ref>
<role-name>administrator</role-name> <role-name>administrator</role-name>

View File

@ -1,9 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
"http://java.sun.com/dtd/web-app_2_3.dtd"> http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<web-app>
<!-- Servlets --> <!-- Servlets -->
<servlet> <servlet>