From aea46e7d4b7a2cd80ade5526dc1b72c37816cd24 Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Mon, 12 Oct 2020 11:39:27 +0200 Subject: [PATCH] added feature recognising the gateway URL from the name minor css adjustments --- .../gcube/portlets/user/vreyard/VreYard.java | 71 ++++++++++++++++--- src/main/webapp/css/main.css | 4 +- src/main/webapp/html/init.jsp | 3 + src/main/webapp/html/vreyard/view.jsp | 11 ++- 4 files changed, 74 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/vreyard/VreYard.java b/src/main/java/org/gcube/portlets/user/vreyard/VreYard.java index b36ca0f..c19ba56 100644 --- a/src/main/java/org/gcube/portlets/user/vreyard/VreYard.java +++ b/src/main/java/org/gcube/portlets/user/vreyard/VreYard.java @@ -1,6 +1,8 @@ package org.gcube.portlets.user.vreyard; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import javax.portlet.PortletException; import javax.portlet.RenderRequest; @@ -10,9 +12,19 @@ import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.infrastructure.detachedres.detachedreslibrary.server.DetachedREsClient; import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.DetachedREs; +import org.gcube.portlets.user.thematicgateways.Gateway; +import org.gcube.vomanagement.usermanagement.GroupManager; +import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager; +import org.gcube.vomanagement.usermanagement.util.ManagementUtils; import com.liferay.portal.kernel.log.LogFactoryUtil; import com.liferay.portal.kernel.util.PrefsPropsUtil; +import com.liferay.portal.model.Group; +import com.liferay.portal.model.LayoutSet; +import com.liferay.portal.model.VirtualHost; +import com.liferay.portal.service.GroupLocalServiceUtil; +import com.liferay.portal.service.LayoutSetLocalServiceUtil; +import com.liferay.portal.service.VirtualHostLocalServiceUtil; import com.liferay.portal.util.PortalUtil; import com.liferay.util.bridges.mvc.MVCPortlet; @@ -26,22 +38,17 @@ public class VreYard extends MVCPortlet { public static final String DEFAULT_USER_PROPERTY = "d4science.publicportlets.user"; public static final String DEFAULT_CONTEXT_PROPERTY = "d4science.publicportlets.context"; public static final String DEFAULT_TOKEN_PROPERTY = "d4science.publicportlets.token"; - - - - public static final String DEFAULT_SCOPE_PROPERTY = "/d4science.research-infrastructures.eu/"; - public static final String DEFAULT_TOKEN = "8effc529-44ec-4895-b727-ed0dc14ad113-843339462"; - + public static final String DEFAULT_ROLE = "OrganizationMember"; - + @Override public void render(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException, IOException { try { - + String context = PrefsPropsUtil.getString(PortalUtil.getCompanyId(renderRequest), DEFAULT_CONTEXT_PROPERTY); String token = PrefsPropsUtil.getString(PortalUtil.getCompanyId(renderRequest), DEFAULT_TOKEN_PROPERTY); - + ScopeProvider.instance.set(context); SecurityTokenProvider.instance.set(token); DetachedREsClient detachedREsClient = new DetachedREsClient(); @@ -52,12 +59,54 @@ public class VreYard extends MVCPortlet { _log.error(e.getLocalizedMessage(), e); } - - + + //renderRequest.setAttribute("theGateways", theGateways); super.render(renderRequest, renderResponse); } + /** + * @param gatewayName e.g.DESIRA Gateway + * @return the url of the gateway that matches the name, or null there is no match + * @throws Exception + */ + public static String getGatewayHTTPURLByName(String gatewayName) throws Exception { + List theGateways = getGateways(new LiferayGroupManager()); + List vHosts = VirtualHostLocalServiceUtil.getVirtualHosts(0, VirtualHostLocalServiceUtil.getVirtualHostsCount()); + for (Gateway gateway : theGateways) { + if (gateway.getSite().getName().compareToIgnoreCase(gatewayName) == 0) { + LayoutSet lSet = LayoutSetLocalServiceUtil.getLayoutSet(gateway.getSite().getGroupId(), false); + for (VirtualHost vHost : vHosts) { + long layoutSetId = vHost.getLayoutSetId(); + if (lSet.getLayoutSetId() == layoutSetId) { + return "https://"+vHost.getHostname()+"/"; + } + } + } + } + return null; + } + + public static List getGateways(GroupManager groupsManager) { + List toReturn = new ArrayList<>(); + try{ + List candidateGateways = GroupLocalServiceUtil.getGroups(ManagementUtils.getCompany().getCompanyId(), 0, true); + // real gateways have no children as well + for (Group group : candidateGateways) { + List children = group.getChildren(true); + if(children == null || children.isEmpty()) + if(! (group.getFriendlyURL().equals("/guest") || group.getFriendlyURL().equals("/global") )) {// skipping these sites + ArrayList theVRENames = new ArrayList<>(); + toReturn.add(new Gateway(group, theVRENames)); + } + } + } catch(Exception e){ + _log.error("Failed to retrieve the list of gateways", e); + return null; + } + return toReturn; + } + } diff --git a/src/main/webapp/css/main.css b/src/main/webapp/css/main.css index abd54f9..1121d83 100644 --- a/src/main/webapp/css/main.css +++ b/src/main/webapp/css/main.css @@ -16,8 +16,10 @@ div.vre-yard-portlet h1 { font-size: 2em; line-height: 25px; color: #555; + font-weight: 200; } div.vre-yard-portlet h1 > small { font-size: 15px; -} \ No newline at end of file + font-weight: 200; +} diff --git a/src/main/webapp/html/init.jsp b/src/main/webapp/html/init.jsp index 10bee34..350cc70 100644 --- a/src/main/webapp/html/init.jsp +++ b/src/main/webapp/html/init.jsp @@ -48,12 +48,15 @@ <%@ page import="com.liferay.portal.webserver.WebServerServletTokenUtil" %> <%@ page import="com.liferay.portal.service.VirtualHostLocalServiceUtil" %> <%@ page import="org.gcube.portlets.user.thematicgateways.*" %> +<%@ page import="org.gcube.portlets.user.vreyard.VreYard" %> <%@ page import="org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.DetachedREs"%> <%@ page import="org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.Gateway"%> <%@ page import="org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.VO"%> <%@ page import="org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.VRE"%> + + diff --git a/src/main/webapp/html/vreyard/view.jsp b/src/main/webapp/html/vreyard/view.jsp index f280044..362c66a 100644 --- a/src/main/webapp/html/vreyard/view.jsp +++ b/src/main/webapp/html/vreyard/view.jsp @@ -11,7 +11,7 @@

We couldn't find the page you were looking for, perhaps you were interested in one of the following Virtual - Research Environment, that have been hosted on D4Science in the past.

+ Research Environments, that have been hosted on D4Science in the past.

<% SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); @@ -31,10 +31,15 @@ } // end for VO pageContext.setAttribute("gatewayVREs", gatewayVREs); - String gatewayDisplayName = gateway.getName().replace("Detached", ""); + String gatewayDisplayName = gateway.getName().replace("Detached ", ""); + String gatewayURL = VreYard.getGatewayHTTPURLByName(gatewayDisplayName); + if (gatewayURL != null) { %> - +

<%=gatewayDisplayName%>
<%=gateway.getDescription()%> + <%} + else {%>

<%=gatewayDisplayName%>
<%=gateway.getDescription()%> + <%} %>