adapted for Liferay 6.2

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/admin/register-vre-users@125519 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2016-03-16 17:46:20 +00:00
parent 1bef444ee2
commit 15179e1595
6 changed files with 43 additions and 53 deletions

View File

@ -5,9 +5,6 @@
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/target/generated-sources/gwt"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<dependent-module archiveName="invites-common-library-1.1.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/invites-common-library/invites-common-library">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="java-output-path" value="/${module}/target/www/WEB-INF/classes"/>
<property name="context-root" value="register-vre-users"/>
</wb-module>

View File

@ -15,8 +15,6 @@
<includes>
<include>README</include>
<include>LICENSE</include>
<include>INSTALL</include>
<include>MAINTAINERS</include>
<include>changelog.xml</include>
</includes>
<fileMode>755</fileMode>

View File

@ -98,13 +98,7 @@
<groupId>org.gcube.common</groupId>
<artifactId>home-library</artifactId>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>asm-all</artifactId>
<groupId>asm</groupId>
</exclusion>
</exclusions>
</dependency>
</dependency>
<dependency>
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>invite-friends-widget</artifactId>

View File

@ -7,6 +7,7 @@ import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager;
import org.gcube.applicationsupportlayer.social.NotificationsManager;
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingUser;
import org.gcube.common.homelibrary.home.HomeLibrary;
import org.gcube.common.homelibrary.home.workspace.Workspace;
import org.gcube.common.scope.impl.ScopeBean;
@ -38,11 +39,11 @@ import com.liferay.portal.service.UserLocalServiceUtil;
public class ManageUsersServiceImpl extends RemoteServiceServlet implements ManageUsersService {
private static final Logger _log = LoggerFactory.getLogger(ManageUsersServiceImpl.class);
private boolean withinPortal = false;
private GroupManager groupM = new LiferayGroupManager();
private UserManager userM = new LiferayUserManager();
private final static String POSITION = "POSITION";
private final static String LABS = "LABS";
@ -59,16 +60,28 @@ public class ManageUsersServiceImpl extends RemoteServiceServlet implements Man
}
else {
_log.info("LIFERAY PORTAL DETECTED user=" + user);
withinPortal = true;
}
return SessionManager.getInstance().getASLSession(sessionID, user);
}
/**
*
* @return true if you're running into the portal, false if in development
*/
private boolean isWithinPortal() {
try {
UserLocalServiceUtil.getService();
return true;
}
catch (com.liferay.portal.kernel.bean.BeanLocatorException ex) {
_log.trace("Development Mode ON");
return false;
}
}
@Override
public ArrayList<PortalUserDTO> getAvailableUsers() {
getASLSession();
ArrayList<PortalUserDTO> toReturn = new ArrayList<PortalUserDTO>();
if (withinPortal) {
if (isWithinPortal()) {
return getNonBelongingUsersForVRE();
}
else {
@ -105,19 +118,23 @@ public class ManageUsersServiceImpl extends RemoteServiceServlet implements Man
try {
long companyId = SiteManagerUtil.getCompany().getCompanyId();
_log.trace("Setting Thread Permission");
User user = UserLocalServiceUtil.getUserByScreenName(companyId, ScopeHelper.getAdministratorUsername());
PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user);
User userAdmin = UserLocalServiceUtil.getUserByScreenName(companyId, ScopeHelper.getAdministratorUsername());
_log.trace("Setting Thread Permission for admin="+userAdmin.getScreenName());
PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(userAdmin);
PermissionThreadLocal.setPermissionChecker(permissionChecker);
_log.trace("Setting Permission ok!");
ArrayList<PortalUserDTO> unregisteredUsers = new ArrayList<PortalUserDTO>();
List<GCubeUser> notBelongingUsers = userM.listUnregisteredUsersByGroup(getCurrentGroupID());
for (GCubeUser u : notBelongingUsers) {
String id = u.getScreenName();
user = UserLocalServiceUtil.getUserByScreenName(companyId, id);
String position = (user.getExpandoBridge().getAttribute(POSITION) != null) ? user.getExpandoBridge().getAttribute(POSITION).toString() : "";
String labs = (user.getExpandoBridge().getAttribute(LABS) != null) ? user.getExpandoBridge().getAttribute(LABS).toString() : "";
String id = u.getUsername();
User user = UserLocalServiceUtil.getUserByScreenName(companyId, id);
String position = "";
String labs = "";
if (user.getExpandoBridge() != null && user.getExpandoBridge().hasAttribute(POSITION)) {
position = (user.getExpandoBridge().getAttribute(POSITION) != null) ? user.getExpandoBridge().getAttribute(POSITION).toString() : "";
labs = (user.getExpandoBridge().getAttribute(LABS) != null) ? user.getExpandoBridge().getAttribute(LABS).toString() : "";
}
if ((u.getLastName() != null && u.getLastName().compareTo("") != 0)) {
String firstLetter = u.getLastName().substring(0,1);
String scope = getASLSession().getScope();
@ -125,21 +142,19 @@ public class ManageUsersServiceImpl extends RemoteServiceServlet implements Man
String email = u.getEmail();
String username = id;
if (validator.is(Type.VRE)) {
email = "********@"+ email.split("@")[1];
email = "********@"+ email.split("@")[1];
}
PortalUserDTO myUser = new PortalUserDTO(username, firstLetter, u.getFirstName(), u.getLastName(), email, position, labs);
unregisteredUsers.add(myUser);
}
}
_log.debug("The total unregistered users are: " + unregisteredUsers.size());
_log.trace("Setting Thread Permission back to regular");
user = UserLocalServiceUtil.getUserByScreenName(companyId, getASLSession().getUsername());
permissionChecker = PermissionCheckerFactoryUtil.create(user, false);
User user = UserLocalServiceUtil.getUserByScreenName(companyId, getASLSession().getUsername());
permissionChecker = PermissionCheckerFactoryUtil.create(user);
PermissionThreadLocal.setPermissionChecker(permissionChecker);
_log.trace("Setting Permission ok!");
return unregisteredUsers;
}
catch (Exception e) {
@ -156,9 +171,6 @@ public class ManageUsersServiceImpl extends RemoteServiceServlet implements Man
try {
//add the user to the VRE
userM.assignUserToGroup(getCurrentGroupID(), userM.getUserId(user.getId()));
//add him to the HL
ASLSession session = getASLSession();
addUserToHLGroup(user.getId(), session.getScope(), session.getUsername());
//send notification
sendNotificationToUser(user);
}
@ -181,16 +193,17 @@ public class ManageUsersServiceImpl extends RemoteServiceServlet implements Man
List<String> recipientIds = new ArrayList<String>();
recipientIds.add(addressee.getId());
List<GenericItemBean> recipients = new ArrayList<GenericItemBean>();
recipients.add(new GenericItemBean(addressee.getId(), addressee.getId(), addressee.getName() + " " + addressee.getLastName(), ""));
String subject = "Registration to Group Notification";
String body = "Dear "+addressee.getName()+", \n\n" + session.getUserFullName() + " has registered you to the group " + getASLSession().getGroupName()+".";
String body = "Dear "+addressee.getName()+", \n\n" + session.getUserFullName() + " has registered you to the group " + session.getGroupName()+".";
String messageId = workspace.getWorkspaceMessageManager().sendMessageToPortalLogins(subject, body, new ArrayList<String>(), recipientIds);
_log.debug("Sending message notification to: " + recipientIds.toString());
NotificationsManager nm = new ApplicationNotificationsManager(getASLSession());
NotificationsManager nm = new ApplicationNotificationsManager(session.getScope(), new SocialNetworkingUser(
session.getUsername(), session.getUserEmailAddress(), session.getUserFullName(), session.getUserAvatarId()));
Thread thread = new Thread(new MessageNotificationsThread(recipients, messageId, subject, body, nm));
thread.start();
@ -215,16 +228,4 @@ public class ManageUsersServiceImpl extends RemoteServiceServlet implements Man
return toReturn;
}
private void addUserToHLGroup(String username, String group, String adminUsername) {
try {
org.gcube.common.homelibrary.home.workspace.usermanager.UserManager um = HomeLibrary.getHomeManagerFactory().getUserManager();
um.associateUserToGroup(group, username, adminUsername);
} catch (Exception e) {
_log.error("Failed to get the usermanager from HL. Could not add user to the HL group");
}
}
}

View File

@ -1,5 +1,5 @@
<?xml version="1.0"?>
<!DOCTYPE display PUBLIC "-//Liferay//DTD Display 5.2.0//EN" "http://www.liferay.com/dtd/liferay-display_5_2_0.dtd">
<!DOCTYPE display PUBLIC "-//Liferay//DTD Display 6.2.0//EN" "http://www.liferay.com/dtd/liferay-display_6_2_0.dtd">
<display>
<category name="gCube Enabling Apps">

View File

@ -1,5 +1,5 @@
<?xml version="1.0"?>
<!DOCTYPE liferay-portlet-app PUBLIC "-//Liferay//DTD Portlet Application 5.2.0//EN" "http://www.liferay.com/dtd/liferay-portlet-app_5_2_0.dtd">
<!DOCTYPE liferay-portlet-app PUBLIC "-//Liferay//DTD Portlet Application 6.2.0//EN" "http://www.liferay.com/dtd/liferay-portlet-app_6_2_0.dtd">
<liferay-portlet-app>
<portlet>