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;
@ -17,27 +18,29 @@ import org.gcube.portlets.widgets.workspacesharingwidget.server.util.WsUtil;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel;
/**
*
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
*
*/
public class NotificationsProducer {
protected ScopeBean scope;
protected static Logger logger = Logger.getLogger(NotificationsProducer.class);
protected NotificationsManager notificationsMng;
protected ASLSession aslSession;
protected String userId;
/**
*
* @param aslSession
* Instantiates a new notifications producer.
*
* @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();
}
@ -53,7 +56,7 @@ public class NotificationsProducer {
public ASLSession getAslSession() {
return aslSession;
}
/**
* Runs a new thread to notify the contacts passed in input
@ -65,22 +68,22 @@ public class NotificationsProducer {
new Thread(){
@Override
public void run() {
logger.trace("Send notifies folder sharing is running...");
for (InfoContactModel infoContactModel : listContacts) {
try{
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
if(infoContactModel.getLogin().compareTo(userId)!=0){
if(infoContactModel.getLogin().compareTo(userId)!=0){
logger.trace("Sending notification new share folder "+sharedFolder.getName()+" for user "+infoContactModel.getLogin());
//DEBUG
System.out.println("Sending notification new share folder "+sharedFolder.getName()+" for user "+infoContactModel.getLogin());
boolean notify = notificationsMng.notifyFolderSharing(infoContactModel.getLogin(), sharedFolder);
if(!notify)
logger.error("An error occured when notify user: "+infoContactModel.getLogin());
}
@ -89,19 +92,19 @@ public class NotificationsProducer {
// e.printStackTrace();
}
}
logger.trace("notifies share folder is completed");
}
}.start();
}
/**
* Runs a new thread to notify the contacts passed in input
* @param folderItem
* @param folderItem
* @param listContacts
* @param sharedFolder
*/
@ -110,34 +113,34 @@ public class NotificationsProducer {
new Thread(){
@Override
public void run() {
logger.trace("Send notifies shared folder was renamed is running...");
try {
if(NotificationsUtil.checkIsRootFolderShared(folderItem.getId(), idsharedFolder)){
logger.trace("Notification isn't sent because the event is on root shared folder");
return;
}
} catch (InternalErrorException e1) {
logger.error("An error occurred in checkIsRootFolderShared ", e1);
return;
}
for (InfoContactModel infoContactModel : listSharedContact) {
try{
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
if(infoContactModel.getLogin().compareTo(userId)!=0){
if(infoContactModel.getLogin().compareTo(userId)!=0){
logger.trace("Sending notification share folder "+itemOldName+" was renamed as " + itemNewName+ "for user "+infoContactModel.getLogin());
//DEBUG
System.out.println("Sending notification share folder "+itemOldName+" was renamed as " + itemNewName+ "for user "+infoContactModel.getLogin());
boolean notify = notificationsMng.notifyFolderRenaming(infoContactModel.getLogin(), itemOldName, itemNewName, idsharedFolder);
if(!notify)
logger.error("An error occured when notify user: "+infoContactModel.getLogin());
}
@ -146,15 +149,15 @@ public class NotificationsProducer {
// e.printStackTrace();
}
}
logger.trace("notifies share folder was renamed is completed");
}
}.start();
}
/**
* Runs a new thread to notify the contacts passed in input
* @param listContacts
@ -165,21 +168,21 @@ public class NotificationsProducer {
new Thread(){
@Override
public void run() {
logger.trace("Send notifies shared item was updated is running...");
for (InfoContactModel infoContactModel : listSharedContact) {
try{
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
if(infoContactModel.getLogin().compareTo(userId)!=0){
if(infoContactModel.getLogin().compareTo(userId)!=0){
logger.trace("Sending notification to user "+infoContactModel.getLogin() + " updated item "+item.getName());
//DEBUG
System.out.println("Sending notification to user "+infoContactModel.getLogin() + " updated item "+item.getName());
// notificationsMng.notifyItemRenaming(infoContactModel.getLogin(), previousName, item, sharedFolder);
boolean notify = notificationsMng.notifyItemRenaming(infoContactModel.getLogin(), previousName, item, sharedFolder);
if(!notify)
@ -190,19 +193,19 @@ public class NotificationsProducer {
// e.printStackTrace();
}
}
logger.trace("notifies shared item was updated is completed");
}
}.start();
}
/**
* Runs a new thread to notify the new contacts passed in input
* @param listSharedContact - list of contacts already shared
* @param listSharingContact - list of "new" contacts witch share
* @param listSharingContact - list of "new" contacts witch share
* @param sharedFolder - the shared folder
*/
public void notifyAddedUsersToSharing(final List<InfoContactModel> listSharedContact, final List<InfoContactModel> listSharingContact, final WorkspaceSharedFolder sharedFolder) {
@ -210,76 +213,76 @@ public class NotificationsProducer {
new Thread() {
@Override
public void run() {
try{
DiffereceBeetweenInfoContactModel diff = new DiffereceBeetweenInfoContactModel(listSharingContact, listSharedContact);
List<InfoContactModel> listExclusiveContacts = diff.getDifferentsContacts();
System.out.println("list exclusive contacts: "+listExclusiveContacts);
if(listExclusiveContacts.size()>0){
if(listExclusiveContacts.size()==1){ //CASE ONLY ONE CONTACS WAS ADDED
InfoContactModel infoContactModel = listExclusiveContacts.get(0);
for (InfoContactModel contact : listSharedContact) { //NOTIFIES ALREADY SHARED CONTACTS THATH A NEW USER WAS ADDED
try{
logger.trace("Sending notification to user "+contact.getLogin()+", added user "+ infoContactModel.getLogin() +" to share folder "+sharedFolder.getName());
//DEBUG
// System.out.println("Sending notification added user "+ infoContactModel.getLogin() +" to share folder "+sharedFolder.getName() + " for user "+contact.getLogin());
boolean notify = notificationsMng.notifyFolderAddedUser(contact.getLogin(), sharedFolder, infoContactModel.getLogin());
if(!notify)
logger.error("An error occured when notifies user: "+contact.getLogin());
}catch (Exception e) {
logger.error("An error occured in notifyFolderAddedUser ", e);
// e.printStackTrace();
}
}
List<InfoContactModel> listCts = new ArrayList<InfoContactModel>();
listCts.add(infoContactModel);
notifyFolderSharing(listCts, sharedFolder); //NOTIFIER NEW USER OF SHARING FOLDER
}else{ //CASE MORE THEN ONE CONTACS WAS ADDED
List<String> listLogins = UserUtil.getListLoginByInfoContactModel(listExclusiveContacts);
for (InfoContactModel contact : listSharedContact) { //NOTIFIES ALREADY SHARED CONTACTS THATH A NEW USER WAS ADDED
try{
logger.trace("Sending notification to user "+contact.getLogin()+", added "+listLogins.size()+" users to share folder "+sharedFolder.getName());
//DEBUG
// System.out.println("Sending notification added user "+ infoContactModel.getLogin() +" to share folder "+sharedFolder.getName() + " for user "+contact.getLogin());
boolean notify = notificationsMng.notifyFolderAddedUsers(contact.getLogin(), sharedFolder, listLogins);
if(!notify)
logger.error("An error occured when notifies user: "+contact.getLogin());
}catch (Exception e) {
logger.error("An error occured in notifyFolderAddedUser ", e);
// e.printStackTrace();
}
}
notifyFolderSharing(listExclusiveContacts, sharedFolder); //NOTIFIER NEW USER OF SHARING FOLDER
}
}
}catch (Exception e) {
logger.error("An error occured in notifyAddedUserToSharing ", e);
// e.printStackTrace();
@ -287,9 +290,9 @@ public class NotificationsProducer {
}
}.start();
}
/**
* Runs a new thread to notify the contacts passed in input
@ -298,26 +301,26 @@ public class NotificationsProducer {
*/
public void notifyFolderUnSharing(final List<InfoContactModel> listContacts, final WorkspaceSharedFolder unSharedFolder) {
new Thread() {
@Override
public void run() {
// printContacts(listContacts);
logger.trace("Send notifies folder un share is running...");
for (InfoContactModel infoContactModel : listContacts) {
try{
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
if(infoContactModel.getLogin().compareTo(userId)!=0){
logger.trace("Sending notification to user "+infoContactModel.getLogin() +" un shared folder "+unSharedFolder.getName());
//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());
}
@ -326,16 +329,16 @@ public class NotificationsProducer {
// e.printStackTrace();
}
}
logger.trace("notifies of un share notifications is completed");
}
}.start();
}
/**
* Runs a new thread to notify the contacts passed in input
* @param listContacts
@ -346,27 +349,27 @@ public class NotificationsProducer {
new Thread() {
@Override
public void run() {
// printContacts(listContacts);
logger.trace("Send notifies added item in sharedfolder is running...");
//DEBUG
System.out.println("Send notifies added item in sharedfolder is running...");
for (InfoContactModel infoContactModel : listContacts) {
try{
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
if(infoContactModel.getLogin().compareTo(userId)!=0){
if(infoContactModel.getLogin().compareTo(userId)!=0){
logger.trace("Sending notification to user "+infoContactModel.getLogin() +" added item "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName());
//DEBUG
System.out.println("Sending notification to user "+infoContactModel.getLogin() +" added item "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName());
//DEBUG
// System.out.println("Send notify folder un share user "+infoContactModel.getLogin());
boolean notify = notificationsMng.notifyAddedItem(infoContactModel.getLogin(), workspaceItem, sharedFolder);
if(!notify){
@ -380,17 +383,17 @@ public class NotificationsProducer {
// e.printStackTrace();
}
}
logger.trace("notifies of added item in shared folder is completed");
//DEBUG
// System.out.println("notifies of added item in shared folder is completed");
}
}.start();
}
/**
* Runs a new thread to notify the contacts passed in input
* @param listContacts
@ -401,27 +404,27 @@ public class NotificationsProducer {
new Thread() {
@Override
public void run() {
// printContacts(listContacts);
logger.trace("Send notifies updated item in shared folder is running...");
//DEBUG
// System.out.println("Send notifies updated item in shared folder is running...");
for (InfoContactModel infoContactModel : listContacts) {
try{
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
if(infoContactModel.getLogin().compareTo(userId)!=0){
if(infoContactModel.getLogin().compareTo(userId)!=0){
logger.trace("Sending notification to user "+infoContactModel.getLogin() +" updated item "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName());
//DEBUG
// System.out.println("Sending notification to user "+infoContactModel.getLogin() +" updated item "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName());
//DEBUG
// System.out.println("Send notify folder un share user "+infoContactModel.getLogin());
boolean notify = notificationsMng.notifyUpdatedItem(infoContactModel.getLogin(), workspaceItem, sharedFolder);
if(!notify){
@ -435,20 +438,20 @@ public class NotificationsProducer {
e.printStackTrace();
}
}
logger.trace("notifies of updated item in shared folder is completed");
//DEBUG
// System.out.println("notifies of updated item in shared folder is completed");
}
}.start();
}
/**
* Runs a new thread to notify the contacts passed in input
* @param listContacts
@ -456,38 +459,38 @@ public class NotificationsProducer {
*/
public void notifyMovedItemToSharing(final List<InfoContactModel> listContacts, final WorkspaceItem workspaceItem, final WorkspaceSharedFolder sharedFolder) {
new Thread() {
@Override
public void run() {
logger.trace("Sending notification remove item in shared folder is running...");
// printContacts(listContacts);
try {
if(NotificationsUtil.checkIsRootFolderShared(workspaceItem.getId(), sharedFolder.getId())){
logger.trace("Notification isn't sent because the event is on root shared folder");
return;
}
} catch (InternalErrorException e1) {
logger.error("An error occurred in checkIsRootFolderShared ", e1);
return;
}
logger.trace("Sending notification moved item in shared folder is running...");
// System.out.println("Sending notification moved item in shared folder is running...");
for (InfoContactModel infoContactModel : listContacts) {
try{
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
if(infoContactModel.getLogin().compareTo(userId)!=0){
logger.trace("Sending notification to user "+infoContactModel.getLogin() +" moved item "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName());
//DEBUG
// System.out.println("Sending notification to user "+infoContactModel.getLogin() +" moved item "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName());
@ -495,7 +498,7 @@ public class NotificationsProducer {
if(!notify){
logger.error("An error occured when notify user: "+infoContactModel.getLogin());
//DEBUG
// System.out.println("An error occured when notify user: "+infoContactModel.getLogin());
}
@ -505,20 +508,20 @@ public class NotificationsProducer {
e.printStackTrace();
}
}
logger.trace("notifies of moved item in shared folder is completed");
//DEBUG
// System.out.println("notifies of moved item in shared folder is completed");
}
}.start();
}
/**
* Runs a new thread to notify the contacts passed in input
* @param listContacts
@ -526,35 +529,35 @@ public class NotificationsProducer {
*/
public void notifyRemovedItemToSharing(final List<InfoContactModel> listContacts, final String itemName, final WorkspaceSharedFolder sharedFolder) {
new Thread() {
@Override
public void run() {
logger.trace("Sending notification remove item in shared folder is running...");
// printContacts(listContacts);
if(itemName==null || itemName.isEmpty()){
logger.trace("Notification isn't sent - itemName is null or empty");
return;
}
if(sharedFolder==null){
logger.trace("Notification isn't sent - sharedFolder is null");
}
logger.trace("Sending notification removed item in shared folder is running...");
// System.out.println("Sending notification removed item in shared folder is running...");
for (InfoContactModel infoContactModel : listContacts) {
try{
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
if(infoContactModel.getLogin().compareTo(userId)!=0){
logger.trace("Sending notification to user "+infoContactModel.getLogin() +" removed item "+itemName+" in shared folder "+sharedFolder.getName());
//DEBUG
// System.out.println("Sending notification to user "+infoContactModel.getLogin() +" removed item "+itemName+" in shared folder "+sharedFolder.getName());
@ -562,7 +565,7 @@ public class NotificationsProducer {
if(!notify){
logger.error("An error occured when notify user: "+infoContactModel.getLogin());
//DEBUG
// System.out.println("An error occured when notify user: "+infoContactModel.getLogin());
}
@ -572,16 +575,16 @@ public class NotificationsProducer {
// e.printStackTrace();
}
}
logger.trace("notifies of moved item in shared folder is completed");
//DEBUG
// System.out.println("notifies of moved item in shared folder is completed");
}
}.start();
}
/**
* Runs a new thread to notify the contacts passed in input
* @param listContacts
@ -589,28 +592,28 @@ public class NotificationsProducer {
*/
public void notifySharedFolderDeleted(final List<InfoContactModel> listContacts, final String folderNameDeleted) {
new Thread() {
@Override
public void run() {
// printContacts(listContacts);
logger.trace("Send notifies shared folder deleted is running...");
for (InfoContactModel infoContactModel : listContacts) {
try{
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
if(infoContactModel.getLogin().compareTo(userId)!=0){
logger.trace("Sending notification to user "+infoContactModel.getLogin() +" deleted shared folder "+folderNameDeleted);
//DEBUG
System.out.println("Sending notification to user "+infoContactModel.getLogin() +" deleted shared folder "+folderNameDeleted);
//TODO
// boolean notify = notificationsMng.
// if(!notify)
// logger.error("An error occured when notifies user: "+infoContactModel.getLogin());
}
@ -619,19 +622,19 @@ public class NotificationsProducer {
// e.printStackTrace();
}
}
logger.trace("notifies of deleted shared foder is completed");
}
}.start();
}
//DEBUG
private void printContacts(List<InfoContactModel> listContacts){
System.out.println("Print contacts");
for (InfoContactModel infoContactModel : listContacts) {
System.out.println(infoContactModel);
@ -639,26 +642,24 @@ 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";
String scopeString = "/gcube/devsec/devVRE";
String fullName = "Francesco Mangiacrapa";
ScopeBean scope;
ASLSession session;
session = SessionManager.getInstance().getASLSession(sessionID, user);
scope = new ScopeBean(scopeString);
session.setScope(scope.toString());
session.setUserAvatarId(user + "Avatar");
session.setUserFullName(fullName);
NotificationsProducer feeder = new NotificationsProducer(session);
}
}*/
}

View File

@ -1,11 +1,12 @@
/**
*
*
*/
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;
@ -24,86 +25,89 @@ import org.slf4j.LoggerFactory;
*
*/
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");
if(folderDestinationItem!=null){
if(folderDestinationItem!=null){
try{
//if folder destination is shared folder
if(folderDestinationItem.isShared()){ //Notify Added Item To Sharing?
logger.info("checkNotifyAddItemToShare source item: "+sourceItem.getName()+" sourceSharedId: "+sourceSharedId + " folder destination: "+folderDestinationItem.getName() + " folder destination shared folder id: "+folderDestinationItem.getIdSharedFolder());
//share condition is true if source shared folder is not null
boolean shareChangeCondition = sourceSharedId==null?false:true;
//System.out.println("shareChangeCondition add item: "+ shareChangeCondition);
logger.info("shareChangeCondition add item: "+shareChangeCondition);
//if shareChangeCondition is true.. notifies added item to sharing
if(shareChangeCondition){
if(shareChangeCondition){
Workspace workspace = WsUtil.getWorkspace(httpSession);
List<InfoContactModel> listContacts = getListUserSharedByFolderSharedId(workspace, folderDestinationItem.getIdSharedFolder());
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)
np.notifyAddedItemToSharing(listContacts, sourceItem, (WorkspaceSharedFolder) destinationSharedFolder);
np.notifyAddedItemToSharing(listContacts, sourceItem, (WorkspaceSharedFolder) destinationSharedFolder);
else
np.notifyUpdatedItemToSharing(listContacts, sourceItem, (WorkspaceSharedFolder) destinationSharedFolder);
np.notifyUpdatedItemToSharing(listContacts, sourceItem, (WorkspaceSharedFolder) destinationSharedFolder);
logger.info("The notifies was sent correctly");
// np.notifyAddedItemToSharing(listContacts, (WorkspaceFolder) folderDestinationItem);
}
// np.notifyAddedItemToSharing(listContacts, (WorkspaceFolder) folderDestinationItem);
}
}
else
logger.info("folder destination is not shared");
}catch (Exception e) {
logger.error("An error occurred in checkSendNotifyAddItemToShare ",e);
}
}else
logger.warn("The notifies is failure in checkSendNotifyAddItemToShare because folder destination item is null");
logger.warn("The notifies is failure in checkSendNotifyAddItemToShare because folder destination item is null");
}
/**
*
*
* @param workspace
* @param idSharedFolder
* @return
* @throws Exception
*/
public static List<InfoContactModel> getListUserSharedByFolderSharedId(Workspace workspace, String idSharedFolder) throws Exception {
logger.info("getListUserSharedByFolderSharedId "+ idSharedFolder);
try {
WorkspaceItem wsItem = workspace.getItem(idSharedFolder);
if(isARootSharedFolder(wsItem)){
WorkspaceSharedFolder wsFolder = (WorkspaceSharedFolder) wsItem;
GWTWorkspaceSharingBuilder builder = new GWTWorkspaceSharingBuilder();
@ -113,16 +117,16 @@ public class NotificationsUtil {
logger.info("getListUserSharedByFolderSharedId return "+ listPortalLogin.size() + " user");
return builder.buildGxtInfoContactsFromPortalLogins(listPortalLogin);
}
else{
logger.info("the item with id: "+idSharedFolder+ " is not "+WorkspaceItemType.SHARED_FOLDER);
//DEBUG
//System.out.println("the item with id: "+folderSharedId+ " is not "+WorkspaceItemType.SHARED_FOLDER);
}
return new ArrayList<InfoContactModel>();
} catch (Exception e) {
logger.error("Error in getListUserSharedByItemId ", e);
throw new Exception(e.getMessage());
@ -131,78 +135,78 @@ public class NotificationsUtil {
/**
*
*
* @param httpSession
* @param sourceItemIsShared
* @param oldItemName
* @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:");
try{
if(!sourceItemIsShared){
if(!sourceItemIsShared){
logger.info("checkSendNotifyRemoveItemToShare returned, source item is not shared");
return;
}
String idSharedFolder = sourceFolderSharedId!=null?sourceFolderSharedId:"";
// System.out.println("shareChangeCondition remove item: "+ shareChangeCondition);
boolean isRootFolderShared = checkIsRootFolderShared(oldItemId, idSharedFolder);
logger.info("isRootFolderShared is: "+ isRootFolderShared);
if(isRootFolderShared){
logger.info("Notification doesn't send because the event is on root shared folder");
return;
}
boolean isSharedFolder = isASharedFolderForId(httpSession,idSharedFolder);
logger.info("idSharedFolder is: "+ idSharedFolder +" is shared folder: "+isSharedFolder);
//Notify Removed Item To Sharing?
if(isSharedFolder && !isRootFolderShared){
Workspace workspace = WsUtil.getWorkspace(httpSession);
//get contacts
List<InfoContactModel> listContacts = getListUserSharedByFolderSharedId(workspace, idSharedFolder);
WorkspaceItem sourceSharedFolder = workspace.getItem(idSharedFolder);
//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);
else
logger.info("Source shared folder "+sourceSharedFolder + " is not instanceof WorkspaceSharedFolder, skipping");
logger.info("The notifies was sent correctly");
}
}catch (Exception e) {
logger.error("An error occurred in checkSendNotifyRemoveItemToShare ",e);
}
}
/**
*
*
* @param wsItem
* @return
*/
@ -211,52 +215,52 @@ public class NotificationsUtil {
return wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER);
return false;
}
/**
*
*
* @param wsItem
* @return
*/
public static boolean isASharedFolderForId(HttpSession httpSession, String itemId){
if(itemId==null || itemId.isEmpty())
return false;
try {
Workspace workspace = WsUtil.getWorkspace(httpSession);
WorkspaceItem wsItem = workspace.getItem(itemId);
if(wsItem!=null)
return wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER);
return false;
} catch (Exception e) {
logger.error("An errror occurred in isASharedFolderForId", e);
return false;
}
}
/**
*
*
* @param itemId
* @param rootFolderSharedId
* @return
*/
public static boolean checkIsRootFolderShared(String itemId, String rootFolderSharedId) {
logger.info("checkIsRootFolderShared between [itemid: "+itemId +", rootFolderSharedId: "+rootFolderSharedId+"]");
if(itemId==null)
return false;
if(rootFolderSharedId==null)
return false;
if(itemId.compareTo(rootFolderSharedId)==0)
return true;
return false;
}
}

View File

@ -3,123 +3,45 @@ 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;
/**
*
*
* @author Massimiliano Assante ISTI-CNR
*
*
* @version 2.0 Jan 10th 2012
*
*
* changed by Francesco Mangiacrapa
*/
public class LoginServiceUtil {
/**
*
*
*/
public static final String ROOT_ORG = "rootorganization";
/**
*
*
*/
public static final String PUBLIC_LAYOUT_NAME = " Data e-Infrastructure gateway";
/**
*
*
*/
public static final String GUEST_COMMUNITY_NAME = "Guest";
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
@ -143,12 +65,12 @@ public class LoginServiceUtil {
emVO.setImageURL("http://portal.d4science.research-infrastructures.eu/vologin/html/RedGrid.jpg");
emVO.setUserBelonging(UserBelonging.NOT_BELONGING);
//
//
//
//
VRE cool_EM_VRE = new VRE();
cool_EM_VRE.setName("COOL EM VRE");
cool_EM_VRE.setGroupName("/d4science.research-infrastructures.eu/EM/COOLEMVRE");
cool_EM_VRE.setDescription("cool_EM_VRE VRE Description<br />"+
cool_EM_VRE.setDescription("cool_EM_VRE VRE Description<br />"+
"This Virtual Research Environment is for cool authors, managers and researchers who produce reports containing cool data.");
cool_EM_VRE.setImageURL("http://portal.d4science.research-infrastructures.eu/vologin/html/gcm-preview.jpg");
cool_EM_VRE.setUserBelonging(UserBelonging.BELONGING);
@ -157,7 +79,7 @@ public class LoginServiceUtil {
VRE cool_EM_VRE2 = new VRE();
cool_EM_VRE2.setName("COOL VRE 2");
cool_EM_VRE2.setGroupName("/d4science.research-infrastructures.eu/EM/COOLEMVRE2");
cool_EM_VRE2.setDescription("Cool VRE Description<br />"+
cool_EM_VRE2.setDescription("Cool VRE Description<br />"+
"This Virtual Research Environment is for cool authors, managers and researchers who produce reports containing cool data.");
cool_EM_VRE2.setImageURL("http://portal.d4science.research-infrastructures.eu/vologin/html/aquamaps-preview.jpg");
@ -166,7 +88,7 @@ public class LoginServiceUtil {
VRE cool_EM_VRE3 = new VRE();
cool_EM_VRE3.setName("COOL EM VRE TRE");
cool_EM_VRE3.setGroupName("/d4science.research-infrastructures.eu/EM/COOlVRE3");
cool_EM_VRE3.setDescription("Cool VRE Description<br />"+
cool_EM_VRE3.setDescription("Cool VRE Description<br />"+
"This Virtual Research Environment is for cool authors, managers and researchers who produce reports containing cool data.");
cool_EM_VRE3.setImageURL("http://portal.d4science.research-infrastructures.eu/vologin/html/aquamaps-preview.jpg");
@ -175,7 +97,7 @@ public class LoginServiceUtil {
VRE demo = new VRE();
demo.setName("Demo");
demo.setGroupName("/d4science.research-infrastructures.eu/EM/Demo");
demo.setDescription("Cool VRE Description<br />"+
demo.setDescription("Cool VRE Description<br />"+
"This Virtual Research Environment is for cool authors, managers and researchers who produce reports containing cool data.");
demo.setImageURL("http://portal.d4science.research-infrastructures.eu/vologin/html/RedGrid.jpg");
@ -184,7 +106,7 @@ public class LoginServiceUtil {
VRE vreGCM = new VRE();
vreGCM.setName("GCM");
vreGCM.setGroupName("/d4science.research-infrastructures.eu/EM/GCM");
vreGCM.setDescription("Global Ocean Chlorophyll Monitoring (GCM) Virtual Research Environment<br />"
vreGCM.setDescription("Global Ocean Chlorophyll Monitoring (GCM) Virtual Research Environment<br />"
+ "The phytoplankton plays a similar role to terrestrial green plants in the photosynthetic process and are credited with removing as much carbon dioxide from the atmosphere as their earthbound counterparts, making it important to monitor and model plankton into calculations of future climate change.");
vreGCM.setImageURL("http://portal.d4science.research-infrastructures.eu/vologin/html/aquamaps-preview.jpg");
vreGCM.setUserBelonging(UserBelonging.BELONGING);
@ -204,7 +126,7 @@ public class LoginServiceUtil {
}
/**
*
*
* @param scopename a string
* @return true if any VRE Exists
*/
@ -215,13 +137,13 @@ public class LoginServiceUtil {
try {
_log.info("Searching for VREs into " + scope.name());
String currScope = ScopeProvider.instance.get();
ScopeProvider.instance.set(scope.toString());
ScopeProvider.instance.set(scope.toString());
SimpleQuery query = queryFor(GenericResource.class);
query.addCondition("$resource/Profile/SecondaryType/text() eq '"+ Type.VRE +"'");
DiscoveryClient<GenericResource> client = clientFor(GenericResource.class);
boolean result = client.submit(query).size() > 0;
ScopeProvider.instance.set(currScope);
boolean result = client.submit(query).size() > 0;
ScopeProvider.instance.set(currScope);
return result;
} catch (Exception e) {
_log.error("Generic Exception for " + scope.name() + " " + e.getMessage());
@ -230,7 +152,7 @@ public class LoginServiceUtil {
}
}
/**
*
*
* @param scopename a string
* @return an arraylist of <class>VRE</class> with just name and description filled
*/
@ -242,7 +164,7 @@ public class LoginServiceUtil {
try {
_log.info("Searching for VREs into " + scope.name());
String currScope = ScopeProvider.instance.get();
ScopeProvider.instance.set(scope.toString());
ScopeProvider.instance.set(scope.toString());
SimpleQuery query = queryFor(GenericResource.class);
query.addCondition("$resource/Profile/SecondaryType/text() eq '"+ Type.VRE +"'");
@ -250,7 +172,7 @@ public class LoginServiceUtil {
for (GenericResource genres : client.submit(query)) {
toReturn.add(new VRE(genres.profile().name(), genres.profile().description(), "", "", "", null));
}
ScopeProvider.instance.set(currScope);
ScopeProvider.instance.set(currScope);
return toReturn;
} catch (Exception e) {
e.printStackTrace();
@ -258,5 +180,5 @@ public class LoginServiceUtil {
return null;
}
}
}

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);
}