diff --git a/distro/descriptor.xml b/distro/descriptor.xml
index c468f13..308f7f9 100644
--- a/distro/descriptor.xml
+++ b/distro/descriptor.xml
@@ -15,8 +15,6 @@
README
LICENSE
- INSTALL
- MAINTAINERS
changelog.xml
755
@@ -39,10 +37,5 @@
/${artifactId}
-
-
- /${artifactId}
- true
-
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index bdf24c2..e24431d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
org.gcube.portal
custom-portal-handler
- 1.8.0-SNAPSHOT
+ 2.0.0-SNAPSHOT
jar
Custom Portal Handler
@@ -26,7 +26,7 @@
distro
1.7
1.7
-
+ 6.2.5
UTF-8
UTF-8
@@ -55,6 +55,7 @@
org.gcube.common.portal
portal-manager
+ [2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)
provided
@@ -65,10 +66,31 @@
org.gcube.dvos
usermanagement-core
+ [2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)
com.liferay.portal
portal-service
+ ${liferay.version}
+ provided
+
+
+ com.liferay.portal
+ util-bridges
+ ${liferay.version}
+ provided
+
+
+ com.liferay.portal
+ util-taglib
+ ${liferay.version}
+ provided
+
+
+ com.liferay.portal
+ util-java
+ ${liferay.version}
+ provided
javax.portlet
diff --git a/src/main/java/org/gcube/portal/custom/communitymanager/GCubeSiteManager.java b/src/main/java/org/gcube/portal/custom/communitymanager/GCubeSiteManager.java
new file mode 100644
index 0000000..7239214
--- /dev/null
+++ b/src/main/java/org/gcube/portal/custom/communitymanager/GCubeSiteManager.java
@@ -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);
+
+}
diff --git a/src/main/java/org/gcube/portal/custom/communitymanager/PortletsIdManager.java b/src/main/java/org/gcube/portal/custom/communitymanager/PortletsIdManager.java
index 34bfcc0..ec25f0f 100644
--- a/src/main/java/org/gcube/portal/custom/communitymanager/PortletsIdManager.java
+++ b/src/main/java/org/gcube/portal/custom/communitymanager/PortletsIdManager.java
@@ -128,7 +128,7 @@ public final class PortletsIdManager {
Properties props = new Properties();
String toReturn = "";
try {
- String propertyfile = OrganizationsUtil.getTomcatFolder()+"conf/gcube-portlets.properties";
+ String propertyfile = SiteManagerUtil.getTomcatFolder()+"conf/gcube-portlets.properties";
File propsFile = new File(propertyfile);
FileInputStream fis = new FileInputStream(propsFile);
props.load( fis );
diff --git a/src/main/java/org/gcube/portal/custom/communitymanager/OrganizationsUtil.java b/src/main/java/org/gcube/portal/custom/communitymanager/SiteManagerUtil.java
similarity index 78%
rename from src/main/java/org/gcube/portal/custom/communitymanager/OrganizationsUtil.java
rename to src/main/java/org/gcube/portal/custom/communitymanager/SiteManagerUtil.java
index 8a9018d..41c422d 100644
--- a/src/main/java/org/gcube/portal/custom/communitymanager/OrganizationsUtil.java
+++ b/src/main/java/org/gcube/portal/custom/communitymanager/SiteManagerUtil.java
@@ -4,17 +4,15 @@ 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 org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
import com.liferay.portal.kernel.exception.PortalException;
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.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 {
+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)));
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
@@ -288,34 +253,13 @@ public class OrganizationsUtil {
public boolean addUserToGroup(long groupid, String username) {
UserManager uman = new LiferayUserManager();
try {
- uman.assignUserToGroup(""+groupid, uman.getUserId(username));
+ 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
*/
@@ -325,7 +269,7 @@ public class OrganizationsUtil {
String toReturn = "";
try {
- String propertyfile = OrganizationsUtil.getTomcatFolder()+"conf/gcube-data.properties";
+ String propertyfile = SiteManagerUtil.getTomcatFolder()+"conf/gcube-data.properties";
File propsFile = new File(propertyfile);
FileInputStream fis = new FileInputStream(propsFile);
props.load( fis);
@@ -340,20 +284,5 @@ public class OrganizationsUtil {
_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/impl/CommunityManagerImpl.java b/src/main/java/org/gcube/portal/custom/communitymanager/impl/CommunityManagerImpl.java
deleted file mode 100644
index f9c875a..0000000
--- a/src/main/java/org/gcube/portal/custom/communitymanager/impl/CommunityManagerImpl.java
+++ /dev/null
@@ -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 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/GCubeSiteManagerImpl.java
similarity index 70%
rename from src/main/java/org/gcube/portal/custom/communitymanager/impl/OrganizationManagerImpl.java
rename to src/main/java/org/gcube/portal/custom/communitymanager/impl/GCubeSiteManagerImpl.java
index 1bbc0d7..1ee081e 100644
--- a/src/main/java/org/gcube/portal/custom/communitymanager/impl/OrganizationManagerImpl.java
+++ b/src/main/java/org/gcube/portal/custom/communitymanager/impl/GCubeSiteManagerImpl.java
@@ -2,15 +2,14 @@ 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 java.util.Arrays;
import java.util.List;
-import org.gcube.portal.custom.communitymanager.OrganizationsUtil;
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.GCUBEPortlet;
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.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 org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
+import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager;
+import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
+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.exception.PortalException;
@@ -31,14 +31,14 @@ 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.Organization;
-import com.liferay.portal.model.Role;
import com.liferay.portal.model.Theme;
import com.liferay.portal.model.User;
+import com.liferay.portal.security.auth.PrincipalThreadLocal;
import com.liferay.portal.security.permission.PermissionChecker;
import com.liferay.portal.security.permission.PermissionCheckerFactoryUtil;
import com.liferay.portal.security.permission.PermissionThreadLocal;
+import com.liferay.portal.service.GroupLocalServiceUtil;
import com.liferay.portal.service.LayoutSetLocalServiceUtil;
-import com.liferay.portal.service.OrganizationLocalServiceUtil;
import com.liferay.portal.service.ThemeLocalServiceUtil;
import com.liferay.portal.service.UserLocalServiceUtil;
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
*
*/
-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
*/
- 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";
public static List getVirtualGroups() throws PortalException, SystemException {
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");
return Arrays.asList(groups);
} 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 {
- long companyId = OrganizationsUtil.getCompany().getCompanyId();
_log.debug("Setting Thread Permission");
- User user = UserLocalServiceUtil.getUserByScreenName(companyId, ScopeHelper.getAdministratorUsername());
- PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user, false);
- PermissionThreadLocal.setPermissionChecker(permissionChecker);
- _log.debug("Setting Permission ok!");
+ long userId = LiferayUserManager.getAdmin().getUserId();
+ PrincipalThreadLocal.setName(userId);
+ PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(UserLocalServiceUtil.getUser(userId), false);
+ 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));
return null;
} else {
- String[] values = (String[]) organization.getExpandoBridge().getAttribute(CATEGORY);
+ String[] values = (String[]) site.getExpandoBridge().getAttribute(CATEGORY);
return values[0];
}
} 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) {
Group voToCreate = null;
try {
- //create the Group
- User creator = validateUser(username);
GroupManager gm = new LiferayGroupManager();
- GroupModel groupModel = null;
+ GCubeGroup 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();
+ if (parentid == 0)
+ groupModel = gm.createRootVO(voName, voDesc);
+ else
+ groupModel = gm.createVO(voName, parentid, voDesc);
+ long groupModelid = groupModel.getGroupId();
+ voToCreate = GroupLocalServiceUtil.getGroup(groupModelid);
//associate the layout to the group
createLayout(voToCreate, validateUser(username), siteLayout);
@@ -120,30 +120,36 @@ public class OrganizationManagerImpl extends OrganizationsUtil {
_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);
+ InputStream is = GCubeSiteManagerImpl.class.getResourceAsStream(SITE_DEFAULT_LOGO);
+ //FileInputStream fis = new FileInputStream(writeTempLogo(is));
+ LayoutSetLocalServiceUtil.updateLogo(voToCreate.getGroupId(), true, true, is);
_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(username));
- Role created = OrganizationsUtil.createRole("VO-Admin", voName, uid);
- _log.debug("Admin Role VO-Admin Created Successfully");
-
- uman.assignUserToGroup(""+voToCreate.getClassPK(), ""+uid);
+ long uid = uman.getUserId(username);
+
+
+ uman.assignUserToGroup(groupModel.getGroupId(), uid);
_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();
- 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 ...");
} catch (Exception e) {
e.printStackTrace();
}
- _log.info("Created" + voName + " with id " + voToCreate.getOrganizationId());
- return voToCreate.getOrganizationId();
+ _log.info("Created" + voName + " with id " + voToCreate.getGroupId());
+ return voToCreate.getGroupId();
}
@@ -153,7 +159,7 @@ public class OrganizationManagerImpl extends OrganizationsUtil {
* @param voDesc -
* @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);
}
/**
@@ -162,53 +168,54 @@ public class OrganizationManagerImpl extends OrganizationsUtil {
* @param voDesc -
* @return the organizationid of the created VO
*/
- public static long createVRE(String username, String voName, String voDesc, long parentid, GCUBESiteLayout siteLayout, String themeid) {
-
- Group voToCreate = null;
- try {
- //create the Group
- User creator = validateUser(username);
+ public static long createVRE(String username, String vreName, String voDesc, long parentid, GCUBESiteLayout siteLayout, String themeid) {
+ Group vreToCreate = null;
+ try {
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();
-
+ GCubeGroup groupModel = null;
+ _log.info("createVRE " + vreName + " with parentid " + parentid);
+ groupModel = gm.createVRE(vreName, parentid, voDesc);
+ long groupModelid = groupModel.getGroupId();
+ vreToCreate = GroupLocalServiceUtil.getGroup(groupModelid);
//associate the layout to the group
- createLayout(voToCreate, validateUser(username), siteLayout);
+ createLayout(vreToCreate, validateUser(username), siteLayout);
Theme themeToApply = ThemeLocalServiceUtil.getTheme(getCompany().getCompanyId(), themeid, false);
//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");
//update logo
- InputStream is = OrganizationManagerImpl.class.getResourceAsStream(ORGANIZATION_DEFAULT_LOGO);
- FileInputStream fis = new FileInputStream(writeTempLogo(is));
- LayoutSetLocalServiceUtil.updateLogo(voToCreate.getGroupId(), true, true, fis);
+ InputStream is = GCubeSiteManagerImpl.class.getResourceAsStream(SITE_DEFAULT_LOGO);
+ //FileInputStream fis = new FileInputStream(writeTempLogo(is));
+ 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
UserManager uman = new LiferayUserManager();
- long uid = Long.parseLong(uman.getUserId(username));
- Role created = OrganizationsUtil.createRole("VRE-Manager", voName, uid);
- _log.debug("Admin Role VRE-Manager Created Successfully");
+ long uid = uman.getUserId(username);
+
+
+ uman.assignUserToGroup(groupModel.getGroupId(), uid);
+ _log.debug("Added user " + username + " to group " + vreName + " with Success");
- uman.assignUserToGroup(""+voToCreate.getClassPK(), ""+uid);
- _log.debug("Added user " + username + " to group " + voName + " with Success");
-
- _log.debug("Assigning Role: VRE-Manager");
+ _log.debug("Assigning Role: " + GCubeRole.VRE_MANAGER_LABEL);
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 ...");
-
} catch (Exception e) {
e.printStackTrace();
}
- _log.info("Created" + voName + " with id " + voToCreate.getOrganizationId());
- return voToCreate.getOrganizationId();
+ _log.info("Created" + vreName + " with id " + vreToCreate.getGroupId());
+ 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 {
GCUBESiteLayout siteLayout = null;
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,
new GCUBEPortlet("gCube Loggedin", PortletsIdManager.getLRPortletId(PortletsIdManager.GCUBE_LOGGEDIN))));
@@ -281,14 +288,14 @@ public class OrganizationManagerImpl extends OrganizationsUtil {
}
try {
- long companyId = OrganizationsUtil.getCompany().getCompanyId();
+ long companyId = SiteManagerUtil.getCompany().getCompanyId();
_log.trace("Setting Thread Permission");
User user = UserLocalServiceUtil.getUserByScreenName(companyId, ScopeHelper.getAdministratorUsername());
PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user, false);
PermissionThreadLocal.setPermissionChecker(permissionChecker);
_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("")) {
_log.trace("Attribute " + attrToCheck + " must be initialized");
setOrgCustomAttribute(username, currOrg, attrToCheck);
@@ -328,7 +335,7 @@ public class OrganizationManagerImpl extends OrganizationsUtil {
return;
}
try {
- long companyId = OrganizationsUtil.getCompany().getCompanyId();
+ long companyId = SiteManagerUtil.getCompany().getCompanyId();
_log.trace("Setting Thread Permission");
User user = UserLocalServiceUtil.getUserByScreenName(companyId, ScopeHelper.getAdministratorUsername());
PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user, false);
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
index 5950b41..46c1038 100644
Binary files a/src/main/java/org/gcube/portal/custom/communitymanager/resources/default_logo.png and b/src/main/java/org/gcube/portal/custom/communitymanager/resources/default_logo.png differ
diff --git a/src/main/java/org/gcube/portal/custom/scopemanager/scopehelper/ScopeHelper.java b/src/main/java/org/gcube/portal/custom/scopemanager/scopehelper/ScopeHelper.java
index 2aa4df2..909bc69 100644
--- a/src/main/java/org/gcube/portal/custom/scopemanager/scopehelper/ScopeHelper.java
+++ b/src/main/java/org/gcube/portal/custom/scopemanager/scopehelper/ScopeHelper.java
@@ -1,11 +1,8 @@
package org.gcube.portal.custom.scopemanager.scopehelper;
-import static org.gcube.common.authorization.client.Constants.authorizationService;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.List;
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.util.GenderType;
import org.gcube.common.portal.PortalContext;
-import org.gcube.common.scope.api.ScopeProvider;
-import org.gcube.portal.custom.communitymanager.OrganizationsUtil;
+import org.gcube.portal.custom.communitymanager.SiteManagerUtil;
+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.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.Role;
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.UserLocalServiceUtil;
import com.liferay.portal.theme.ThemeDisplay;
@@ -38,20 +35,20 @@ import com.liferay.portal.theme.ThemeDisplay;
public class ScopeHelper {
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_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 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";
@@ -72,30 +69,25 @@ public class ScopeHelper {
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;
-
+ GCubeGroup currentGroup = 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);
+ GroupManager gm = new LiferayGroupManager();
+ long groupId = themeDisplay.getLayout().getGroup().getGroupId();
+ currentGroup = gm.getGroup(groupId);
- 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 { //
+ boolean isInfrastructureScope = false;
+ if (gm.isRootVO(groupId)) {
+ scopeToSet = "/"+PortalContext.getConfiguration().getInfrastructureName();
+ }
+ else if (gm.isVO(groupId) || gm.isVRE(groupId)) {
+ scopeToSet = gm.getInfrastructureScope(groupId);
+ isInfrastructureScope = true;
+ } else {
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(CURR_ORG, curOrg, PortletSession.APPLICATION_SCOPE);
+ request.getPortletSession().setAttribute(CURR_RESEARCH_ENV, currentGroup, PortletSession.APPLICATION_SCOPE);
- if (curOrg != null) {
- SessionManager.getInstance().getASLSession(sessionID, username).setGroupModelInfos(curOrg.getName(), curOrg.getOrganizationId());
+ if (isInfrastructureScope) {
+ SessionManager.getInstance().getASLSession(sessionID, username).setGroupModelInfos(currentGroup.getGroupName(), groupId);
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;
+ scopeToSet = "/"+PortalContext.getConfiguration().getInfrastructureName();
+ _log.info("CONTEXT INITIALIZED CORRECTLY OUTSIDE VREs, set rootvo as scope: " + scopeToSet);
SessionManager.getInstance().getASLSession(sessionID, username).setScope(scopeToSet);
}
//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).setUserAvatarId(thumbnailURL);
SessionManager.getInstance().getASLSession(sessionID, username).setUserGender(isMale? GenderType.MALE : GenderType.FEMALE);
-
+
setAuthorizationToken(SessionManager.getInstance().getASLSession(sessionID, username));
-
+ } catch (UserManagementSystemException e) {
+ e.printStackTrace();
+ } catch (GroupRetrievalFault e) {
+ e.printStackTrace();
} catch (PortalException e) {
e.printStackTrace();
} catch (SystemException e) {
@@ -144,26 +138,26 @@ public class ScopeHelper {
}
private final static String DEFAULT_ROLE = "OrganizationMember";
private final static String TEST_USER = "test.user";
-
+
private static void setAuthorizationToken(ASLSession session) {
-
- String username = session.getUsername();
- _log.debug("Generating token");
- String managerName = "lucio.lelii";
- if (username.compareTo(TEST_USER) == 0)
- return;
- String scope = session.getScope();
- ScopeProvider.instance.set(scope);
- _log.debug("calling service token on scope " + scope);
- List userRoles = new ArrayList<>();
- userRoles.add(DEFAULT_ROLE);
- if (username.compareTo("lucio.lelii")==0)
- userRoles.add("VRE-Manager");
- session.setSecurityToken(null);
- String token = authorizationService().build().generate(session.getUsername(), userRoles);
- _log.debug("received token: "+token);
- session.setSecurityToken(token);
- _log.info("Security token set in session for: "+username + " on " + scope);
+ //TODO:
+ // String username = session.getUsername();
+ // _log.debug("Generating token");
+ // String managerName = "lucio.lelii";
+ // if (username.compareTo(TEST_USER) == 0)
+ // return;
+ // String scope = session.getScope();
+ // ScopeProvider.instance.set(scope);
+ // _log.debug("calling service token on scope " + scope);
+ // List userRoles = new ArrayList<>();
+ // userRoles.add(DEFAULT_ROLE);
+ // if (username.compareTo("lucio.lelii")==0)
+ // userRoles.add("VRE-Manager");
+ // session.setSecurityToken(null);
+ // String token = authorizationService().build().generate(session.getUsername(), userRoles);
+ // _log.debug("received token: "+token);
+ // session.setSecurityToken(token);
+ // _log.info("Security token set in session for: "+username + " on " + scope);
}
/**
* read the root VO name from a property file and retuns it
@@ -174,7 +168,7 @@ public class ScopeHelper {
String toReturn = "";
try {
- String propertyfile = OrganizationsUtil.getTomcatFolder()+"conf/gcube-data.properties";
+ String propertyfile = SiteManagerUtil.getTomcatFolder()+"conf/gcube-data.properties";
File propsFile = new File(propertyfile);
FileInputStream fis = new FileInputStream(propsFile);
props.load( fis);
@@ -193,26 +187,13 @@ public class ScopeHelper {
}
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() {
return PortalContext.getConfiguration().getInfrastructureName();
}
-
+
/**
* return one of the Administrators Username from LiferayDB
*/
@@ -221,10 +202,16 @@ public class ScopeHelper {
String toReturn = "";
try {
- Role adminRole = RoleLocalServiceUtil.getRole(OrganizationsUtil.getCompany().getCompanyId(),"Administrator");
+ Role adminRole = RoleLocalServiceUtil.getRole(SiteManagerUtil.getCompany().getCompanyId(),"Administrator");
List adminUsers = UserLocalServiceUtil.getRoleUsers(adminRole.getRoleId());
- if (adminUsers != null && adminUsers.size() > 0)
- toReturn = adminUsers.get(0).getScreenName();
+ if (adminUsers != null && adminUsers.size() > 0) {
+ for (User user : adminUsers) {
+ if (user.isActive()) {
+ toReturn = adminUsers.get(0).getScreenName();
+ break;
+ }
+ }
+ }
else
_log.warn("No users with Administrator Role in this portal!");
}