added getAdministratorUsername method in ScopeHelper, moved to Java7

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/custom-portal-handler@94129 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2014-04-02 17:20:54 +00:00
parent 9e80d27a5d
commit b138d0ae37
6 changed files with 58 additions and 20 deletions

View File

@ -12,16 +12,16 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/> <attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="owner.project.facets" value="java"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/> <classpathentry kind="output" path="target/classes"/>
</classpath> </classpath>

View File

@ -1,13 +1,12 @@
#Sat Dec 22 19:34:21 CET 2012
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6 org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.6 org.eclipse.jdt.core.compiler.source=1.7

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<faceted-project> <faceted-project>
<installed facet="java" version="1.6"/>
<installed facet="jst.utility" version="1.0"/> <installed facet="jst.utility" version="1.0"/>
<installed facet="java" version="1.7"/>
</faceted-project> </faceted-project>

View File

@ -9,8 +9,13 @@
<Change>Removed GCF Dependency</Change> <Change>Removed GCF Dependency</Change>
<Change>Logging with sl4j Enabled</Change> <Change>Logging with sl4j Enabled</Change>
</Changeset> </Changeset>
<Changeset component="org.gcube.portal.custom-portal-handler.1-4-0" <Changeset component="org.gcube.portal.custom-portal-handler.1-4-0"
date="2014-03-4"> date="2014-03-4">
<Change>Added possibility to create programmatically layouts with framed portlets</Change> <Change>Added possibility to create programmatically layouts with
framed portlets</Change>
</Changeset>
<Changeset component="org.gcube.portal.custom-portal-handler.1-5-0"
date="2014-04-02">
<Change>Added getAdministratorUsername method in ScopeHelper</Change>
</Changeset> </Changeset>
</ReleaseNotes> </ReleaseNotes>

10
pom.xml
View File

@ -10,7 +10,7 @@
<groupId>org.gcube.portal</groupId> <groupId>org.gcube.portal</groupId>
<artifactId>custom-portal-handler</artifactId> <artifactId>custom-portal-handler</artifactId>
<version>1.4.0-SNAPSHOT</version> <version>1.5.0-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>Custom Portal Handler</name> <name>Custom Portal Handler</name>
<description> <description>
@ -24,8 +24,8 @@
</scm> </scm>
<properties> <properties>
<distroDirectory>distro</distroDirectory> <distroDirectory>distro</distroDirectory>
<maven.compiler.source>1.6</maven.compiler.source> <maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target> <maven.compiler.target>1.7</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
@ -93,8 +93,8 @@
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version> <version>3.0</version>
<configuration> <configuration>
<source>1.6</source> <source>1.7</source>
<target>1.6</target> <target>1.7</target>
</configuration> </configuration>
</plugin> </plugin>

View File

@ -3,6 +3,7 @@ package org.gcube.portal.custom.scopemanager.scopehelper;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.List;
import java.util.Properties; import java.util.Properties;
import javax.portlet.PortletSession; import javax.portlet.PortletSession;
@ -20,9 +21,15 @@ import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.WebKeys; import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.model.Group; import com.liferay.portal.model.Group;
import com.liferay.portal.model.Organization; import com.liferay.portal.model.Organization;
import com.liferay.portal.model.Role;
import com.liferay.portal.model.User; import com.liferay.portal.model.User;
import com.liferay.portal.security.auth.PrincipalThreadLocal;
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.GroupLocalServiceUtil;
import com.liferay.portal.service.OrganizationLocalServiceUtil; import com.liferay.portal.service.OrganizationLocalServiceUtil;
import com.liferay.portal.service.RoleLocalServiceUtil;
import com.liferay.portal.service.UserLocalServiceUtil; import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.theme.ThemeDisplay; import com.liferay.portal.theme.ThemeDisplay;
@ -45,7 +52,7 @@ public class ScopeHelper {
public static final String CURR_ORG = "CURR_RE_NAME"; public static final String CURR_ORG = "CURR_RE_NAME";
public static final String MAIL = "supportmail"; public static final String MAIL = "notificationSenderEmail";
public static void setContext(RenderRequest request) { public static void setContext(RenderRequest request) {
setContext(request, USERNAME_ATTRIBUTE); setContext(request, USERNAME_ATTRIBUTE);
@ -148,14 +155,14 @@ public class ScopeHelper {
props.load( fis); props.load( fis);
toReturn = props.getProperty(MAIL); toReturn = props.getProperty(MAIL);
if (toReturn == null || toReturn.compareTo("")==0) { if (toReturn == null || toReturn.compareTo("")==0) {
toReturn = "support_team@d4science.org"; toReturn = "do-not-reply@isti.cnr.it";
_log.error("Property "+MAIL+" in $CATALINA_HOME/conf/gcube-data.properties was not found, returning default support mailing address " + toReturn); _log.error("Property "+MAIL+" in $CATALINA_HOME/conf/gcube-data.properties was not found, returning default support mailing address " + toReturn);
} else } else
_log.trace("Found Mail Support address: " + toReturn ); _log.trace("Found Mail Support address: " + toReturn );
} }
//catch exception in case properties file does not exist //catch exception in case properties file does not exist
catch(IOException e) { catch(IOException e) {
toReturn = "support_team@d4science.org"; toReturn = "do-not-reply@isti.cnr.it";
_log.error("gcube-data.properties file not found under $CATALINA_HOME/conf dir, returning default support mailing address " + toReturn); _log.error("gcube-data.properties file not found under $CATALINA_HOME/conf dir, returning default support mailing address " + toReturn);
return toReturn; return toReturn;
} }
@ -180,4 +187,31 @@ public class ScopeHelper {
public static String getRootConfigFromGCore() { public static String getRootConfigFromGCore() {
return PortalContext.getConfiguration().getInfrastructureName(); return PortalContext.getConfiguration().getInfrastructureName();
} }
/**
* return one of the Administrators Username from LiferayDB
*/
public static String getAdministratorUsername() {
String toReturn = "";
try {
Role adminRole = RoleLocalServiceUtil.getRole(OrganizationsUtil.getCompany().getCompanyId(),"Administrator");
List<User> adminUsers = UserLocalServiceUtil.getRoleUsers(adminRole.getRoleId());
if (adminUsers != null && adminUsers.size() > 0)
toReturn = adminUsers.get(0).getScreenName();
else
_log.warn("No users with Administrator Role in this portal!");
}
//catch exception in case properties file does not exist
catch(Exception e) {
toReturn = "Exception";
_log.error("No users with Administrator Role in this portal, returning " + toReturn);
e.printStackTrace();
return toReturn;
}
_log.debug("Returning ADMIN username=" + toReturn );
return toReturn;
}
} }