191 lines
6.6 KiB
Java
191 lines
6.6 KiB
Java
/**
|
|
*
|
|
*/
|
|
package org.gcube.portlets.user.workspace.server.notifications;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import javax.servlet.http.HttpSession;
|
|
|
|
import org.apache.log4j.Logger;
|
|
import org.gcube.portlets.user.homelibrary.home.workspace.Workspace;
|
|
import org.gcube.portlets.user.homelibrary.home.workspace.WorkspaceFolder;
|
|
import org.gcube.portlets.user.homelibrary.home.workspace.WorkspaceItem;
|
|
import org.gcube.portlets.user.homelibrary.home.workspace.WorkspaceItemType;
|
|
import org.gcube.portlets.user.homelibrary.home.workspace.WorkspaceSharedFolder;
|
|
import org.gcube.portlets.user.workspace.client.model.InfoContactModel;
|
|
import org.gcube.portlets.user.workspace.server.GWTWorkspaceBuilder;
|
|
import org.gcube.portlets.user.workspace.server.util.Util;
|
|
|
|
/**
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
|
* @May 27, 2013
|
|
*
|
|
*/
|
|
public class NotificationsUtil {
|
|
|
|
|
|
protected static Logger logger = Logger.getLogger(NotificationsUtil.class);
|
|
|
|
/**
|
|
*
|
|
* @param httpSession
|
|
* @param sourceItem
|
|
* @param sourceSharedId
|
|
* @param folderDestinationItem
|
|
*/
|
|
public static void checkNotifyAddItemToShare(HttpSession httpSession, final WorkspaceItem sourceItem, final String sourceSharedId, final WorkspaceItem folderDestinationItem) {
|
|
|
|
logger.trace("checkNotifyAddItemToShare");
|
|
|
|
if(folderDestinationItem!=null){
|
|
|
|
try{
|
|
//if folder destination is shared folder
|
|
if(folderDestinationItem.isShared()){ //Notify Added Item To Sharing?
|
|
|
|
logger.trace("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.trace("shareChangeCondition add item: "+shareChangeCondition);
|
|
|
|
//if shareChangeCondition is true.. notifies added item to sharing
|
|
if(shareChangeCondition){
|
|
|
|
Workspace workspace = Util.getWorkspace(httpSession);
|
|
|
|
List<InfoContactModel> listContacts = getListUserSharedByFolderSharedId(workspace, folderDestinationItem.getIdSharedFolder());
|
|
|
|
WorkspaceItem destinationSharedFolder = workspace.getItem(folderDestinationItem.getIdSharedFolder());
|
|
|
|
NotificationsProducer np = new NotificationsProducer(Util.getAslSession(httpSession));
|
|
|
|
np.notifyAddedItemToSharing(listContacts, sourceItem, (WorkspaceFolder) destinationSharedFolder);
|
|
|
|
logger.trace("The notifies was sent correctly");
|
|
// np.notifyAddedItemToSharing(listContacts, (WorkspaceFolder) folderDestinationItem);
|
|
}
|
|
}
|
|
else
|
|
logger.trace("folder destination is not shared");
|
|
|
|
}catch (Exception e) {
|
|
logger.error("An error occurred in verifyNotifyAddItemToShare ",e);
|
|
}
|
|
}else
|
|
logger.warn("The notifies is failure in verifyNotifyAddItemToShare 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.trace("getListUserSharedByFolderSharedId "+ idSharedFolder);
|
|
|
|
try {
|
|
|
|
WorkspaceItem wsItem = workspace.getItem(idSharedFolder);
|
|
|
|
if(Util.isASharedFolder(wsItem)){
|
|
|
|
WorkspaceSharedFolder wsFolder = (WorkspaceSharedFolder) wsItem;
|
|
|
|
GWTWorkspaceBuilder builder = new GWTWorkspaceBuilder();
|
|
|
|
List<String> listPortalLogin = wsFolder.getUsers();
|
|
|
|
logger.trace("getListUserSharedByFolderSharedId return "+ listPortalLogin.size() + " user");
|
|
|
|
return builder.buildGxtInfoContactsFromPortalLogins(listPortalLogin);
|
|
|
|
}
|
|
else{
|
|
logger.trace("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());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
*
|
|
* @param httpSession
|
|
* @param sourceItemIsShared
|
|
* @param sourceItem
|
|
* @param sourceSharedId
|
|
* @param folderDestinationItem
|
|
*/
|
|
|
|
public static void checkNotifyRemoveItemToShare(HttpSession httpSession, final boolean sourceItemIsShared, final WorkspaceItem sourceItem, final String sourceSharedId, final WorkspaceItem folderDestinationItem) {
|
|
|
|
logger.trace("checkNotifyRemoveItemToShare:");
|
|
|
|
try{
|
|
|
|
if(folderDestinationItem!=null){
|
|
|
|
String idSharedFolder = folderDestinationItem.getIdSharedFolder()!=null?folderDestinationItem.getIdSharedFolder():"";
|
|
|
|
//share condition is true if source shared folder is not equal to destination shared folder
|
|
boolean shareChangeCondition = sourceSharedId==null?false:(sourceSharedId.compareTo(idSharedFolder)!=0);
|
|
|
|
logger.trace("checkNotifyRemoveItemToShare source item: "+sourceItem.getName()+" sourceSharedId: "+sourceSharedId + " folder destination: "+folderDestinationItem.getName() +" sourceItemIsShared: "+sourceItemIsShared);
|
|
|
|
// System.out.println("shareChangeCondition remove item: "+ shareChangeCondition);
|
|
|
|
logger.trace("shareChangeCondition remove item: "+ shareChangeCondition);
|
|
|
|
//Notify Removed Item To Sharing?
|
|
//if source Item is shared and folder destination is not shared or shareChangeCondition is true.. notifies removed item to sharing
|
|
if(sourceItemIsShared && (!folderDestinationItem.isShared() || shareChangeCondition)){
|
|
|
|
Workspace workspace = Util.getWorkspace(httpSession);
|
|
|
|
//get contacts
|
|
List<InfoContactModel> listContacts = getListUserSharedByFolderSharedId(workspace, sourceSharedId);
|
|
|
|
|
|
WorkspaceItem sourceSharedFolder = workspace.getItem(sourceSharedId);
|
|
|
|
//System.out.println(" name sourceSharedFolder: "+ sourceSharedFolder.getName());
|
|
|
|
NotificationsProducer np = new NotificationsProducer(Util.getAslSession(httpSession));
|
|
|
|
np.notifyRemovedItemToSharing(listContacts, sourceItem, (WorkspaceFolder) sourceSharedFolder);
|
|
|
|
logger.trace("The notifies was sent correctly");
|
|
|
|
}
|
|
|
|
}else
|
|
logger.warn("The notifies is failure in verifyNotifyRemoveItemToShare because folder destination item is null");
|
|
|
|
}catch (Exception e) {
|
|
logger.error("An error occurred in checkNotifyRemoveItemToShare ",e);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|