added notifications to administrators upgrade/downgrade

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@100271 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2014-09-30 10:13:26 +00:00
parent 696726c5cc
commit 7b7af0e7e8
2 changed files with 107 additions and 0 deletions

View File

@ -60,6 +60,7 @@ import org.gcube.portlets.user.workspace.server.notifications.NotificationsProdu
import org.gcube.portlets.user.workspace.server.notifications.NotificationsUtil; import org.gcube.portlets.user.workspace.server.notifications.NotificationsUtil;
import org.gcube.portlets.user.workspace.server.resolver.UriResolverReaderParameter; import org.gcube.portlets.user.workspace.server.resolver.UriResolverReaderParameter;
import org.gcube.portlets.user.workspace.server.shortener.UrlShortener; import org.gcube.portlets.user.workspace.server.shortener.UrlShortener;
import org.gcube.portlets.user.workspace.server.util.DiffereceBeetweenInfoContactModel;
import org.gcube.portlets.user.workspace.server.util.HttpRequestUtil; import org.gcube.portlets.user.workspace.server.util.HttpRequestUtil;
import org.gcube.portlets.user.workspace.server.util.StringUtil; import org.gcube.portlets.user.workspace.server.util.StringUtil;
import org.gcube.portlets.user.workspace.server.util.UserUtil; import org.gcube.portlets.user.workspace.server.util.UserUtil;
@ -3064,9 +3065,36 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
if(item!=null && item.getType().equals(WorkspaceItemType.SHARED_FOLDER)){ if(item!=null && item.getType().equals(WorkspaceItemType.SHARED_FOLDER)){
WorkspaceSharedFolder sharedFolder = (WorkspaceSharedFolder) item; WorkspaceSharedFolder sharedFolder = (WorkspaceSharedFolder) item;
//retrieving old administrators list
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder();
workspaceLogger.info("Retrieving old administator/s..");
List<InfoContactModel> oldAdmins = builder.buildGxtInfoContactsFromPortalLogins(sharedFolder.getAdministrators());
workspaceLogger.info("Retrieving old administator/s are/is: "+oldAdmins.size());
workspaceLogger.info("Setting administators:"); workspaceLogger.info("Setting administators:");
printList(listContactLogins); printList(listContactLogins);
sharedFolder.setAdmins(listContactLogins); sharedFolder.setAdmins(listContactLogins);
workspaceLogger.info("Converting new administator/s..");
List<InfoContactModel> newAdmins = builder.buildGxtInfoContactsFromPortalLogins(listContactLogins);
NotificationsProducer np = getNotificationProducer();
workspaceLogger.info("Sending notifications downgrade/upgrade administator/s..");
DiffereceBeetweenInfoContactModel diff1 = new DiffereceBeetweenInfoContactModel(oldAdmins, newAdmins);
List<InfoContactModel> contactsDowngrade = diff1.getDifferentsContacts();
for (InfoContactModel infoContactModel : contactsDowngrade) {
np.notifyAdministratorDowngrade(infoContactModel, sharedFolder);
}
DiffereceBeetweenInfoContactModel diff2 = new DiffereceBeetweenInfoContactModel(newAdmins, oldAdmins);
List<InfoContactModel> contactsUpgrade = diff2.getDifferentsContacts();
for (InfoContactModel infoContactModel : contactsUpgrade) {
np.notifyAdministratorUpgrade(infoContactModel, sharedFolder);
}
return true; return true;
}else }else

View File

@ -631,7 +631,86 @@ public class NotificationsProducer {
} }
/**
* Runs a new thread to notify the contacts passed in input
* @param userToNotify
* @param sharedFolder
*/
public void notifyAdministratorUpgrade(final InfoContactModel userToNotify, final WorkspaceSharedFolder sharedFolder){
new Thread() {
@Override
public void run() {
// printContacts(listContacts);
logger.trace("Send notifies administrator upgrade is running...");
if(userToNotify==null || userToNotify.getLogin()==null){
logger.warn("Notification abort user to notify is null...");
return;
}
if(sharedFolder==null){
logger.warn("Notification abort sharedFolder to notify is null...");
return;
}
try{
String login = userToNotify.getLogin();
logger.trace("Send notifies administrator upgrade for login: "+login);
boolean notify = notificationsMng.notifyAdministratorUpgrade(login, sharedFolder);
logger.trace("Notification sent correctly? "+notify);
}catch (Exception e) {
logger.error("An error occured in notifyAdministratorUpgrade ", e);
}
logger.trace("notifies of administrator upgrade completed");
}
}.start();
}
/**
* Runs a new thread to notify the contacts passed in input
* @param userToNotify
* @param sharedFolder
*/
public void notifyAdministratorDowngrade(final InfoContactModel userToNotify, final WorkspaceSharedFolder sharedFolder){
new Thread() {
@Override
public void run() {
// printContacts(listContacts);
logger.trace("Send notifies administrator Downgrade is running...");
if(userToNotify==null || userToNotify.getLogin()==null){
logger.warn("Notification abort user to notify is null...");
return;
}
if(sharedFolder==null){
logger.warn("Notification abort sharedFolder to notify is null...");
return;
}
try{
String login = userToNotify.getLogin();
logger.trace("Send notifies administrator Downgrade for login: "+login);
boolean notify = notificationsMng.notifyAdministratorDowngrade(login, sharedFolder);
logger.trace("Notification sent correctly? "+notify);
}catch (Exception e) {
logger.error("An error occured in notifyAdministratorDowngrade ", e);
}
logger.trace("notifies of administrator Downgrade completed");
}
}.start();
}
//DEBUG //DEBUG
private void printContacts(List<InfoContactModel> listContacts){ private void printContacts(List<InfoContactModel> listContacts){