From 16636000375062db62e66d0d64004476e87dd94e Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Wed, 28 Feb 2018 17:00:10 +0000 Subject: [PATCH] for exploratory and apps the direct VRE Url is passed if the member belongs to the VRE, the page to ask for registration on this VRE othwerise git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/sbd-uploadshare-portlet@164627 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../org/gcube/portlets/user/sbd/Utils.java | 36 +++++++++++++++++++ .../user/sbdportlets/AccessExploratory.java | 3 +- .../webapp/html/accessapplication/view.jsp | 20 +++++++---- .../webapp/html/accessexploratory/view.jsp | 20 +++++++---- 4 files changed, 65 insertions(+), 14 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/sbd/Utils.java diff --git a/src/main/java/org/gcube/portlets/user/sbd/Utils.java b/src/main/java/org/gcube/portlets/user/sbd/Utils.java new file mode 100644 index 0000000..d1d16d7 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/sbd/Utils.java @@ -0,0 +1,36 @@ +package org.gcube.portlets.user.sbd; + +import org.gcube.common.portal.GCubePortalConstants; + +import com.liferay.portal.kernel.log.Log; +import com.liferay.portal.kernel.log.LogFactoryUtil; +import com.liferay.portal.model.User; +import com.liferay.portal.service.GroupLocalServiceUtil; + +public class Utils { + private static Log _log = LogFactoryUtil.getLog(Utils.class); + /** + * + * @param currentUser + * @param urlContainingGroupId + * @return the direct VRE Url if the member belongs to the VRE, the page to ask for registration on this VRE othwerise + */ + public static String getVREFriendlyURL(User currentUser, String urlContainingGroupId) { + String[] splits = urlContainingGroupId.split("="); + long groupId = -1; + try { + if (splits.length > 0) { + groupId = Long.parseLong(splits[1]); + long[] userGroupIds = currentUser.getGroupIds(); + for (int i = 0; i < userGroupIds.length; i++) { + if (groupId == userGroupIds[i]) + return GCubePortalConstants.PREFIX_GROUP_URL +GroupLocalServiceUtil.getGroup(groupId).getFriendlyURL(); + } + } + return urlContainingGroupId; + } catch (Exception e) { + _log.error("Something is wrong in the url passed: " + urlContainingGroupId); + return urlContainingGroupId; + } + } +} diff --git a/src/main/java/org/gcube/portlets/user/sbdportlets/AccessExploratory.java b/src/main/java/org/gcube/portlets/user/sbdportlets/AccessExploratory.java index daee872..72ec025 100644 --- a/src/main/java/org/gcube/portlets/user/sbdportlets/AccessExploratory.java +++ b/src/main/java/org/gcube/portlets/user/sbdportlets/AccessExploratory.java @@ -6,6 +6,5 @@ import com.liferay.util.bridges.mvc.MVCPortlet; * Portlet implementation class AccessExploratory */ public class AccessExploratory extends MVCPortlet { - - + } diff --git a/src/main/webapp/html/accessapplication/view.jsp b/src/main/webapp/html/accessapplication/view.jsp index 7948ff9..f2f90ce 100644 --- a/src/main/webapp/html/accessapplication/view.jsp +++ b/src/main/webapp/html/accessapplication/view.jsp @@ -1,6 +1,11 @@ <%@include file="init.jsp"%> +<%@ page import="org.gcube.portlets.user.sbd.Utils" %> +<%@ page import="com.liferay.portal.model.User" %> +<%@ page import="com.liferay.portal.util.PortalUtil" %> + <% long groupId = themeDisplay.getLayout().getGroupId(); + User currentUser = PortalUtil.getUser( request ); pageContext.setAttribute("icondocURL", GetterUtil.getString(portletPreferences.getValue("icondocURL", StringPool.BLANK))); @@ -18,12 +23,15 @@ long applicationName3DocumentId = GetterUtil .getLong(portletPreferences.getValue("applicationName3-DocumentId", StringPool.BLANK)); - pageContext.setAttribute("application1Url", - GetterUtil.getString(portletPreferences.getValue("application1-Url", StringPool.BLANK))); - pageContext.setAttribute("application2Url", - GetterUtil.getString(portletPreferences.getValue("application2-Url", StringPool.BLANK))); - pageContext.setAttribute("application3Url", - GetterUtil.getString(portletPreferences.getValue("application3-Url", StringPool.BLANK))); + + String url1 = GetterUtil.getString(portletPreferences.getValue("application1-Url", StringPool.BLANK)); + pageContext.setAttribute("application1Url", Utils.getVREFriendlyURL(currentUser, url1)); + + String url2 = GetterUtil.getString(portletPreferences.getValue("application2-Url", StringPool.BLANK)); + pageContext.setAttribute("application2Url", Utils.getVREFriendlyURL(currentUser, url2)); + + String url3 = GetterUtil.getString(portletPreferences.getValue("application3-Url", StringPool.BLANK)); + pageContext.setAttribute("application3Url", Utils.getVREFriendlyURL(currentUser, url3)); String content1 = ""; if (applicationName1DocumentId > 0) { diff --git a/src/main/webapp/html/accessexploratory/view.jsp b/src/main/webapp/html/accessexploratory/view.jsp index 515d6d8..8b5a856 100644 --- a/src/main/webapp/html/accessexploratory/view.jsp +++ b/src/main/webapp/html/accessexploratory/view.jsp @@ -1,6 +1,12 @@ <%@include file="init.jsp"%> +<%@ page import="org.gcube.portlets.user.sbd.Utils" %> +<%@ page import="com.liferay.portal.model.User" %> +<%@ page import="com.liferay.portal.util.PortalUtil" %> + <% long groupId = themeDisplay.getLayout().getGroupId(); + User currentUser = PortalUtil.getUser( request ); + pageContext.setAttribute("icondocURL", GetterUtil.getString(portletPreferences.getValue("icondocURL", StringPool.BLANK))); @@ -18,12 +24,14 @@ long exploratoryName3DocumentId = GetterUtil .getLong(portletPreferences.getValue("exploratoryName3-DocumentId", StringPool.BLANK)); - pageContext.setAttribute("exploratory1Url", - GetterUtil.getString(portletPreferences.getValue("exploratory1-Url", StringPool.BLANK))); - pageContext.setAttribute("exploratory2Url", - GetterUtil.getString(portletPreferences.getValue("exploratory2-Url", StringPool.BLANK))); - pageContext.setAttribute("exploratory3Url", - GetterUtil.getString(portletPreferences.getValue("exploratory3-Url", StringPool.BLANK))); + String url1 = GetterUtil.getString(portletPreferences.getValue("exploratory1-Url", StringPool.BLANK)); + pageContext.setAttribute("exploratory1Url", Utils.getVREFriendlyURL(currentUser, url1)); + + String url2 = GetterUtil.getString(portletPreferences.getValue("exploratory2-Url", StringPool.BLANK)); + pageContext.setAttribute("exploratory2Url", Utils.getVREFriendlyURL(currentUser, url2)); + + String url3 = GetterUtil.getString(portletPreferences.getValue("exploratory3-Url", StringPool.BLANK)); + pageContext.setAttribute("exploratory3Url", Utils.getVREFriendlyURL(currentUser, url3)); String content1 = ""; if (exploratoryName1DocumentId > 0) {