package org.gcube.portlets.user.vremembers.server; import java.util.ArrayList; import java.util.Collections; import org.gcube.application.framework.core.session.ASLSession; import org.gcube.application.framework.core.session.SessionManager; import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; import org.gcube.portlets.user.joinvre.client.JoinService; import org.gcube.portlets.user.vremembers.shared.UserBelonging; import org.gcube.portlets.user.vremembers.shared.VRE; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.gwt.user.server.rpc.RemoteServiceServlet; import com.liferay.portal.service.UserLocalServiceUtil; /** * @author Massimiliano Assante, ISTI-CNR - massimiliano.assante@isti.cnr.it * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ */ @SuppressWarnings("serial") public class JoinServiceImpl extends RemoteServiceServlet implements JoinService { private static final Logger _log = LoggerFactory.getLogger(JoinServiceImpl.class); /** * 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"; return 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; } } /** * * @param session the Asl Session * @param withinPortal true when is on Liferay portal * @return the users belonging to the current organization (scope) */ @Override public ArrayList getVREs() { ArrayList vres = new ArrayList(); try { if (isWithinPortal()) { } else { vres.add(new VRE(0, "devsec", "devsec VRE", "", "", "/group/devsec", UserBelonging.NOT_BELONGING, false)); vres.add(new VRE(0, "devVRE", "devVRE VRE", "", "", "/group/devVRE", UserBelonging.NOT_BELONGING, false)); vres.add(new VRE(0, "devmode", "devmode VRE", "", "", "/group/devmode", UserBelonging.NOT_BELONGING, true)); } } catch (Exception e) { _log.error("Error in server get all contacts ", e); } // Ordering VREs by Name Collections.sort(vres); return vres; } }