diff --git a/.classpath b/.classpath index 44c67f9..13f8d5b 100644 --- a/.classpath +++ b/.classpath @@ -1,6 +1,6 @@ - + @@ -31,5 +31,5 @@ - + diff --git a/.settings/com.google.gdt.eclipse.core.prefs b/.settings/com.google.gdt.eclipse.core.prefs index 9dae3d0..953ee40 100644 --- a/.settings/com.google.gdt.eclipse.core.prefs +++ b/.settings/com.google.gdt.eclipse.core.prefs @@ -1,5 +1,5 @@ eclipse.preferences.version=1 jarsExcludedFromWebInfLib= -lastWarOutDir=/Users/massi/Documents/workspace/gcube-loggedin/target/gcube-loggedin-2.5.0-SNAPSHOT +lastWarOutDir=/Users/massi/Documents/workspace/gcube-loggedin/target/gcube-loggedin-2.5.1-SNAPSHOT warSrcDir=src/main/webapp warSrcDirIsOutput=false diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index b9f44a3..4e1b3a2 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -3,6 +3,9 @@ + + uses + uses diff --git a/pom.xml b/pom.xml index 5170f03..1cad8dd 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.gcube.portlets.user gcube-loggedin war - 2.5.0-SNAPSHOT + 2.5.1-SNAPSHOT gCube Loggedin Portlet @@ -66,7 +66,7 @@ org.gcube.portlets.user gcube-widgets - provided + compile org.gcube.portlets.widgets diff --git a/src/main/java/org/gcube/portlets/user/gcubeloggedin/client/GCubeLoggedin.java b/src/main/java/org/gcube/portlets/user/gcubeloggedin/client/GCubeLoggedin.java index 73be6ee..f810081 100644 --- a/src/main/java/org/gcube/portlets/user/gcubeloggedin/client/GCubeLoggedin.java +++ b/src/main/java/org/gcube/portlets/user/gcubeloggedin/client/GCubeLoggedin.java @@ -5,6 +5,7 @@ import org.gcube.portlets.user.gcubeloggedin.shared.VObject; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.Window.Location; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.ServiceDefTarget; import com.google.gwt.user.client.ui.HTML; @@ -35,7 +36,7 @@ public class GCubeLoggedin implements EntryPoint { // Associate the new panel with the HTML host page. RootPanel.get("LoggedinDiv").add(main_panel); - loggedinService.getSelectedRE(new AsyncCallback() { + loggedinService.getSelectedRE(Location.getHref(), new AsyncCallback() { public void onFailure(Throwable caught) { } public void onSuccess(VObject result) { diff --git a/src/main/java/org/gcube/portlets/user/gcubeloggedin/client/LoggedinService.java b/src/main/java/org/gcube/portlets/user/gcubeloggedin/client/LoggedinService.java index 796a8d9..cad889d 100644 --- a/src/main/java/org/gcube/portlets/user/gcubeloggedin/client/LoggedinService.java +++ b/src/main/java/org/gcube/portlets/user/gcubeloggedin/client/LoggedinService.java @@ -11,7 +11,7 @@ import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; @RemoteServiceRelativePath("LoggedinServiceImpl") public interface LoggedinService extends RemoteService { - VObject getSelectedRE(); + VObject getSelectedRE(String portalURL); String getDefaultCommunityURL(); diff --git a/src/main/java/org/gcube/portlets/user/gcubeloggedin/client/LoggedinServiceAsync.java b/src/main/java/org/gcube/portlets/user/gcubeloggedin/client/LoggedinServiceAsync.java index 3d3006f..c0cffc3 100644 --- a/src/main/java/org/gcube/portlets/user/gcubeloggedin/client/LoggedinServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/gcubeloggedin/client/LoggedinServiceAsync.java @@ -10,7 +10,7 @@ import com.google.gwt.user.client.rpc.AsyncCallback; public interface LoggedinServiceAsync { - void getSelectedRE(AsyncCallback callback); + void getSelectedRE(String portalURL, AsyncCallback callback); void getDefaultCommunityURL(AsyncCallback callback); diff --git a/src/main/java/org/gcube/portlets/user/gcubeloggedin/server/LoggedinServiceImpl.java b/src/main/java/org/gcube/portlets/user/gcubeloggedin/server/LoggedinServiceImpl.java index f96678d..da973db 100644 --- a/src/main/java/org/gcube/portlets/user/gcubeloggedin/server/LoggedinServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/gcubeloggedin/server/LoggedinServiceImpl.java @@ -23,6 +23,7 @@ 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.UserManager; import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; @@ -46,6 +47,7 @@ import com.liferay.portal.security.permission.PermissionChecker; import com.liferay.portal.security.permission.PermissionCheckerFactoryUtil; import com.liferay.portal.security.permission.PermissionThreadLocal; import com.liferay.portal.service.GroupLocalServiceUtil; +import com.liferay.portal.service.OrganizationLocalServiceUtil; import com.liferay.portal.service.UserLocalServiceUtil; import com.liferay.portal.theme.ThemeDisplay; @@ -70,7 +72,7 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi _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); @@ -94,19 +96,33 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi * return the current selected VRE */ - public VObject getSelectedRE() { + public VObject getSelectedRE(String portalURL) { ASLSession aslSession = getASLSession(); String username = aslSession.getUsername(); - if (! isWithinPortal()) { + String friendlyURL = ScopeServiceImpl.extractOrgFriendlyURL(portalURL); + + if (friendlyURL == null) {//the URL is not a portal URL, we are in devmode. return new VREClient("Test", "", "" + "Fishery and Aquaculture Resources Management (FARM) Virtual Organisation The FARM Virtual Organisation is the dynamic group of individuals and/or institutions defined around a set of sharing rules in which resource providers and consumers 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 Fisheries and Aquaculture Resources Management. This VO is conceived to support various application scenarios arising in the FARM Community including the production of Fisheries and Aquaculture Country Profiles, the management of catch statistics including harmonisation, the dynamic generation of biodiversity maps and species distribution maps. This Virtual Organisation currently consists of:
  • approximately 13 gCube nodes, i.e. machines dedicated to run the gCube system;
  • approximately 89 running instances, i.e. running gCube services supporting the operation of the infrastructure;
  • approximately 25 collections, i.e. set of D4Science Information Objects including Earth images, AquaMaps, Graphs on catch statistics;
  • approximately 66 metadata collections, i.e. set of Metadata Objects describing the Information Objects through various features and schemas;
  • approximately 58 other resources including transformation programs, index types, etc.
" + "", "", "", UserBelongingClient.BELONGING, false, true); } _log.trace("getting Selected Research Environment"); - - HttpSession session = this.getThreadLocalRequest().getSession(); - ThemeDisplay themeDisplay = (ThemeDisplay) this.getThreadLocalRequest().getSession().getAttribute(WebKeys.THEME_DISPLAY); - Organization currOrg = (Organization) session.getAttribute("CURR_RE_NAME"); + Organization currOrg = null; + try { + List groups = GroupLocalServiceUtil.getGroups(0, GroupLocalServiceUtil.getGroupsCount()); + for (Group g : groups) { + if (g.isOrganization() || g.isCommunity()) + if (g.getFriendlyURL().compareTo(friendlyURL) == 0) { + long organizationId = g.getClassPK(); + currOrg = OrganizationLocalServiceUtil.getOrganization(organizationId); + String scopeToSet = ScopeServiceImpl.buildScope(g); + getASLSession().setScope(scopeToSet); + _log.info("GOT Selected Research Environment: " + scopeToSet); + } + } + } catch (Exception e) { + e.printStackTrace(); + } /** * set the current ORG bean in session @@ -120,6 +136,7 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi String name = currOrg.getName(); long logoId = currOrg.getLogoId(); + ThemeDisplay themeDisplay = (ThemeDisplay) this.getThreadLocalRequest().getSession().getAttribute(WebKeys.THEME_DISPLAY); String logoURL = themeDisplay.getPathImage()+"/organization_logo?img_id="+ logoId +"&t" + ImageServletTokenUtil.getToken(logoId); String desc = ""; //set the description for the vre @@ -128,7 +145,7 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi VREClient vre = new VREClient(name, "", desc, logoURL, "", UserBelongingClient.BELONGING, isEnabled(username, currOrg, MANDATORY_GROUP), isEnabled(username, currOrg, REQUEST_BASED_GROUP)); return vre; } - + private Boolean isEnabled(String username, Organization currOrg, String attrToCheck) { Boolean isEnabled = false; @@ -137,7 +154,7 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi return true; } try { - + long companyId = OrganizationsUtil.getCompany().getCompanyId(); _log.trace("Setting Thread Permission"); User user = UserLocalServiceUtil.getUserByScreenName(companyId, ScopeHelper.getAdministratorUsername()); @@ -190,18 +207,18 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user, false); PermissionThreadLocal.setPermissionChecker(permissionChecker); _log.trace("Setting Permission ok!"); - + _log.debug("Creating and Setting custom attribute for colName " + attribute2Set + " to " +true); //add the custom attrs currUser = UserLocalServiceUtil.getUserByScreenName(companyId, username); - + if (! currOrg.getExpandoBridge().hasAttribute(attribute2Set)) currOrg.getExpandoBridge().addAttribute(attribute2Set); - + currOrg.getExpandoBridge().setAttribute(attribute2Set, "true"); _log.trace("setAttribute true"); - - + + _log.trace("Setting Thread Permission back to regular"); permissionChecker = PermissionCheckerFactoryUtil.create(currUser, false); PermissionThreadLocal.setPermissionChecker(permissionChecker); @@ -275,7 +292,7 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi _log.trace("\n getPortalBasicUrl: " +toReturn + "queryString: " + request.getQueryString()); return toReturn; } - + /** *@return the redirect url if everything goes ok, null otherwise */ @@ -296,7 +313,7 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi return null; } } - + /** * Get the current group ID * @@ -318,18 +335,18 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi } return null; } - + private void removeUserFromHLGroup(String username, String group) { - try { + try { org.gcube.common.homelibrary.home.workspace.usermanager.UserManager um = HomeLibrary.getHomeManagerFactory().getUserManager(); um.removeUserFromGroup(group, username, getASLSession().getUsername()); } catch (InternalErrorException e) { _log.error("Failed to get the usermanager from HL. Could not add remove user from the HL group"); } catch (ItemNotFoundException e1) { - + } } - + protected static ArrayList getAdministratorsEmails(String scope) { LiferayUserManager userManager = new LiferayUserManager(); LiferayGroupManager groupManager = new LiferayGroupManager(); @@ -369,7 +386,7 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi } return adminEmailsList; } - + /** * * @param scope . @@ -414,7 +431,7 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi mailToAdmin.sendEmail(); } - + private String readGatewayName() { //get the portles to look for from the property file @@ -432,8 +449,8 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi //catch exception in case properties file does not exist catch(IOException e) { _log.warn("$CATALINA_HOME/conf/gcube-data.properties not found, Returning gateway name: " + gatewayLabel); - } - + } + return gatewayLabel; } } diff --git a/src/main/resources/org/gcube/portlets/user/gcubeloggedin/GCubeLoggedin.gwt.xml b/src/main/resources/org/gcube/portlets/user/gcubeloggedin/GCubeLoggedin.gwt.xml index e8c96ac..a8451bb 100644 --- a/src/main/resources/org/gcube/portlets/user/gcubeloggedin/GCubeLoggedin.gwt.xml +++ b/src/main/resources/org/gcube/portlets/user/gcubeloggedin/GCubeLoggedin.gwt.xml @@ -4,7 +4,7 @@ - + diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 751d5d9..f867bfa 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -4,21 +4,21 @@ "http://java.sun.com/dtd/web-app_2_3.dtd"> - - - - LoggedinServiceImpl - org.gcube.portlets.user.gcubeloggedin.server.LoggedinServiceImpl - - - - LoggedinServiceImpl - /gcubeloggedin/LoggedinServiceImpl - - - - - GCubeLoggedin.html - + + + + LoggedinServiceImpl + org.gcube.portlets.user.gcubeloggedin.server.LoggedinServiceImpl + + + + LoggedinServiceImpl + /gcubeloggedin/LoggedinServiceImpl + + + + + GCubeLoggedin.html +