diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..d430d8b
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.project b/.project
new file mode 100644
index 0000000..f97b392
--- /dev/null
+++ b/.project
@@ -0,0 +1,36 @@
+
+
+ custom-portal-handler
+
+
+
+
+
+ org.eclipse.wst.common.project.facet.core.builder
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.m2e.core.maven2Builder
+
+
+
+
+ org.eclipse.wst.validation.validationbuilder
+
+
+
+
+
+ org.eclipse.jem.workbench.JavaEMFNature
+ org.eclipse.wst.common.modulecore.ModuleCoreNature
+ org.eclipse.m2e.core.maven2Nature
+ org.eclipse.jdt.core.javanature
+ org.eclipse.wst.common.project.facet.core.nature
+
+
diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..913d474
--- /dev/null
+++ b/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,4 @@
+#Sat Dec 22 19:37:10 CET 2012
+eclipse.preferences.version=1
+encoding//src/main/java=UTF-8
+encoding/=UTF-8
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..884eab3
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -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
diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs
new file mode 100644
index 0000000..6dfeeba
--- /dev/null
+++ b/.settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,5 @@
+#Sat Dec 22 19:31:51 CET 2012
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component
new file mode 100644
index 0000000..05af005
--- /dev/null
+++ b/.settings/org.eclipse.wst.common.component
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml
new file mode 100644
index 0000000..c78d932
--- /dev/null
+++ b/.settings/org.eclipse.wst.common.project.facet.core.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/distro/INSTALL b/distro/INSTALL
new file mode 100644
index 0000000..28c3ef6
--- /dev/null
+++ b/distro/INSTALL
@@ -0,0 +1,3 @@
+* Configure
+nothing to be done
+
diff --git a/distro/LICENSE b/distro/LICENSE
new file mode 100644
index 0000000..cc51139
--- /dev/null
+++ b/distro/LICENSE
@@ -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.
\ No newline at end of file
diff --git a/distro/MAINTAINERS b/distro/MAINTAINERS
new file mode 100644
index 0000000..ac810c2
--- /dev/null
+++ b/distro/MAINTAINERS
@@ -0,0 +1 @@
+* CNR Pisa, Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo"
\ No newline at end of file
diff --git a/distro/README b/distro/README
new file mode 100644
index 0000000..3299d0f
--- /dev/null
+++ b/distro/README
@@ -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.
diff --git a/distro/changelog.xml b/distro/changelog.xml
new file mode 100644
index 0000000..5327efd
--- /dev/null
+++ b/distro/changelog.xml
@@ -0,0 +1,5 @@
+
+
+ Fixed invalidate session bug
+
+
\ No newline at end of file
diff --git a/distro/descriptor.xml b/distro/descriptor.xml
new file mode 100644
index 0000000..c468f13
--- /dev/null
+++ b/distro/descriptor.xml
@@ -0,0 +1,48 @@
+
+ servicearchive
+
+ tar.gz
+
+ /
+
+
+ ${distroDirectory}
+ /
+ true
+
+ README
+ LICENSE
+ INSTALL
+ MAINTAINERS
+ changelog.xml
+
+ 755
+ true
+
+
+ target/apidocs
+ /${artifactId}/doc/api
+ true
+ 755
+
+
+
+
+
+ ./
+ true
+
+
+
+ /${artifactId}
+
+
+
+ /${artifactId}
+ true
+
+
+
\ No newline at end of file
diff --git a/distro/profile.xml b/distro/profile.xml
new file mode 100644
index 0000000..8f9c283
--- /dev/null
+++ b/distro/profile.xml
@@ -0,0 +1,25 @@
+
+
+
+ Library
+
+ Custom Portal Handler
+ Portal
+ ${artifactId}
+ 1.0.0
+
+
+ ${artifactId}
+ ${version}
+
+ ${groupId}
+ ${artifactId}
+ ${version}
+
+
+ ${build.finalName}.jar
+
+
+
+
+
diff --git a/distro/svnpath.txt b/distro/svnpath.txt
new file mode 100644
index 0000000..edacb04
--- /dev/null
+++ b/distro/svnpath.txt
@@ -0,0 +1 @@
+${scm.url}
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..a43424a
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,162 @@
+
+ 4.0.0
+
+ maven-parent
+ org.gcube.tools
+ 1.0.0
+
+
+
+ org.gcube.portal
+ custom-portal-handler
+ 1.2.0-SNAPSHOT
+ jar
+ Custom Portal Handler
+
+ 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.
+
+
+ scm:svn:http://svn.d4science.research-infrastructures.eu/gcube/trunk/portal/${project.artifactId}
+ scm:https://svn.d4science.research-infrastructures.eu/gcube/trunk/portal/${project.artifactId}
+ http://svn.d4science.research-infrastructures.eu/gcube/trunk/portlal/${project.artifactId}
+
+
+ distro
+ 1.6
+ 1.6
+
+ UTF-8
+ UTF-8
+
+
+
+ org.gcube.core
+ gcf
+ [1.4.0,1.6.0]
+ provided
+
+
+ org.gcube.applicationsupportlayer
+ aslcore
+ 3.2.0-SNAPSHOT
+
+
+ com.liferay.portal
+ portal-service
+ 6.0.6
+
+
+ javax.portlet
+ portlet-api
+ 2.0
+ provided
+
+
+ org.gcube.dvos
+ usermanagement-core
+ 1.3.0-SNAPSHOT
+
+
+ log4j
+ log4j
+ 1.2.6
+
+
+
+
+
+
+ src/main/java
+
+ **/*.*
+
+
+
+
+
+ maven-compiler-plugin
+ 3.0
+
+
+ 1.6
+
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ 2.2
+
+
+
+ test-jar
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.12
+
+ true
+
+
+
+ org.apache.maven.plugins
+ maven-resources-plugin
+ 2.5
+
+
+ copy-profile
+ install
+
+ copy-resources
+
+
+ target
+
+
+ ${distroDirectory}
+ true
+
+ profile.xml
+
+
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-assembly-plugin
+ 2.2
+
+
+ ${distroDirectory}/descriptor.xml
+
+
+
+ fully.qualified.MainClass
+
+
+
+
+
+ servicearchive
+ install
+
+ single
+
+
+
+
+
+
+
+
diff --git a/src/main/java/org/gcube/portal/custom/communitymanager/CommunityManager.java b/src/main/java/org/gcube/portal/custom/communitymanager/CommunityManager.java
new file mode 100644
index 0000000..cf80a65
--- /dev/null
+++ b/src/main/java/org/gcube/portal/custom/communitymanager/CommunityManager.java
@@ -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 getGCubePortlets(String communityName);
+}
diff --git a/src/main/java/org/gcube/portal/custom/communitymanager/OrganizationManager.java b/src/main/java/org/gcube/portal/custom/communitymanager/OrganizationManager.java
new file mode 100644
index 0000000..eb50a54
--- /dev/null
+++ b/src/main/java/org/gcube/portal/custom/communitymanager/OrganizationManager.java
@@ -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);
+
+}
diff --git a/src/main/java/org/gcube/portal/custom/communitymanager/OrganizationsUtil.java b/src/main/java/org/gcube/portal/custom/communitymanager/OrganizationsUtil.java
new file mode 100644
index 0000000..905e299
--- /dev/null
+++ b/src/main/java/org/gcube/portal/custom/communitymanager/OrganizationsUtil.java
@@ -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 org.gcube.portal.custom.communitymanager.ThemesIdManager
+ * @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 getVREBelongingPortlets(List belongingPorltets) {
+ List toReturn = new LinkedList();
+ 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 getDefaultPortlets() {
+ List toReturn = new ArrayList();
+ 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 roleNames = new HashMap();
+ 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 roleNames = new HashMap();
+ 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 =
+ "" +
+ "lfr-wap-initial-window-stateNORMAL"+
+ "portlet-setup-show-bordersfalse" +
+ " portlet-setup-use-custom-titlefalse" +
+ ""
+ ;
+
+ 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;
+ }
+}
diff --git a/src/main/java/org/gcube/portal/custom/communitymanager/PortletsIdManager.java b/src/main/java/org/gcube/portal/custom/communitymanager/PortletsIdManager.java
new file mode 100644
index 0000000..a4237bf
--- /dev/null
+++ b/src/main/java/org/gcube/portal/custom/communitymanager/PortletsIdManager.java
@@ -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;
+ }
+}
diff --git a/src/main/java/org/gcube/portal/custom/communitymanager/ThemesIdManager.java b/src/main/java/org/gcube/portal/custom/communitymanager/ThemesIdManager.java
new file mode 100644
index 0000000..71cba5a
--- /dev/null
+++ b/src/main/java/org/gcube/portal/custom/communitymanager/ThemesIdManager.java
@@ -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";
+
+}
diff --git a/src/main/java/org/gcube/portal/custom/communitymanager/components/GCUBELayoutTab.java b/src/main/java/org/gcube/portal/custom/communitymanager/components/GCUBELayoutTab.java
new file mode 100644
index 0000000..1bb2b13
--- /dev/null
+++ b/src/main/java/org/gcube/portal/custom/communitymanager/components/GCUBELayoutTab.java
@@ -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 portlets;
+ /**
+ * list of portlets to place in the layout
+ */
+ private ArrayList subtabs;
+ /**
+ *
+ * @param caption the tab caption
+ * @param type the type of the layout
+ * @param portlets a list of GCUBEPortlet to place in the layout, list order is used as layout order
+ */
+ public GCUBELayoutTab(String caption, GCUBELayoutType type, List 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 GCUBEPortlet to place in the layout, list order is used as layout order
+ */
+ public GCUBELayoutTab(String caption, String description, GCUBELayoutType type, List portlets) {
+ this(caption, type, portlets);
+ this.description = description;
+ }
+ /**
+ *
+ * @param caption the tab caption
+ * @param type the type of the layout
+ * @param portlet a single GCUBEPortlet to place in the layout
+ */
+ public GCUBELayoutTab(String caption, GCUBELayoutType type, GCUBEPortlet portlet) {
+ this(caption, type, new ArrayList());
+ ArrayList toPass = new ArrayList();
+ toPass.add(portlet);
+ this.portlets = toPass;
+ }
+ /**
+ * method to add children tabs
+ * @param subtab
+ */
+ public void addSubTab(GCUBELayoutTab subtab) {
+ if (subtabs == null)
+ subtabs = new ArrayList();
+ subtabs.add(subtab);
+ }
+
+ public boolean hasChildren() {
+ if (subtabs == null) return false;
+ return (! subtabs.isEmpty() );
+ }
+ /**
+ *
+ * @return
+ */
+ public ArrayList getSubTabs() {
+ if (subtabs == null) return new ArrayList();
+ return subtabs;
+ }
+ /**
+ *
+ * @return the type
+ */
+ public GCUBELayoutType getType() {
+ return type;
+ }
+ /**
+ *
+ * @return the list of portlets
+ */
+ public List 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;
+ }
+}
diff --git a/src/main/java/org/gcube/portal/custom/communitymanager/components/GCUBEPortlet.java b/src/main/java/org/gcube/portal/custom/communitymanager/components/GCUBEPortlet.java
new file mode 100644
index 0000000..a54a0b4
--- /dev/null
+++ b/src/main/java/org/gcube/portal/custom/communitymanager/components/GCUBEPortlet.java
@@ -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;
+ }
+
+
+
+}
diff --git a/src/main/java/org/gcube/portal/custom/communitymanager/components/GCUBESiteLayout.java b/src/main/java/org/gcube/portal/custom/communitymanager/components/GCUBESiteLayout.java
new file mode 100644
index 0000000..109472e
--- /dev/null
+++ b/src/main/java/org/gcube/portal/custom/communitymanager/components/GCUBESiteLayout.java
@@ -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 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();
+ }
+ /**
+ *
+ * @return the layout tab objects
+ */
+ public List 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;
+ }
+
+
+}
diff --git a/src/main/java/org/gcube/portal/custom/communitymanager/impl/CommunityManagerImpl.java b/src/main/java/org/gcube/portal/custom/communitymanager/impl/CommunityManagerImpl.java
new file mode 100644
index 0000000..f9c875a
--- /dev/null
+++ b/src/main/java/org/gcube/portal/custom/communitymanager/impl/CommunityManagerImpl.java
@@ -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 GCUBESiteLayout 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 getGCubePortlets(String communityName) {
+ return null;
+ }
+
+
+}
diff --git a/src/main/java/org/gcube/portal/custom/communitymanager/impl/OrganizationManagerImpl.java b/src/main/java/org/gcube/portal/custom/communitymanager/impl/OrganizationManagerImpl.java
new file mode 100644
index 0000000..21aa279
--- /dev/null
+++ b/src/main/java/org/gcube/portal/custom/communitymanager/impl/OrganizationManagerImpl.java
@@ -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;
+ }
+ }
+}
diff --git a/src/main/java/org/gcube/portal/custom/communitymanager/resources/default_logo.png b/src/main/java/org/gcube/portal/custom/communitymanager/resources/default_logo.png
new file mode 100644
index 0000000..5950b41
Binary files /dev/null and b/src/main/java/org/gcube/portal/custom/communitymanager/resources/default_logo.png differ
diff --git a/src/main/java/org/gcube/portal/custom/communitymanager/resources/portlets.properties b/src/main/java/org/gcube/portal/custom/communitymanager/resources/portlets.properties
new file mode 100644
index 0000000..6283705
--- /dev/null
+++ b/src/main/java/org/gcube/portal/custom/communitymanager/resources/portlets.properties
@@ -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
+
+
diff --git a/src/main/java/org/gcube/portal/custom/communitymanager/types/GCUBELayoutType.java b/src/main/java/org/gcube/portal/custom/communitymanager/types/GCUBELayoutType.java
new file mode 100644
index 0000000..2e31660
--- /dev/null
+++ b/src/main/java/org/gcube/portal/custom/communitymanager/types/GCUBELayoutType.java
@@ -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;
+}
diff --git a/src/main/java/org/gcube/portal/custom/scopemanager/scopehelper/ScopeHelper.java b/src/main/java/org/gcube/portal/custom/scopemanager/scopehelper/ScopeHelper.java
new file mode 100644
index 0000000..75640ea
--- /dev/null
+++ b/src/main/java/org/gcube/portal/custom/scopemanager/scopehelper/ScopeHelper.java
@@ -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;
+ }
+}