From 199462799b3ae741c958a8d994bf82264c0ecac4 Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Fri, 8 Apr 2016 11:12:47 +0000 Subject: [PATCH] removed customAttributeKeys from portalManager git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portal/portal-manager@126883 82a268e6-3cf1-43bd-a215-b396298e98cf --- pom.xml | 5 ++ .../common/portal/CustomAttributeKeys.java | 24 ------ .../gcube/common/portal/PortalContext.java | 85 +++++++++++++++---- 3 files changed, 75 insertions(+), 39 deletions(-) delete mode 100644 src/main/java/org/gcube/common/portal/CustomAttributeKeys.java diff --git a/pom.xml b/pom.xml index e2e446a..7d711aa 100644 --- a/pom.xml +++ b/pom.xml @@ -41,6 +41,11 @@ + + org.gcube.dvos + usermanagement-core + [2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT) + javax.servlet servlet-api diff --git a/src/main/java/org/gcube/common/portal/CustomAttributeKeys.java b/src/main/java/org/gcube/common/portal/CustomAttributeKeys.java deleted file mode 100644 index 7c7c483..0000000 --- a/src/main/java/org/gcube/common/portal/CustomAttributeKeys.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.gcube.common.portal; -/** - * - * @author Massimiliano Assante, CNR-ISTI - * For gCube Portal Bundle (Site) Custom Attributes keys - * - */ -public enum CustomAttributeKeys { - MANDATORY("Mandatory"), - IS_EXTERNAL("Isexternal"), - URL("Url"), - POST_NOTIFICATION("Postnotificationviaemail"), - VIRTUAL_GROUP("Virtualgroup"); - - private String name; - - private CustomAttributeKeys(String name) { - this.name = name; - } - - public String getKeyName() { - return this.name; - } -} diff --git a/src/main/java/org/gcube/common/portal/PortalContext.java b/src/main/java/org/gcube/common/portal/PortalContext.java index 56e681e..46e8e68 100644 --- a/src/main/java/org/gcube/common/portal/PortalContext.java +++ b/src/main/java/org/gcube/common/portal/PortalContext.java @@ -9,6 +9,9 @@ import java.util.Properties; import javax.servlet.http.HttpServletRequest; +import org.gcube.vomanagement.usermanagement.GroupManager; +import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager; +import org.gcube.vomanagement.usermanagement.model.CustomAttributeKeys; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,7 +37,10 @@ import com.liferay.portal.service.VirtualHostLocalServiceUtil; public class PortalContext { private static final Logger _log = LoggerFactory.getLogger(PortalContext.class); - + private static final String DEFAULT_INFRA_NAME = "gcube"; + private static final String DEFAULT_VO_NAME = "devsec"; + private static final String DEFAULT_GATEWAY_NAME = "D4science Gateway"; + private static final String DEFAULT_GATEWAY_EMAIL = "do-not-reply@d4science.org"; private static PortalContext singleton = new PortalContext(); @@ -63,9 +69,9 @@ public class PortalContext { vos = props.getProperty(GCubePortalConstants.SCOPES); } catch(IOException e) { - infra = "gcube"; - vos = "devsec"; - _log.error("infrastructure.properties file not found under $CATALINA_HOME/conf/ dir, setting default infrastructure Name and devsec as VO Name" + infra); + infra = DEFAULT_INFRA_NAME; + vos = DEFAULT_VO_NAME; + _log.error("infrastructure.properties file not found under $CATALINA_HOME/conf/ dir, setting default infrastructure Name " + infra + " and VO Name " + vos); } _log.info("PortalContext configurator correctly initialized on " + infra); } @@ -132,6 +138,22 @@ public class PortalContext { */ public String getSiteLandingPagePath(final HttpServletRequest request) throws PortalException, SystemException { String sitePath = StringPool.BLANK; + Group site = getSiteFromServletRequest(request); + if (site.getPrivateLayoutsPageCount() > 0) { + sitePath = getGroupFriendlyURL(request, site); + } else { + _log.debug(site.getName() + " site doesn't have any private page. Default landing page will be used"); + } + return sitePath; + } + /** + * + * @param request + * @return the current Group instance based on the request + * @throws PortalException + * @throws SystemException + */ + private Group getSiteFromServletRequest(final HttpServletRequest request) throws PortalException, SystemException { String serverName = request.getServerName(); _log.debug("currentHost is " + serverName); Group site = null; @@ -144,14 +166,10 @@ public class PortalContext { long layoutSetId = virtualHost.getLayoutSetId(); site = LayoutSetLocalServiceUtil.getLayoutSet(layoutSetId).getGroup(); _log.debug("Found match! Your site is " + site.getName()); + return site; } } - if (site.getPrivateLayoutsPageCount() > 0) { - sitePath = getGroupFriendlyURL(request, site); - } else { - _log.debug(site.getName() + " site doesn't have any private page. Default landing page will be used"); - } - return sitePath; + return null; } /** * @param request @@ -162,15 +180,34 @@ public class PortalContext { * @throws PortalException * @throws SystemException */ - private static String getGroupFriendlyURL(final HttpServletRequest request, final Group currentGroup) throws PortalException, SystemException { + private static String getGroupFriendlyURL(HttpServletRequest request, final Group currentGroup) throws PortalException, SystemException { String friendlyURL = GCubePortalConstants.PREFIX_GROUP_URL; StringBundler sb = new StringBundler(); sb.append(friendlyURL).append(currentGroup.getFriendlyURL()); return sb.toString(); } /** - * read the infrastructure gateway name from a property file and returns it + * + * @param request the HttpServletRequest instance of your servlet + * @return the current Site Name based on the request */ + public String getGatewayName(HttpServletRequest request) { + String toReturn = DEFAULT_GATEWAY_NAME; + try { + Group currSite = getSiteFromServletRequest(request); + toReturn = (String) new LiferayGroupManager().readCustomAttr(currSite.getGroupId(), CustomAttributeKeys.GATEWAY_SITE_NAME.getKeyName()); + } catch (Exception e) { + toReturn = DEFAULT_GATEWAY_NAME; + _log.error("Could not read Site Custom Attr: " + CustomAttributeKeys.GATEWAY_SITE_NAME.getKeyName() + ", returning default Gateway Name " + toReturn); + } + return toReturn; + } + + /** + * read the infrastructure gateway name from a property file and returns it + * @deprecated use getGatewayName(HttpServletRequest request) + */ + @Deprecated public String getGatewayName() { //get the portles to look for from the property file Properties props = new Properties(); @@ -185,7 +222,7 @@ public class PortalContext { } //catch exception in case properties file does not exist catch(IOException e) { - toReturn = "D4science Gateway"; + toReturn = DEFAULT_GATEWAY_NAME; _log.error("gcube-data.properties file not found under $CATALINA_HOME/conf dir, returning default Portal Name " + toReturn); return toReturn; } @@ -193,8 +230,26 @@ public class PortalContext { return toReturn; } /** - * read the sender (from) email address for notifications name from a property file and returns it + * + * @param request the HttpServletRequest instance of your servlet + * @return the sender (from) email address for the current Site based on the request */ + public String getSenderEmail(HttpServletRequest request) { + String toReturn = DEFAULT_GATEWAY_EMAIL; + try { + Group currSite = getSiteFromServletRequest(request); + toReturn = (String) new LiferayGroupManager().readCustomAttr(currSite.getGroupId(), CustomAttributeKeys.GATEWAY_SITE_EMAIL_SENDER.getKeyName()); + } catch (Exception e) { + toReturn = DEFAULT_GATEWAY_EMAIL; + _log.error("Could not read Site Custom Attr: " + CustomAttributeKeys.GATEWAY_SITE_EMAIL_SENDER.getKeyName() + ", returning default Gateway Email Sender " + toReturn); + } + return toReturn; + } + /** + * read the sender (from) email address for notifications name from a property file and returns it + * @deprecated use getSenderEmail(HttpServletRequest request) + */ + @Deprecated public String getSenderEmail() { //get the portles to look for from the property file Properties props = new Properties(); @@ -209,7 +264,7 @@ public class PortalContext { } //catch exception in case properties file does not exist catch(IOException e) { - toReturn = "do-not-reply@d4science.org"; + toReturn = DEFAULT_GATEWAY_EMAIL; _log.error("gcube-data.properties file not found under $CATALINA_HOME/conf dir, returning default Email" + toReturn); return toReturn; }