git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/liferay62-plugins/landing-page-library@163239 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2018-02-13 17:11:51 +00:00
parent bbb5e4f2e8
commit 7349f85233
4 changed files with 118 additions and 142 deletions

View File

@ -85,11 +85,9 @@ public class LandingPageManager {
_log.info("currentVirtualHost = " + currentVirtualHost);
//only for SBD Gateway we check if the user belongs to resource catalogue VRE and SoBigDataLab VRE
if (currentVirtualHost.equalsIgnoreCase(SBD_GATEWAY_VHOST)) {
_log.info("currentVirtualHost.equalsIgnoreCase ->" + SBD_GATEWAY_VHOST);
Thread resourceCatalogueSBDThread = new Thread(new ResourceCatalogueRegistrationThread(userSites, currentUser, portalURL));
_log.debug("currentVirtualHost.equalsIgnoreCase ->" + SBD_GATEWAY_VHOST);
Thread resourceCatalogueSBDThread = new Thread(new ResourceCatalogueAndSBDLabRegistrationThread(userSites, currentUser, portalURL));
resourceCatalogueSBDThread.start();
Thread sobigdatalabSBDThread = new Thread(new SoBigDataLabRegistrationThread(userSites, currentUser, portalURL));
sobigdatalabSBDThread.start();
}
}
break;
@ -117,30 +115,6 @@ public class LandingPageManager {
emailSiteManagersThread.start();
}
/**
* the user to the VRE, plus send notifications to the vre manages of the vre
* in order to register a user i had to create a fake membership request because assigning a user to a group would have required
* the user to logout and login otherwise
*/
protected static void registerUserToVRE(User user, Group vre, String siteURL) throws SystemException {
UserManager um = new LiferayUserManager();
try {
um.requestMembership(user.getUserId(), vre.getGroupId(), "Automatic Request at " + new Date());
_log.debug("fakeRequest sent");
String replierUsername = LiferayUserManager.getAdmin().getScreenName();
_log.trace("Sleep 1 second ...");
Thread.sleep(1000);
um.acceptMembershipRequest(user.getUserId(), vre.getGroupId(), true, replierUsername, "Automatic acceptance request at " + new Date());
_log.debug("fakeRequest accepted");
_log.info("User " + user.getScreenName() +" automatically registered to " + vre.getName());
Thread emailSiteManagersThread = new Thread(new NewUserSiteRegistrationNotificationThread(new LiferayUserManager(), new LiferayRoleManager() ,user, vre, siteURL));
emailSiteManagersThread.start();
}catch (Exception e) {
e.printStackTrace();
}
}
public static List<Group> getSites(final long userId) throws PortalException, SystemException {
List<Group> sites = new ArrayList<Group>();
for (Group group : GroupLocalServiceUtil.getUserGroups(userId)) {

View File

@ -0,0 +1,116 @@
package org.gcube.portal.landingpage;
import java.util.Date;
import java.util.List;
import org.gcube.portal.notifications.thread.NewUserSiteRegistrationNotificationThread;
import org.gcube.vomanagement.usermanagement.UserManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.model.Group;
import com.liferay.portal.model.User;
import com.liferay.portal.service.GroupLocalServiceUtil;
/**
*
* @author massi
* register the user to the group having the given group id
*/
public class ResourceCatalogueAndSBDLabRegistrationThread implements Runnable {
private static Logger _log = LoggerFactory.getLogger(ResourceCatalogueAndSBDLabRegistrationThread.class);
private static long RESOURCE_CATALOGUE_GROUPID = 459909;
private static long SOBIGDATA_LAB_GROUPID = 20371853;
private User user;
private Group resourceCatalogueGroup;
private Group soBigDataLabGroup;
private String siteURL;
List<Group> userSites;
UserManager um;
public ResourceCatalogueAndSBDLabRegistrationThread(List<Group> userSites, User user, String siteURL) {
super();
this.user = user;
this.userSites = userSites;
this.siteURL = siteURL;
um = new LiferayUserManager();
try {
resourceCatalogueGroup = GroupLocalServiceUtil.getGroup(RESOURCE_CATALOGUE_GROUPID);
soBigDataLabGroup = GroupLocalServiceUtil.getGroup(SOBIGDATA_LAB_GROUPID);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void run() {
boolean isRegisteredRC = false;
boolean isRegisteredLAB = false;
for (Group group : userSites) {
if (group.getGroupId() == resourceCatalogueGroup.getGroupId()) {
isRegisteredRC = true;
_log.debug("user " + user.getFullName() + " is already registered to the VRE " + resourceCatalogueGroup.getName());
break;
}
}
if (!isRegisteredRC) {
try {
_log.info("SBD Hook " + user.getFullName() + " going to be registered to the VRE " + resourceCatalogueGroup.getName());
registerUserToVRE(user, resourceCatalogueGroup, siteURL);
} catch (SystemException e) {
_log.error("Could not register to "+ resourceCatalogueGroup.getName());
e.printStackTrace();
}
}
try {
Thread.sleep(3000);
_log.info("SBD Hook checking the VRE " + soBigDataLabGroup.getName());
} catch (InterruptedException e1) {
e1.printStackTrace();
}
for (Group group : userSites) {
if (group.getGroupId() == soBigDataLabGroup.getGroupId()) {
isRegisteredLAB = true;
_log.debug("user " + user.getFullName() + " is already registered to the VRE " + soBigDataLabGroup.getName());
break;
}
}
if (!isRegisteredLAB) {
try {
_log.info("SBD Hook " + user.getFullName() + " going to be registered to the VRE " + soBigDataLabGroup.getName());
registerUserToVRE(user, soBigDataLabGroup, siteURL);
} catch (SystemException e) {
_log.error("Could not register to "+ soBigDataLabGroup.getName());
e.printStackTrace();
}
}
}
/**
* the user to the VRE, plus send notifications to the vre manages of the vre
* in order to register a user i had to create a fake membership request because assigning a user to a group would have required
* the user to logout and login otherwise
*/
protected void registerUserToVRE(User user, Group vre, String siteURL) throws SystemException {
try {
um.requestMembership(user.getUserId(), vre.getGroupId(), "Automatic Request at " + new Date());
_log.info("fakeRequest sent");
String replierUsername = LiferayUserManager.getAdmin().getScreenName();
_log.trace("Sleep 1 second ...");
Thread.sleep(2000);
um.acceptMembershipRequest(user.getUserId(), vre.getGroupId(), true, replierUsername, "Automatic acceptance request at " + new Date());
_log.info("fakeRequest accepted");
_log.info("User " + user.getScreenName() +" automatically registered to " + vre.getName());
Thread emailSiteManagersThread = new Thread(new NewUserSiteRegistrationNotificationThread(new LiferayUserManager(), new LiferayRoleManager() ,user, vre, siteURL));
emailSiteManagersThread.start();
}catch (Exception e) {
_log.error("registerUserToVRE FAILED for: "+ vre.getName());
e.printStackTrace();
}
}
}

View File

@ -1,57 +0,0 @@
package org.gcube.portal.landingpage;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.model.Group;
import com.liferay.portal.model.User;
import com.liferay.portal.service.GroupLocalServiceUtil;
/**
*
* @author massi
* register the user to the group having the given group id
*/
public class ResourceCatalogueRegistrationThread implements Runnable {
private static Logger _log = LoggerFactory.getLogger(ResourceCatalogueRegistrationThread.class);
private static long RESOURCE_CATALOGUE_GROUPID = 459909;
private User user;
private Group resourceCatalogueGroup;
private String siteURL;
List<Group> userSites;
public ResourceCatalogueRegistrationThread(List<Group> userSites, User user, String siteURL) {
super();
this.user = user;
this.userSites = userSites;
this.siteURL = siteURL;
try {
resourceCatalogueGroup = GroupLocalServiceUtil.getGroup(RESOURCE_CATALOGUE_GROUPID);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void run() {
boolean isRegistered = false;
for (Group group : userSites) {
if (group.getGroupId() == resourceCatalogueGroup.getGroupId()) {
isRegistered = true;
_log.debug("user " + user.getFullName() + " is already registered to the VRE " + resourceCatalogueGroup.getName());
break;
}
}
if (!isRegistered) {
try {
_log.info("SBD Hook " + user.getFullName() + " is not registered to the Resource Catalogue VRE, forcing registration.");
LandingPageManager.registerUserToVRE(user, resourceCatalogueGroup, siteURL);
} catch (SystemException e) {
e.printStackTrace();
}
}
}
}

View File

@ -1,57 +0,0 @@
package org.gcube.portal.landingpage;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.model.Group;
import com.liferay.portal.model.User;
import com.liferay.portal.service.GroupLocalServiceUtil;
/**
*
* @author massi
* register the user to the group having the given group id
*/
public class SoBigDataLabRegistrationThread implements Runnable {
private static Logger _log = LoggerFactory.getLogger(SoBigDataLabRegistrationThread.class);
private static long SOBIGDATA_LAB_GROUPID = 20371853;
private User user;
private Group soBigDataLabGroup;
private String siteURL;
List<Group> userSites;
public SoBigDataLabRegistrationThread(List<Group> userSites, User user, String siteURL) {
super();
this.user = user;
this.userSites = userSites;
this.siteURL = siteURL;
try {
soBigDataLabGroup = GroupLocalServiceUtil.getGroup(SOBIGDATA_LAB_GROUPID);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void run() {
boolean isRegistered = false;
for (Group group : userSites) {
if (group.getGroupId() == soBigDataLabGroup.getGroupId()) {
isRegistered = true;
_log.debug("user " + user.getFullName() + " is already registered to the VRE " + soBigDataLabGroup.getName());
break;
}
}
if (!isRegistered) {
try {
_log.info("SBD Hook " + user.getFullName() + " is not registered to SoBigDataLab VRE, forcing registration.");
LandingPageManager.registerUserToVRE(user, soBigDataLabGroup, siteURL);
} catch (SystemException e) {
e.printStackTrace();
}
}
}
}