removed ASL Session, ported to gCube Client Context

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/gcube-loggedin@134139 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2016-11-14 17:04:27 +00:00
parent 4734c5a829
commit 732dd59f96
11 changed files with 50 additions and 158 deletions

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/gcube-loggedin-3.1.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<classpathentry kind="src" output="target/gcube-loggedin-3.2.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/gcube-loggedin-3.1.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<classpathentry excluding="**" kind="src" output="target/gcube-loggedin-3.2.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
@ -39,5 +39,5 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/gcube-loggedin-3.1.0-SNAPSHOT/WEB-INF/classes"/>
<classpathentry kind="output" path="target/gcube-loggedin-3.2.0-SNAPSHOT/WEB-INF/classes"/>
</classpath>

View File

@ -4,10 +4,7 @@
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<dependent-module archiveName="gcube-widgets-2.0.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/gcube-widgets/gcube-widgets">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="session-checker-1.0.1-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/session-checker/session-checker">
<dependent-module archiveName="gcube-widgets-2.1.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/gcube-widgets/gcube-widgets">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="java-output-path" value="/${module}/target/www/WEB-INF/classes"/>

19
pom.xml
View File

@ -13,7 +13,7 @@
<groupId>org.gcube.portlets.user</groupId>
<artifactId>gcube-loggedin</artifactId>
<packaging>war</packaging>
<version>3.1.0-SNAPSHOT</version>
<version>3.2.0-SNAPSHOT</version>
<name>gCube Environment Home Portlet</name>
<description>
@ -76,12 +76,7 @@
<dependency>
<groupId>com.github.gwtbootstrap</groupId>
<artifactId>gwt-bootstrap</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>custom-portal-handler</artifactId>
<scope>provided</scope>
</dependency>
</dependency>
<dependency>
<groupId>org.gcube.common.portal</groupId>
<artifactId>portal-manager</artifactId>
@ -92,16 +87,6 @@
<artifactId>gcube-widgets</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>session-checker</artifactId>
<version>[1.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslcore</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.dvos</groupId>
<artifactId>usermanagement-core</artifactId>

View File

@ -22,6 +22,8 @@ public class GCubeLoggedin implements EntryPoint {
* This is the entry point method.
*/
public void onModuleLoad() {
main_panel.setWidth("100%");
main_panel.add(AboutView.getLoadingHTML());
// Associate the new panel with the HTML host page.

View File

@ -4,11 +4,9 @@ import org.gcube.portlets.user.gcubeloggedin.client.LoggedinService;
import org.gcube.portlets.user.gcubeloggedin.client.LoggedinServiceAsync;
import org.gcube.portlets.user.gcubeloggedin.shared.VObject;
import org.gcube.portlets.user.gcubewidgets.client.elements.Span;
import org.gcube.portlets.widgets.sessionchecker.client.CheckSession;
import com.github.gwtbootstrap.client.ui.AlertBlock;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.Heading;
import com.github.gwtbootstrap.client.ui.Hero;
import com.github.gwtbootstrap.client.ui.Image;
import com.github.gwtbootstrap.client.ui.constants.AlertType;
@ -54,11 +52,8 @@ public class AboutView extends Composite {
public AboutView() {
initWidget(uiBinder.createAndBindUi(this));
}
private String vreDescription;
@UiField Image vreImage;
@UiField Heading vreName;
@UiField HTML description;
@UiField Button seeMore;
@UiField Button editButton;
@ -68,7 +63,6 @@ public class AboutView extends Composite {
public AboutView(VObject vobj, LoggedinServiceAsync loggedinService) {
initWidget(uiBinder.createAndBindUi(this));
this.vreDescription = vobj.getDescription();
vreName.setText(vobj.getName());
vreImage.setUrl(vobj.getImageURL());
String desc = vreDescription = vobj.getDescription();
if (desc.length() > MAX_CHAR_DESC) {
@ -192,9 +186,7 @@ public class AboutView extends Composite {
public void onSuccess(String result) {
if (result != null)
Location.assign(result);
else
CheckSession.showLogoutDialog();
}
@Override
public void onFailure(Throwable caught) {

View File

@ -5,7 +5,6 @@
<b:Image ui:field="vreImage" />
<!-- The Caption is optional -->
<b:Caption>
<b:Heading size="3" ui:field="vreName">Thumbnail label</b:Heading>
<g:HTML ui:field="description">
</g:HTML>

View File

@ -2,7 +2,6 @@ package org.gcube.portlets.user.gcubeloggedin.client.ui;
import org.gcube.portlets.user.gcubeloggedin.client.LoggedinService;
import org.gcube.portlets.user.gcubeloggedin.client.LoggedinServiceAsync;
import org.gcube.portlets.user.gcubewidgets.client.ClientScopeHelper;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.Icon;
@ -15,7 +14,6 @@ import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
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;
@ -68,16 +66,7 @@ public class EditDescriptionModal extends Composite {
text2Edit.setText("");
text2Edit.setVisible(false);
loadingContainer.setVisible(true);
ClientScopeHelper.getService().setScope(Location.getHref(), new AsyncCallback<Boolean>() {
@Override
public void onSuccess(Boolean result) {
doSave(vreDescription);
}
@Override
public void onFailure(Throwable caught) {
loadingText.setText("Ops, some problems occurred, please try again in a while or report the problem.");
}
});
doSave(vreDescription);
}
private void doSave(String toSave) {

View File

@ -5,19 +5,17 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.common.portal.PortalContext;
import org.gcube.common.portal.mailing.EmailNotification;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.gcube.portlets.user.gcubeloggedin.client.LoggedinService;
import org.gcube.portlets.user.gcubeloggedin.shared.VObject;
import org.gcube.portlets.user.gcubeloggedin.shared.VObject.UserBelongingClient;
import org.gcube.portlets.user.gcubeloggedin.shared.VREClient;
import org.gcube.portlets.user.gcubewidgets.server.ScopeServiceImpl;
import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.RoleManager;
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.LiferayGroupManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
@ -37,34 +35,22 @@ import com.liferay.portal.service.UserLocalServiceUtil;
public class LoggedinServiceImpl extends RemoteServiceServlet implements LoggedinService {
private static final Logger _log = LoggerFactory.getLogger(LoggedinServiceImpl.class);
private static final String VRE_MANAGER_ROLE = "VRE-Manager";
/**
* the current ASLSession
* @return .
*/
private ASLSession getASLSession() {
String sessionID = this.getThreadLocalRequest().getSession().getId();
String user = (String) this.getThreadLocalRequest().getSession().getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
if (user == null) {
_log.warn("LOGGEDIN PORTLET: USER IS NULL \n\n SESSION ID READ: " +sessionID );
user = "test.user";
_log.warn("session ID= *" + sessionID + "* user= *" + user + "*" );
}
return SessionManager.getInstance().getASLSession(sessionID, user);
}
private PortalContext context = PortalContext.getConfiguration();
/**
* return the current selected VRE
*/
public VObject getSelectedRE(String portalURL) {
ASLSession aslSession = getASLSession();
String friendlyURL = ScopeServiceImpl.extractOrgFriendlyURL(portalURL);
long currGroupId = context.getCurrentGroupId(getThreadLocalRequest());
GroupManager gm = new LiferayGroupManager();
GCubeGroup currGroup = null;
try {
currGroup = gm.getGroup(currGroupId);
} catch (UserManagementSystemException | GroupRetrievalFault e1) {
e1.printStackTrace();
}
String friendlyURL = currGroup.getFriendlyURL();
_log.debug("curr group: " + currGroup.getGroupName() + " friendlyURL = " + friendlyURL);
if (friendlyURL == null) {//the URL is not a portal URL, we are in devmode.
return new VREClient("Test VRE Name", "", "" +
"Fishery and Aquaculture Resources Management (FARM) Virtual Organisation</b> The FARM Virtual Organisation is the <b><i>dynamic group of individuals</i></b> and/or <b><i>institutions</i></b> defined around a set of <b><i>sharing rules</i></b> in which <b><i>resource providers</i></b> and <b><i>consumers</i></b> specify clearly and carefully just what is shared, who is allowed to share, and the conditions under which sharing occurs to serve the needs of the <b><i>Fisheries and Aquaculture Resources Management</i></b>. "
@ -79,39 +65,15 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi
, "http://placehold.it/300x200", "", UserBelongingClient.BELONGING, false, true, true);
}
_log.trace("getting Selected Research Environment");
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();
}
/**
* set the current ORG bean in session
*/
aslSession.setAttribute(ScopeHelper.CURR_ORG, currSite);
aslSession.setGroupModelInfos(currSite.getGroupName(), currSite.getGroupId());
_log.trace("CURRENT ORG SET IN SESSION: " + currSite.getGroupName());
String name = currSite.getGroupName();
String logoURL = gm.getGroupLogoURL(currSite.getLogoId());
String name = currGroup.getGroupName();
String logoURL = gm.getGroupLogoURL(currGroup.getLogoId());
String desc = "";
//set the description for the vre
if (currSite.getDescription() != null)
desc = currSite.getDescription();
if (currGroup.getDescription() != null)
desc = currGroup.getDescription();
return new VREClient(name, "", desc, logoURL, "", UserBelongingClient.BELONGING, false, false, isCurrUserVREManager());
}
@ -120,15 +82,14 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi
* @return
*/
private boolean isCurrUserVREManager() {
ASLSession session = getASLSession();
long userId;
try {
userId = new LiferayUserManager().getUserId(session.getUsername());
long groupId = new LiferayGroupManager().getGroupIdFromInfrastructureScope(session.getScope());
userId = context.getCurrentUser(getThreadLocalRequest()).getUserId();
long groupId = context.getCurrentGroupId(getThreadLocalRequest());
RoleManager rm = new LiferayRoleManager();
long roleId = rm.getRoleIdByName(VRE_MANAGER_ROLE);
long roleId = rm.getRoleIdByName(GCubeRole.VRE_MANAGER_LABEL);
boolean toReturn = rm.hasRole(userId, groupId, roleId);
_log.debug("User " + session.getUsername() + " is " + VRE_MANAGER_ROLE + " for " + session.getScope() + "? -> " + toReturn);
return toReturn;
} catch (Exception e) {
@ -179,11 +140,9 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi
@Override
public String saveVREDescription(String toSave) {
try {
String scope = getASLSession().getScope();
GroupManager gm = new LiferayGroupManager();
long groupId = gm.getGroupIdFromInfrastructureScope(scope);
return gm.updateGroupDescription(groupId, toSave);
try {
long groupId = context.getCurrentGroupId(getThreadLocalRequest());
return new LiferayGroupManager().updateGroupDescription(groupId, toSave);
} catch (Exception e) {
e.printStackTrace();
}
@ -193,30 +152,22 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi
public boolean isLeaveButtonAvailable(String portalURL) {
if(isWithinPortal()){
String friendlyURL = ScopeServiceImpl.extractOrgFriendlyURL(portalURL);
long currGroupId = context.getCurrentGroupId(getThreadLocalRequest());
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();
GCubeGroup currGroup = null;
try {
currGroup = gm.getGroup(currGroupId);
} catch (UserManagementSystemException | GroupRetrievalFault e1) {
e1.printStackTrace();
}
Boolean isMandatory = false;
try{
isMandatory = (Boolean) gm.readCustomAttr(currSite.getGroupId(), org.gcube.vomanagement.usermanagement.model.CustomAttributeKeys.MANDATORY.getKeyName());
isMandatory = (Boolean) gm.readCustomAttr(currGroup.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.error("Unable to evaluate if the leave button can be added for the current group " + currGroup.getGroupName(), e);
}
_log.debug("Is Leave button available in vre " + currSite.getGroupName() + " ? " + isMandatory);
_log.debug("Is Leave button available in vre " + currGroup.getGroupName() + " ? " + isMandatory);
return !isMandatory;
}else return true;
}
@ -225,14 +176,15 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi
*/
@Override
public String removeUserFromVRE() {
String username = getASLSession().getUsername();
String username = context.getCurrentUser(getThreadLocalRequest()).getUsername();
String scope = context.getCurrentScope(getThreadLocalRequest());
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(),
sendUserUnregisteredNotification(username, scope,
PortalContext.getConfiguration().getGatewayURL(getThreadLocalRequest()),
PortalContext.getConfiguration().getGatewayName(getThreadLocalRequest()));
@ -249,16 +201,8 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi
* @throws Exception
* @throws CurrentGroupRetrievalException
*/
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 (Exception e) {
e.printStackTrace();
}
return 0;
private long getCurrentGroupID() {
return context.getCurrentGroupId(getThreadLocalRequest());
}
/**
*

View File

@ -9,8 +9,6 @@ import javax.portlet.PortletRequestDispatcher;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
/**
* LoggedinPortlet Portlet Class
* @author massi
@ -20,9 +18,6 @@ public class LoggedinPortlet extends GenericPortlet {
public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
response.setContentType("text/html");
ScopeHelper.setContext(request);
PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/LoggedinPortlet_view.jsp");
dispatcher.include(request, response);

View File

@ -7,7 +7,6 @@
<!-- <set-property name="user.agent" value="gecko1_8,safari" /> -->
<inherits name='org.gcube.portlets.user.gcubewidgets.WidgetFactory' />
<inherits name='org.gcube.portlets.widgets.sessionchecker.SessionChecker' />
<inherits name="com.github.gwtbootstrap.Bootstrap" />
<!-- Specify the app entry point class. -->
<entry-point

View File

@ -15,16 +15,6 @@
<url-pattern>/gcubeloggedin/LoggedinServiceImpl</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>scopeService</servlet-name>
<servlet-class>org.gcube.portlets.user.gcubewidgets.server.ScopeServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>scopeService</servlet-name>
<url-pattern>/gcubeloggedin/scopeService</url-pattern>
</servlet-mapping>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>GCubeLoggedin.html</welcome-file>