diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java index 0d88b59..3e91df4 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java @@ -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.resolver.UriResolverReaderParameter; 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.StringUtil; 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)){ WorkspaceSharedFolder sharedFolder = (WorkspaceSharedFolder) item; + + //retrieving old administrators list + GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder(); + workspaceLogger.info("Retrieving old administator/s.."); + List oldAdmins = builder.buildGxtInfoContactsFromPortalLogins(sharedFolder.getAdministrators()); + workspaceLogger.info("Retrieving old administator/s are/is: "+oldAdmins.size()); + workspaceLogger.info("Setting administators:"); printList(listContactLogins); sharedFolder.setAdmins(listContactLogins); + + workspaceLogger.info("Converting new administator/s.."); + List newAdmins = builder.buildGxtInfoContactsFromPortalLogins(listContactLogins); + NotificationsProducer np = getNotificationProducer(); + + workspaceLogger.info("Sending notifications downgrade/upgrade administator/s.."); + DiffereceBeetweenInfoContactModel diff1 = new DiffereceBeetweenInfoContactModel(oldAdmins, newAdmins); + List contactsDowngrade = diff1.getDifferentsContacts(); + + for (InfoContactModel infoContactModel : contactsDowngrade) { + np.notifyAdministratorDowngrade(infoContactModel, sharedFolder); + } + + DiffereceBeetweenInfoContactModel diff2 = new DiffereceBeetweenInfoContactModel(newAdmins, oldAdmins); + List contactsUpgrade = diff2.getDifferentsContacts(); + + for (InfoContactModel infoContactModel : contactsUpgrade) { + np.notifyAdministratorUpgrade(infoContactModel, sharedFolder); + } + return true; }else diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/notifications/NotificationsProducer.java b/src/main/java/org/gcube/portlets/user/workspace/server/notifications/NotificationsProducer.java index 673fd16..2f606d3 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/notifications/NotificationsProducer.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/notifications/NotificationsProducer.java @@ -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 private void printContacts(List listContacts){