changed for adding automataccly users to the ResourceCatalogue and SBDLab VREs
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/liferay62-plugins/landing-page-library@163235 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
a76bf59b5e
commit
bbb5e4f2e8
|
@ -1,12 +1,14 @@
|
|||
package org.gcube.portal.landingpage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.gcube.common.portal.PortalContext;
|
||||
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;
|
||||
|
@ -76,11 +78,14 @@ public class LandingPageManager {
|
|||
}
|
||||
}
|
||||
if (! isRegistered) {
|
||||
_log.debug("But user " + currentUser.getFullName() + " is not registered to " + site.getName() + ". going to register ...");
|
||||
_log.info("But user " + currentUser.getFullName() + " is not registered to " + site.getName() + ". going to register ...");
|
||||
String portalURL = PortalContext.getConfiguration().getGatewayURL(request);
|
||||
registerUserToSite(currentUser, site, portalURL);
|
||||
|
||||
_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));
|
||||
resourceCatalogueSBDThread.start();
|
||||
Thread sobigdatalabSBDThread = new Thread(new SoBigDataLabRegistrationThread(userSites, currentUser, portalURL));
|
||||
|
@ -112,6 +117,30 @@ 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)) {
|
||||
|
|
|
@ -47,7 +47,7 @@ public class ResourceCatalogueRegistrationThread implements Runnable {
|
|||
if (!isRegistered) {
|
||||
try {
|
||||
_log.info("SBD Hook " + user.getFullName() + " is not registered to the Resource Catalogue VRE, forcing registration.");
|
||||
LandingPageManager.registerUserToSite(user, resourceCatalogueGroup, siteURL);
|
||||
LandingPageManager.registerUserToVRE(user, resourceCatalogueGroup, siteURL);
|
||||
} catch (SystemException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ public class SoBigDataLabRegistrationThread implements Runnable {
|
|||
if (!isRegistered) {
|
||||
try {
|
||||
_log.info("SBD Hook " + user.getFullName() + " is not registered to SoBigDataLab VRE, forcing registration.");
|
||||
LandingPageManager.registerUserToSite(user, soBigDataLabGroup, siteURL);
|
||||
LandingPageManager.registerUserToVRE(user, soBigDataLabGroup, siteURL);
|
||||
} catch (SystemException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue