release 2.12

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/custom-portal-handler@68380 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2013-01-27 15:08:16 +00:00
parent d35e804098
commit 36197e6471
30 changed files with 2020 additions and 0 deletions

27
.classpath Normal file
View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</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">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

36
.project Normal file
View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>custom-portal-handler</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,4 @@
#Sat Dec 22 19:37:10 CET 2012
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding/<project>=UTF-8

View File

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

View File

@ -0,0 +1,5 @@
#Sat Dec 22 19:31:51 CET 2012
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="custom-portal-handler">
<wb-resource deploy-path="/" source-path="/src/main/java"/>
</wb-module>
</project-modules>

View File

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

3
distro/INSTALL Normal file
View File

@ -0,0 +1,3 @@
* Configure
nothing to be done

6
distro/LICENSE Normal file
View File

@ -0,0 +1,6 @@
gCube System - License
------------------------------------------------------------
The gCube/gCore software is licensed as Free Open Source software conveying to the EUPL (http://ec.europa.eu/idabc/eupl).
The software and documentation is provided by its authors/distributors "as is" and no expressed or
implied warranty is given for its use, quality or fitness for a particular case.

1
distro/MAINTAINERS Normal file
View File

@ -0,0 +1 @@
* CNR Pisa, Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo"

37
distro/README Normal file
View File

@ -0,0 +1,37 @@
The gCube System - Portlets -
------------------------------------------------------------
This work is partially funded by the European Commission in the
context of the D4Science project (www.d4science.eu), under the 1st call of FP7 IST priority.
Authors
-------
Massimiliano Assante
*
Version and Release Date
------------------------
October 2010
Description
-----------
Shared Custom portal Handler LIbrary
Download information
--------------------
Source code is available from SVN:
yes look for it :)
Binaries can be downloaded from:
http://software.d4science.research-infrastructures.eu/
Documentation
-------------
Documentation is available on-line from the Projects Documentation Wiki:
https://gcube.wiki.gcube-system.org/gcube/index.php/Developing_gCube_Portlets_Guide#Set_the_Portlet_Context_.28How_to_get_the_logged_in_user.27s_information.29
Licensing
---------
This software is licensed under the terms you may find in the file named "LICENSE" in this directory.

5
distro/changelog.xml Normal file
View File

@ -0,0 +1,5 @@
<ReleaseNotes>
<Changeset component="org.gcube.portal.custom-portal-handler.1-1-0" date="2012-05-04">
<Change>Fixed invalidate session bug</Change>
</Changeset>
</ReleaseNotes>

48
distro/descriptor.xml Normal file
View File

@ -0,0 +1,48 @@
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>servicearchive</id>
<formats>
<format>tar.gz</format>
</formats>
<baseDirectory>/</baseDirectory>
<fileSets>
<fileSet>
<directory>${distroDirectory}</directory>
<outputDirectory>/</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
<includes>
<include>README</include>
<include>LICENSE</include>
<include>INSTALL</include>
<include>MAINTAINERS</include>
<include>changelog.xml</include>
</includes>
<fileMode>755</fileMode>
<filtered>true</filtered>
</fileSet>
<fileSet>
<directory>target/apidocs</directory>
<outputDirectory>/${artifactId}/doc/api</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
<fileMode>755</fileMode>
</fileSet>
</fileSets>
<files>
<file>
<source>${distroDirectory}/profile.xml</source>
<outputDirectory>./</outputDirectory>
<filtered>true</filtered>
</file>
<file>
<source>target/${build.finalName}.jar</source>
<outputDirectory>/${artifactId}</outputDirectory>
</file>
<file>
<source>${distroDirectory}/svnpath.txt</source>
<outputDirectory>/${artifactId}</outputDirectory>
<filtered>true</filtered>
</file>
</files>
</assembly>

25
distro/profile.xml Normal file
View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<Resource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ID></ID>
<Type>Library</Type>
<Profile>
<Description>Custom Portal Handler</Description>
<Class>Portal</Class>
<Name>${artifactId}</Name>
<Version>1.0.0</Version>
<Packages>
<Software>
<Name>${artifactId}</Name>
<Version>${version}</Version>
<MavenCoordinates>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
</MavenCoordinates>
<Files>
<File>${build.finalName}.jar</File>
</Files>
</Software>
</Packages>
</Profile>
</Resource>

1
distro/svnpath.txt Normal file
View File

@ -0,0 +1 @@
${scm.url}

162
pom.xml Normal file
View File

@ -0,0 +1,162 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>maven-parent</artifactId>
<groupId>org.gcube.tools</groupId>
<version>1.0.0</version>
<relativePath />
</parent>
<groupId>org.gcube.portal</groupId>
<artifactId>custom-portal-handler</artifactId>
<version>1.2.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Custom Portal Handler</name>
<description>
gCube Custom Portal Handler is a component that all portlets need to use to set the context where they running.
It also contains utils from creating community and organization with their layouts into liferay portal.
</description>
<scm>
<connection>scm:svn:http://svn.d4science.research-infrastructures.eu/gcube/trunk/portal/${project.artifactId}</connection>
<developerConnection>scm:https://svn.d4science.research-infrastructures.eu/gcube/trunk/portal/${project.artifactId}</developerConnection>
<url>http://svn.d4science.research-infrastructures.eu/gcube/trunk/portlal/${project.artifactId}</url>
</scm>
<properties>
<distroDirectory>distro</distroDirectory>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>gcf</artifactId>
<version>[1.4.0,1.6.0]</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslcore</artifactId>
<version>3.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>portal-service</artifactId>
<version>6.0.6</version>
</dependency>
<dependency>
<groupId>javax.portlet</groupId>
<artifactId>portlet-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.dvos</groupId>
<artifactId>usermanagement-core</artifactId>
<version>1.3.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.6</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>copy-profile</id>
<phase>install</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>target</outputDirectory>
<resources>
<resource>
<directory>${distroDirectory}</directory>
<filtering>true</filtering>
<includes>
<include>profile.xml</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2</version>
<configuration>
<descriptors>
<descriptor>${distroDirectory}/descriptor.xml</descriptor>
</descriptors>
<archive>
<manifest>
<mainClass>fully.qualified.MainClass</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>servicearchive</id>
<phase>install</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,38 @@
package org.gcube.portal.custom.communitymanager;
import java.util.List;
import org.gcube.portal.custom.communitymanager.components.GCUBESiteLayout;
import com.liferay.portal.model.Portlet;
/**
*
* @author Massimiliano Assante, massimiliano.assante@isti.cnr.it
* @version 1.0 - Jan 4 2012
*
*/
public interface CommunityManager {
/**
*
* @param communityName .
* @param communityDesc .
* @param parentID .
* @return the newly created CommunityID
*/
long createCommunity(String communityName, String communityDesc, long parentID) ;
/**
*
* @param usernameCreator .
* @param communityName .
* @param communityDesc .
* @param siteLayout .
* @param parentID -
* @return the newly created CommunityID
*/
long createCommunity(String usernameCreator, String communityName, String communityDesc, GCUBESiteLayout siteLayout, long parentID) ;
/**
* @param communityName -
* @return list of belonging portlet
*/
List<Portlet> getGCubePortlets(String communityName);
}

View File

@ -0,0 +1,37 @@
package org.gcube.portal.custom.communitymanager;
import org.gcube.portal.custom.communitymanager.components.GCUBESiteLayout;
/**
*
* @author Massimiliano Assante, massimiliano.assante@isti.cnr.it
* @version 1.0 - Jan 4 2012
*
*/
public interface OrganizationManager {
/**
*
* @param rootVoName the voName
* @param voDesc -
* @return the id of the created VO
*/
long createVO(String rootVoName, String voDesc, GCUBESiteLayout siteLayout, String themeid);
/**
*
* @param voName the voName
* @param voDesc -
* @return the id of the created VO
*/
long createVO(String voName, String voDesc, long parentID, GCUBESiteLayout siteLayout, String themeid);
/**
*
* @param rootVoName the voName
* @param voDesc -
* @return the organizationid of the created VO
*/
long createVRE(String voName, String voDesc, long parentid, GCUBESiteLayout siteLayout, String themeid);
}

View File

@ -0,0 +1,358 @@
package org.gcube.portal.custom.communitymanager;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Properties;
import org.gcube.portal.custom.communitymanager.components.GCUBELayoutTab;
import org.gcube.portal.custom.communitymanager.components.GCUBEPortlet;
import org.gcube.portal.custom.communitymanager.components.GCUBESiteLayout;
import org.gcube.vomanagement.usermanagement.UserManager;
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayUserManager;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.PropsUtil;
import com.liferay.portal.model.Company;
import com.liferay.portal.model.Group;
import com.liferay.portal.model.Layout;
import com.liferay.portal.model.Portlet;
import com.liferay.portal.model.PortletPreferences;
import com.liferay.portal.model.Role;
import com.liferay.portal.model.User;
import com.liferay.portal.service.CompanyLocalServiceUtil;
import com.liferay.portal.service.LayoutLocalServiceUtil;
import com.liferay.portal.service.PortletLocalServiceUtil;
import com.liferay.portal.service.PortletPreferencesLocalServiceUtil;
import com.liferay.portal.service.RoleLocalServiceUtil;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portal.service.UserLocalServiceUtil;
public class OrganizationsUtil {
/**
*
*/
private static Log _log = LogFactoryUtil.getLog(OrganizationManager.class);
/**
*
*/
public static final String DEFAULT_COMPANY_WEB_ID = "liferay.com";
/**
*
*/
public static final String ROOT_ORG = "rootorganization";
/**
*
*/
private static final int LIFERAY_REGULAR_ROLE_ID = 1;
/**
* return the companyId
* @param webId .
* @return the company bean
* @throws PortalException .
* @throws SystemException .
*/
public static Company getCompany() throws PortalException, SystemException {
return CompanyLocalServiceUtil.getCompanyByWebId(getDefaultCompanyWebId());
}
/**
*
* @return the default company web-id (e.g. iMarine.eu)
*/
public static String getDefaultCompanyWebId() {
String defaultWebId = "";
try {
defaultWebId = GetterUtil.getString(PropsUtil.get("company.default.web.id"));
}
catch (NullPointerException e) {
_log.info("Cound not find property company.default.web.id in portal.ext file returning default web id: " + DEFAULT_COMPANY_WEB_ID);
return DEFAULT_COMPANY_WEB_ID;
}
return defaultWebId;
}
/**
*
* @return $CATALINA_HOME
*/
public static String getTomcatFolder() {
return (System.getenv("CATALINA_HOME").endsWith("/") ? System.getenv("CATALINA_HOME") : System.getenv("CATALINA_HOME")+"/");
}
/**
* get the themes id for from the property file
* @param themeid see <class>org.gcube.portal.custom.communitymanager.ThemesIdManager</class>
* @return the themeid for LR
*/
public static String getgCubeThemeId(String themeid) {
Properties props = new Properties();
String toReturn = "";
String propertyfile = "";
try {
propertyfile = getTomcatFolder()+"conf/gcube-data.properties";
File propsFile = new File(propertyfile);
FileInputStream fis = new FileInputStream(propsFile);
props.load( fis);
toReturn = props.getProperty(themeid);
}
//catch exception in case properties file does not exist
catch(IOException e) {
_log.error("Error retrieving property "+ themeid +" from " + propertyfile);
e.printStackTrace();
}
return toReturn;
}
/**
*
* @return -
*/
protected List<GCUBEPortlet> getVREBelongingPortlets(List<String> belongingPorltets) {
List<GCUBEPortlet> toReturn = new LinkedList<GCUBEPortlet>();
Properties props = new Properties();
try {
String propertyfile = getTomcatFolder()+"conf/gcube-portlets.properties";
_log.debug("Loading gCube-portlets list from " + propertyfile);
File propsFile = new File(propertyfile);
FileInputStream fis = new FileInputStream(propsFile);
props.load( fis );
}
//catch exception in case properties file does not exist
catch(IOException e) {
e.printStackTrace();
}
for (Object portlet : props.values()) {
String lportletName = (String) portlet.toString();
if (lportletName.compareTo("Login_WAR_Loginportlet") != 0 && lportletName.contains("WAR")) {
toReturn.add(new GCUBEPortlet(lportletName, lportletName));
_log.debug("Adding lportlet id:" + lportletName);
}
}
return toReturn;
}
/**
*
* @return the default template for a community (just one Tab)
*/
public List<GCUBEPortlet> getDefaultPortlets() {
List<GCUBEPortlet> toReturn = new ArrayList<GCUBEPortlet>();
toReturn.add(new GCUBEPortlet(PortletsIdManager.LR_CALENDAR, PortletsIdManager.getLRPortletId(PortletsIdManager.LR_CALENDAR)));
toReturn.add(new GCUBEPortlet(PortletsIdManager.LR_ACTIVITIES, PortletsIdManager.getLRPortletId(PortletsIdManager.LR_ACTIVITIES)));
return toReturn;
}
/**
* Create a Regular Manager Role for the community/Organization
* @param vreName
* @return
* @throws SystemException
* @throws PortalException
*/
public static Role addManagerRole(String vreName, String username) throws PortalException, SystemException {
Company company = getCompany();
User user = validateUser(username);
String roleName = "VRE-Manager-" + vreName.replaceAll(" ", "-");
Locale english = new Locale("en");
HashMap<Locale, String> roleNames = new HashMap<Locale, String>();
roleNames.put(english, roleName);
return RoleLocalServiceUtil.addRole(user.getUserId(), company.getCompanyId(), roleName, roleNames, "VRE Manager of " + vreName, LIFERAY_REGULAR_ROLE_ID);
}
/**
* Create a Regular Manager Role for the community/Organization
* @param vreName
* @return
* @throws SystemException
* @throws PortalException
*/
public static Role addManagerRole(String roleName, String vreName, long userid) throws PortalException, SystemException {
Company company = getCompany();
Locale english = new Locale("en");
HashMap<Locale, String> roleNames = new HashMap<Locale, String>();
roleNames.put(english, roleName);
return RoleLocalServiceUtil.addRole(userid, company.getCompanyId(), roleName, roleNames, "VRE Manager of " + vreName, LIFERAY_REGULAR_ROLE_ID);
}
/**
* check if the user exists in the database and has AuthZ to perform the operation
* @return
* @throws SystemException
* @throws PortalException
*/
public static User validateUser(String username) throws PortalException, SystemException {
Company company = getCompany();
return UserLocalServiceUtil.getUserByScreenName(company.getCompanyId(), username);
}
/**
* Use this method to associate a layout to a Group (whether organization or community)
*
* @param group .
* @param user .
* @param siteLayout .
* @return the layoutid of the yet created layout
* @throws PortalException .
* @throws SystemException .
*/
protected long createLayout(Group group, User user, GCUBESiteLayout siteLayout) throws PortalException, SystemException {
Layout layout = null;
for (GCUBELayoutTab tab : siteLayout.getTabs()) {
String layoutName = siteLayout.getName().replaceAll(" ", "-");
String friendlyURL= "/"+tab.getCaption().replaceAll(" ", "-");
_log.debug("Trying creating layout " + layoutName + " url:" + friendlyURL + " userid:" + user.getUserId() + " groupid:" + group.getGroupId());
ServiceContext ctx = new ServiceContext();
layout = LayoutLocalServiceUtil.addLayout(user.getUserId(), group.getGroupId(), true, 0, tab.getCaption(), layoutName,
group.getDescription(), "portlet", tab.isHidden(), friendlyURL, ctx);
if (tab.hasChildren()) {
for (GCUBELayoutTab subtab : tab.getSubTabs()) {
String subtabfriendlyURL= "/"+subtab.getCaption().replaceAll(" ", "-");
Layout subLayout = LayoutLocalServiceUtil.addLayout(user.getUserId(), group.getGroupId(), true, layout.getLayoutId(), subtab.getCaption(), layoutName,
group.getDescription(), "portlet", subtab.isHidden(), subtabfriendlyURL, ctx);
String typeSettings = subtab.getLayoutTypeSettings();
subLayout.setTypeSettings(typeSettings);
//actually update the sub layout
LayoutLocalServiceUtil.updateLayout(subLayout.getGroupId(), subLayout.isPrivateLayout(), subLayout.getLayoutId(), subLayout.getTypeSettings());
removePortletFrame(subtab, subLayout);
_log.debug("Added subtab " + subtab.getCaption() + " to layout for parent: " + layout.getName());
}
}
_log.debug("Trying creating tab " + tab.getCaption());
//get the typeSettings string for the liferay database from the tab Object
String typeSettings = tab.getLayoutTypeSettings();
//set the typesettings in the model
layout.setTypeSettings(typeSettings);
//actually update the layout
LayoutLocalServiceUtil.updateLayout(layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(), layout.getTypeSettings());
_log.debug("Added tab " + tab.getCaption() + " to layout for Group: " + siteLayout.getName());
removePortletFrame(tab, layout);
}
return layout.getLayoutId();
}
/**
* remove portlet frame for each portlet of the layout
* @param tab an instance of GCUBELayoutTab
* @param layout the layout
* @throws SystemException .
* @throws PortalException .
*/
private void removePortletFrame(GCUBELayoutTab tab, Layout layout) throws PortalException, SystemException {
if (tab == null || layout == null) return;
for (GCUBEPortlet gPortlet : tab.getPortlets()) {
long companyId = getCompany().getCompanyId();
Portlet lPortlet = PortletLocalServiceUtil.getPortletById(companyId, ""+gPortlet.getPortletId());
long ownerId = 0;
int ownerType = 3;
String portletPreferencesString =
"<portlet-preferences>" +
"<preference><name>lfr-wap-initial-window-state</name><value>NORMAL</value></preference>"+
"<preference><name>portlet-setup-show-borders</name><value>false</value></preference>" +
"<preference><name> portlet-setup-use-custom-title</name><value>false</value></preference>" +
"</portlet-preferences>"
;
PortletPreferences pPref = PortletPreferencesLocalServiceUtil.addPortletPreferences(
companyId, ownerId, ownerType, layout.getPlid(), lPortlet.getPortletId(), lPortlet, portletPreferencesString);
_log.debug("Added Preference for portlet " + lPortlet.getPortletName() + " for layout plid:" + layout.getPlid());
}
}
/**
*
* @param groupid the groupid of the organization
* @param username
* @return
*/
public boolean addUserToGroup(long groupid, String username) {
UserManager uman = new LiferayUserManager();
try {
uman.assignUserToGroup(""+groupid, uman.getUserId(username));
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
/**
* Create a Regular Manager Role for the community
* @param vreName
* @return
* @throws PortalException
* @throws SystemException
*/
protected static Role createRole(String roleName, String vreName, long userid){
try {
Company company = getCompany();
String roletoAdd = roleName+"-" + vreName.replaceAll(" ", "-");
return RoleLocalServiceUtil.addRole(userid, company.getCompanyId(), roletoAdd, null, roleName +" of " + vreName, LIFERAY_REGULAR_ROLE_ID);
} catch (PortalException e) {
e.printStackTrace();
} catch (SystemException e) {
e.printStackTrace();
}
return null;
}
/**
* read the root VO name from a property file and retuns it
*/
public static String getRootOrganizationName() {
//get the portles to look for from the property file
Properties props = new Properties();
String toReturn = "";
try {
String propertyfile = OrganizationsUtil.getTomcatFolder()+"conf/gcube-data.properties";
File propsFile = new File(propertyfile);
FileInputStream fis = new FileInputStream(propsFile);
props.load( fis);
toReturn = props.getProperty(ROOT_ORG);
}
//catch exception in case properties file does not exist
catch(IOException e) {
toReturn = "gcube";
_log.error("gcube-data.properties file not found under $CATALINA_HOME/conf dir, returning default VO Name " + toReturn);
return toReturn;
}
_log.debug("Returning Root VO Name: " + toReturn );
return toReturn;
}
/**
*
* @param rolename
* @param organizationName
* @param user
* @return
* @throws SystemException
*/
private boolean hasRole(String rolename, String organizationName, User user) throws SystemException {
for (Role role : user.getRoles()) {
//_log.trace("COMPARING ROLE: " +role.getName() + " -> " + rolename + "-" + organizationName);
if (role.getName().compareTo( rolename + "-" + organizationName) == 0 )
return true;
}
return false;
}
}

View File

@ -0,0 +1,139 @@
package org.gcube.portal.custom.communitymanager;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
public final class PortletsIdManager {
/**
*
*/
public static final String GCUBE_LOGIN = "gCubeLogin";
/**
*
*/
public static final String GCUBE_LOGGEDIN = "gCubeLoggedin";
/**
*
*/
public static final String GCUBE_USERS_MANAGE = "usersManagement";
/**
*
*/
public static final String ACCOUNTING_PORTAL = "portalaccounting";
/**
*
*/
public static final String ACCOUNTING_NODES = "nodeaccounting";
/**
*
*/
public static final String ACCOUNTING_SERVICES= "servicesaccounting";
/**
*
*/
public static final String MONITORING_ECOSYSTEM = "ecomonitoring";
/**
*
*/
public static final String GCUBE_ROLES_MANAGE = "rolesManagement";
/**
*
*/
public static final String TIME_SERIES_MANAGER = "TimeSeriesPortlet";
/**
*
*/
public static final String WORKSPACE = "WorkspacePortlet";
/**
*
*/
public static final String INFORMATION_SPACE_EDITOR = "VREInformationSpaceEditorPortlet";
/**
*
*/
public static final String RESULTS_BROWSING = "newresultset";
/**
*
*/
public static final String RESOURCES_MANAGEMENT = "gCubeRM";
/**
*
*/
public static final String COLLECTIONS_NAVIGATOR = "CollectionsNavigatorPortlet";
/**
*
*/
public static final String SEARCH_UI = "Search";
/**
*
*/
public static final String ANNOTATION = "AnnotationFrontEnd_V2";
/**
*
*/
public static final String REPORT_GENERATOR = "ReportGeneratorPortlet";
/**
*
*/
public static final String REPORT_TEMPLATE_CREATOR = "TemplateGenerator";
/**
*
*/
public static final String LR_NAVIGATION = "LR_navigation";
/**
*
*/
public static final String LR_LOGIN = "LR_login";
/**
*
*/
public static final String LR_VELOCITY = "LR_Hello_Velocity";
/**
*
*/
public static final String LR_WEBCONTENT_DISPLAY = "LR_WebContentDisplay";
/**
*
*/
public static final String LR_CALENDAR = "LR_Calendar";
/**
*
*/
public static final String LR_ACTIVITIES = "LR_Activities";
/**
*
*/
public static final String VRE_DEFINITION = "vredefinition";
/**
*
*/
public static final String VRE_DEPLOYER = "vredeployer";
/**
*
*/
public static final String VRE_DEPLOYMENT = "vredeployment";
/**
* return the portlet name for Liferay
* @return the liferay portlet id for a LR layout
*/
public static String getLRPortletId(String gCubePorletName) {
//get the portles to look for from the property file
Properties props = new Properties();
String toReturn = "";
try {
String propertyfile = OrganizationsUtil.getTomcatFolder()+"conf/gcube-portlets.properties";
File propsFile = new File(propertyfile);
FileInputStream fis = new FileInputStream(propsFile);
props.load( fis );
toReturn = props.getProperty(gCubePorletName);
}
//catch exception in case properties file does not exist
catch(IOException e) {
e.printStackTrace();
}
return toReturn;
}
}

View File

@ -0,0 +1,21 @@
package org.gcube.portal.custom.communitymanager;
public class ThemesIdManager {
/**
*
*/
public static final String GCUBE_PUBLIC_THEME = "gcubepublictheme";
/**
*
*/
public static final String GCUBE_LOGGEDIN_THEME = "gcubeportaltheme";
/**
*
*/
public static final String iMARINE_PUBLIC_THEME = "imarinepublictheme";
/**
*
*/
public static final String iMARINE_LOGGEDIN_THEME = "imarineportaltheme";
}

View File

@ -0,0 +1,238 @@
package org.gcube.portal.custom.communitymanager.components;
import java.util.ArrayList;
import java.util.List;
import org.gcube.portal.custom.communitymanager.types.GCUBELayoutType;
/**
*
* @author Massimiliano Assante, massimiliano.assante@isti.cnr.it
* @version 1.1 Jan 5th 2012
*
*
*/
public class GCUBELayoutTab {
/**
* the caption to display
*/
String caption;
/**
* the description, if any
*/
String description;
/**
* the last part of the URL after last slash, autogenerated if not set
*/
String friendlyURL;
/**
* set to true if you don't want to show the tab
*/
boolean hidden;
/**
* the type of the layout
*/
private GCUBELayoutType type;
/**
* list of portlets to place in the layout
*/
private List<GCUBEPortlet> portlets;
/**
* list of portlets to place in the layout
*/
private ArrayList<GCUBELayoutTab> subtabs;
/**
*
* @param caption the tab caption
* @param type the type of the layout
* @param portlets a list of <class>GCUBEPortlet</class> to place in the layout, list order is used as layout order
*/
public GCUBELayoutTab(String caption, GCUBELayoutType type, List<GCUBEPortlet> portlets) {
this.caption = caption;
this.friendlyURL = "/" + caption.replaceAll(" ", "-");
this.portlets = portlets;
this.type = type;
this.hidden = false;
}
/**
*
* @param caption the tab caption
* @param description the tab description
* @param type the type of the layout
* @param portlets a list of <class>GCUBEPortlet</class> to place in the layout, list order is used as layout order
*/
public GCUBELayoutTab(String caption, String description, GCUBELayoutType type, List<GCUBEPortlet> portlets) {
this(caption, type, portlets);
this.description = description;
}
/**
*
* @param caption the tab caption
* @param type the type of the layout
* @param portlet a single <class>GCUBEPortlet</class> to place in the layout
*/
public GCUBELayoutTab(String caption, GCUBELayoutType type, GCUBEPortlet portlet) {
this(caption, type, new ArrayList<GCUBEPortlet>());
ArrayList<GCUBEPortlet> toPass = new ArrayList<GCUBEPortlet>();
toPass.add(portlet);
this.portlets = toPass;
}
/**
* method to add children tabs
* @param subtab
*/
public void addSubTab(GCUBELayoutTab subtab) {
if (subtabs == null)
subtabs = new ArrayList<GCUBELayoutTab>();
subtabs.add(subtab);
}
public boolean hasChildren() {
if (subtabs == null) return false;
return (! subtabs.isEmpty() );
}
/**
*
* @return
*/
public ArrayList<GCUBELayoutTab> getSubTabs() {
if (subtabs == null) return new ArrayList<GCUBELayoutTab>();
return subtabs;
}
/**
*
* @return the type
*/
public GCUBELayoutType getType() {
return type;
}
/**
*
* @return the list of portlets
*/
public List<GCUBEPortlet> getPortlets() {
return portlets;
}
/**
*
* @return .
*/
public String getCaption() {
return caption;
}
/**
*
* @param caption the caption to display
*/
public void setCaption(String caption) {
this.caption = caption;
}
/**
*
* @return description
*/
public String getDescription() {
return description;
}
/**
*
* @param description desc
*/
public void setDescription(String description) {
this.description = description;
}
/**
*
* @return the string representing the last part of the URL
*/
public String getFriendlyURL() {
return friendlyURL;
}
/**
*
* @param friendlyURL the last part of the URL after slash, autogenerated if not set
*/
public void setFriendlyURL(String friendlyURL) {
this.friendlyURL = friendlyURL;
}
/**
*
* @return .
*/
public boolean isHidden() {
return hidden;
}
/**
*
* @param hidden -
*/
public void setHidden(boolean hidden) {
this.hidden = hidden;
}
/**
* create the layout with portlets in it
*
* 1_column - gives you a single column layout
* 2_columns_i - gives you two columns split 50/50
* 2_columns_ii - gives you two columns split 30/70
* 2_columns_iii - gives you two columns split 70/30
* 3_columns - gives you three columns
* 1_2_columns_i - gives you one top initial row, followed by 2 columns split 30/70
* 1_2_columns_ii - gives you one top initial row, followed by 2 columns split 70/30
* 1_2_1_columns - gives you one top initial row, followed by a row with 2 columns 50/50 split, followed by another row
* 2_2_columns - gives you one row with 2 columns 70/30 split followed by another row with 2 columns 30/70 split.
*
* * e.g.
*
* typeSettings = "layout-template-id=1_2_columns_i\n";
* typeSettings += "column-1=73,\n";
* typeSettings += "column-2=107,\n";
* typeSettings += "column-3=8,";
*
* @return the TypeSettings layout for liferay
*/
public String getLayoutTypeSettings() {
String typeSettings = "";
/**
* choose the appropriate layout
*/
switch (getType()) {
case ONE_COL:
typeSettings = "layout-template-id=1_column\n";
break;
case TWO_COL_5050:
typeSettings = "layout-template-id=2_columns_i\n";
break;
case TWO_COL_3070:
typeSettings = "layout-template-id=2_columns_ii\n";
break;
case TWO_COL_7030:
typeSettings = "layout-template-id=2_columns_iii\n";
break;
case THREE_COL:
typeSettings = "layout-template-id=3_columns\n";
break;
case TWO_ROWS_1_2_3070:
typeSettings = "layout-template-id=1_2_columns_i\n";
break;
case TWO_ROWS_1_2_7030:
typeSettings = "layout-template-id=1_2_columns_ii\n";
break;
case TWO_ROWS_2_7030_2_3070:
typeSettings = "layout-template-id=2_2_columns\n";
break;
case THREE_ROWS_1_2_5050_1:
typeSettings = "layout-template-id=1_2_1_columns\n";
break;
}
/**
* fill the layout with actual portlets
*/
for (int i = 1; i <= portlets.size(); i++) {
typeSettings += "column-"+i+"="+ portlets.get(i-1).getPortletId() + ",\n";
}
return typeSettings;
}
}

View File

@ -0,0 +1,59 @@
package org.gcube.portal.custom.communitymanager.components;
/**
*
* @author Massimiliano Assante, massimiliano.assante@isti.cnr.it
* @version 0.1
*
*/
public class GCUBEPortlet {
/**
*
*/
private String portletId;
/**
*
*/
private String name;
/**
*
* @param name .
* @param portletId .
*/
public GCUBEPortlet(String name, String portletId) {
super();
this.name = name;
this.portletId = portletId;
}
/**
*
* @return -
*/
public String getPortletId() {
return portletId;
}
/**
*
* @param portletId -
*/
public void setPortletId(String portletId) {
this.portletId = portletId;
}
/**
*
* @return -
*/
public String getName() {
return name;
}
/**
*
* @param name -
*/
public void setName(String name) {
this.name = name;
}
}

View File

@ -0,0 +1,74 @@
package org.gcube.portal.custom.communitymanager.components;
import java.util.LinkedList;
import java.util.List;
import org.gcube.portal.custom.communitymanager.impl.CommunityManagerImpl;
import com.liferay.portal.model.Company;
import com.liferay.portal.model.User;
import com.liferay.portal.service.UserLocalServiceUtil;
/**
*
* @author Massimiliano Assante, massimiliano.assante@isti.cnr.it
* @version 0.1
*
*/
public class GCUBESiteLayout {
/**
* layout name
*/
private String name;
/**
* the creator username
*/
long userid;
/**
* list of portlets to place in the layout
*/
private List<GCUBELayoutTab> tabs;
/**
* @param name -
* @param email
*/
public GCUBESiteLayout(Company company, String name, String email) {
User creator = null;
try {
creator = UserLocalServiceUtil.getUserByEmailAddress(company.getCompanyId(), email);
} catch (com.liferay.portal.kernel.exception.PortalException e) {
e.printStackTrace();
} catch (com.liferay.portal.kernel.exception.SystemException e) {
e.printStackTrace();
}
this.name = name;
this.userid = creator.getUserId();
this.tabs = new LinkedList<GCUBELayoutTab>();
}
/**
*
* @return the layout tab objects
*/
public List<GCUBELayoutTab> getTabs() {
return tabs;
}
/**
*
* @param layoutTab -
*/
public void addTab(GCUBELayoutTab layoutTab) {
if (layoutTab == null)
throw new NullPointerException();
tabs.add(layoutTab);
}
/**
*
* @return layout name
*/
public String getName() {
return name;
}
}

View File

@ -0,0 +1,195 @@
package org.gcube.portal.custom.communitymanager.impl;
import java.util.List;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.portal.custom.communitymanager.CommunityManager;
import org.gcube.portal.custom.communitymanager.OrganizationsUtil;
import org.gcube.portal.custom.communitymanager.PortletsIdManager;
import org.gcube.portal.custom.communitymanager.components.GCUBELayoutTab;
import org.gcube.portal.custom.communitymanager.components.GCUBEPortlet;
import org.gcube.portal.custom.communitymanager.components.GCUBESiteLayout;
import org.gcube.portal.custom.communitymanager.types.GCUBELayoutType;
import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayGroupManager;
import org.gcube.vomanagement.usermanagement.model.GroupModel;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.model.Group;
import com.liferay.portal.model.Portlet;
import com.liferay.portal.model.User;
import com.liferay.portal.service.OrganizationLocalServiceUtil;
/**
*
* @author Massimiliano Assante, massimiliano.assante@isti.cnr.it
* @version 1.0
*
*/
public class CommunityManagerImpl extends OrganizationsUtil implements CommunityManager {
private static Log _log = LogFactoryUtil.getLog(CommunityManagerImpl.class);
/**
*
*/
public static final String CURR_ORG = "CURR_RE_NAME";
ASLSession session = null;
/**
*
*/
private String screenName;
/**
*
*/
private static CommunityManagerImpl singleton;
/**
*
* @return the singleton
*/
public static CommunityManagerImpl get() {
return singleton;
}
/**
*
* @param session the ASL session
*/
private CommunityManagerImpl(ASLSession session) {
this.session = session;
this.screenName = session.getUsername();
singleton = this;
}
/**
*
* @param session the session
* @return the singleton
*/
public static CommunityManagerImpl getInstance(ASLSession session) {
return new CommunityManagerImpl(session);
}
/**
* Use this method for creating VRE programmatically and associate a default layout to it
*
* @param communityName -
* @param communityDesc -
* @param parentID -
* @return the community created id
*/
public long createCommunity(String communityName, String communityDesc, long parentID) {
String username = "";
String email = "";
GCUBESiteLayout siteLayout = null;
try {
username = validateUser(screenName).getScreenName();
email = validateUser(screenName).getEmailAddress();
siteLayout = new GCUBESiteLayout(getCompany(), communityName, email);
siteLayout.addTab(new GCUBELayoutTab("Home", GCUBELayoutType.ONE_COL,
new GCUBEPortlet("gCube Loggedin", PortletsIdManager.getLRPortletId(PortletsIdManager.GCUBE_LOGGEDIN))));
siteLayout.addTab(new GCUBELayoutTab("Workspace", GCUBELayoutType.ONE_COL,
new GCUBEPortlet("gCube Workspace", PortletsIdManager.getLRPortletId(PortletsIdManager.WORKSPACE))));
} catch (PortalException e) {
e.printStackTrace();
} catch (SystemException e) {
e.printStackTrace();
}
return createCommunity(username, communityName, communityDesc, siteLayout, parentID);
}
/**
* Use this method for creating VRE programmatically and associate it a layout
*
* @param usernameCreator -
* @param communityName -
* @param communityDesc -
* @param siteLayout a <class>GCUBESiteLayout</class> instance to associate to it
* @param parentID the organization parent
* @return the community created id
*/
public long createCommunity(String usernameCreator, String communityName, String communityDesc, GCUBESiteLayout siteLayout, long parentID) {
String username;
Group tocreate = null;
try {
username = usernameCreator;
//create the group
tocreate = createVRE(communityName, communityDesc, parentID);
// associate a layout to the group
createLayout(tocreate, validateUser(username), siteLayout);
} catch (PortalException e) {
e.printStackTrace();
} catch (SystemException e) {
e.printStackTrace();
}
_log.debug("Returning Organization ID " + tocreate.getClassPK());
return tocreate.getClassPK();
}
/**
* Create the group in the database
*
* @return
* @throws SystemException
* @throws PortalException
*/
private Group createVRE(String communityName, String communityDesc, long parentID) throws PortalException, SystemException {
User creator = validateUser(screenName);
GroupManager gm = new LiferayGroupManager();
long groupid = parentID;
GroupModel currOrg = null;
try {
currOrg = gm.getGroup(""+groupid);
} catch (UserManagementSystemException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (GroupRetrievalFault e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
_log.info("Creating VRE " + communityName + " SUBORG OF " +currOrg.getGroupName());
GroupModel groupModel = null;
try {
groupModel = gm.createVRE(communityName, ""+groupid, ""+creator.getUserId(), "Description for "+communityName);
} catch (Exception e) {
e.printStackTrace();
}
_log.trace("Calling groupModel.getGroupId() ");
long curGroupid = Long.parseLong(groupModel.getGroupId());
_log.trace("curGroupid " + curGroupid );
Group toReturn = OrganizationLocalServiceUtil.getOrganization(curGroupid).getGroup();
_log.debug("GROUP created id:" + toReturn.getGroupId());
return toReturn;
}
/**
*
* @param communityName -
* @return list of belonging portlet
*/
public List<Portlet> getGCubePortlets(String communityName) {
return null;
}
}

View File

@ -0,0 +1,226 @@
package org.gcube.portal.custom.communitymanager.impl;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.portal.custom.communitymanager.OrganizationManager;
import org.gcube.portal.custom.communitymanager.OrganizationsUtil;
import org.gcube.portal.custom.communitymanager.components.GCUBESiteLayout;
import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.RoleManager;
import org.gcube.vomanagement.usermanagement.UserManager;
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayGroupManager;
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayRoleManager;
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayUserManager;
import org.gcube.vomanagement.usermanagement.model.GroupModel;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.model.Group;
import com.liferay.portal.model.Role;
import com.liferay.portal.model.Theme;
import com.liferay.portal.model.User;
import com.liferay.portal.service.LayoutSetLocalServiceUtil;
import com.liferay.portal.service.OrganizationLocalServiceUtil;
import com.liferay.portal.service.ThemeLocalServiceUtil;
/**
*
* @author Massimiliano Assante, massimiliano.assante@isti.cnr.it
* @version 1.0 - Jan 4 2012
*
*/
public class OrganizationManagerImpl extends OrganizationsUtil implements OrganizationManager {
private static Log _log = LogFactoryUtil.getLog(OrganizationManagerImpl.class);
/**
* FIXME public as generic resource
*/
protected static final String ORGANIZATION_DEFAULT_LOGO = "/org/gcube/portal/custom/communitymanager/resources/default_logo.png";
ASLSession session = null;
/**
*
*/
private String screenName;
/**
*
*/
private static OrganizationManagerImpl singleton;
/**
*
* @return the singleton
*/
public static OrganizationManagerImpl get() {
return singleton;
}
/**
*
* @param session the ASL session
*/
private OrganizationManagerImpl(ASLSession session) {
this.session = session;
this.screenName = session.getUsername();
singleton = this;
}
/**
*
* @param session the session
* @return the singleton
*/
public static OrganizationManagerImpl getInstance(ASLSession session) {
return new OrganizationManagerImpl(session);
}
/**
*
* @param rootVoName the voName
* @param voDesc -
* @return the organizationid of the created VO
*/
public long createVO(String voName, String voDesc, long parentid, GCUBESiteLayout siteLayout, String themeid) {
String email = "";
Group voToCreate = null;
try {
email = validateUser(screenName).getEmailAddress();
//create the Group
User creator = validateUser(screenName);
GroupManager gm = new LiferayGroupManager();
GroupModel groupModel = null;
_log.info("createVO " + voName + " with parentid " + parentid);
groupModel = gm.createVRE(voName, ""+parentid, ""+creator.getUserId(), "Description for "+voName);
long groupModelid = Long.parseLong(groupModel.getGroupId());
voToCreate = OrganizationLocalServiceUtil.getOrganization(groupModelid).getGroup();
//associate the layout to the group
createLayout(voToCreate, validateUser(screenName), siteLayout);
Theme themeToApply = ThemeLocalServiceUtil.getTheme(getCompany().getCompanyId(), themeid, false);
//update theme
LayoutSetLocalServiceUtil.updateLookAndFeel(voToCreate.getGroupId(), themeToApply.getThemeId(), "", "", false);
_log.debug("LayoutSet Theme with id " + themeid + " Applied Correctly");
//update logo
InputStream is = OrganizationManagerImpl.class.getResourceAsStream(ORGANIZATION_DEFAULT_LOGO);
FileInputStream fis = new FileInputStream(writeTempLogo(is));
LayoutSetLocalServiceUtil.updateLogo(voToCreate.getGroupId(), true, true, fis);
_log.debug("Adding the Admin Role VO-Admin for this VO");
//add the role ADMIN
UserManager uman = new LiferayUserManager();
long uid = Long.parseLong(uman.getUserId(screenName));
Role created = OrganizationsUtil.createRole("VO-Admin", voName, uid);
_log.debug("Admin Role VO-Admin Created Successfully");
uman.assignUserToGroup(""+voToCreate.getClassPK(), ""+uid);
_log.debug("Added user " + screenName + " to group " + voName + " with Success");
_log.debug("Assigning Role: VO-Admin");
RoleManager rm = new LiferayRoleManager();
rm.assignRoleToUser(""+voToCreate.getClassPK(), ""+created.getRoleId(), ""+uid);
_log.debug("Admin Role VO-Admin Associated to user " + screenName + " .... returning ...");
} catch (Exception e) {
e.printStackTrace();
}
_log.info("Created" + voName + " with id " + voToCreate.getOrganizationId());
return voToCreate.getOrganizationId();
}
/**
* create a VO with no parent (root VO)
* @param voName the voName
* @param voDesc -
* @return the id of the created VO
*/
public long createVO(String voName, String voDesc, GCUBESiteLayout siteLayout, String themeid) {
return createVO(voName, voDesc, 0, siteLayout, themeid);
}
/**
*
* @param rootVoName the voName
* @param voDesc -
* @return the organizationid of the created VO
*/
public long createVRE(String voName, String voDesc, long parentid, GCUBESiteLayout siteLayout, String themeid) {
String email = "";
Group voToCreate = null;
try {
email = validateUser(screenName).getEmailAddress();
//create the Group
User creator = validateUser(screenName);
GroupManager gm = new LiferayGroupManager();
GroupModel groupModel = null;
_log.info("createVRE " + voName + " with parentid " + parentid);
groupModel = gm.createVRE(voName, ""+parentid, ""+creator.getUserId(), voDesc);
long groupModelid = Long.parseLong(groupModel.getGroupId());
voToCreate = OrganizationLocalServiceUtil.getOrganization(groupModelid).getGroup();
//associate the layout to the group
createLayout(voToCreate, validateUser(screenName), siteLayout);
Theme themeToApply = ThemeLocalServiceUtil.getTheme(getCompany().getCompanyId(), themeid, false);
//update theme
LayoutSetLocalServiceUtil.updateLookAndFeel(voToCreate.getGroupId(), themeToApply.getThemeId(), "", "", false);
_log.debug("LayoutSet Theme with id " + themeid + " Applied Correctly");
//update logo
InputStream is = OrganizationManagerImpl.class.getResourceAsStream(ORGANIZATION_DEFAULT_LOGO);
FileInputStream fis = new FileInputStream(writeTempLogo(is));
LayoutSetLocalServiceUtil.updateLogo(voToCreate.getGroupId(), true, true, fis);
_log.debug("Adding the MANAGER Role VRE-Manager for this VRE");
//add the role ADMIN
UserManager uman = new LiferayUserManager();
long uid = Long.parseLong(uman.getUserId(screenName));
Role created = OrganizationsUtil.createRole("VRE-Manager", voName, uid);
_log.debug("Admin Role VRE-Manager Created Successfully");
uman.assignUserToGroup(""+voToCreate.getClassPK(), ""+uid);
_log.debug("Added user " + screenName + " to group " + voName + " with Success");
_log.debug("Assigning Role: VRE-Manager");
RoleManager rm = new LiferayRoleManager();
rm.assignRoleToUser(""+voToCreate.getClassPK(), ""+created.getRoleId(), ""+uid);
_log.debug("Admin Role VRE-Manager Associated to user " + screenName + " .... returning ...");
} catch (Exception e) {
e.printStackTrace();
}
_log.info("Created" + voName + " with id " + voToCreate.getOrganizationId());
return voToCreate.getOrganizationId();
}
/***
* simple helper method
* @param inputStream
* @return
*/
private File writeTempLogo(InputStream inputStream) {
try {
File temp = File.createTempFile("logoimage", ".png");
// write the inputStream to a FileOutputStream
FileOutputStream out = new FileOutputStream(temp);
int read = 0;
byte[] bytes = new byte[1024];
while ((read = inputStream.read(bytes)) != -1)
out.write(bytes, 0, read);
inputStream.close();
out.flush();
out.close();
return temp;
} catch (IOException e) {
return null;
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

View File

@ -0,0 +1,24 @@
gCubeLogin=Login_WAR_Loginportlet
gCubeLoggedin=Loggedin_WAR_GCubeLoggedinportlet
TimeSeriesPortlet=TimeSeriesPortlet
WorkspacePortlet=WorkspacePortlet_WAR_WorkspacePortlet
Ontology_Front_End=Ontology_Front_End
OntologyAdminPortlet=OntologyAdminPortlet
SCORMPackagingPortlet=SCORMPackagingPortlet
HTMLProxyPortlet=HTMLProxyPortlet
UserProfileEditingPortlet=UserProfileEditingPortlet
LayoutcreatorPortlet=LayoutcreatorPortlet
VREInformationSpaceEditorPortlet=VREInformationSpaceEditorPortlet
resultpresentation=resultspresentation_WAR_resultspresentationportlet
newresultset=newresultset
CollectionsNavigatorPortlet=CollectionsNavigatorPortlet
Search=Search
GoogleSearchPortlet=GoogleSearchPortlet
GeoSpatialPortlet=geospatial_WAR_geospatialportlet
QuickSearchPortlet=QuickSearchPortlet
AnnotationFrontEnd_V2=AnnotationFrontEnd_V2
ReportGeneratorPortlet=reporting_WAR_reportingportlet
TemplateGenerator=TemplateGenerator_WAR_TemplateGeneratorportlet
Metadata_Editing_Portlet=Metadata_Editing_Portlet

View File

@ -0,0 +1,43 @@
package org.gcube.portal.custom.communitymanager.types;
/**
*
* @author massi
*/
public enum GCUBELayoutType {
/**
* gives you a single column layout
*/
ONE_COL,
/**
* gives you two columns split 50/50
*/
TWO_COL_5050,
/**
* gives you two columns split 30/70
*/
TWO_COL_3070,
/**
* gives you two columns split 70/30
*/
TWO_COL_7030,
/**
* gives you three columns
*/
THREE_COL,
/**
* gives you one top initial row, followed by 2 columns split 30/70
*/
TWO_ROWS_1_2_3070,
/**
* gives you one top initial row, followed by 2 columns split 70/30
*/
TWO_ROWS_1_2_7030,
/**
* gives you one top initial row, followed by a row with 2 columns 50/50 split, followed by another row
*/
THREE_ROWS_1_2_5050_1,
/**
* gives you one row with 2 columns 70/30 split followed by another row with 2 columns 30/70 split.
*/
TWO_ROWS_2_7030_2_3070;
}

View File

@ -0,0 +1,184 @@
package org.gcube.portal.custom.scopemanager.scopehelper;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import javax.portlet.PortletSession;
import javax.portlet.RenderRequest;
import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.application.framework.core.util.GenderType;
import org.gcube.common.core.contexts.GHNContext;
import org.gcube.portal.custom.communitymanager.OrganizationsUtil;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.model.Group;
import com.liferay.portal.model.Organization;
import com.liferay.portal.model.User;
import com.liferay.portal.model.UserModel;
import com.liferay.portal.service.GroupLocalServiceUtil;
import com.liferay.portal.service.OrganizationLocalServiceUtil;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.theme.ThemeDisplay;
public class ScopeHelper {
public static final String USERNAME_ATTRIBUTE = "username";
public static final String USER_FULL_NAME_ATTRIBUTE = "USER_FULL_NAME";
public static final String USER_EMAIL_ATTRIBUTE = "USER_EMAIL";
public static final String USER_AVATAR_ID_ATTRIBUTE = "USER_AVATAR_ID";
public static final String USER_GENDER_ATTRIBUTE = "USER_GENDER";
/**
*
*/
public static final String ROOT_ORG = "rootorganization";
public static final String CURR_ORG = "CURR_RE_NAME";
public static final String MAIL = "supportmail";
public static void setContext(RenderRequest request) {
setContext(request, USERNAME_ATTRIBUTE);
}
private static Log _log = LogFactoryUtil.getLog(ScopeHelper.class);
/**
*
* @param session the session
* @return the singleton
*/
public static void setContext(RenderRequest request, String username_attr) {
_log.info("SETTING CONTEXT .. ");
String scopeToSet = "";
long userid = Long.parseLong(request.getRemoteUser());
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
request.getPortletSession().setAttribute(WebKeys.THEME_DISPLAY, themeDisplay, PortletSession.APPLICATION_SCOPE);
User user = null;
Group currentGroup = null;
Organization curOrg = null;
try {
user = UserLocalServiceUtil.getUser(userid);
currentGroup = GroupLocalServiceUtil.getGroup(themeDisplay.getLayout().getGroup().getGroupId());
// the group MUST BE an Organization
if (currentGroup.isOrganization()) {
long organizationId = currentGroup.getClassPK();
curOrg = OrganizationLocalServiceUtil.getOrganization(organizationId);
if (curOrg.isRoot()) {
scopeToSet = "/"+curOrg.getName();
} else if (isVO(curOrg)) {
scopeToSet = "/"+curOrg.getParentOrganization().getName()+"/"+curOrg.getName();
} else { //is a VRE
Organization vo = curOrg.getParentOrganization();
scopeToSet = "/"+vo.getParentOrganization().getName()+"/"+vo.getName()+"/"+curOrg.getName();
}
} else { //
scopeToSet = "PORTAL";
_log.info("Not an organization, scopeToSet set to PORTAL");
}
//get the username
String username = user.getScreenName();
String sessionID = request.getPortletSession().getId();
_log.info("SETTING CONTEXT ID: " + sessionID + " - username: " + username);
request.getPortletSession().setAttribute(username_attr, username, PortletSession.APPLICATION_SCOPE);
request.getPortletSession().setAttribute(CURR_ORG, curOrg, PortletSession.APPLICATION_SCOPE);
if (curOrg != null) {
SessionManager.getInstance().getASLSession(sessionID, username).setGroupModelInfos(curOrg.getName(), curOrg.getOrganizationId());
SessionManager.getInstance().getASLSession(sessionID, username).setScope(scopeToSet);
_log.info("CONTEXT INITIALIZED CORRECTLY SCOPE: " + scopeToSet);
}
else {
String rootVO = getRootConfigFromGCore();
_log.info("CONTEXT INITIALIZED CORRECTLY OUTSIDE VREs, setting rootvo as scope: " + rootVO);
scopeToSet = "/"+rootVO;
SessionManager.getInstance().getASLSession(sessionID, username).setScope(scopeToSet);
}
//add the social information needed by apps
String fullName = user.getFirstName() + " " + user.getLastName();
String email = user.getEmailAddress();
String thumbnailURL = "/image/user_male_portrait?img_id="+user.getPortraitId();
boolean isMale = user.isMale();
SessionManager.getInstance().getASLSession(sessionID, username).setUserFullName(fullName);
SessionManager.getInstance().getASLSession(sessionID, username).setUserEmailAddress(email);
SessionManager.getInstance().getASLSession(sessionID, username).setUserAvatarId(thumbnailURL);
SessionManager.getInstance().getASLSession(sessionID, username).setUserGender(isMale? GenderType.MALE : GenderType.FEMALE);
} catch (PortalException e) {
e.printStackTrace();
} catch (SystemException e) {
e.printStackTrace();
}
}
/**
* read the root VO name from a property file and retuns it
*/
public static String getSupportMainlingListAddr() {
//get the portles to look for from the property file
Properties props = new Properties();
String toReturn = "";
try {
String propertyfile = OrganizationsUtil.getTomcatFolder()+"conf/gcube-data.properties";
File propsFile = new File(propertyfile);
FileInputStream fis = new FileInputStream(propsFile);
props.load( fis);
toReturn = props.getProperty(MAIL);
if (toReturn == null || toReturn.compareTo("")==0) {
toReturn = "support_team@d4science.org";
_log.error("Property "+MAIL+" in $CATALINA_HOME/conf/gcube-data.properties was not found, returning default support mailing address " + toReturn);
} else
_log.trace("Found Mail Support address: " + toReturn );
}
//catch exception in case properties file does not exist
catch(IOException e) {
toReturn = "support_team@d4science.org";
_log.error("gcube-data.properties file not found under $CATALINA_HOME/conf dir, returning default support mailing address " + toReturn);
return toReturn;
}
return toReturn;
}
/**
*
* @param currentGroup
* @return true id the organization is a VO
* @throws SystemException
* @throws PortalException
* @throws SystemException .
* @throws PortalException .
*/
private static boolean isVO(Organization currentOrg) throws PortalException, SystemException {
return (currentOrg.getParentOrganization().getParentOrganization() == null);
}
/**
* return the infrastructure name
*/
public static String getRootConfigFromGCore() {
String toReturn = "";
GHNContext ctx = GHNContext.getContext();
toReturn = (String) ctx.getProperty(GHNContext.INFRASTRUCTURE_NAME, true);
return toReturn;
}
}