removed ASL Session, ported to gCube Client Context

git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portlets/user/share-updates@134138 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2016-11-14 17:03:55 +00:00
parent 2d84816a04
commit d0222dc355
7 changed files with 78 additions and 176 deletions

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/share-updates-2.1.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<classpathentry kind="src" output="target/share-updates-2.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/share-updates-2.1.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<classpathentry excluding="**" kind="src" output="target/share-updates-2.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/share-updates-2.1.0-SNAPSHOT/WEB-INF/classes"/>
<classpathentry kind="output" path="target/share-updates-2.2.0-SNAPSHOT/WEB-INF/classes"/>
</classpath>

View File

@ -5,7 +5,7 @@
<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="gcube-widgets-2.0.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/gcube-widgets/gcube-widgets">
<dependent-module archiveName="gcube-widgets-2.1.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/gcube-widgets/gcube-widgets">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="java-output-path" value="/${module}/target/www/WEB-INF/classes"/>

19
pom.xml
View File

@ -13,7 +13,7 @@
<groupId>org.gcube.portlets.user</groupId>
<artifactId>share-updates</artifactId>
<packaging>war</packaging>
<version>2.1.0-SNAPSHOT</version>
<version>2.2.0-SNAPSHOT</version>
<name>gCube Share Updates Portlet</name>
<description>
gCube Share Updates for exchanging updates with other users of VREs.
@ -72,6 +72,7 @@
<dependency>
<groupId>org.gcube.common.portal</groupId>
<artifactId>portal-manager</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
@ -83,11 +84,6 @@
<artifactId>notifications-common-library</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslcore</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslsocial</artifactId>
@ -130,10 +126,6 @@
<artifactId>storage-manager-wrapper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>accesslogger</artifactId>
</dependency>
<dependency>
<groupId>org.swinglabs</groupId>
<artifactId>pdf-renderer</artifactId>
@ -173,16 +165,9 @@
<artifactId>home-library-jcr</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>custom-portal-handler</artifactId>
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.dvos</groupId>
<artifactId>usermanagement-core</artifactId>
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>
<dependency>

View File

@ -1,11 +1,8 @@
package org.gcube.portlets.user.shareupdates.client;
import org.gcube.portlets.user.gcubewidgets.client.ClientScopeHelper;
import org.gcube.portlets.user.shareupdates.client.view.ShareUpdateForm;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Window.Location;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.RootPanel;
/**
@ -16,15 +13,6 @@ import com.google.gwt.user.client.ui.RootPanel;
public class ShareUpdates implements EntryPoint {
public void onModuleLoad() {
// start UI and related stuff
ClientScopeHelper.getService().setScope(Location.getHref(), new AsyncCallback<Boolean>() {
@Override
public void onSuccess(Boolean result) {
RootPanel.get("shareUpdateDiv").add(new ShareUpdateForm());
}
@Override
public void onFailure(Throwable caught) {
}
});
RootPanel.get("shareUpdateDiv").add(new ShareUpdateForm());
}
}

View File

@ -19,8 +19,6 @@ import java.util.UUID;
import javax.net.ssl.HttpsURLConnection;
import org.apache.commons.validator.routines.UrlValidator;
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.SocialNetworkingSite;
@ -34,7 +32,6 @@ import org.gcube.contentmanagement.blobstorage.service.IClient;
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
import org.gcube.contentmanager.storageclient.wrapper.MemoryType;
import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
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.Attachment;
@ -105,26 +102,6 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
store.closeConnection();
}
/**
* the current ASsLSession
* @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/devsec/devVRE");
}
return SessionManager.getInstance().getASLSession(sessionID, user);
}
public String getDevelopmentUser() {
String user = TEST_USER;
// user = "costantino.perciante";
return user;
}
/**
*
* @return true if you're running into the portal, false if in development
@ -134,12 +111,11 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
UserLocalServiceUtil.getService();
return true;
}
catch (com.liferay.portal.kernel.bean.BeanLocatorException ex) {
catch (Exception ex) {
_log.trace("Development Mode ON");
return false;
}
}
/**
* Share post that could contain a link preview.
*/
@ -162,26 +138,14 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
escapedFeedText = Utils.convertMentionPeopleAnchorHTML(escapedFeedText, mentionedUsers, getThreadLocalRequest());
}
// get session
ASLSession session = getASLSession();
String username = session.getUsername();
String email = username+"@isti.cnr.it";
String fullName = username+" FULL";
String thumbnailAvatarURL = "images/Avatar_default.png";
boolean withinPortal = isWithinPortal();
if (withinPortal && username.compareTo(TEST_USER) != 0) {
try {
UserInfo user = getUserSettings().getUserInfo();
email = user.getEmailaddress();
fullName = user.getFullName();
thumbnailAvatarURL = user.getAvatarId();
} catch (Exception e) {
e.printStackTrace();
}
}
PortalContext context = PortalContext.getConfiguration();
GCubeUser currUser = context.getCurrentUser(getThreadLocalRequest());
String username = currUser.getUsername();
String email = currUser.getEmail();
String fullName = currUser.getFullname();
String thumbnailAvatarURL = currUser.getUserAvatarId();
// get data from the preview of the link
String linkTitle = preview.getTitle();
String linkDesc = preview.getDescription();
@ -195,7 +159,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
//get the VRE scope if single channel post
String vreScope2Set = "";
if (pLevel == PrivacyLevel.SINGLE_VRE && vreOrgId != null) {
vreScope2Set = (withinPortal) ? getScopeByGroupId(vreOrgId) : session.getScope();
vreScope2Set = context.getCurrentScope(getThreadLocalRequest());
}
// build the feed to share (and save on cassandra)
@ -283,24 +247,13 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
escapedFeedText = Utils.convertMentionPeopleAnchorHTML(escapedFeedText, mentionedUsers, getThreadLocalRequest());
}
ASLSession session = getASLSession();
String username = session.getUsername();
String email = username+"@isti.cnr.it";
String fullName = username+" FULL";
String thumbnailAvatarURL = "images/Avatar_default.png";
PortalContext context = PortalContext.getConfiguration();
GCubeUser currUser = context.getCurrentUser(getThreadLocalRequest());
boolean withinPortal = isWithinPortal();
if (withinPortal && username.compareTo(TEST_USER) != 0) {
try {
UserInfo user = getUserSettings().getUserInfo();
email = user.getEmailaddress();
fullName = user.getFullName();
thumbnailAvatarURL = user.getAvatarId();
} catch (Exception e) {
e.printStackTrace();
}
}
String username = currUser.getUsername();
String email = currUser.getEmail();
String fullName = currUser.getFullname();
String thumbnailAvatarURL = currUser.getUserAvatarId();
// Managing attachments: the first one will use the same fields of a link preview.
// If more than one attachments are present, they will be saved as Attachment objects.
@ -366,7 +319,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
//get the VRE scope if single channel post
String vreScope2Set = "";
if (pLevel == PrivacyLevel.SINGLE_VRE && vreOrgId != null ) {
vreScope2Set = (withinPortal) ? getScopeByGroupId(vreOrgId) : session.getScope();
vreScope2Set = context.getCurrentScope(getThreadLocalRequest());
}
Feed toShare = null;
@ -568,46 +521,31 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
@Override
public UserSettings getUserSettings() {
try {
ASLSession session = getASLSession();
String username = session.getUsername();
PortalContext context = PortalContext.getConfiguration();
GCubeUser currUser = context.getCurrentUser(getThreadLocalRequest());
String username = currUser.getUsername();
_log.debug("getUserSettings() for " + username);
String email = username+"@isti.cnr.it";
String fullName = username+" FULL";
String thumbnailURL = "images/Avatar_default.png";
if (isWithinPortal() && username.compareTo(TEST_USER) != 0) {
UserManager um = new LiferayUserManager();
GCubeUser user = um.getUserByUsername(username);
thumbnailURL = user.getUserAvatarURL();
fullName = user.getFullname();
email = user.getEmail();
final String profilePageURL =
GCubePortalConstants.PREFIX_GROUP_URL +
PortalContext.getConfiguration().getSiteLandingPagePath(getThreadLocalRequest())+
GCubePortalConstants.USER_PROFILE_FRIENDLY_URL;
String accountURL = profilePageURL;
try {
accountURL = "";
}catch (NullPointerException e) {
e.printStackTrace();
}
HashMap<String, String> vreNames = getUserVreNames(username);
UserInfo userInfo = new UserInfo(username, fullName, thumbnailURL, user.getEmail(), accountURL, true, isAdmin(), vreNames);
UserSettings toReturn = new UserSettings(userInfo, 0, session.getScopeName(), isInfrastructureScope(), isNotificationViaEmailEnabled(session));
_log.debug("getUserSettings() return " + toReturn);
return toReturn;
String thumbnailURL = currUser.getUserAvatarURL();
String fullName = currUser.getFullname();
String email = currUser.getEmail();
final String profilePageURL =
GCubePortalConstants.PREFIX_GROUP_URL +
PortalContext.getConfiguration().getSiteLandingPagePath(getThreadLocalRequest())+
GCubePortalConstants.USER_PROFILE_FRIENDLY_URL;
String accountURL = profilePageURL;
try {
accountURL = "";
}catch (NullPointerException e) {
e.printStackTrace();
}
else {
_log.info("Returning test USER = " + session.getUsername());
HashMap<String, String> fakeVreNames = new HashMap<String, String>();
fakeVreNames.put("/gcube/devsec/devVRE","devVRE");
//fakeVreNames.put("/gcube/devNext/NexNext","NexNext");
HashMap<String, String> vreNames = getUserVreNames(username);
UserInfo userInfo = new UserInfo(username, fullName, thumbnailURL, email, accountURL, true, isAdmin(), vreNames);
UserSettings toReturn = new UserSettings(userInfo, 0, context.getCurrentScope(getThreadLocalRequest()), isInfrastructureScope(), isNotificationViaEmailEnabled());
_log.debug("getUserSettings() return " + toReturn);
return toReturn;
UserInfo user = new UserInfo(session.getUsername(), fullName, thumbnailURL, email, "fakeAccountUrl", true, false, fakeVreNames);
return new UserSettings(user, 0, session.getScopeName(), false, true);
}
} catch (Exception e) {
e.printStackTrace();
@ -615,10 +553,12 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
return new UserSettings();
}
private boolean isNotificationViaEmailEnabled(ASLSession session) throws UserManagementSystemException, GroupRetrievalFault {
private boolean isNotificationViaEmailEnabled() throws UserManagementSystemException, GroupRetrievalFault {
if (! isWithinPortal())
return false;
PortalContext context = PortalContext.getConfiguration();
GroupManager gm = new LiferayGroupManager();
GCubeGroup group = gm.getGroup(session.getGroupId());
return (Boolean) gm.readCustomAttr(group.getGroupId(), CustomAttributeKeys.POST_NOTIFICATION.getKeyName());
return (Boolean) gm.readCustomAttr(context.getCurrentGroupId(getThreadLocalRequest()), CustomAttributeKeys.POST_NOTIFICATION.getKeyName());
}
/**
* tell if the user is a portal administrator or not
@ -631,8 +571,9 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
if (! isWithinPortal())
return false;
try {
GCubeUser curUser = new LiferayUserManager().getUserByUsername(getASLSession().getUsername());
return new LiferayRoleManager().isAdmin(curUser.getUserId());
PortalContext context = PortalContext.getConfiguration();
GCubeUser currUser = context.getCurrentUser(getThreadLocalRequest());
return new LiferayRoleManager().isAdmin(currUser.getUserId());
}
catch (Exception e) {
_log.error("Could not check if the user is an Administrator, returning false");
@ -644,13 +585,16 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
*/
@Override
public LinkPreview checkUploadedFile(String fileName, String fileabsolutePathOnServer) {
PortalContext context = PortalContext.getConfiguration();
LinkPreview toReturn = null;
String randomUploadFolderName = UUID.randomUUID().toString();
String remoteFilePath = UPLOAD_DIR + "/" + randomUploadFolderName + "/" + fileName;
//get the Storage Client
String currScope = ScopeProvider.instance.get();
ScopeProvider.instance.set(getASLSession().getScope());
ScopeProvider.instance.set(context.getCurrentScope(getThreadLocalRequest()));
IClient storageClient = new StorageClient(STORAGE_OWNER, AccessType.SHARED, MemoryType.PERSISTENT).getClient();
ScopeProvider.instance.set(currScope);
@ -814,9 +758,11 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
* @return the id as key and the names as value of the vre a user is subscribed to
*/
private HashMap<String, String> getUserVreNames(String username) {
PortalContext context = PortalContext.getConfiguration();
String groupName = context.getCurrentGroupName(getThreadLocalRequest());
HashMap<String, String> toReturn = new HashMap<String, String>();
for (GCubeGroup vre : getUserVREs(username)) {
if (vre.getGroupName().compareTo(getASLSession().getGroupName())==0)
if (vre.getGroupName().compareTo(groupName)==0)
toReturn.put(vre.getGroupId()+"", vre.getGroupName());
}
return toReturn;
@ -859,7 +805,8 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
* @return <code>true</code> if it is, <code>false</code> otherwise.
*/
private boolean isInfrastructureScope() {
ScopeBean scope = new ScopeBean(getASLSession().getScope());
PortalContext context = PortalContext.getConfiguration();
ScopeBean scope = new ScopeBean(context.getCurrentScope(getThreadLocalRequest()));
return scope.is(Type.INFRASTRUCTURE);
}
@ -886,19 +833,24 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
@Override
public ArrayList<ItemBean> getPortalItemBeans() {
ASLSession session = getASLSession();
PortalContext context = PortalContext.getConfiguration();
context.getCurrentScope(getThreadLocalRequest());
String scope = context.getCurrentScope(getThreadLocalRequest());
String username = context.getCurrentUser(getThreadLocalRequest()).getUsername();
boolean withinPortal = false;
if (isWithinPortal() && session.getUsername().compareTo(TEST_USER) != 0) {
if (isWithinPortal() && username.compareTo(TEST_USER) != 0) {
withinPortal = true;
}
// retrieve user and group beans
return Utils.getDisplayableItemBeans(session.getScope(), session.getUsername(), withinPortal);
return Utils.getDisplayableItemBeans(scope, username, withinPortal);
}
@Override
public ArrayList<ItemBean> getHashtags() {
ASLSession session = getASLSession();
String scope = session.getScope();
PortalContext context = PortalContext.getConfiguration();
context.getCurrentScope(getThreadLocalRequest());
String scope = context.getCurrentScope(getThreadLocalRequest());
_log.error("getting hashtags for " + scope);
Map<String, Integer> map = store.getVREHashtagsWithOccurrence(scope);
ArrayList<HashTagAndOccurrence> toSort = new ArrayList<HashTagAndOccurrence>();

View File

@ -1,27 +1,23 @@
package org.gcube.portlets.user.shareupdates.server.portlet;
import javax.portlet.GenericPortlet;
import javax.portlet.ActionRequest;
import javax.portlet.RenderRequest;
import javax.portlet.ActionResponse;
import javax.portlet.RenderResponse;
import javax.portlet.PortletException;
import java.io.IOException;
import javax.portlet.PortletRequestDispatcher;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
/**
* WfTemplatesPortlet Portlet Class
*
* @author Massimiliano Assante, ISTI-CNR - massimiliano.assante@isti.cnr.it
* @version May 2011 (0.1)
*/
public class ShareUpdatesPortlet extends GenericPortlet {
public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
response.setContentType("text/html");
ScopeHelper.setContext(request);
PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/ShareUpdates_view.jsp");
dispatcher.include(request, response);
}

View File

@ -1,19 +0,0 @@
package org.gcube.portlets.user.shareupdates.test;
import static org.junit.Assert.*;
import org.gcube.portlets.user.shareupdates.server.ShareUpdateServiceImpl;
import org.junit.Test;
public class TestForDeploy {
@Test
public void testUserIsTestUser() {
ShareUpdateServiceImpl serviceImpl = new ShareUpdateServiceImpl();
String username = serviceImpl.getDevelopmentUser();
System.out.println("username for deploy is: " + username);
assertTrue(username.compareTo(ShareUpdateServiceImpl.TEST_USER) == 0);
System.out.println("Test OK!");
}
}