From 36197e64715555917cc27a17a81820e8d5a8e20c Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Sun, 27 Jan 2013 15:08:16 +0000 Subject: [PATCH] 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 --- .classpath | 27 ++ .project | 36 ++ .settings/org.eclipse.core.resources.prefs | 4 + .settings/org.eclipse.jdt.core.prefs | 13 + .settings/org.eclipse.m2e.core.prefs | 5 + .settings/org.eclipse.wst.common.component | 6 + ....eclipse.wst.common.project.facet.core.xml | 5 + distro/INSTALL | 3 + distro/LICENSE | 6 + distro/MAINTAINERS | 1 + distro/README | 37 ++ distro/changelog.xml | 5 + distro/descriptor.xml | 48 +++ distro/profile.xml | 25 ++ distro/svnpath.txt | 1 + pom.xml | 162 ++++++++ .../communitymanager/CommunityManager.java | 38 ++ .../communitymanager/OrganizationManager.java | 37 ++ .../communitymanager/OrganizationsUtil.java | 358 ++++++++++++++++++ .../communitymanager/PortletsIdManager.java | 139 +++++++ .../communitymanager/ThemesIdManager.java | 21 + .../components/GCUBELayoutTab.java | 238 ++++++++++++ .../components/GCUBEPortlet.java | 59 +++ .../components/GCUBESiteLayout.java | 74 ++++ .../impl/CommunityManagerImpl.java | 195 ++++++++++ .../impl/OrganizationManagerImpl.java | 226 +++++++++++ .../resources/default_logo.png | Bin 0 -> 10081 bytes .../resources/portlets.properties | 24 ++ .../types/GCUBELayoutType.java | 43 +++ .../scopemanager/scopehelper/ScopeHelper.java | 184 +++++++++ 30 files changed, 2020 insertions(+) create mode 100644 .classpath create mode 100644 .project create mode 100644 .settings/org.eclipse.core.resources.prefs create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 .settings/org.eclipse.m2e.core.prefs create mode 100644 .settings/org.eclipse.wst.common.component create mode 100644 .settings/org.eclipse.wst.common.project.facet.core.xml create mode 100644 distro/INSTALL create mode 100644 distro/LICENSE create mode 100644 distro/MAINTAINERS create mode 100644 distro/README create mode 100644 distro/changelog.xml create mode 100644 distro/descriptor.xml create mode 100644 distro/profile.xml create mode 100644 distro/svnpath.txt create mode 100644 pom.xml create mode 100644 src/main/java/org/gcube/portal/custom/communitymanager/CommunityManager.java create mode 100644 src/main/java/org/gcube/portal/custom/communitymanager/OrganizationManager.java create mode 100644 src/main/java/org/gcube/portal/custom/communitymanager/OrganizationsUtil.java create mode 100644 src/main/java/org/gcube/portal/custom/communitymanager/PortletsIdManager.java create mode 100644 src/main/java/org/gcube/portal/custom/communitymanager/ThemesIdManager.java create mode 100644 src/main/java/org/gcube/portal/custom/communitymanager/components/GCUBELayoutTab.java create mode 100644 src/main/java/org/gcube/portal/custom/communitymanager/components/GCUBEPortlet.java create mode 100644 src/main/java/org/gcube/portal/custom/communitymanager/components/GCUBESiteLayout.java create mode 100644 src/main/java/org/gcube/portal/custom/communitymanager/impl/CommunityManagerImpl.java create mode 100644 src/main/java/org/gcube/portal/custom/communitymanager/impl/OrganizationManagerImpl.java create mode 100644 src/main/java/org/gcube/portal/custom/communitymanager/resources/default_logo.png create mode 100644 src/main/java/org/gcube/portal/custom/communitymanager/resources/portlets.properties create mode 100644 src/main/java/org/gcube/portal/custom/communitymanager/types/GCUBELayoutType.java create mode 100644 src/main/java/org/gcube/portal/custom/scopemanager/scopehelper/ScopeHelper.java 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 + + + + + ${distroDirectory}/profile.xml + ./ + true + + + target/${build.finalName}.jar + /${artifactId} + + + ${distroDirectory}/svnpath.txt + /${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 + 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 0000000000000000000000000000000000000000..5950b41fe2361d24142a7ed104428fbd393bd6b4 GIT binary patch literal 10081 zcmbVyWmFx_wjjaXAwYl-Ah;gf-6gooK@RR5+%>pEf;$9vcL?rsaCZq#a2dXP-+ePb z-kMo!dadq~-d=lm)voGrB}FMTWFllJC@3@;X>pbJ()6Dj5&Hf4<_`_?UJ!yMw7{zN zW?(lXClHi~sl73XOvcv89Has=GWBpA2Ju5d!I)X9X@RvA|9)23}gTnRu*O!05dCqk(G;=4ZzF7LiS%5`8zi!Q!`!_amoMU z_1+R7w*Z43c$t~q+}xPl*qH2{%$ZqvczFJy0RS+*Lohmf*ny4Q8SR`Y{zE|=WF0w$iHj}B z4lE-sK>q%Q$<)%6my4ZSj6*~Wz{(C_;pApz%IJnq2B_+98|3l+{!sP_8 zivu{sIN8`(0IaMMtlR)rF;Ol63kN5+B#Stk=znl!?3}?yb|#?z@U?vB`(L;m|5sdI zF(;4_*xpIa-rnXv9-w4l54Lx--TiR$2tBFXZcUpy9fSL{cqQQZ~S-gfb8BQ#_2sY z#9Zl=pr9z?WyD3)+?Q8?^%`@p~e%~#2lEY%EOa2PR$mPbfBhJqL4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%z;BB#H| zd5Ja0pYkWa+TV_~+f8%W-L(JO|9hv0Hrli`RildYMxS~e8K@jzn2{0c;KG~z$AOg7 zQZJjf8Z$yK^WjK7&))iUfj8s(S>m`(y#xTKnCkVweYZYs!6}1=o=0Ya2y%wM(r2B4 zpdZ?h&7=hkQ>}?y*pG<{{Wh1zd20LGsD9FMQm4Kp0~1EN`g}l2rG_$m~=W)aQvq zlcx?VS-EpgpMSgUW7xey%As;fD)B{S;8^@H z5AX4iD#SF6J#gult9HFXWYK!wbsC3Vg~e=y88>aU9$<77Z{&JNjsCm6S?)3vIYqyU z3QbySIEc!4sYKe7E)`{Wms>&CKXA`O@s!o>kE_sz@ya!A;*9!=nFql0)pPR~v+I{k zjO$%T39H)-e`6$J~*z=8($OCxJR=C!NW2xSs8JAGR_N|QiOr4efN3^E6D zdJGz9&8Ty=+6Y1GN;S{?q@p*JCNfYH`Q8x><`N_Cu(1b+y~E*3TDh0bsn9v>b0|XBunYRYUKMqVB6#u%Z`ScbySiOZ7Fe@BG{CLYd zOEnZfJ2kQPH2CCj_cok5tjF?`2)QUUsH8`0;70L z8pvvqQSI1`n72FCbPTzDT5>v@^%raeu6}D nW?J+J4qj$!Sif~a!9WQy{j`CVKJNJEr#Bf1Me#~eVBr4(_pA8< literal 0 HcmV?d00001 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; + } +}