moved to version 2.0
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/custom-portal-handler@125277 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
cac2c2dc1b
commit
e8d6da2814
|
@ -15,8 +15,6 @@
|
||||||
<includes>
|
<includes>
|
||||||
<include>README</include>
|
<include>README</include>
|
||||||
<include>LICENSE</include>
|
<include>LICENSE</include>
|
||||||
<include>INSTALL</include>
|
|
||||||
<include>MAINTAINERS</include>
|
|
||||||
<include>changelog.xml</include>
|
<include>changelog.xml</include>
|
||||||
</includes>
|
</includes>
|
||||||
<fileMode>755</fileMode>
|
<fileMode>755</fileMode>
|
||||||
|
@ -39,10 +37,5 @@
|
||||||
<source>target/${build.finalName}.jar</source>
|
<source>target/${build.finalName}.jar</source>
|
||||||
<outputDirectory>/${artifactId}</outputDirectory>
|
<outputDirectory>/${artifactId}</outputDirectory>
|
||||||
</file>
|
</file>
|
||||||
<file>
|
|
||||||
<source>${distroDirectory}/svnpath.txt</source>
|
|
||||||
<outputDirectory>/${artifactId}</outputDirectory>
|
|
||||||
<filtered>true</filtered>
|
|
||||||
</file>
|
|
||||||
</files>
|
</files>
|
||||||
</assembly>
|
</assembly>
|
26
pom.xml
26
pom.xml
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
<groupId>org.gcube.portal</groupId>
|
<groupId>org.gcube.portal</groupId>
|
||||||
<artifactId>custom-portal-handler</artifactId>
|
<artifactId>custom-portal-handler</artifactId>
|
||||||
<version>1.8.0-SNAPSHOT</version>
|
<version>2.0.0-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>Custom Portal Handler</name>
|
<name>Custom Portal Handler</name>
|
||||||
<description>
|
<description>
|
||||||
|
@ -26,7 +26,7 @@
|
||||||
<distroDirectory>distro</distroDirectory>
|
<distroDirectory>distro</distroDirectory>
|
||||||
<maven.compiler.source>1.7</maven.compiler.source>
|
<maven.compiler.source>1.7</maven.compiler.source>
|
||||||
<maven.compiler.target>1.7</maven.compiler.target>
|
<maven.compiler.target>1.7</maven.compiler.target>
|
||||||
|
<liferay.version>6.2.5</liferay.version>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
@ -55,6 +55,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.common.portal</groupId>
|
<groupId>org.gcube.common.portal</groupId>
|
||||||
<artifactId>portal-manager</artifactId>
|
<artifactId>portal-manager</artifactId>
|
||||||
|
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -65,10 +66,31 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.dvos</groupId>
|
<groupId>org.gcube.dvos</groupId>
|
||||||
<artifactId>usermanagement-core</artifactId>
|
<artifactId>usermanagement-core</artifactId>
|
||||||
|
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.liferay.portal</groupId>
|
<groupId>com.liferay.portal</groupId>
|
||||||
<artifactId>portal-service</artifactId>
|
<artifactId>portal-service</artifactId>
|
||||||
|
<version>${liferay.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.liferay.portal</groupId>
|
||||||
|
<artifactId>util-bridges</artifactId>
|
||||||
|
<version>${liferay.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.liferay.portal</groupId>
|
||||||
|
<artifactId>util-taglib</artifactId>
|
||||||
|
<version>${liferay.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.liferay.portal</groupId>
|
||||||
|
<artifactId>util-java</artifactId>
|
||||||
|
<version>${liferay.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.portlet</groupId>
|
<groupId>javax.portlet</groupId>
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
package org.gcube.portal.custom.communitymanager;
|
||||||
|
|
||||||
|
import org.gcube.portal.custom.communitymanager.components.GCUBESiteLayout;
|
||||||
|
|
||||||
|
import com.liferay.portal.model.Organization;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Massimiliano Assante, massimiliano.assante@isti.cnr.it
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public interface GCubeSiteManager {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @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);
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param username the screenname of the current user
|
||||||
|
* @param currOrg the organization in which to check the custom attribute
|
||||||
|
* @param attrToCheck the key to check
|
||||||
|
* @return true or false
|
||||||
|
*/
|
||||||
|
Boolean readOrganizationCustomAttribute(String username, Organization currOrg, String attrToCheck);
|
||||||
|
|
||||||
|
}
|
|
@ -128,7 +128,7 @@ public final class PortletsIdManager {
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
String toReturn = "";
|
String toReturn = "";
|
||||||
try {
|
try {
|
||||||
String propertyfile = OrganizationsUtil.getTomcatFolder()+"conf/gcube-portlets.properties";
|
String propertyfile = SiteManagerUtil.getTomcatFolder()+"conf/gcube-portlets.properties";
|
||||||
File propsFile = new File(propertyfile);
|
File propsFile = new File(propertyfile);
|
||||||
FileInputStream fis = new FileInputStream(propsFile);
|
FileInputStream fis = new FileInputStream(propsFile);
|
||||||
props.load( fis );
|
props.load( fis );
|
||||||
|
|
|
@ -4,17 +4,15 @@ import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.gcube.portal.custom.communitymanager.components.GCUBELayoutTab;
|
import org.gcube.portal.custom.communitymanager.components.GCUBELayoutTab;
|
||||||
import org.gcube.portal.custom.communitymanager.components.GCUBEPortlet;
|
import org.gcube.portal.custom.communitymanager.components.GCUBEPortlet;
|
||||||
import org.gcube.portal.custom.communitymanager.components.GCUBESiteLayout;
|
import org.gcube.portal.custom.communitymanager.components.GCUBESiteLayout;
|
||||||
import org.gcube.vomanagement.usermanagement.UserManager;
|
import org.gcube.vomanagement.usermanagement.UserManager;
|
||||||
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayUserManager;
|
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
||||||
|
|
||||||
import com.liferay.portal.kernel.exception.PortalException;
|
import com.liferay.portal.kernel.exception.PortalException;
|
||||||
import com.liferay.portal.kernel.exception.SystemException;
|
import com.liferay.portal.kernel.exception.SystemException;
|
||||||
|
@ -33,15 +31,14 @@ import com.liferay.portal.service.CompanyLocalServiceUtil;
|
||||||
import com.liferay.portal.service.LayoutLocalServiceUtil;
|
import com.liferay.portal.service.LayoutLocalServiceUtil;
|
||||||
import com.liferay.portal.service.PortletLocalServiceUtil;
|
import com.liferay.portal.service.PortletLocalServiceUtil;
|
||||||
import com.liferay.portal.service.PortletPreferencesLocalServiceUtil;
|
import com.liferay.portal.service.PortletPreferencesLocalServiceUtil;
|
||||||
import com.liferay.portal.service.RoleLocalServiceUtil;
|
|
||||||
import com.liferay.portal.service.ServiceContext;
|
import com.liferay.portal.service.ServiceContext;
|
||||||
import com.liferay.portal.service.UserLocalServiceUtil;
|
import com.liferay.portal.service.UserLocalServiceUtil;
|
||||||
|
|
||||||
public class OrganizationsUtil {
|
public class SiteManagerUtil {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private static Log _log = LogFactoryUtil.getLog(OrganizationManager.class);
|
private static Log _log = LogFactoryUtil.getLog(GCubeSiteManager.class);
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -150,39 +147,7 @@ public class OrganizationsUtil {
|
||||||
toReturn.add(new GCUBEPortlet(PortletsIdManager.LR_ACTIVITIES, PortletsIdManager.getLRPortletId(PortletsIdManager.LR_ACTIVITIES)));
|
toReturn.add(new GCUBEPortlet(PortletsIdManager.LR_ACTIVITIES, PortletsIdManager.getLRPortletId(PortletsIdManager.LR_ACTIVITIES)));
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Create a Regular Manager Role for the community/Organization
|
|
||||||
* @param vreName
|
|
||||||
* @return
|
|
||||||
* @throws SystemException
|
|
||||||
* @throws PortalException
|
|
||||||
*/
|
|
||||||
public static Role addManagerRole(String vreName, String username) throws PortalException, SystemException {
|
|
||||||
Company company = getCompany();
|
|
||||||
User user = validateUser(username);
|
|
||||||
String roleName = "VRE-Manager-" + vreName.replaceAll(" ", "-");
|
|
||||||
Locale english = new Locale("en");
|
|
||||||
HashMap<Locale, String> roleNames = new HashMap<Locale, String>();
|
|
||||||
roleNames.put(english, roleName);
|
|
||||||
return RoleLocalServiceUtil.addRole(user.getUserId(), company.getCompanyId(), roleName, roleNames, "VRE Manager of " + vreName, LIFERAY_REGULAR_ROLE_ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a Regular Manager Role for the community/Organization
|
|
||||||
* @param vreName
|
|
||||||
* @return
|
|
||||||
* @throws SystemException
|
|
||||||
* @throws PortalException
|
|
||||||
*/
|
|
||||||
public static Role addManagerRole(String roleName, String vreName, long userid) throws PortalException, SystemException {
|
|
||||||
Company company = getCompany();
|
|
||||||
Locale english = new Locale("en");
|
|
||||||
HashMap<Locale, String> roleNames = new HashMap<Locale, String>();
|
|
||||||
roleNames.put(english, roleName);
|
|
||||||
return RoleLocalServiceUtil.addRole(userid, company.getCompanyId(), roleName, roleNames, "VRE Manager of " + vreName, LIFERAY_REGULAR_ROLE_ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check if the user exists in the database and has AuthZ to perform the operation
|
* check if the user exists in the database and has AuthZ to perform the operation
|
||||||
|
@ -288,34 +253,13 @@ public class OrganizationsUtil {
|
||||||
public boolean addUserToGroup(long groupid, String username) {
|
public boolean addUserToGroup(long groupid, String username) {
|
||||||
UserManager uman = new LiferayUserManager();
|
UserManager uman = new LiferayUserManager();
|
||||||
try {
|
try {
|
||||||
uman.assignUserToGroup(""+groupid, uman.getUserId(username));
|
uman.assignUserToGroup(groupid, uman.getUserId(username));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
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
|
* read the root VO name from a property file and retuns it
|
||||||
*/
|
*/
|
||||||
|
@ -325,7 +269,7 @@ public class OrganizationsUtil {
|
||||||
String toReturn = "";
|
String toReturn = "";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String propertyfile = OrganizationsUtil.getTomcatFolder()+"conf/gcube-data.properties";
|
String propertyfile = SiteManagerUtil.getTomcatFolder()+"conf/gcube-data.properties";
|
||||||
File propsFile = new File(propertyfile);
|
File propsFile = new File(propertyfile);
|
||||||
FileInputStream fis = new FileInputStream(propsFile);
|
FileInputStream fis = new FileInputStream(propsFile);
|
||||||
props.load( fis);
|
props.load( fis);
|
||||||
|
@ -340,20 +284,5 @@ public class OrganizationsUtil {
|
||||||
_log.debug("Returning Root VO Name: " + toReturn );
|
_log.debug("Returning Root VO Name: " + toReturn );
|
||||||
return 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -1,195 +0,0 @@
|
||||||
package org.gcube.portal.custom.communitymanager.impl;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.gcube.application.framework.core.session.ASLSession;
|
|
||||||
import org.gcube.portal.custom.communitymanager.CommunityManager;
|
|
||||||
import org.gcube.portal.custom.communitymanager.OrganizationsUtil;
|
|
||||||
import org.gcube.portal.custom.communitymanager.PortletsIdManager;
|
|
||||||
import org.gcube.portal.custom.communitymanager.components.GCUBELayoutTab;
|
|
||||||
import org.gcube.portal.custom.communitymanager.components.GCUBEPortlet;
|
|
||||||
import org.gcube.portal.custom.communitymanager.components.GCUBESiteLayout;
|
|
||||||
import org.gcube.portal.custom.communitymanager.types.GCUBELayoutType;
|
|
||||||
import org.gcube.vomanagement.usermanagement.GroupManager;
|
|
||||||
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
|
|
||||||
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
|
|
||||||
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayGroupManager;
|
|
||||||
import org.gcube.vomanagement.usermanagement.model.GroupModel;
|
|
||||||
|
|
||||||
import com.liferay.portal.kernel.exception.PortalException;
|
|
||||||
import com.liferay.portal.kernel.exception.SystemException;
|
|
||||||
import com.liferay.portal.kernel.log.Log;
|
|
||||||
import com.liferay.portal.kernel.log.LogFactoryUtil;
|
|
||||||
import com.liferay.portal.model.Group;
|
|
||||||
import com.liferay.portal.model.Portlet;
|
|
||||||
import com.liferay.portal.model.User;
|
|
||||||
import com.liferay.portal.service.OrganizationLocalServiceUtil;
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Massimiliano Assante, massimiliano.assante@isti.cnr.it
|
|
||||||
* @version 1.0
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class CommunityManagerImpl extends OrganizationsUtil implements CommunityManager {
|
|
||||||
|
|
||||||
private static Log _log = LogFactoryUtil.getLog(CommunityManagerImpl.class);
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public static final String CURR_ORG = "CURR_RE_NAME";
|
|
||||||
|
|
||||||
|
|
||||||
ASLSession session = null;
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private String screenName;
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private static CommunityManagerImpl singleton;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @return the singleton
|
|
||||||
*/
|
|
||||||
public static CommunityManagerImpl get() {
|
|
||||||
return singleton;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param session the ASL session
|
|
||||||
*/
|
|
||||||
private CommunityManagerImpl(ASLSession session) {
|
|
||||||
this.session = session;
|
|
||||||
this.screenName = session.getUsername();
|
|
||||||
singleton = this;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param session the session
|
|
||||||
* @return the singleton
|
|
||||||
*/
|
|
||||||
public static CommunityManagerImpl getInstance(ASLSession session) {
|
|
||||||
return new CommunityManagerImpl(session);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Use this method for creating VRE programmatically and associate a default layout to it
|
|
||||||
*
|
|
||||||
* @param communityName -
|
|
||||||
* @param communityDesc -
|
|
||||||
* @param parentID -
|
|
||||||
* @return the community created id
|
|
||||||
*/
|
|
||||||
public long createCommunity(String communityName, String communityDesc, long parentID) {
|
|
||||||
String username = "";
|
|
||||||
String email = "";
|
|
||||||
GCUBESiteLayout siteLayout = null;
|
|
||||||
try {
|
|
||||||
username = validateUser(screenName).getScreenName();
|
|
||||||
email = validateUser(screenName).getEmailAddress();
|
|
||||||
|
|
||||||
siteLayout = new GCUBESiteLayout(getCompany(), communityName, email);
|
|
||||||
siteLayout.addTab(new GCUBELayoutTab("Home", GCUBELayoutType.ONE_COL,
|
|
||||||
new GCUBEPortlet("gCube Loggedin", PortletsIdManager.getLRPortletId(PortletsIdManager.GCUBE_LOGGEDIN))));
|
|
||||||
siteLayout.addTab(new GCUBELayoutTab("Workspace", GCUBELayoutType.ONE_COL,
|
|
||||||
new GCUBEPortlet("gCube Workspace", PortletsIdManager.getLRPortletId(PortletsIdManager.WORKSPACE))));
|
|
||||||
} catch (PortalException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (SystemException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return createCommunity(username, communityName, communityDesc, siteLayout, parentID);
|
|
||||||
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Use this method for creating VRE programmatically and associate it a layout
|
|
||||||
*
|
|
||||||
* @param usernameCreator -
|
|
||||||
* @param communityName -
|
|
||||||
* @param communityDesc -
|
|
||||||
* @param siteLayout a <class>GCUBESiteLayout</class> instance to associate to it
|
|
||||||
* @param parentID the organization parent
|
|
||||||
* @return the community created id
|
|
||||||
*/
|
|
||||||
public long createCommunity(String usernameCreator, String communityName, String communityDesc, GCUBESiteLayout siteLayout, long parentID) {
|
|
||||||
String username;
|
|
||||||
Group tocreate = null;
|
|
||||||
try {
|
|
||||||
username = usernameCreator;
|
|
||||||
//create the group
|
|
||||||
tocreate = createVRE(communityName, communityDesc, parentID);
|
|
||||||
|
|
||||||
// associate a layout to the group
|
|
||||||
createLayout(tocreate, validateUser(username), siteLayout);
|
|
||||||
} catch (PortalException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (SystemException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
_log.debug("Returning Organization ID " + tocreate.getClassPK());
|
|
||||||
return tocreate.getClassPK();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create the group in the database
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
* @throws SystemException
|
|
||||||
* @throws PortalException
|
|
||||||
*/
|
|
||||||
private Group createVRE(String communityName, String communityDesc, long parentID) throws PortalException, SystemException {
|
|
||||||
|
|
||||||
User creator = validateUser(screenName);
|
|
||||||
GroupManager gm = new LiferayGroupManager();
|
|
||||||
|
|
||||||
long groupid = parentID;
|
|
||||||
|
|
||||||
|
|
||||||
GroupModel currOrg = null;
|
|
||||||
try {
|
|
||||||
currOrg = gm.getGroup(""+groupid);
|
|
||||||
} catch (UserManagementSystemException e1) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e1.printStackTrace();
|
|
||||||
} catch (GroupRetrievalFault e1) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
_log.info("Creating VRE " + communityName + " SUBORG OF " +currOrg.getGroupName());
|
|
||||||
GroupModel groupModel = null;
|
|
||||||
try {
|
|
||||||
groupModel = gm.createVRE(communityName, ""+groupid, ""+creator.getUserId(), "Description for "+communityName);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
_log.trace("Calling groupModel.getGroupId() ");
|
|
||||||
long curGroupid = Long.parseLong(groupModel.getGroupId());
|
|
||||||
_log.trace("curGroupid " + curGroupid );
|
|
||||||
|
|
||||||
Group toReturn = OrganizationLocalServiceUtil.getOrganization(curGroupid).getGroup();
|
|
||||||
_log.debug("GROUP created id:" + toReturn.getGroupId());
|
|
||||||
return toReturn;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param communityName -
|
|
||||||
* @return list of belonging portlet
|
|
||||||
*/
|
|
||||||
public List<Portlet> getGCubePortlets(String communityName) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -2,15 +2,14 @@ package org.gcube.portal.custom.communitymanager.impl;
|
||||||
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.gcube.portal.custom.communitymanager.OrganizationsUtil;
|
|
||||||
import org.gcube.portal.custom.communitymanager.PortletsIdManager;
|
import org.gcube.portal.custom.communitymanager.PortletsIdManager;
|
||||||
|
import org.gcube.portal.custom.communitymanager.SiteManagerUtil;
|
||||||
import org.gcube.portal.custom.communitymanager.components.GCUBELayoutTab;
|
import org.gcube.portal.custom.communitymanager.components.GCUBELayoutTab;
|
||||||
import org.gcube.portal.custom.communitymanager.components.GCUBEPortlet;
|
import org.gcube.portal.custom.communitymanager.components.GCUBEPortlet;
|
||||||
import org.gcube.portal.custom.communitymanager.components.GCUBESiteLayout;
|
import org.gcube.portal.custom.communitymanager.components.GCUBESiteLayout;
|
||||||
|
@ -19,10 +18,11 @@ import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
|
||||||
import org.gcube.vomanagement.usermanagement.GroupManager;
|
import org.gcube.vomanagement.usermanagement.GroupManager;
|
||||||
import org.gcube.vomanagement.usermanagement.RoleManager;
|
import org.gcube.vomanagement.usermanagement.RoleManager;
|
||||||
import org.gcube.vomanagement.usermanagement.UserManager;
|
import org.gcube.vomanagement.usermanagement.UserManager;
|
||||||
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayGroupManager;
|
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
|
||||||
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayRoleManager;
|
import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager;
|
||||||
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayUserManager;
|
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
||||||
import org.gcube.vomanagement.usermanagement.model.GroupModel;
|
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
|
||||||
|
import org.gcube.vomanagement.usermanagement.model.GCubeRole;
|
||||||
|
|
||||||
import com.liferay.portal.kernel.bean.BeanLocatorException;
|
import com.liferay.portal.kernel.bean.BeanLocatorException;
|
||||||
import com.liferay.portal.kernel.exception.PortalException;
|
import com.liferay.portal.kernel.exception.PortalException;
|
||||||
|
@ -31,14 +31,14 @@ import com.liferay.portal.kernel.log.Log;
|
||||||
import com.liferay.portal.kernel.log.LogFactoryUtil;
|
import com.liferay.portal.kernel.log.LogFactoryUtil;
|
||||||
import com.liferay.portal.model.Group;
|
import com.liferay.portal.model.Group;
|
||||||
import com.liferay.portal.model.Organization;
|
import com.liferay.portal.model.Organization;
|
||||||
import com.liferay.portal.model.Role;
|
|
||||||
import com.liferay.portal.model.Theme;
|
import com.liferay.portal.model.Theme;
|
||||||
import com.liferay.portal.model.User;
|
import com.liferay.portal.model.User;
|
||||||
|
import com.liferay.portal.security.auth.PrincipalThreadLocal;
|
||||||
import com.liferay.portal.security.permission.PermissionChecker;
|
import com.liferay.portal.security.permission.PermissionChecker;
|
||||||
import com.liferay.portal.security.permission.PermissionCheckerFactoryUtil;
|
import com.liferay.portal.security.permission.PermissionCheckerFactoryUtil;
|
||||||
import com.liferay.portal.security.permission.PermissionThreadLocal;
|
import com.liferay.portal.security.permission.PermissionThreadLocal;
|
||||||
|
import com.liferay.portal.service.GroupLocalServiceUtil;
|
||||||
import com.liferay.portal.service.LayoutSetLocalServiceUtil;
|
import com.liferay.portal.service.LayoutSetLocalServiceUtil;
|
||||||
import com.liferay.portal.service.OrganizationLocalServiceUtil;
|
|
||||||
import com.liferay.portal.service.ThemeLocalServiceUtil;
|
import com.liferay.portal.service.ThemeLocalServiceUtil;
|
||||||
import com.liferay.portal.service.UserLocalServiceUtil;
|
import com.liferay.portal.service.UserLocalServiceUtil;
|
||||||
import com.liferay.portlet.expando.model.ExpandoBridge;
|
import com.liferay.portlet.expando.model.ExpandoBridge;
|
||||||
|
@ -48,19 +48,19 @@ import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
|
||||||
* @author Massimiliano Assante, massimiliano.assante@isti.cnr.it
|
* @author Massimiliano Assante, massimiliano.assante@isti.cnr.it
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class OrganizationManagerImpl extends OrganizationsUtil {
|
public class GCubeSiteManagerImpl extends SiteManagerUtil {
|
||||||
|
|
||||||
private static Log _log = LogFactoryUtil.getLog(OrganizationManagerImpl.class);
|
private static Log _log = LogFactoryUtil.getLog(GCubeSiteManagerImpl.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FIXME public as generic resource
|
* FIXME public as generic resource
|
||||||
*/
|
*/
|
||||||
protected static final String ORGANIZATION_DEFAULT_LOGO = "/org/gcube/portal/custom/communitymanager/resources/default_logo.png";
|
public static final String SITE_DEFAULT_LOGO = "/org/gcube/portal/custom/communitymanager/resources/default_logo.png";
|
||||||
private static final String CATEGORY = "Virtualgroup";
|
private static final String CATEGORY = "Virtualgroup";
|
||||||
|
|
||||||
public static List<String> getVirtualGroups() throws PortalException, SystemException {
|
public static List<String> getVirtualGroups() throws PortalException, SystemException {
|
||||||
try {
|
try {
|
||||||
ExpandoBridge expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(OrganizationsUtil.getCompany().getCompanyId(), Organization.class.getName());
|
ExpandoBridge expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(SiteManagerUtil.getCompany().getCompanyId(), Organization.class.getName());
|
||||||
String[] groups = (String[]) expandoBridge.getAttributeDefault("Virtualgroup");
|
String[] groups = (String[]) expandoBridge.getAttributeDefault("Virtualgroup");
|
||||||
return Arrays.asList(groups);
|
return Arrays.asList(groups);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -70,20 +70,19 @@ public class OrganizationManagerImpl extends OrganizationsUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String getVirtualGroupName(Organization organization){
|
public static String getVirtualGroupName(Group site){
|
||||||
try {
|
try {
|
||||||
long companyId = OrganizationsUtil.getCompany().getCompanyId();
|
|
||||||
_log.debug("Setting Thread Permission");
|
_log.debug("Setting Thread Permission");
|
||||||
User user = UserLocalServiceUtil.getUserByScreenName(companyId, ScopeHelper.getAdministratorUsername());
|
long userId = LiferayUserManager.getAdmin().getUserId();
|
||||||
PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user, false);
|
PrincipalThreadLocal.setName(userId);
|
||||||
PermissionThreadLocal.setPermissionChecker(permissionChecker);
|
PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(UserLocalServiceUtil.getUser(userId), false);
|
||||||
_log.debug("Setting Permission ok!");
|
PermissionThreadLocal.setPermissionChecker(permissionChecker);
|
||||||
|
|
||||||
if (organization.getExpandoBridge().getAttribute(CATEGORY) == null || organization.getExpandoBridge().getAttribute(CATEGORY).equals("")) {
|
if (site.getExpandoBridge().getAttribute(CATEGORY) == null || site.getExpandoBridge().getAttribute(CATEGORY).equals("")) {
|
||||||
_log.warn(String.format("Attribute %s not initialized.", CATEGORY));
|
_log.warn(String.format("Attribute %s not initialized.", CATEGORY));
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
String[] values = (String[]) organization.getExpandoBridge().getAttribute(CATEGORY);
|
String[] values = (String[]) site.getExpandoBridge().getAttribute(CATEGORY);
|
||||||
return values[0];
|
return values[0];
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -101,14 +100,15 @@ public class OrganizationManagerImpl extends OrganizationsUtil {
|
||||||
public static long createVO(String username, String voName, String voDesc, long parentid, GCUBESiteLayout siteLayout, String themeid) {
|
public static long createVO(String username, String voName, String voDesc, long parentid, GCUBESiteLayout siteLayout, String themeid) {
|
||||||
Group voToCreate = null;
|
Group voToCreate = null;
|
||||||
try {
|
try {
|
||||||
//create the Group
|
|
||||||
User creator = validateUser(username);
|
|
||||||
GroupManager gm = new LiferayGroupManager();
|
GroupManager gm = new LiferayGroupManager();
|
||||||
GroupModel groupModel = null;
|
GCubeGroup groupModel = null;
|
||||||
_log.info("createVO " + voName + " with parentid " + parentid);
|
_log.info("createVO " + voName + " with parentid " + parentid);
|
||||||
groupModel = gm.createVRE(voName, ""+parentid, ""+creator.getUserId(), "Description for "+voName);
|
if (parentid == 0)
|
||||||
long groupModelid = Long.parseLong(groupModel.getGroupId());
|
groupModel = gm.createRootVO(voName, voDesc);
|
||||||
voToCreate = OrganizationLocalServiceUtil.getOrganization(groupModelid).getGroup();
|
else
|
||||||
|
groupModel = gm.createVO(voName, parentid, voDesc);
|
||||||
|
long groupModelid = groupModel.getGroupId();
|
||||||
|
voToCreate = GroupLocalServiceUtil.getGroup(groupModelid);
|
||||||
|
|
||||||
//associate the layout to the group
|
//associate the layout to the group
|
||||||
createLayout(voToCreate, validateUser(username), siteLayout);
|
createLayout(voToCreate, validateUser(username), siteLayout);
|
||||||
|
@ -120,30 +120,36 @@ public class OrganizationManagerImpl extends OrganizationsUtil {
|
||||||
_log.debug("LayoutSet Theme with id " + themeid + " Applied Correctly");
|
_log.debug("LayoutSet Theme with id " + themeid + " Applied Correctly");
|
||||||
|
|
||||||
//update logo
|
//update logo
|
||||||
InputStream is = OrganizationManagerImpl.class.getResourceAsStream(ORGANIZATION_DEFAULT_LOGO);
|
InputStream is = GCubeSiteManagerImpl.class.getResourceAsStream(SITE_DEFAULT_LOGO);
|
||||||
FileInputStream fis = new FileInputStream(writeTempLogo(is));
|
//FileInputStream fis = new FileInputStream(writeTempLogo(is));
|
||||||
LayoutSetLocalServiceUtil.updateLogo(voToCreate.getGroupId(), true, true, fis);
|
LayoutSetLocalServiceUtil.updateLogo(voToCreate.getGroupId(), true, true, is);
|
||||||
|
|
||||||
_log.debug("Adding the Admin Role VO-Admin for this VO");
|
_log.debug("Adding the Admin Role VO-Admin for this VO");
|
||||||
//add the role ADMIN
|
//add the role ADMIN
|
||||||
UserManager uman = new LiferayUserManager();
|
UserManager uman = new LiferayUserManager();
|
||||||
long uid = Long.parseLong(uman.getUserId(username));
|
long uid = uman.getUserId(username);
|
||||||
Role created = OrganizationsUtil.createRole("VO-Admin", voName, uid);
|
|
||||||
_log.debug("Admin Role VO-Admin Created Successfully");
|
|
||||||
|
uman.assignUserToGroup(groupModel.getGroupId(), uid);
|
||||||
uman.assignUserToGroup(""+voToCreate.getClassPK(), ""+uid);
|
|
||||||
_log.debug("Added user " + username + " to group " + voName + " with Success");
|
_log.debug("Added user " + username + " to group " + voName + " with Success");
|
||||||
|
|
||||||
_log.debug("Assigning Role: VO-Admin");
|
_log.debug("Assigning Role: " + GCubeRole.VO_ADMIN_LABEL);
|
||||||
RoleManager rm = new LiferayRoleManager();
|
RoleManager rm = new LiferayRoleManager();
|
||||||
rm.assignRoleToUser(""+voToCreate.getClassPK(), ""+created.getRoleId(), ""+uid);
|
long roleId = -1;
|
||||||
|
for (GCubeRole role : rm.listAllGroupRoles()) {
|
||||||
|
if (role.getRoleName().compareTo(GCubeRole.VO_ADMIN_LABEL) == 0) {
|
||||||
|
roleId = role.getRoleId();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rm.assignRoleToUser(uid, groupModel.getGroupId(), roleId);
|
||||||
_log.debug("Admin Role VO-Admin Associated to user " + username + " .... returning ...");
|
_log.debug("Admin Role VO-Admin Associated to user " + username + " .... returning ...");
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
_log.info("Created" + voName + " with id " + voToCreate.getOrganizationId());
|
_log.info("Created" + voName + " with id " + voToCreate.getGroupId());
|
||||||
return voToCreate.getOrganizationId();
|
return voToCreate.getGroupId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -153,7 +159,7 @@ public class OrganizationManagerImpl extends OrganizationsUtil {
|
||||||
* @param voDesc -
|
* @param voDesc -
|
||||||
* @return the id of the created VO
|
* @return the id of the created VO
|
||||||
*/
|
*/
|
||||||
public static long createVO(String username, String voName, String voDesc, GCUBESiteLayout siteLayout, String themeid) {
|
public static long createRootVO(String username, String voName, String voDesc, GCUBESiteLayout siteLayout, String themeid) {
|
||||||
return createVO(username, voName, voDesc, 0, siteLayout, themeid);
|
return createVO(username, voName, voDesc, 0, siteLayout, themeid);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -162,53 +168,54 @@ public class OrganizationManagerImpl extends OrganizationsUtil {
|
||||||
* @param voDesc -
|
* @param voDesc -
|
||||||
* @return the organizationid of the created VO
|
* @return the organizationid of the created VO
|
||||||
*/
|
*/
|
||||||
public static long createVRE(String username, String voName, String voDesc, long parentid, GCUBESiteLayout siteLayout, String themeid) {
|
public static long createVRE(String username, String vreName, String voDesc, long parentid, GCUBESiteLayout siteLayout, String themeid) {
|
||||||
|
Group vreToCreate = null;
|
||||||
Group voToCreate = null;
|
try {
|
||||||
try {
|
|
||||||
//create the Group
|
|
||||||
User creator = validateUser(username);
|
|
||||||
GroupManager gm = new LiferayGroupManager();
|
GroupManager gm = new LiferayGroupManager();
|
||||||
GroupModel groupModel = null;
|
GCubeGroup groupModel = null;
|
||||||
_log.info("createVRE " + voName + " with parentid " + parentid);
|
_log.info("createVRE " + vreName + " with parentid " + parentid);
|
||||||
groupModel = gm.createVRE(voName, ""+parentid, ""+creator.getUserId(), voDesc);
|
groupModel = gm.createVRE(vreName, parentid, voDesc);
|
||||||
long groupModelid = Long.parseLong(groupModel.getGroupId());
|
long groupModelid = groupModel.getGroupId();
|
||||||
voToCreate = OrganizationLocalServiceUtil.getOrganization(groupModelid).getGroup();
|
vreToCreate = GroupLocalServiceUtil.getGroup(groupModelid);
|
||||||
|
|
||||||
//associate the layout to the group
|
//associate the layout to the group
|
||||||
createLayout(voToCreate, validateUser(username), siteLayout);
|
createLayout(vreToCreate, validateUser(username), siteLayout);
|
||||||
|
|
||||||
Theme themeToApply = ThemeLocalServiceUtil.getTheme(getCompany().getCompanyId(), themeid, false);
|
Theme themeToApply = ThemeLocalServiceUtil.getTheme(getCompany().getCompanyId(), themeid, false);
|
||||||
|
|
||||||
//update theme
|
//update theme
|
||||||
LayoutSetLocalServiceUtil.updateLookAndFeel(voToCreate.getGroupId(), themeToApply.getThemeId(), "", "", false);
|
LayoutSetLocalServiceUtil.updateLookAndFeel(vreToCreate.getGroupId(), themeToApply.getThemeId(), "", "", false);
|
||||||
_log.debug("LayoutSet Theme with id " + themeid + " Applied Correctly");
|
_log.debug("LayoutSet Theme with id " + themeid + " Applied Correctly");
|
||||||
|
|
||||||
//update logo
|
//update logo
|
||||||
InputStream is = OrganizationManagerImpl.class.getResourceAsStream(ORGANIZATION_DEFAULT_LOGO);
|
InputStream is = GCubeSiteManagerImpl.class.getResourceAsStream(SITE_DEFAULT_LOGO);
|
||||||
FileInputStream fis = new FileInputStream(writeTempLogo(is));
|
//FileInputStream fis = new FileInputStream(writeTempLogo(is));
|
||||||
LayoutSetLocalServiceUtil.updateLogo(voToCreate.getGroupId(), true, true, fis);
|
LayoutSetLocalServiceUtil.updateLogo(vreToCreate.getGroupId(), true, true, is);
|
||||||
|
|
||||||
_log.debug("Adding the MANAGER Role VRE-Manager for this VRE");
|
_log.debug("Adding the Admin Role VRE-Admin for this VRE");
|
||||||
//add the role ADMIN
|
//add the role ADMIN
|
||||||
UserManager uman = new LiferayUserManager();
|
UserManager uman = new LiferayUserManager();
|
||||||
long uid = Long.parseLong(uman.getUserId(username));
|
long uid = uman.getUserId(username);
|
||||||
Role created = OrganizationsUtil.createRole("VRE-Manager", voName, uid);
|
|
||||||
_log.debug("Admin Role VRE-Manager Created Successfully");
|
|
||||||
|
uman.assignUserToGroup(groupModel.getGroupId(), uid);
|
||||||
|
_log.debug("Added user " + username + " to group " + vreName + " with Success");
|
||||||
|
|
||||||
uman.assignUserToGroup(""+voToCreate.getClassPK(), ""+uid);
|
_log.debug("Assigning Role: " + GCubeRole.VRE_MANAGER_LABEL);
|
||||||
_log.debug("Added user " + username + " to group " + voName + " with Success");
|
|
||||||
|
|
||||||
_log.debug("Assigning Role: VRE-Manager");
|
|
||||||
RoleManager rm = new LiferayRoleManager();
|
RoleManager rm = new LiferayRoleManager();
|
||||||
rm.assignRoleToUser(""+voToCreate.getClassPK(), ""+created.getRoleId(), ""+uid);
|
long roleId = -1;
|
||||||
|
for (GCubeRole role : rm.listAllGroupRoles()) {
|
||||||
|
if (role.getRoleName().compareTo(GCubeRole.VRE_MANAGER_LABEL) == 0) {
|
||||||
|
roleId = role.getRoleId();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rm.assignRoleToUser(uid, groupModel.getGroupId(), roleId);
|
||||||
_log.debug("Admin Role VRE-Manager Associated to user " + username + " .... returning ...");
|
_log.debug("Admin Role VRE-Manager Associated to user " + username + " .... returning ...");
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
_log.info("Created" + voName + " with id " + voToCreate.getOrganizationId());
|
_log.info("Created" + vreName + " with id " + vreToCreate.getGroupId());
|
||||||
return voToCreate.getOrganizationId();
|
return vreToCreate.getOrganizationId();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -220,7 +227,7 @@ public class OrganizationManagerImpl extends OrganizationsUtil {
|
||||||
public static GCUBESiteLayout getBaseLayout(String voName, boolean isVO, String username) throws PortalException, SystemException {
|
public static GCUBESiteLayout getBaseLayout(String voName, boolean isVO, String username) throws PortalException, SystemException {
|
||||||
GCUBESiteLayout siteLayout = null;
|
GCUBESiteLayout siteLayout = null;
|
||||||
String email = validateUser(username).getEmailAddress();
|
String email = validateUser(username).getEmailAddress();
|
||||||
siteLayout = new GCUBESiteLayout(OrganizationManagerImpl.getCompany(), voName, email);
|
siteLayout = new GCUBESiteLayout(GCubeSiteManagerImpl.getCompany(), voName, email);
|
||||||
siteLayout.addTab(new GCUBELayoutTab(voName, GCUBELayoutType.ONE_COL,
|
siteLayout.addTab(new GCUBELayoutTab(voName, GCUBELayoutType.ONE_COL,
|
||||||
new GCUBEPortlet("gCube Loggedin", PortletsIdManager.getLRPortletId(PortletsIdManager.GCUBE_LOGGEDIN))));
|
new GCUBEPortlet("gCube Loggedin", PortletsIdManager.getLRPortletId(PortletsIdManager.GCUBE_LOGGEDIN))));
|
||||||
|
|
||||||
|
@ -281,14 +288,14 @@ public class OrganizationManagerImpl extends OrganizationsUtil {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|
||||||
long companyId = OrganizationsUtil.getCompany().getCompanyId();
|
long companyId = SiteManagerUtil.getCompany().getCompanyId();
|
||||||
_log.trace("Setting Thread Permission");
|
_log.trace("Setting Thread Permission");
|
||||||
User user = UserLocalServiceUtil.getUserByScreenName(companyId, ScopeHelper.getAdministratorUsername());
|
User user = UserLocalServiceUtil.getUserByScreenName(companyId, ScopeHelper.getAdministratorUsername());
|
||||||
PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user, false);
|
PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user, false);
|
||||||
PermissionThreadLocal.setPermissionChecker(permissionChecker);
|
PermissionThreadLocal.setPermissionChecker(permissionChecker);
|
||||||
_log.trace("Setting Permission ok!");
|
_log.trace("Setting Permission ok!");
|
||||||
|
|
||||||
User currentUser = OrganizationsUtil.validateUser(username);
|
User currentUser = SiteManagerUtil.validateUser(username);
|
||||||
if (currOrg.getExpandoBridge().getAttribute(attrToCheck) == null || currOrg.getExpandoBridge().getAttribute(attrToCheck).equals("")) {
|
if (currOrg.getExpandoBridge().getAttribute(attrToCheck) == null || currOrg.getExpandoBridge().getAttribute(attrToCheck).equals("")) {
|
||||||
_log.trace("Attribute " + attrToCheck + " must be initialized");
|
_log.trace("Attribute " + attrToCheck + " must be initialized");
|
||||||
setOrgCustomAttribute(username, currOrg, attrToCheck);
|
setOrgCustomAttribute(username, currOrg, attrToCheck);
|
||||||
|
@ -328,7 +335,7 @@ public class OrganizationManagerImpl extends OrganizationsUtil {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
long companyId = OrganizationsUtil.getCompany().getCompanyId();
|
long companyId = SiteManagerUtil.getCompany().getCompanyId();
|
||||||
_log.trace("Setting Thread Permission");
|
_log.trace("Setting Thread Permission");
|
||||||
User user = UserLocalServiceUtil.getUserByScreenName(companyId, ScopeHelper.getAdministratorUsername());
|
User user = UserLocalServiceUtil.getUserByScreenName(companyId, ScopeHelper.getAdministratorUsername());
|
||||||
PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user, false);
|
PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user, false);
|
Binary file not shown.
Before Width: | Height: | Size: 9.8 KiB After Width: | Height: | Size: 8.2 KiB |
|
@ -1,11 +1,8 @@
|
||||||
package org.gcube.portal.custom.scopemanager.scopehelper;
|
package org.gcube.portal.custom.scopemanager.scopehelper;
|
||||||
|
|
||||||
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
@ -16,20 +13,20 @@ import org.gcube.application.framework.core.session.ASLSession;
|
||||||
import org.gcube.application.framework.core.session.SessionManager;
|
import org.gcube.application.framework.core.session.SessionManager;
|
||||||
import org.gcube.application.framework.core.util.GenderType;
|
import org.gcube.application.framework.core.util.GenderType;
|
||||||
import org.gcube.common.portal.PortalContext;
|
import org.gcube.common.portal.PortalContext;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.portal.custom.communitymanager.SiteManagerUtil;
|
||||||
import org.gcube.portal.custom.communitymanager.OrganizationsUtil;
|
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.LiferayGroupManager;
|
||||||
|
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
|
||||||
|
|
||||||
import com.liferay.portal.kernel.exception.PortalException;
|
import com.liferay.portal.kernel.exception.PortalException;
|
||||||
import com.liferay.portal.kernel.exception.SystemException;
|
import com.liferay.portal.kernel.exception.SystemException;
|
||||||
import com.liferay.portal.kernel.log.Log;
|
import com.liferay.portal.kernel.log.Log;
|
||||||
import com.liferay.portal.kernel.log.LogFactoryUtil;
|
import com.liferay.portal.kernel.log.LogFactoryUtil;
|
||||||
import com.liferay.portal.kernel.util.WebKeys;
|
import com.liferay.portal.kernel.util.WebKeys;
|
||||||
import com.liferay.portal.model.Group;
|
|
||||||
import com.liferay.portal.model.Organization;
|
|
||||||
import com.liferay.portal.model.Role;
|
import com.liferay.portal.model.Role;
|
||||||
import com.liferay.portal.model.User;
|
import com.liferay.portal.model.User;
|
||||||
import com.liferay.portal.service.GroupLocalServiceUtil;
|
|
||||||
import com.liferay.portal.service.OrganizationLocalServiceUtil;
|
|
||||||
import com.liferay.portal.service.RoleLocalServiceUtil;
|
import com.liferay.portal.service.RoleLocalServiceUtil;
|
||||||
import com.liferay.portal.service.UserLocalServiceUtil;
|
import com.liferay.portal.service.UserLocalServiceUtil;
|
||||||
import com.liferay.portal.theme.ThemeDisplay;
|
import com.liferay.portal.theme.ThemeDisplay;
|
||||||
|
@ -38,20 +35,20 @@ import com.liferay.portal.theme.ThemeDisplay;
|
||||||
public class ScopeHelper {
|
public class ScopeHelper {
|
||||||
|
|
||||||
public static final String USERNAME_ATTRIBUTE = "username";
|
public static final String USERNAME_ATTRIBUTE = "username";
|
||||||
|
public static final String CURR_ORG = "CURR_RE_NAME";
|
||||||
public static final String USER_FULL_NAME_ATTRIBUTE = "USER_FULL_NAME";
|
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_EMAIL_ATTRIBUTE = "USER_EMAIL";
|
||||||
public static final String USER_AVATAR_ID_ATTRIBUTE = "USER_AVATAR_ID";
|
public static final String USER_AVATAR_ID_ATTRIBUTE = "USER_AVATAR_ID";
|
||||||
public static final String USER_GENDER_ATTRIBUTE = "USER_GENDER";
|
public static final String USER_GENDER_ATTRIBUTE = "USER_GENDER";
|
||||||
|
|
||||||
public static final String ASSERTION_ID = "assertionID";
|
public static final String ASSERTION_ID = "assertionID";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static final String ROOT_ORG = "rootorganization";
|
public static final String ROOT_VO = "rootVO";
|
||||||
|
|
||||||
public static final String CURR_ORG = "CURR_RE_NAME";
|
public static final String CURR_RESEARCH_ENV = "CURR_RE_NAME";
|
||||||
|
|
||||||
public static final String MAIL = "notificationSenderEmail";
|
public static final String MAIL = "notificationSenderEmail";
|
||||||
|
|
||||||
|
@ -72,30 +69,25 @@ public class ScopeHelper {
|
||||||
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
|
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
|
||||||
request.getPortletSession().setAttribute(WebKeys.THEME_DISPLAY, themeDisplay, PortletSession.APPLICATION_SCOPE);
|
request.getPortletSession().setAttribute(WebKeys.THEME_DISPLAY, themeDisplay, PortletSession.APPLICATION_SCOPE);
|
||||||
User user = null;
|
User user = null;
|
||||||
Group currentGroup = null;
|
GCubeGroup currentGroup = null;
|
||||||
Organization curOrg = null;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
user = UserLocalServiceUtil.getUser(userid);
|
user = UserLocalServiceUtil.getUser(userid);
|
||||||
|
|
||||||
currentGroup = GroupLocalServiceUtil.getGroup(themeDisplay.getLayout().getGroup().getGroupId());
|
|
||||||
|
|
||||||
// the group MUST BE an Organization
|
GroupManager gm = new LiferayGroupManager();
|
||||||
if (currentGroup.isOrganization()) {
|
long groupId = themeDisplay.getLayout().getGroup().getGroupId();
|
||||||
long organizationId = currentGroup.getClassPK();
|
currentGroup = gm.getGroup(groupId);
|
||||||
curOrg = OrganizationLocalServiceUtil.getOrganization(organizationId);
|
|
||||||
|
|
||||||
if (curOrg.isRoot()) {
|
boolean isInfrastructureScope = false;
|
||||||
scopeToSet = "/"+curOrg.getName();
|
if (gm.isRootVO(groupId)) {
|
||||||
} else if (isVO(curOrg)) {
|
scopeToSet = "/"+PortalContext.getConfiguration().getInfrastructureName();
|
||||||
scopeToSet = "/"+curOrg.getParentOrganization().getName()+"/"+curOrg.getName();
|
}
|
||||||
} else { //is a VRE
|
else if (gm.isVO(groupId) || gm.isVRE(groupId)) {
|
||||||
Organization vo = curOrg.getParentOrganization();
|
scopeToSet = gm.getInfrastructureScope(groupId);
|
||||||
scopeToSet = "/"+vo.getParentOrganization().getName()+"/"+vo.getName()+"/"+curOrg.getName();
|
isInfrastructureScope = true;
|
||||||
}
|
} else {
|
||||||
} else { //
|
|
||||||
scopeToSet = "PORTAL";
|
scopeToSet = "PORTAL";
|
||||||
_log.info("Not an organization, scopeToSet set to PORTAL");
|
_log.info("Not a VO or VRE, scopeToSet set to PORTAL");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -108,18 +100,17 @@ public class ScopeHelper {
|
||||||
|
|
||||||
|
|
||||||
request.getPortletSession().setAttribute(username_attr, username, PortletSession.APPLICATION_SCOPE);
|
request.getPortletSession().setAttribute(username_attr, username, PortletSession.APPLICATION_SCOPE);
|
||||||
request.getPortletSession().setAttribute(CURR_ORG, curOrg, PortletSession.APPLICATION_SCOPE);
|
request.getPortletSession().setAttribute(CURR_RESEARCH_ENV, currentGroup, PortletSession.APPLICATION_SCOPE);
|
||||||
|
|
||||||
|
|
||||||
if (curOrg != null) {
|
if (isInfrastructureScope) {
|
||||||
SessionManager.getInstance().getASLSession(sessionID, username).setGroupModelInfos(curOrg.getName(), curOrg.getOrganizationId());
|
SessionManager.getInstance().getASLSession(sessionID, username).setGroupModelInfos(currentGroup.getGroupName(), groupId);
|
||||||
SessionManager.getInstance().getASLSession(sessionID, username).setScope(scopeToSet);
|
SessionManager.getInstance().getASLSession(sessionID, username).setScope(scopeToSet);
|
||||||
_log.info("CONTEXT INITIALIZED CORRECTLY SCOPE: " + scopeToSet);
|
_log.info("CONTEXT INITIALIZED CORRECTLY SCOPE: " + scopeToSet);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
String rootVO = getRootConfigFromGCore();
|
scopeToSet = "/"+PortalContext.getConfiguration().getInfrastructureName();
|
||||||
_log.info("CONTEXT INITIALIZED CORRECTLY OUTSIDE VREs, setting rootvo as scope: " + rootVO);
|
_log.info("CONTEXT INITIALIZED CORRECTLY OUTSIDE VREs, set rootvo as scope: " + scopeToSet);
|
||||||
scopeToSet = "/"+rootVO;
|
|
||||||
SessionManager.getInstance().getASLSession(sessionID, username).setScope(scopeToSet);
|
SessionManager.getInstance().getASLSession(sessionID, username).setScope(scopeToSet);
|
||||||
}
|
}
|
||||||
//add the social information needed by apps
|
//add the social information needed by apps
|
||||||
|
@ -132,9 +123,12 @@ public class ScopeHelper {
|
||||||
SessionManager.getInstance().getASLSession(sessionID, username).setUserEmailAddress(email);
|
SessionManager.getInstance().getASLSession(sessionID, username).setUserEmailAddress(email);
|
||||||
SessionManager.getInstance().getASLSession(sessionID, username).setUserAvatarId(thumbnailURL);
|
SessionManager.getInstance().getASLSession(sessionID, username).setUserAvatarId(thumbnailURL);
|
||||||
SessionManager.getInstance().getASLSession(sessionID, username).setUserGender(isMale? GenderType.MALE : GenderType.FEMALE);
|
SessionManager.getInstance().getASLSession(sessionID, username).setUserGender(isMale? GenderType.MALE : GenderType.FEMALE);
|
||||||
|
|
||||||
setAuthorizationToken(SessionManager.getInstance().getASLSession(sessionID, username));
|
setAuthorizationToken(SessionManager.getInstance().getASLSession(sessionID, username));
|
||||||
|
} catch (UserManagementSystemException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (GroupRetrievalFault e) {
|
||||||
|
e.printStackTrace();
|
||||||
} catch (PortalException e) {
|
} catch (PortalException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (SystemException e) {
|
} catch (SystemException e) {
|
||||||
|
@ -144,26 +138,26 @@ public class ScopeHelper {
|
||||||
}
|
}
|
||||||
private final static String DEFAULT_ROLE = "OrganizationMember";
|
private final static String DEFAULT_ROLE = "OrganizationMember";
|
||||||
private final static String TEST_USER = "test.user";
|
private final static String TEST_USER = "test.user";
|
||||||
|
|
||||||
private static void setAuthorizationToken(ASLSession session) {
|
private static void setAuthorizationToken(ASLSession session) {
|
||||||
|
//TODO:
|
||||||
String username = session.getUsername();
|
// String username = session.getUsername();
|
||||||
_log.debug("Generating token");
|
// _log.debug("Generating token");
|
||||||
String managerName = "lucio.lelii";
|
// String managerName = "lucio.lelii";
|
||||||
if (username.compareTo(TEST_USER) == 0)
|
// if (username.compareTo(TEST_USER) == 0)
|
||||||
return;
|
// return;
|
||||||
String scope = session.getScope();
|
// String scope = session.getScope();
|
||||||
ScopeProvider.instance.set(scope);
|
// ScopeProvider.instance.set(scope);
|
||||||
_log.debug("calling service token on scope " + scope);
|
// _log.debug("calling service token on scope " + scope);
|
||||||
List<String> userRoles = new ArrayList<>();
|
// List<String> userRoles = new ArrayList<>();
|
||||||
userRoles.add(DEFAULT_ROLE);
|
// userRoles.add(DEFAULT_ROLE);
|
||||||
if (username.compareTo("lucio.lelii")==0)
|
// if (username.compareTo("lucio.lelii")==0)
|
||||||
userRoles.add("VRE-Manager");
|
// userRoles.add("VRE-Manager");
|
||||||
session.setSecurityToken(null);
|
// session.setSecurityToken(null);
|
||||||
String token = authorizationService().build().generate(session.getUsername(), userRoles);
|
// String token = authorizationService().build().generate(session.getUsername(), userRoles);
|
||||||
_log.debug("received token: "+token);
|
// _log.debug("received token: "+token);
|
||||||
session.setSecurityToken(token);
|
// session.setSecurityToken(token);
|
||||||
_log.info("Security token set in session for: "+username + " on " + scope);
|
// _log.info("Security token set in session for: "+username + " on " + scope);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* read the root VO name from a property file and retuns it
|
* read the root VO name from a property file and retuns it
|
||||||
|
@ -174,7 +168,7 @@ public class ScopeHelper {
|
||||||
String toReturn = "";
|
String toReturn = "";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String propertyfile = OrganizationsUtil.getTomcatFolder()+"conf/gcube-data.properties";
|
String propertyfile = SiteManagerUtil.getTomcatFolder()+"conf/gcube-data.properties";
|
||||||
File propsFile = new File(propertyfile);
|
File propsFile = new File(propertyfile);
|
||||||
FileInputStream fis = new FileInputStream(propsFile);
|
FileInputStream fis = new FileInputStream(propsFile);
|
||||||
props.load( fis);
|
props.load( fis);
|
||||||
|
@ -193,26 +187,13 @@ public class ScopeHelper {
|
||||||
}
|
}
|
||||||
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
|
* return the infrastructure name
|
||||||
*/
|
*/
|
||||||
public static String getRootConfigFromGCore() {
|
public static String getRootConfigFromGCore() {
|
||||||
return PortalContext.getConfiguration().getInfrastructureName();
|
return PortalContext.getConfiguration().getInfrastructureName();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return one of the Administrators Username from LiferayDB
|
* return one of the Administrators Username from LiferayDB
|
||||||
*/
|
*/
|
||||||
|
@ -221,10 +202,16 @@ public class ScopeHelper {
|
||||||
String toReturn = "";
|
String toReturn = "";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Role adminRole = RoleLocalServiceUtil.getRole(OrganizationsUtil.getCompany().getCompanyId(),"Administrator");
|
Role adminRole = RoleLocalServiceUtil.getRole(SiteManagerUtil.getCompany().getCompanyId(),"Administrator");
|
||||||
List<User> adminUsers = UserLocalServiceUtil.getRoleUsers(adminRole.getRoleId());
|
List<User> adminUsers = UserLocalServiceUtil.getRoleUsers(adminRole.getRoleId());
|
||||||
if (adminUsers != null && adminUsers.size() > 0)
|
if (adminUsers != null && adminUsers.size() > 0) {
|
||||||
toReturn = adminUsers.get(0).getScreenName();
|
for (User user : adminUsers) {
|
||||||
|
if (user.isActive()) {
|
||||||
|
toReturn = adminUsers.get(0).getScreenName();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
_log.warn("No users with Administrator Role in this portal!");
|
_log.warn("No users with Administrator Role in this portal!");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue