removed ASL Session, ported to gCube Client Context
git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portlets/user/join-vre@134164 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
51fb7e23c9
commit
402b9ede25
|
@ -1,12 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/join-vre-3.1.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
|
||||
<classpathentry kind="src" output="target/join-vre-3.2.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/join-vre-3.1.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
|
||||
<classpathentry excluding="**" kind="src" output="target/join-vre-3.2.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/join-vre-3.1.0-SNAPSHOT/WEB-INF/classes"/>
|
||||
<classpathentry kind="output" path="target/join-vre-3.2.0-SNAPSHOT/WEB-INF/classes"/>
|
||||
</classpath>
|
||||
|
|
12
pom.xml
12
pom.xml
|
@ -13,7 +13,7 @@
|
|||
<groupId>org.gcube.portlets.user</groupId>
|
||||
<artifactId>join-vre</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<version>3.1.0-SNAPSHOT</version>
|
||||
<version>3.2.0-SNAPSHOT</version>
|
||||
<name>gCube Join VRE Portlet</name>
|
||||
<description>Display the available VRE to Join</description>
|
||||
<scm>
|
||||
|
@ -70,21 +70,11 @@
|
|||
<groupId>com.github.gwtbootstrap</groupId>
|
||||
<artifactId>gwt-bootstrap</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.portal</groupId>
|
||||
<artifactId>custom-portal-handler</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common.portal</groupId>
|
||||
<artifactId>portal-manager</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.applicationsupportlayer</groupId>
|
||||
<artifactId>aslcore</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.portal</groupId>
|
||||
<artifactId>invites-common-library</artifactId>
|
||||
|
|
|
@ -8,11 +8,8 @@ import java.util.List;
|
|||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.gcube.application.framework.core.session.ASLSession;
|
||||
import org.gcube.application.framework.core.session.SessionManager;
|
||||
import org.gcube.common.portal.GCubePortalConstants;
|
||||
import org.gcube.common.portal.PortalContext;
|
||||
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
|
||||
import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl;
|
||||
import org.gcube.portal.databook.server.DatabookStore;
|
||||
import org.gcube.portal.databook.shared.Invite;
|
||||
|
@ -63,33 +60,7 @@ import com.liferay.portal.util.PortalUtil;
|
|||
@SuppressWarnings("serial")
|
||||
public class JoinServiceImpl extends RemoteServiceServlet implements JoinService {
|
||||
private static Log _log = LogFactoryUtil.getLog(JoinServiceImpl.class);
|
||||
public static final String TEST_USER = "test.user";
|
||||
private static final String TEST_SCOPE = "/gcube/devsec/devVRE";
|
||||
private static DatabookStore store;
|
||||
/**
|
||||
* the current ASLSession
|
||||
* @return the session
|
||||
*/
|
||||
private ASLSession getASLSession() {
|
||||
String sessionID = this.getThreadLocalRequest().getSession().getId();
|
||||
String user = (String) this.getThreadLocalRequest().getSession().getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
|
||||
if (user == null) {
|
||||
_log.warn("USER IS NULL setting test.user and Running OUTSIDE PORTAL");
|
||||
user = getDevelopmentUser();
|
||||
SessionManager.getInstance().getASLSession(sessionID, user).setScope("/gcube");
|
||||
}
|
||||
return SessionManager.getInstance().getASLSession(sessionID, user);
|
||||
}
|
||||
|
||||
/**
|
||||
* when packaging test will fail if the user is not set to test.user
|
||||
* @return .
|
||||
*/
|
||||
public String getDevelopmentUser() {
|
||||
String user = TEST_USER;
|
||||
// user = "andrea.rossi";
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -143,7 +114,7 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
|
|||
*/
|
||||
public LinkedHashMap<VRECategory, ArrayList<VRE>> getPortalSitesMappedToVRE() throws Exception {
|
||||
|
||||
ASLSession session = getASLSession();
|
||||
|
||||
GroupManager gm = new LiferayGroupManager();
|
||||
LinkedHashMap<VRECategory, ArrayList<VRE>> toReturn = new LinkedHashMap<VRECategory, ArrayList<VRE>>();
|
||||
|
||||
|
@ -163,10 +134,11 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
|
|||
_log.error("Cannot find root organziation, please check gcube-data.properties file in $CATALINA_HOME/conf folder, unless your installing the Bundle");
|
||||
return toReturn;
|
||||
}
|
||||
PortalContext pContext = PortalContext.getConfiguration();
|
||||
|
||||
List<GCubeGroup> currUserGroups = new ArrayList<GCubeGroup>();
|
||||
if (session.getUsername().compareTo(TEST_USER) != 0) {
|
||||
GCubeUser currUser = new LiferayUserManager().getUserByUsername(session.getUsername());
|
||||
GCubeUser currUser = pContext.getCurrentUser(getThreadLocalRequest());
|
||||
if (currUser != null) {
|
||||
currUserGroups = gm.listGroupsByUser(currUser.getUserId());
|
||||
}
|
||||
|
||||
|
@ -193,8 +165,7 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
|
|||
ArrayList<VRE> toUpdate = toReturn.get(toLookFor);
|
||||
UserBelonging belongs = UserBelonging.NOT_BELONGING;
|
||||
VRE toAdd = new VRE(vreID,vreName, vreDescription, vreLogoURL, groupName, friendlyURL, belongs, getVREMembershipType(vreOrganization.getMembershipType()));
|
||||
if (session.getUsername().compareTo(TEST_USER) != 0) {
|
||||
GCubeUser currUser = new LiferayUserManager().getUserByUsername(session.getUsername());
|
||||
if (currUser != null) {
|
||||
//check if the user belongs to it
|
||||
if (currUserGroups.contains(vreOrganization)) {
|
||||
toAdd.setUserBelonging(UserBelonging.BELONGING);
|
||||
|
@ -279,11 +250,10 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
|
|||
@Override
|
||||
public VRE getSelectedVRE(Long groupId) {
|
||||
_log.debug("*getting Selected Research Environment from referral, site id = " + groupId);
|
||||
ASLSession session = getASLSession();
|
||||
|
||||
VRE toReturn = null;
|
||||
try {
|
||||
GroupManager gm = new LiferayGroupManager();
|
||||
UserManager um = new LiferayUserManager();
|
||||
GCubeGroup selectedVRE = gm.getGroup(groupId);
|
||||
String vreName = selectedVRE.getGroupName();
|
||||
String vreDescription = selectedVRE.getDescription();
|
||||
|
@ -295,14 +265,12 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
|
|||
String friendlyURL = GCubePortalConstants.PREFIX_GROUP_URL+selectedVRE.getFriendlyURL();
|
||||
|
||||
|
||||
|
||||
|
||||
GCubeUser currUser = um.getUserByUsername(session.getUsername());
|
||||
GCubeUser currUser = PortalContext.getConfiguration().getCurrentUser(getThreadLocalRequest());
|
||||
//check if the user belongs to it
|
||||
UserBelonging belongEnum = UserBelonging.NOT_BELONGING;
|
||||
if (gm.listGroupsByUser(currUser.getUserId()).contains(selectedVRE))
|
||||
belongEnum = UserBelonging.BELONGING;
|
||||
else if (checkPending(session.getUsername(), selectedVRE.getGroupId()))
|
||||
else if (checkPending(currUser.getUsername(), selectedVRE.getGroupId()))
|
||||
belongEnum = UserBelonging.PENDING;
|
||||
//return the selected VRE for this user
|
||||
toReturn = new VRE(groupId, vreName, vreDescription, vreLogoURL, infraScope, friendlyURL, belongEnum, getVREMembershipType(selectedVRE.getMembershipType()));
|
||||
|
@ -348,7 +316,7 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
|
|||
|
||||
@Override
|
||||
public void addMembershipRequest(String scope, String optionalMessage) {
|
||||
String username = getASLSession().getUsername();
|
||||
String username = PortalContext.getConfiguration().getCurrentUser(getThreadLocalRequest()).getUsername();
|
||||
if (optionalMessage == null || optionalMessage.compareTo("") == 0)
|
||||
optionalMessage = "none";
|
||||
try {
|
||||
|
@ -387,13 +355,11 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
|
|||
public boolean registerUser(String scope, long groupId, boolean isInvitation) {
|
||||
UserManager um = new LiferayUserManager();
|
||||
try {
|
||||
ASLSession session = getASLSession();
|
||||
String username = session.getUsername();
|
||||
_log.debug("registerUser " +username + " to "+ scope);
|
||||
GCubeUser currUser = um.getUserByUsername(username);
|
||||
GCubeUser currUser = PortalContext.getConfiguration().getCurrentUser(getThreadLocalRequest());
|
||||
_log.debug("registerUser " +currUser.getUsername() + " to "+ scope);
|
||||
GroupManager gm = new LiferayGroupManager();
|
||||
um.requestMembership(currUser.getUserId(), gm.getGroupIdFromInfrastructureScope(scope), "Automatic Request at " + new Date());
|
||||
_log.info("fakeRequest sent");
|
||||
_log.debug("fakeRequest sent");
|
||||
String replierUsername = LiferayUserManager.getAdmin().getScreenName();
|
||||
_log.trace("Sleep 1 second ...");
|
||||
Thread.sleep(1000);
|
||||
|
@ -401,15 +367,15 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
|
|||
_log.info("fakeRequest accepted");
|
||||
if (isInvitation) {
|
||||
initStore();
|
||||
String inviteId = store.isExistingInvite(scope, session.getUserEmailAddress());
|
||||
String inviteId = store.isExistingInvite(scope, currUser.getEmail());
|
||||
if (inviteId != null) {
|
||||
Invite invite = store.readInvite(inviteId);
|
||||
store.setInviteStatus(scope, session.getUserEmailAddress(), InviteStatus.ACCEPTED);
|
||||
LoginServiceUtil.notifyUserAcceptedInvite(username, scope, invite, getThreadLocalRequest());
|
||||
store.setInviteStatus(scope, currUser.getEmail(), InviteStatus.ACCEPTED);
|
||||
LoginServiceUtil.notifyUserAcceptedInvite(currUser.getUsername(), scope, invite, getThreadLocalRequest());
|
||||
}
|
||||
}
|
||||
else {
|
||||
LoginServiceUtil.notifyUserSelfRegistration(username, scope, getThreadLocalRequest());
|
||||
LoginServiceUtil.notifyUserSelfRegistration(currUser.getUsername(), scope, getThreadLocalRequest());
|
||||
_log.info("notifyUserSelfRegistration sent");
|
||||
}
|
||||
}
|
||||
|
@ -434,26 +400,15 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
|
|||
|
||||
@Override
|
||||
public String isExistingInvite(long groupId) {
|
||||
getASLSession();
|
||||
|
||||
_log.debug("initiating Store");
|
||||
initStore();
|
||||
_log.debug("initStore OK");
|
||||
String infraScope = "";
|
||||
String email = "";
|
||||
if (! isWithinPortal()) {
|
||||
infraScope = TEST_SCOPE;
|
||||
email = "m.assante@gmail.com";
|
||||
} else {
|
||||
GroupManager gm = new LiferayGroupManager();
|
||||
email = getASLSession().getUserEmailAddress();
|
||||
try {
|
||||
infraScope = gm.getInfrastructureScope(groupId);
|
||||
} catch (UserManagementSystemException | GroupRetrievalFault e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
_log.debug("checking if invite exists for " + email + " on " +infraScope);
|
||||
|
||||
String email = PortalContext.getConfiguration().getCurrentUser(getThreadLocalRequest()).getEmail();
|
||||
String infraScope = PortalContext.getConfiguration().getCurrentScope(getThreadLocalRequest());
|
||||
|
||||
_log.debug("checking if invite exists for " + email + " on " +infraScope);
|
||||
return store.isExistingInvite(infraScope, email);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,34 +7,15 @@ import javax.portlet.ActionResponse;
|
|||
import javax.portlet.GenericPortlet;
|
||||
import javax.portlet.PortletException;
|
||||
import javax.portlet.PortletRequestDispatcher;
|
||||
import javax.portlet.PortletSession;
|
||||
import javax.portlet.RenderRequest;
|
||||
import javax.portlet.RenderResponse;
|
||||
|
||||
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
|
||||
|
||||
import com.liferay.portal.kernel.log.Log;
|
||||
import com.liferay.portal.kernel.log.LogFactoryUtil;
|
||||
import com.liferay.portal.kernel.util.WebKeys;
|
||||
import com.liferay.portal.theme.ThemeDisplay;
|
||||
|
||||
/**
|
||||
* @author Massimiliano Assante, ISTI-CNR - massimiliano.assante@isti.cnr.it
|
||||
*/
|
||||
public class JoinVREPortlet extends GenericPortlet {
|
||||
|
||||
private static Log _log = LogFactoryUtil.getLog(JoinVREPortlet.class);
|
||||
|
||||
public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
|
||||
response.setContentType("text/html");
|
||||
try {
|
||||
ScopeHelper.setContext(request);
|
||||
} catch(Exception e){
|
||||
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
|
||||
request.getPortletSession().setAttribute(WebKeys.THEME_DISPLAY, themeDisplay, PortletSession.APPLICATION_SCOPE);
|
||||
_log.error("The following exception is acceptable if the user is not logged.");
|
||||
}
|
||||
|
||||
PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/JoinVRE_view.jsp");
|
||||
dispatcher.include(request, response);
|
||||
}
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
package org.gcube.portlets.user.test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.gcube.portlets.user.joinvre.server.JoinServiceImpl;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestForDeploy {
|
||||
|
||||
@Test
|
||||
public void testUserIsTestUser() {
|
||||
JoinServiceImpl serviceImpl = new JoinServiceImpl();
|
||||
String username = serviceImpl.getDevelopmentUser();
|
||||
System.out.println("username for deploy is: " + username);
|
||||
assertTrue(username.compareTo(JoinServiceImpl.TEST_USER) == 0);
|
||||
System.out.println("Test OK!");
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue