Migrated to Liferay 6.2

Updated pom version at 1.7.0

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-sharing-widget@128923 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2016-05-31 14:35:57 +00:00
parent e06cccb40f
commit 2604f4daae
8 changed files with 321 additions and 372 deletions

View File

@ -14,7 +14,7 @@
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>workspace-sharing-widget</artifactId>
<packaging>jar</packaging>
<version>1.6.0-SNAPSHOT</version>
<version>1.7.0-SNAPSHOT</version>
<name>gCube Workspace Sharing Widget</name>
<description>
gCube Workspace Sharing Widget allows users to share gCube Workspace items

View File

@ -30,7 +30,7 @@ import org.gcube.portlets.widgets.workspacesharingwidget.shared.WorkspaceACL;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.WorkspaceACL.USER_TYPE;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.system.VO;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.system.VRE;
import org.gcube.vomanagement.usermanagement.model.UserModel;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -230,7 +230,7 @@ public class GWTWorkspaceSharingBuilder {
* @throws InternalErrorException the internal error exception
*/
public List<InfoContactModel> buildGXTListContactsModelFromUserModel(
List<UserModel> listUsers) throws InternalErrorException {
List<GCubeUser> listUsers) throws InternalErrorException {
List<InfoContactModel> listContactsModel = new ArrayList<InfoContactModel>();
@ -241,7 +241,7 @@ public class GWTWorkspaceSharingBuilder {
+ listUsers.size());
logger.trace("Building list contact model list user model");
for (UserModel userModel : listUsers) {
for (GCubeUser userModel : listUsers) {
String fullName = userModel.getFullname();
if (fullName != null && !fullName.isEmpty())

View File

@ -4,6 +4,8 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.common.homelibary.model.items.type.WorkspaceItemType;
import org.gcube.common.homelibrary.home.HomeLibrary;
@ -34,7 +36,7 @@ import org.gcube.portlets.widgets.workspacesharingwidget.shared.SessionExpiredEx
import org.gcube.portlets.widgets.workspacesharingwidget.shared.WorkspaceACL;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.system.VO;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.system.VRE;
import org.gcube.vomanagement.usermanagement.model.UserModel;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -79,11 +81,12 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
/**
* Gets the notification producer.
*
* @param request the request
* @return the notification producer
*/
protected NotificationsProducer getNotificationProducer(){
protected NotificationsProducer getNotificationProducer(HttpServletRequest request){
return WsUtil.getNotificationProducer(WsUtil.getAslSession(this.getThreadLocalRequest().getSession()));
return WsUtil.getNotificationProducer(WsUtil.getAslSession(this.getThreadLocalRequest().getSession()), request);
}
/**
@ -137,7 +140,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
logger.info("Liferay User Manager getting list users by group: "+groupId);
List<InfoContactModel> listContactsModel = builder.buildGXTListContactsModelFromUserModel(userManag.listUsersByGroup(groupId));
*/
List<UserModel> users = UserUtil.getOrganizationUsers(aslSession.getScope());
List<GCubeUser> users = UserUtil.getOrganizationUsers(aslSession.getScope());
if(users==null)
throw new Exception("An error occurred on recovering users from Portal, try again later");
@ -427,7 +430,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
setACLs(sharedFolder.getId(), listLogin, acl.getId().toString());
if(created){
NotificationsProducer np = getNotificationProducer();
NotificationsProducer np = getNotificationProducer(this.getThreadLocalRequest());
if(!sourceFolderIsShared) {//if source folder is not already shared
//TODO ADD NOTIFICATION

View File

@ -3,9 +3,10 @@ package org.gcube.portlets.widgets.workspacesharingwidget.server.notifications;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.applicationsupportlayer.social.NotificationsManager;
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
@ -33,11 +34,13 @@ public class NotificationsProducer {
/**
* Instantiates a new notifications producer.
*
* @param aslSession
* @param aslSession the asl session
* @param request the request
*/
public NotificationsProducer(ASLSession aslSession) {
this.notificationsMng = WsUtil.getNotificationManager(aslSession);
public NotificationsProducer(ASLSession aslSession, HttpServletRequest request) {
this.notificationsMng = WsUtil.getNotificationManager(aslSession, request);
this.aslSession = aslSession;
this.userId = aslSession.getUsername();
}
@ -316,7 +319,7 @@ public class NotificationsProducer {
//DEBUG
// System.out.println("Sending notification to user "+infoContactModel.getLogin() +" un shared folder "+unSharedFolder.getName());
boolean notify = notificationsMng.notifyFolderRemovedUser(infoContactModel.getLogin(), (WorkspaceSharedFolder) unSharedFolder);
boolean notify = notificationsMng.notifyFolderRemovedUser(infoContactModel.getLogin(), unSharedFolder);
if(!notify)
logger.error("An error occured when notifies user: "+infoContactModel.getLogin());
@ -639,7 +642,7 @@ public class NotificationsProducer {
System.out.println("End print contacts");
}
public static void main(String[] args) throws Exception
/*public static void main(String[] args) throws Exception
{
String sessionID = "1";
String user = "francesco.mangiacrapa";
@ -657,8 +660,6 @@ public class NotificationsProducer {
NotificationsProducer feeder = new NotificationsProducer(session);
}
}*/
}

View File

@ -6,6 +6,7 @@ package org.gcube.portlets.widgets.workspacesharingwidget.server.notifications;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.gcube.common.homelibary.model.items.type.WorkspaceItemType;
@ -29,13 +30,16 @@ public class NotificationsUtil {
protected static Logger logger = LoggerFactory.getLogger(NotificationsUtil.class);
/**
* Send a notification if an item is added or updated to sharing folder
* @param httpSession
* @param sourceItem
* @param sourceSharedId
* @param folderDestinationItem
* Send a notification if an item is added or updated to sharing folder.
*
* @param request the request
* @param httpSession the http session
* @param sourceItem the source item
* @param sourceSharedId the source shared id
* @param folderDestinationItem the folder destination item
* @param isOverwrite the is overwrite
*/
public static void checkSendNotifyChangedItemToShare(HttpSession httpSession, final WorkspaceItem sourceItem, final String sourceSharedId, final WorkspaceItem folderDestinationItem, boolean isOverwrite) {
public static void checkSendNotifyChangedItemToShare(HttpServletRequest request, HttpSession httpSession, final WorkspaceItem sourceItem, final String sourceSharedId, final WorkspaceItem folderDestinationItem, boolean isOverwrite) {
logger.info("checkSendNotifyAddItemToShare");
@ -63,7 +67,7 @@ public class NotificationsUtil {
WorkspaceItem destinationSharedFolder = workspace.getItem(folderDestinationItem.getIdSharedFolder());
NotificationsProducer np = new NotificationsProducer(WsUtil.getAslSession(httpSession));
NotificationsProducer np = new NotificationsProducer(WsUtil.getAslSession(httpSession), request);
//SWITCH BEETWEEN ADDED OR UPDATED
if(!isOverwrite)
@ -140,7 +144,7 @@ public class NotificationsUtil {
* @param oldItemId
* @param sourceFolderSharedId
*/
public static void checkSendNotifyRemoveItemToShare(HttpSession httpSession, final boolean sourceItemIsShared, final String oldItemName, String oldItemId, final String sourceFolderSharedId) {
public static void checkSendNotifyRemoveItemToShare(HttpServletRequest request, HttpSession httpSession, final boolean sourceItemIsShared, final String oldItemName, String oldItemId, final String sourceFolderSharedId) {
logger.info("checkNotifyRemoveItemToShare:");
@ -184,7 +188,7 @@ public class NotificationsUtil {
//System.out.println(" name sourceSharedFolder: "+ sourceSharedFolder.getName());
NotificationsProducer np = new NotificationsProducer(WsUtil.getAslSession(httpSession));
NotificationsProducer np = new NotificationsProducer(WsUtil.getAslSession(httpSession), request);
if(sourceSharedFolder instanceof WorkspaceSharedFolder)
np.notifyRemovedItemToSharing(listContacts, oldItemName, (WorkspaceSharedFolder) sourceSharedFolder);

View File

@ -3,29 +3,18 @@ package org.gcube.portlets.widgets.workspacesharingwidget.server.util;
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import org.gcube.common.resources.gcore.GenericResource;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.common.scope.impl.ScopeBean.Type;
import org.gcube.portal.custom.communitymanager.OrganizationsUtil;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.system.UserBelonging;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.system.VO;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.system.VRE;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayUserManager;
import org.gcube.vomanagement.usermanagement.model.UserModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -53,73 +42,6 @@ public class LoginServiceUtil {
private static final Logger _log = LoggerFactory.getLogger(LoginServiceUtil.class);
/**
*
* @param screenName
* @param organizatioId
* @return
*/
protected static boolean checkPending(String screenName, long organizationId) {
try {
for (UserModel userModel : new LiferayUserManager().listPendingUsersByGroup(""+organizationId))
if (userModel.getScreenName().compareTo(screenName) == 0) return true;
} catch (UserManagementSystemException e) {
e.printStackTrace();
} catch (GroupRetrievalFault e) {
e.printStackTrace();
} catch (UserRetrievalFault e) {
e.printStackTrace();
}
return false;
}
/**
* add a property to gcube-data.properties for root vo, it make the login portlet understand the installation was setup already
* @param rootVoName .
*/
protected static void appendRootOrganizationName(String rootVoName) {
Properties props = new Properties();
try {
String propertyfile = OrganizationsUtil.getTomcatFolder()+"conf/gcube-data.properties";
File propsFile = new File(propertyfile);
FileInputStream fis = new FileInputStream(propsFile);
props.load( fis);
props.setProperty(ROOT_ORG, rootVoName);
FileOutputStream fos = new FileOutputStream(propsFile);
props.store(fos, null);
}
//catch exception in case properties file does not exist
catch(IOException e) {
e.printStackTrace();
}
_log.info("Added property Root VO Name: " + rootVoName );
}
/**
* read the root VO name from a property file and retuns it
*/
protected static String getRootOrganizationName() {
//get the portles to look for from the property file
Properties props = new Properties();
String toReturn = "";
try {
String propertyfile = OrganizationsUtil.getTomcatFolder()+"conf/gcube-data.properties";
File propsFile = new File(propertyfile);
FileInputStream fis = new FileInputStream(propsFile);
props.load( fis);
toReturn = props.getProperty(ROOT_ORG);
}
//catch exception in case properties file does not exist
catch(IOException e) {
toReturn = "gcube";
_log.error("gcube-data.properties file not found under $CATALINA_HOME/conf dir, returning default VO Name " + toReturn);
return toReturn;
}
_log.debug("Returning Root VO Name: " + toReturn );
return toReturn;
}
/**
* simply returns fake VOS for debugging purpose
* @return

View File

@ -1,3 +1,6 @@
/*
*
*/
package org.gcube.portlets.widgets.workspacesharingwidget.server.util;
import java.util.ArrayList;
@ -8,12 +11,11 @@ import org.gcube.common.scope.impl.ScopeBean.Type;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel;
import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.UserManager;
import org.gcube.vomanagement.usermanagement.exception.UserManagementPortalException;
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayGroupManager;
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayUserManager;
import org.gcube.vomanagement.usermanagement.model.UserModel;
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -47,19 +49,17 @@ public class UserUtil {
logger.info("Into portal: "+WsUtil.isWithinPortal());
if (portalLogin.compareTo(WsUtil.TEST_USER) != 0 && WsUtil.isWithinPortal()) { //skip test.user
UserModel curr = null;
GCubeUser curr = null;
try {
try {
curr = um.getUserByScreenName(portalLogin);
curr = um.getUserByUsername(portalLogin);
} catch (UserManagementSystemException e) {
logger.error("An error occurred in getUserFullName "+e,e);
} catch (UserRetrievalFault e) {
logger.error("An error occurred in getUserFullName "+e,e);
}
} catch (UserManagementPortalException ume) {
logger.error("An error occurred in getUserFullName "+ume,ume);
}catch (Exception e) {
logger.error("An error occurred in getUserFullName "+e,e);
logger.warn("Return portal login "+portalLogin);
@ -87,7 +87,7 @@ public class UserUtil {
* @param scope the scope
* @return the organization users
*/
public static List<UserModel> getOrganizationUsers(String scope) {
public static List<GCubeUser> getOrganizationUsers(String scope) {
try {
logger.info("Getting organization users by scope: "+scope);
UserManager um = new LiferayUserManager();

View File

@ -6,6 +6,7 @@ package org.gcube.portlets.widgets.workspacesharingwidget.server.util;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.commons.lang.StringUtils;
@ -13,6 +14,7 @@ import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager;
import org.gcube.applicationsupportlayer.social.NotificationsManager;
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite;
import org.gcube.common.homelibrary.home.HomeLibrary;
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
@ -204,7 +206,15 @@ public class WsUtil {
}
public static NotificationsManager getNotificationManager(ASLSession session)
/**
* Gets the notification manager.
*
* @param session the session
* @param request the request
* @return the notification manager
*/
public static NotificationsManager getNotificationManager(ASLSession session, HttpServletRequest request)
{
NotificationsManager notifMng = (NotificationsManager) session.getAttribute(NOTIFICATION_MANAGER);
@ -213,7 +223,8 @@ public class WsUtil {
try{
logger.info("Create new NotificationsManager for user: "+session.getUsername());
logger.info("New ApplicationNotificationsManager with portlet class name: "+NOTIFICATION_PORTLET_CLASS_ID);
notifMng = new ApplicationNotificationsManager(session, NOTIFICATION_PORTLET_CLASS_ID);
SocialNetworkingSite site = new SocialNetworkingSite(request);
notifMng = new ApplicationNotificationsManager(site, session.getScope(), null, NOTIFICATION_PORTLET_CLASS_ID);
session.setAttribute(NOTIFICATION_MANAGER, notifMng);
}catch (Exception e) {
logger.error("An error occurred instancing ApplicationNotificationsManager for user: "+session.getUsername(),e);
@ -223,14 +234,22 @@ public class WsUtil {
return notifMng;
}
public static NotificationsProducer getNotificationProducer(ASLSession session)
/**
* Gets the notification producer.
*
* @param session the session
* @param request the request
* @return the notification producer
*/
public static NotificationsProducer getNotificationProducer(ASLSession session, HttpServletRequest request)
{
NotificationsProducer notifProducer = (NotificationsProducer) session.getAttribute(NOTIFICATION_PRODUCER);
if (notifProducer == null) {
logger.info("Create new Notification Producer for user: "+session.getUsername());
notifProducer = new NotificationsProducer(session);
notifProducer = new NotificationsProducer(session, request);
session.setAttribute(NOTIFICATION_PRODUCER, notifProducer);
}