From 27d8febb238016cd05ad45e0d8e2a3a947907223 Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Wed, 6 Dec 2017 14:51:39 +0000 Subject: [PATCH] Feature #5729 and Task #10052 git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/admin/vre-deploy@160115 82a268e6-3cf1-43bd-a215-b396298e98cf --- .classpath | 6 +- distro/changelog.xml | 25 ++- pom.xml | 9 +- .../server/NewVRECreatedThread.java | 144 ++++++++++++++++++ .../server/VREDeployerServiceImpl.java | 72 ++------- 5 files changed, 187 insertions(+), 69 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/admin/vredeployer/server/NewVRECreatedThread.java diff --git a/.classpath b/.classpath index 702669a..253e532 100644 --- a/.classpath +++ b/.classpath @@ -1,12 +1,12 @@ - + - + @@ -39,5 +39,5 @@ - + diff --git a/distro/changelog.xml b/distro/changelog.xml index 5f0eb9e..40edf67 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -1,15 +1,28 @@ - + + Feature #5729, send email to infraManagers upon new VRE + cretions + Task #10052, send email to infraManagers upon new VRE cretions + + + Fixed pom dependency for registry publisher - + Ported to Liferay 6.2 API - - Fix for bug #712, VRE Folder not created if manager and designer are the same user + + Fix for bug #712, VRE Folder not created if manager and + designer are the same user - - Added creation of New Layout including Register Users Portlet + + Added creation of New Layout including Register Users Portlet + diff --git a/pom.xml b/pom.xml index 38bbf68..3855722 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ org.gcube.portlets.admin vre-deploy war - 4.0.1-SNAPSHOT + 4.1.0-SNAPSHOT gCube VRE Deploy Wizard Portlet gCube VRE Deploy Wizard Portlet. @@ -28,7 +28,7 @@ distro 1.7 - 1.7 + 1.8 ${project.build.directory}/${project.build.finalName} UTF-8 @@ -46,6 +46,11 @@ + + org.gcube.information-system + resource-registry-context-client + [1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT) + com.google.gwt gwt-user diff --git a/src/main/java/org/gcube/portlets/admin/vredeployer/server/NewVRECreatedThread.java b/src/main/java/org/gcube/portlets/admin/vredeployer/server/NewVRECreatedThread.java new file mode 100644 index 0000000..c8c655e --- /dev/null +++ b/src/main/java/org/gcube/portlets/admin/vredeployer/server/NewVRECreatedThread.java @@ -0,0 +1,144 @@ +package org.gcube.portlets.admin.vredeployer.server; + +import java.util.List; + + +import org.gcube.common.portal.PortalContext; +import org.gcube.common.portal.mailing.EmailNotification; +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.informationsystem.impl.entity.ContextImpl; +import org.gcube.informationsystem.model.entity.Context; +import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryContextClient; +import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryContextClientFactory; +import org.gcube.vomanagement.usermanagement.GroupManager; +import org.gcube.vomanagement.usermanagement.RoleManager; +import org.gcube.vomanagement.usermanagement.UserManager; +import org.gcube.vomanagement.usermanagement.exception.RoleRetrievalFault; +import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager; +import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager; +import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager; +import org.gcube.vomanagement.usermanagement.model.GCubeGroup; +import org.gcube.vomanagement.usermanagement.model.GCubeUser; +import org.gcube.vomanagement.usermanagement.model.GatewayRolesNames; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author Massimiliano Assante ISTI-CNR + * + */ +public class NewVRECreatedThread implements Runnable { + private static Logger _log = LoggerFactory.getLogger(NewVRECreatedThread.class); + + final String SUBJECT = "New VRE Created notification"; + private GroupManager gm; + + private String creatorUserName; + private String creatorFullName; + private String vreScope; + private String vreName; + private long currentScopeGroupId; + + public NewVRECreatedThread(String creatorUserName, String creatorFullName, String vreScope, String vreName, long currentScopeGroupId) { + super(); + this.creatorUserName = creatorUserName; + this.creatorFullName = creatorFullName; + this.vreScope = vreScope; + this.vreName = vreName; + this.currentScopeGroupId = currentScopeGroupId; + gm = new LiferayGroupManager(); + } + + @Override + public void run() { + handleVRECreatedNotificationEmail(creatorUserName, creatorFullName, vreScope); + handleVRECreatedContextAddonResourceRegistry(vreScope, vreName, currentScopeGroupId); + } + + private void handleVRECreatedContextAddonResourceRegistry(String vreScope, String vreName, long currentScopeGroupId) { + try { + final GCubeGroup voGroup = gm.getGroup(currentScopeGroupId); + + String currentScope = gm.getInfrastructureScope(currentScopeGroupId); + _log.debug("handleVRECreatedContextAddonResourceRegistry, VO Scope= " + currentScope); + ScopeProvider.instance.set(currentScope); + ResourceRegistryContextClient rrClient = ResourceRegistryContextClientFactory.create(); + Context context = new ContextImpl(vreName); + + List contexts = rrClient.all(); + Context parent = null; + for(Context c : contexts){ + if(c.getName().compareTo(voGroup.getGroupName()) == 0){ + parent = c; + break; + } + } + _log.debug("setting parent as= " + parent.getName()); + context.setParent(parent); + _log.debug("creating context: " + context.toString()); + rrClient.create(context); + _log.debug("created context OK"); + } catch (Exception e) { + _log.error("an error occurred wehn creating new context on Resource Registry" , e); + } + } + + + private void handleVRECreatedNotificationEmail(String newUserUserName, String newUserFullName, String vreScope) { + UserManager um = new LiferayUserManager(); + RoleManager rm = new LiferayRoleManager(); + try { + String rootVoName = PortalContext.getConfiguration().getInfrastructureName(); + long groupId = gm.getGroupIdFromInfrastructureScope("/"+rootVoName); + long infraManagerRoleId = -1; + try { + infraManagerRoleId = rm.getRoleIdByName(GatewayRolesNames.INFRASTRUCTURE_MANAGER.getRoleName()); + } + catch (RoleRetrievalFault e) { + _log.warn("There is no (Site) Role " + infraManagerRoleId + " in this portal. Will not notify about newly VRE creations."); + return; + } + _log.trace("Root is: " + rootVoName + " Scanning roles ...."); + + List managers = um.listUsersByGroupAndRole(groupId, infraManagerRoleId); + if (managers == null || managers.isEmpty()) { + _log.warn("There are no users with (Site) Role " + infraManagerRoleId + " on " + rootVoName + " in this portal. Will not notify about newly VRE creations."); + } + else { + for (GCubeUser manager : managers) { + sendNotification(manager, newUserUserName, newUserFullName, vreScope); + _log.info("sent email to manager: " + manager.getEmail()); + } + } + + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void sendNotification(GCubeUser manager, String creatorUserName, String creaotrFullName, String vreScope) { + EmailNotification toSend = new EmailNotification(manager.getEmail(), SUBJECT, + getHTMLEmail(manager.getFirstName(), creatorUserName, creaotrFullName, vreScope), null); + toSend.sendEmail(); + } + + private static String getHTMLEmail(String userFirstName, String creatorUsername, String creatorFullName, String vreScope) { + String sender = creatorFullName + " ("+creatorUsername+") "; + + StringBuilder body = new StringBuilder(); + + body.append("
") + .append("
") + .append("Dear ").append(userFirstName).append(",") //dear + .append("

").append(sender).append(" ").append("created the following email: ") // has done something + .append(vreScope) + .append("


") + .append("

You received this email because you are an Infrastructure Manager in this portal

") + .append("

") + .append(""); + + return body.toString(); + } + +} diff --git a/src/main/java/org/gcube/portlets/admin/vredeployer/server/VREDeployerServiceImpl.java b/src/main/java/org/gcube/portlets/admin/vredeployer/server/VREDeployerServiceImpl.java index 21dbbdd..8f50f67 100644 --- a/src/main/java/org/gcube/portlets/admin/vredeployer/server/VREDeployerServiceImpl.java +++ b/src/main/java/org/gcube/portlets/admin/vredeployer/server/VREDeployerServiceImpl.java @@ -78,7 +78,6 @@ import org.gcube.vomanagement.usermanagement.RoleManager; import org.gcube.vomanagement.usermanagement.UserManager; 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.LiferayGroupManager; import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager; import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager; @@ -119,7 +118,7 @@ import com.liferay.portal.service.UserLocalServiceUtil; /** * The server side implementation of the RPC service. */ -@SuppressWarnings("serial") +@SuppressWarnings({ "deprecation", "serial" }) public class VREDeployerServiceImpl extends RemoteServiceServlet implements VredeployerService { private static final Logger log = LoggerFactory.getLogger(VREDeployerServiceImpl.class); @@ -133,7 +132,6 @@ public class VREDeployerServiceImpl extends RemoteServiceServlet implements Vre protected static final String ORGANIZATION_DEFAULT_LOGO = "/org/gcube/portal/custom/communitymanager/resources/default_logo.png"; protected static final String ORGANIZATION_DEFAULT_LOGO_URL = "http://ftp.d4science.org/apps/profiles/d4slogo.png"; - private static final int LIFERAY_REGULAR_ROLE_ID = 1; /** * */ @@ -271,29 +269,6 @@ public class VREDeployerServiceImpl extends RemoteServiceServlet implements Vre } - - - /** - * return the name and last name of the user - * @param username - * @return - */ - private String getFullname(String screenName) { - UserManager um = new LiferayUserManager(); - GCubeUser user = null; - try { - user = um.getUserByScreenName(screenName); - } catch (UserManagementSystemException e) { - e.printStackTrace(); - } catch (UserRetrievalFault e) { - e.printStackTrace(); - } - return user.getFullname(); - } - - - - /** * read the available functionality from the service through ASL extension */ @@ -698,11 +673,11 @@ public class VREDeployerServiceImpl extends RemoteServiceServlet implements Vre if (report.getStatus() == Status.Finished) { log.info("--- Create VRE COMPLETED, CREATING LAYOUTS AND COMMUNITY ... "); - String name = ""; + String vreName = ""; String description = ""; try { VREDescription de = vreGenerator.getVREModel(); - name = de.name(); + vreName = de.name(); description = de.description(); } catch (RemoteException e) { e.printStackTrace(); @@ -712,15 +687,16 @@ public class VREDeployerServiceImpl extends RemoteServiceServlet implements Vre log.info("ADDING user designer and manager, found designer: " + designer + " found manager: "+manager); - long vreCreatedId = createCommunityAndLayoutAndHLFolder(name, description); + long vreCreatedId = createCommunityAndLayoutAndHLFolder(vreName, description); log.info("--- createCommunityAndLayout COMPLETED, vreCreatedId="+vreCreatedId); - + String vreScope = ""; + GCubeUser userManager = null; if (vreCreatedId > 0) { try { org.gcube.vomanagement.usermanagement.model.GCubeGroup vreCreated = new LiferayGroupManager().getGroup(vreCreatedId); log.info("--- CREATED LAYOUTS AND COMMUNITY OK, updating Calendar Application Profile."); - String vreScope = new LiferayGroupManager().getInfrastructureScope(vreCreatedId); + vreScope = new LiferayGroupManager().getInfrastructureScope(vreCreatedId); String vreUrl = "/group/"+vreCreated.getGroupName().toLowerCase(); boolean calandarAppProfileUpdated = false; try { @@ -741,13 +717,13 @@ public class VREDeployerServiceImpl extends RemoteServiceServlet implements Vre UserManager um = new LiferayUserManager(); GCubeUser userDesigner = um.getUserByUsername(designer); - GCubeUser userManager = um.getUserByUsername(manager); + userManager = um.getUserByUsername(manager); Workspace workspace = HomeLibrary.getUserWorkspace(getASLSession().getUsername()); ArrayList toSend = new ArrayList(); toSend.add(designer); String subject = "Definition approved and deployed"; - String body = "Dear "+userDesigner.getFirstName()+", \n\n" + userManager.getFullname() + " has approved the deployment of the group you requested: " + name +"."; + String body = "Dear "+userDesigner.getFirstName()+", \n\n" + userManager.getFullname() + " has approved the deployment of the group you requested: " + vreName +"."; body+=".\n\nThis group has been deployed successfully and is already available for you on this portal. Please, check your list."; String messageId = workspace.getWorkspaceMessageManager().sendMessageToPortalLogins(subject, body, new ArrayList(), toSend); NotificationsManager nnm = new ApplicationNotificationsManager( @@ -763,7 +739,10 @@ public class VREDeployerServiceImpl extends RemoteServiceServlet implements Vre //log.info("--- Trying to share a news for this VRE"); //shareCreatedVRENews(designer, manager, name, description); - + log.info("onAfterCreate VRE: " + vreScope); + long currGroupId = PortalContext.getConfiguration().getCurrentGroupId(getThreadLocalRequest()); + Thread emailManagersThread = new Thread(new NewVRECreatedThread(userManager.getUsername(), userManager.getFullname(), vreScope, vreName, currGroupId)); + emailManagersThread.start(); } else @@ -881,7 +860,7 @@ public class VREDeployerServiceImpl extends RemoteServiceServlet implements Vre log.error("NO VRE-MANAGER FOUND IN THIS VRE"); } ScopeProvider.instance.set(currScope); - } + } /** * return the infrastructure name @@ -1176,19 +1155,6 @@ public class VREDeployerServiceImpl extends RemoteServiceServlet implements Vre } } - - /** - * CHECK IF THE VRE DEPLOYMENT IS FINISHED - * @param report - * @return - */ - private String getGlobalDeploymentStatus(String report) { - String ret = "NOT FINISHED"; - - return ret; - } - - /** * * @param profile @@ -1259,16 +1225,6 @@ public class VREDeployerServiceImpl extends RemoteServiceServlet implements Vre return resultStream.toString(); } - - /** - * simulate a report - * @return - */ - private DeployReport simulateReport() { - DeployReport reportToReturn = new DeployReport(); - return reportToReturn; - } - /** * * @param path