From f997057b839fae6b9469f32c59aba5c764975266 Mon Sep 17 00:00:00 2001 From: Alfredo Oliviero Date: Thu, 30 May 2024 11:03:09 +0200 Subject: [PATCH] config dinamica --- deploy.sh | 2 +- pom.xml | 2 +- .../cloudcomputing/CloudComputingConfig.java | 3 +- .../CloudComputingConfigPortlet.java | 87 +++++++++++++++++-- src/main/webapp/html/boot/boot.jsp | 34 +++++++- 5 files changed, 116 insertions(+), 12 deletions(-) diff --git a/deploy.sh b/deploy.sh index 7bed5fa..6f0ce09 100755 --- a/deploy.sh +++ b/deploy.sh @@ -24,7 +24,7 @@ MVN_FINALNAME=$(mvn -q \ exec:exec) echo "MVN_FINALNAME=${MVN_FINALNAME}" -mvn clean package -U +mvn clean package scp target/$MVN_FINALNAME.war life@$DEST_HOST:/home/life/Portal-Bundle/deploy/$MVN_NAME.war diff --git a/pom.xml b/pom.xml index 872f2d5..c0b65a1 100644 --- a/pom.xml +++ b/pom.xml @@ -89,7 +89,7 @@ common-scope provided - + org.gcube.dvos usermanagement-core diff --git a/src/main/java/org/gcube/portlets/user/cloudcomputing/CloudComputingConfig.java b/src/main/java/org/gcube/portlets/user/cloudcomputing/CloudComputingConfig.java index 0a3edd8..b6d0fc9 100644 --- a/src/main/java/org/gcube/portlets/user/cloudcomputing/CloudComputingConfig.java +++ b/src/main/java/org/gcube/portlets/user/cloudcomputing/CloudComputingConfig.java @@ -8,7 +8,8 @@ public class CloudComputingConfig { public String auth_url = "https://accounts.dev.d4science.org/auth"; public String ccp_url = "https://ccp.cloud-dev.d4science.org"; - // public String cdn_url = "https://cdn.cloud.d4science.org"; //"https://cdn.cloud-dev.d4science.org"; + // public String cdn_url = "https://cdn.cloud.d4science.org"; + // //"https://cdn.cloud-dev.d4science.org"; public String cdn_url = "https://cdn.cloud-dev.d4science.org"; } diff --git a/src/main/java/org/gcube/portlets/user/cloudcomputing/CloudComputingConfigPortlet.java b/src/main/java/org/gcube/portlets/user/cloudcomputing/CloudComputingConfigPortlet.java index dce4390..9f78c67 100644 --- a/src/main/java/org/gcube/portlets/user/cloudcomputing/CloudComputingConfigPortlet.java +++ b/src/main/java/org/gcube/portlets/user/cloudcomputing/CloudComputingConfigPortlet.java @@ -1,25 +1,54 @@ package org.gcube.portlets.user.cloudcomputing; import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; import javax.portlet.PortletException; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; +import javax.servlet.http.HttpServletRequest; import org.gcube.common.portal.PortalContext; +import com.liferay.portal.kernel.exception.PortalException; +import com.liferay.portal.kernel.exception.SystemException; import com.liferay.portal.kernel.log.LogFactoryUtil; +import com.liferay.portal.model.Group; +import com.liferay.portal.service.GroupLocalServiceUtil; import com.liferay.portal.util.PortalUtil; import com.liferay.util.bridges.mvc.MVCPortlet; public class CloudComputingConfigPortlet extends MVCPortlet { private static com.liferay.portal.kernel.log.Log _log = LogFactoryUtil.getLog(CloudComputingConfigPortlet.class); - public CloudComputingConfig getConfig() { - return new CloudComputingConfig(); + public CloudComputingConfig getConfig(RenderRequest renderRequest) throws MalformedURLException { + + CloudComputingConfig config = new CloudComputingConfig(); + + String currentContext = getCurrentContext(renderRequest); + String encodedContext = getEncodedContext(currentContext); + config.encoded_context = encodedContext; + + // config.redirect_url = redirect_url; + HttpServletRequest httpReq = PortalUtil + .getOriginalServletRequest(PortalUtil.getHttpServletRequest(renderRequest)); + String current_url = PortalUtil.getCurrentURL(renderRequest); + // current_url = /group/devvre/cloudcomputing + + String absolute_current_url = PortalUtil.getAbsoluteURL(httpReq, current_url); + // absolute_current_url = + // https://next.dev.d4science.org/group/devvre/cloudcomputing + + config.redirect_url = absolute_current_url; + + URL base_url = new URL(PortalUtil.getAbsoluteURL(httpReq, "/")); + String host = base_url.getHost(); + config.gateway = host; + return config; } - private String getCurrentContext(RenderRequest request) { + protected String getCurrentContext(RenderRequest request) { long groupId = -1; try { groupId = PortalUtil.getScopeGroupId(request); @@ -30,7 +59,7 @@ public class CloudComputingConfigPortlet extends MVCPortlet { return null; } - private String getCurrentContext(long groupId) { + protected String getCurrentContext(long groupId) { try { PortalContext pContext = PortalContext.getConfiguration(); return pContext.getCurrentScope("" + groupId); @@ -40,6 +69,10 @@ public class CloudComputingConfigPortlet extends MVCPortlet { return null; } + protected String getEncodedContext(String context) { + return context.replace("/", "%2F"); + } + @Override public void render(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException, IOException { @@ -52,7 +85,7 @@ public class CloudComputingConfigPortlet extends MVCPortlet { // String redirect_url = "https://sobigdata.d4science.org/group/sobigdatalab"; // String url = "https://accounts.d4science.org/auth"; - CloudComputingConfig config = getConfig(); + CloudComputingConfig config = getConfig(renderRequest); renderRequest.setAttribute("encoded_context", config.encoded_context); renderRequest.setAttribute("gateway", config.gateway); @@ -61,8 +94,50 @@ public class CloudComputingConfigPortlet extends MVCPortlet { renderRequest.setAttribute("ccp_url", config.ccp_url); renderRequest.setAttribute("cdn_url", config.cdn_url); + String current_url = PortalUtil.getCurrentURL(renderRequest); + renderRequest.setAttribute("current_url", current_url); + + String infrastructure = PortalContext.getConfiguration().getInfrastructureName(); + renderRequest.setAttribute("infrastructure", infrastructure); + + HttpServletRequest httpReq = PortalUtil + .getOriginalServletRequest(PortalUtil.getHttpServletRequest(renderRequest)); + String absolute_current_url = PortalUtil.getAbsoluteURL(httpReq, current_url); + renderRequest.setAttribute("absolute_current_url", absolute_current_url); + + String calculated_gateway = absolute_current_url + .replace("https://", "") + .replace("http://", "") + .replace(current_url, ""); + renderRequest.setAttribute("calculated_gateway", calculated_gateway); + + String base_url = PortalUtil.getAbsoluteURL(httpReq, "/"); + renderRequest.setAttribute("base_url", base_url); + URL a = new URL(base_url); + + renderRequest.setAttribute("host", a.getHost()); + + try { + Group group = (Group) GroupLocalServiceUtil.getGroup(PortalUtil.getScopeGroupId(renderRequest)); + String group_url = group.getFriendlyURL(); + renderRequest.setAttribute("group_url", group_url); + renderRequest.setAttribute("group_name", group.getName()); + + } catch (PortalException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SystemException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + String completeURL = PortalUtil.getCurrentCompleteURL(httpReq); + renderRequest.setAttribute("completeURL", completeURL); + // User theUser = PortalUtil.getUser(renderRequest); - // String currentContext = getCurrentContext(renderRequest); + String currentContext = getCurrentContext(renderRequest); + renderRequest.setAttribute("current_context", currentContext); + // ScopeBean bean = new ScopeBean(currentContext); // String context; // String excapedContext; diff --git a/src/main/webapp/html/boot/boot.jsp b/src/main/webapp/html/boot/boot.jsp index 2577f93..9eb8f4a 100644 --- a/src/main/webapp/html/boot/boot.jsp +++ b/src/main/webapp/html/boot/boot.jsp @@ -1,12 +1,27 @@ <%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %> <%@include file="../init.jsp" %> <% + + +pageContext.setAttribute("current_context", request.getAttribute("current_context")); + pageContext.setAttribute("encoded_context", request.getAttribute("encoded_context")); pageContext.setAttribute("redirect_url", request.getAttribute("redirect_url")); pageContext.setAttribute("auth_url", request.getAttribute("auth_url")); -pageContext.setAttribute("ccp_url", -request.getAttribute("ccp_url")); -pageContext.setAttribute("cdn_url", request.getAttribute("cdn_url")); %> +pageContext.setAttribute("ccp_url", request.getAttribute("ccp_url")); +pageContext.setAttribute("cdn_url", request.getAttribute("cdn_url")); + + +pageContext.setAttribute("current_url", request.getAttribute("current_url")); +pageContext.setAttribute("infrastructure", request.getAttribute("infrastructure")); +pageContext.setAttribute("absolute_current_url", request.getAttribute("absolute_current_url")); +pageContext.setAttribute("calculated_gateway", request.getAttribute("calculated_gateway")); +pageContext.setAttribute("base_url", request.getAttribute("base_url")); +pageContext.setAttribute("group_url", request.getAttribute("group_url")); +pageContext.setAttribute("group_name", request.getAttribute("group_name")); +pageContext.setAttribute("host", request.getAttribute("host")); + +%> @@ -25,10 +40,23 @@ pageContext.setAttribute("cdn_url", request.getAttribute("cdn_url")); %> Boot Portlet