Massimiliano Assante 6 years ago
parent ce14e4a45d
commit 27d8febb23

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/vre-deploy-4.0.1-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<classpathentry kind="src" output="target/vre-deploy-4.1.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/vre-deploy-4.0.1-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<classpathentry excluding="**" kind="src" output="target/vre-deploy-4.1.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
@ -39,5 +39,5 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/vre-deploy-4.0.1-SNAPSHOT/WEB-INF/classes"/>
<classpathentry kind="output" path="target/vre-deploy-4.1.0-SNAPSHOT/WEB-INF/classes"/>
</classpath>

@ -1,15 +1,28 @@
<ReleaseNotes>
<Changeset component="org.gcube.portlets-admin.vre-deploy.4-0-1" date="2016-10-04">
<Changeset component="org.gcube.portlets-admin.vre-deploy.4-1-0"
date="2017-12-06">
<Change>Feature #5729, send email to infraManagers upon new VRE
cretions</Change>
<Change>Task #10052, send email to infraManagers upon new VRE cretions
</Change>
</Changeset>
<Changeset component="org.gcube.portlets-admin.vre-deploy.4-0-1"
date="2016-10-04">
<Change>Fixed pom dependency for registry publisher</Change>
</Changeset>
<Changeset component="org.gcube.portlets-admin.vre-deploy.4-0-0" date="2016-06-30">
<Changeset component="org.gcube.portlets-admin.vre-deploy.4-0-0"
date="2016-06-30">
<Change>Ported to Liferay 6.2 API</Change>
</Changeset>
<Changeset component="org.gcube.portlets-admin.vre-deploy.3-4-0" date="2015-10-05">
<Change>Fix for bug #712, VRE Folder not created if manager and designer are the same user</Change>
<Changeset component="org.gcube.portlets-admin.vre-deploy.3-4-0"
date="2015-10-05">
<Change>Fix for bug #712, VRE Folder not created if manager and
designer are the same user</Change>
</Changeset>
<Changeset component="org.gcube.portlets-admin.vre-deploy.3-3-0" date="2014-06-06">
<Change>Added creation of New Layout including Register Users Portlet</Change>
<Changeset component="org.gcube.portlets-admin.vre-deploy.3-3-0"
date="2014-06-06">
<Change>Added creation of New Layout including Register Users Portlet
</Change>
</Changeset>
<Changeset component="org.gcube.portlets-admin.vre-deploy.3-1-0"
date="2014-02-14">

@ -12,7 +12,7 @@
<groupId>org.gcube.portlets.admin</groupId>
<artifactId>vre-deploy</artifactId>
<packaging>war</packaging>
<version>4.0.1-SNAPSHOT</version>
<version>4.1.0-SNAPSHOT</version>
<name>gCube VRE Deploy Wizard Portlet</name>
<description>
gCube VRE Deploy Wizard Portlet.
@ -28,7 +28,7 @@
<distroDirectory>distro</distroDirectory>
<!-- GWT needs at least java 1.6 -->
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.target>1.8</maven.compiler.target>
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -46,6 +46,11 @@
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.gcube.information-system</groupId>
<artifactId>resource-registry-context-client</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>

@ -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<Context> 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<GCubeUser> 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("<body><br />")
.append("<div style=\"color:#000; font-size:13px; font-family:'lucida grande',tahoma,verdana,arial,sans-serif;\">")
.append("Dear ").append(userFirstName).append(",") //dear <user>
.append("<p>").append(sender).append(" ").append("created the following email: ") // has done something
.append(vreScope)
.append("</div><br />")
.append("<p>You received this email because you are an Infrastructure Manager in this portal</p>")
.append("</div></p>")
.append("</body>");
return body.toString();
}
}

@ -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<String> toSend = new ArrayList<String>();
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<String>(), 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

Loading…
Cancel
Save