moved to version 2.1: removed asl session, changed logging system to liferay's one

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/social-profile@134190 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-11-15 14:18:08 +00:00
parent 6aee580e56
commit 8fc252df86
19 changed files with 93 additions and 131 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" output="target/social-profile-2.0.1-SNAPSHOT/WEB-INF/classes" path="src/main/java"> <classpathentry kind="src" output="target/social-profile-2.1.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes> <attributes>
<attribute name="optional" value="true"/> <attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
@ -35,5 +35,5 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="output" path="target/social-profile-2.0.1-SNAPSHOT/WEB-INF/classes"/> <classpathentry kind="output" path="target/social-profile-2.1.0-SNAPSHOT/WEB-INF/classes"/>
</classpath> </classpath>

1
.tern-project Normal file
View File

@ -0,0 +1 @@
{"ide":{"scriptPaths":[]},"plugins":{"aui":{},"liferay":{},"yui":{}},"libs":["ecma5","browser"]}

View File

@ -1,4 +1,9 @@
<ReleaseNotes> <ReleaseNotes>
<Changeset component="org.gcube.portlet.user.socialprofile.2-1-0"
date="2016-12-10">
<Change>ASL session removed</Change>
<Change>Moved to Liferay logging system</Change>
</Changeset>
<Changeset component="org.gcube.portlet.user.socialprofile.2-0-1" <Changeset component="org.gcube.portlet.user.socialprofile.2-0-1"
date="2016-10-10"> date="2016-10-10">
<Change>Minor dependencies fix</Change> <Change>Minor dependencies fix</Change>

16
pom.xml
View File

@ -13,7 +13,7 @@
<groupId>org.gcube.portlets.user</groupId> <groupId>org.gcube.portlets.user</groupId>
<artifactId>social-profile</artifactId> <artifactId>social-profile</artifactId>
<packaging>war</packaging> <packaging>war</packaging>
<version>2.0.1-SNAPSHOT</version> <version>2.1.0-SNAPSHOT</version>
<name>gCube Social Profile Portlet</name> <name>gCube Social Profile Portlet</name>
<description> <description>
Social Profile Social Profile
@ -67,7 +67,7 @@
<dependency> <dependency>
<groupId>org.gcube.portlets.user</groupId> <groupId>org.gcube.portlets.user</groupId>
<artifactId>gcube-widgets</artifactId> <artifactId>gcube-widgets</artifactId>
<scope>provided</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.gcube.portal</groupId> <groupId>org.gcube.portal</groupId>
@ -93,7 +93,7 @@
<dependency> <dependency>
<groupId>org.gcube.core</groupId> <groupId>org.gcube.core</groupId>
<artifactId>common-scope-maps</artifactId> <artifactId>common-scope-maps</artifactId>
<scope>compile</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.googlecode.json-simple</groupId> <groupId>com.googlecode.json-simple</groupId>
@ -106,11 +106,6 @@
<version>1.2.0</version> <version>1.2.0</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslcore</artifactId>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>org.gcube.portal</groupId> <groupId>org.gcube.portal</groupId>
<artifactId>social-networking-library</artifactId> <artifactId>social-networking-library</artifactId>
@ -176,6 +171,11 @@
<artifactId>ic-client</artifactId> <artifactId>ic-client</artifactId>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.gcube.common.portal</groupId>
<artifactId>portal-manager</artifactId>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
<!-- Generate compiled stuff in the folder used for developing mode --> <!-- Generate compiled stuff in the folder used for developing mode -->

View File

@ -11,6 +11,7 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
@ -24,9 +25,8 @@ import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair; import org.apache.http.message.BasicNameValuePair;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.common.encryption.StringEncrypter; import org.gcube.common.encryption.StringEncrypter;
import org.gcube.common.portal.PortalContext;
import org.gcube.common.resources.gcore.ServiceEndpoint; import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint; import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.Property; import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
@ -35,7 +35,6 @@ import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.impl.ScopeBean; import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.common.scope.impl.ScopeBean.Type; import org.gcube.common.scope.impl.ScopeBean.Type;
import org.gcube.portal.custom.communitymanager.SiteManagerUtil; import org.gcube.portal.custom.communitymanager.SiteManagerUtil;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.gcube.portal.databook.shared.UserInfo; import org.gcube.portal.databook.shared.UserInfo;
import org.gcube.portlets.user.socialprofile.client.SocialService; import org.gcube.portlets.user.socialprofile.client.SocialService;
import org.gcube.portlets.user.socialprofile.shared.UserContext; import org.gcube.portlets.user.socialprofile.shared.UserContext;
@ -47,11 +46,11 @@ import org.gcube.vomanagement.usermanagement.model.CustomAttributeKeys;
import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.json.simple.parser.ContainerFactory; import org.json.simple.parser.ContainerFactory;
import org.json.simple.parser.JSONParser; import org.json.simple.parser.JSONParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import com.google.gwt.user.server.rpc.RemoteServiceServlet; import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.model.Contact; import com.liferay.portal.model.Contact;
import com.liferay.portal.service.ContactLocalServiceUtil; import com.liferay.portal.service.ContactLocalServiceUtil;
import com.liferay.portal.service.UserLocalServiceUtil; import com.liferay.portal.service.UserLocalServiceUtil;
@ -62,7 +61,8 @@ import com.liferay.portal.service.UserLocalServiceUtil;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class SocialServiceImpl extends RemoteServiceServlet implements SocialService { public class SocialServiceImpl extends RemoteServiceServlet implements SocialService {
private static final Logger _log = LoggerFactory.getLogger(SocialServiceImpl.class); //private static final Logger logger = LoggerFactory.getLogger(SocialServiceImpl.class);
private static final Log logger = LogFactoryUtil.getLog(SocialServiceImpl.class);
private static final String LINKEDIN_HOST_SERVICE_NAME = "host"; private static final String LINKEDIN_HOST_SERVICE_NAME = "host";
private static final String LINKEDIN_CLIEND_ID_PROPNAME = "client_id"; private static final String LINKEDIN_CLIEND_ID_PROPNAME = "client_id";
@ -71,29 +71,36 @@ public class SocialServiceImpl extends RemoteServiceServlet implements SocialSer
private static final String LINKEDIN_API_REQUEST = "https://api.linkedin.com/v1/people/~:(id,headline,summary,location:(name),industry,positions,picture-urls::(original),public-profile-url)"; private static final String LINKEDIN_API_REQUEST = "https://api.linkedin.com/v1/people/~:(id,headline,summary,location:(name),industry,positions,picture-urls::(original),public-profile-url)";
/** /**
* the current ASLSession * Retrieve the current user by using the portal manager
* @return the session * @return a GcubeUser object
*/ */
private ASLSession getASLSession() { private GCubeUser getCurrentUser(HttpServletRequest request){
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);
}
/** if(request == null)
* when packaging test will fail if the user is not set to test.user throw new IllegalArgumentException("HttpServletRequest is null!");
* @return .
*/ PortalContext pContext = PortalContext.getConfiguration();
public String getDevelopmentUser() { GCubeUser user = pContext.getCurrentUser(request);
String user = "test.user"; logger.debug("Returning user " + user);
// user = "costantino.perciante";
return user; return user;
} }
/**
* Retrieve the current scope by using the portal manager
* @return a string representing the context
*/
private String getCurrentContext(HttpServletRequest request){
if(request == null)
throw new IllegalArgumentException("HttpServletRequest is null!");
PortalContext pContext = PortalContext.getConfiguration();
String context = pContext.getCurrentScope(request);
logger.debug("Returning context " + context);
return context;
}
/** /**
* *
* @return true if you're running into the portal, false if in development * @return true if you're running into the portal, false if in development
@ -104,37 +111,39 @@ public class SocialServiceImpl extends RemoteServiceServlet implements SocialSer
return true; return true;
} }
catch (com.liferay.portal.kernel.bean.BeanLocatorException ex) { catch (com.liferay.portal.kernel.bean.BeanLocatorException ex) {
_log.trace("Development Mode ON"); logger.trace("Development Mode ON");
return false; return false;
} }
} }
@Override @Override
public UserContext getUserContext(String userid) { public UserContext getUserContext(String userid) {
if (userid == null || userid.equals("") || userid.equals(getASLSession().getUsername())) { if (userid == null || userid.equals("") || userid.equals(getCurrentUser(this.getThreadLocalRequest()).getUsername())) {
System.out.println("Own Profile"); System.out.println("Own Profile");
_log.info("Own Profile"); logger.info("Own Profile");
return getOwnProfile(); return getOwnProfile();
} }
else { else {
System.out.println("Reading Profile"); System.out.println("Reading Profile");
_log.info(userid + " Reading Profile"); logger.info(userid + " Reading Profile");
return getUserProfile(userid); return getUserProfile(userid);
} }
} }
@Override @Override
public String saveProfessionalBackground(String summary) { public String saveProfessionalBackground(String summary) {
String username = getCurrentUser(this.getThreadLocalRequest()).getUsername();
// parse (html sanitize) // parse (html sanitize)
String toReturn = transformSummary(summary); String toReturn = transformSummary(summary);
if(isWithinPortal()){ if(isWithinPortal()){
UserManager um = new LiferayUserManager(); UserManager um = new LiferayUserManager();
ASLSession session = getASLSession();
try{ try{
GCubeUser user = um.getUserByUsername(session.getUsername()); GCubeUser user = um.getUserByUsername(username);
um.setUserProfessionalBackground(user.getUserId(), summary); // save as it is um.setUserProfessionalBackground(user.getUserId(), summary); // save as it is
return toReturn; // sanitized return toReturn; // sanitized
}catch(Exception e){ }catch(Exception e){
_log.error("Unable to save the professional background " + summary + " for user " + session.getUsername()); logger.error("Unable to save the professional background " + summary + " for user " + username);
return null; return null;
} }
}else }else
@ -142,10 +151,11 @@ public class SocialServiceImpl extends RemoteServiceServlet implements SocialSer
} }
private UserContext getUserProfile(String username) { private UserContext getUserProfile(String username) {
ASLSession session = getASLSession();
String email = username+"@isti.cnr.it"; String email = username+"@isti.cnr.it";
String fullName = username+" FULL"; String fullName = username+" FULL";
String thumbnailURL = "images/Avatar_default.png"; String thumbnailURL = "images/Avatar_default.png";
PortalContext pContext = PortalContext.getConfiguration();
String contextName = pContext.getCurrentGroupName(this.getThreadLocalRequest());
if (isWithinPortal()) { if (isWithinPortal()) {
try { try {
UserManager um = new LiferayUserManager(); UserManager um = new LiferayUserManager();
@ -160,14 +170,14 @@ public class SocialServiceImpl extends RemoteServiceServlet implements SocialSer
String company = user.getLocation_industry(); String company = user.getLocation_industry();
String summary = transformSummary(um.getUserProfessionalBackground(user.getUserId())); String summary = transformSummary(um.getUserProfessionalBackground(user.getUserId()));
return new UserContext(userInfo, headline, company, summary, session.getScopeName(), false, isInfrastructureScope()); return new UserContext(userInfo, headline, company, summary, contextName, false, isInfrastructureScope());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return new UserContext(); return new UserContext();
} }
} else { } else {
_log.info("Returning test USER"); logger.info("Returning test USER");
HashMap<String, String> fakeVreNames = new HashMap<String, String>(); HashMap<String, String> fakeVreNames = new HashMap<String, String>();
fakeVreNames.put("/gcube/devsec/devVRE","devVRE"); fakeVreNames.put("/gcube/devsec/devVRE","devVRE");
//fakeVreNames.put("/gcube/devNext/NexNext","NexNext"); //fakeVreNames.put("/gcube/devNext/NexNext","NexNext");
@ -175,14 +185,15 @@ public class SocialServiceImpl extends RemoteServiceServlet implements SocialSer
UserInfo user = new UserInfo(username, username+ "FULL", thumbnailURL, email, "fakeAccountUrl", true, false, fakeVreNames); UserInfo user = new UserInfo(username, username+ "FULL", thumbnailURL, email, "fakeAccountUrl", true, false, fakeVreNames);
return new UserContext(user, "", "", "" return new UserContext(user, "", "", ""
+ "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam." + "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam."
+ "", session.getScopeName(), false, isInfrastructureScope()); + "", contextName, false, isInfrastructureScope());
} }
} }
private UserContext getOwnProfile() { private UserContext getOwnProfile() {
try { try {
ASLSession session = getASLSession(); PortalContext pContext = PortalContext.getConfiguration();
String username = session.getUsername(); String contextName = pContext.getCurrentGroupName(this.getThreadLocalRequest());
String username = getCurrentUser(this.getThreadLocalRequest()).getUsername();
String email = username+"@isti.cnr.it"; String email = username+"@isti.cnr.it";
String fullName = username+" FULL"; String fullName = username+" FULL";
String thumbnailURL = "images/Avatar_default.png"; String thumbnailURL = "images/Avatar_default.png";
@ -203,18 +214,18 @@ public class SocialServiceImpl extends RemoteServiceServlet implements SocialSer
String company = user.getLocation_industry(); String company = user.getLocation_industry();
String summary = transformSummary(um.getUserProfessionalBackground(user.getUserId())); String summary = transformSummary(um.getUserProfessionalBackground(user.getUserId()));
return new UserContext(userInfo, headline, company, summary, session.getScopeName(), true, isInfrastructureScope() ); return new UserContext(userInfo, headline, company, summary, contextName, true, isInfrastructureScope() );
} }
else { else {
_log.info("Returning test USER"); logger.info("Returning test USER");
HashMap<String, String> fakeVreNames = new HashMap<String, String>(); HashMap<String, String> fakeVreNames = new HashMap<String, String>();
fakeVreNames.put("/gcube/devsec/devVRE","devVRE"); fakeVreNames.put("/gcube/devsec/devVRE","devVRE");
//fakeVreNames.put("/gcube/devNext/NexNext","NexNext"); //fakeVreNames.put("/gcube/devNext/NexNext","NexNext");
UserInfo user = new UserInfo(getASLSession().getUsername(), fullName, thumbnailURL, email, "fakeAccountUrl", true, false, fakeVreNames); UserInfo user = new UserInfo(username, fullName, thumbnailURL, email, "fakeAccountUrl", true, false, fakeVreNames);
return new UserContext(user, "", "", "" return new UserContext(user, "", "", ""
+ "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam." + "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam."
+ "", session.getScopeName(), true, isInfrastructureScope() ); + "", contextName, true, isInfrastructureScope() );
} }
} catch (Exception e) { } catch (Exception e) {
@ -237,7 +248,7 @@ public class SocialServiceImpl extends RemoteServiceServlet implements SocialSer
public Boolean saveHeadline(String newHeadline) { public Boolean saveHeadline(String newHeadline) {
try { try {
UserManager um = new LiferayUserManager(); UserManager um = new LiferayUserManager();
return um.updateJobTitle(um.getUserId(getASLSession().getUsername()), newHeadline); return um.updateJobTitle(um.getUserId(getCurrentUser(this.getThreadLocalRequest()).getUsername()), newHeadline);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return false; return false;
@ -249,7 +260,7 @@ public class SocialServiceImpl extends RemoteServiceServlet implements SocialSer
//try save the location/industry //try save the location/industry
try { try {
UserManager um = new LiferayUserManager(); UserManager um = new LiferayUserManager();
um.saveCustomAttr(um.getUserId(getASLSession().getUsername()), CustomAttributeKeys.USER_LOCATION_INDUSTRY.getKeyName(), institution); um.saveCustomAttr(um.getUserId(getCurrentUser(this.getThreadLocalRequest()).getUsername()), CustomAttributeKeys.USER_LOCATION_INDUSTRY.getKeyName(), institution);
return true; return true;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -287,7 +298,7 @@ public class SocialServiceImpl extends RemoteServiceServlet implements SocialSer
InputStream myInputStream = entity.getContent(); InputStream myInputStream = entity.getContent();
try { try {
String jsonText = IOUtils.toString(myInputStream, "UTF-8"); String jsonText = IOUtils.toString(myInputStream, "UTF-8");
_log.debug("LinkedIn response: " + jsonText); logger.debug("LinkedIn response: " + jsonText);
if (jsonText == null) if (jsonText == null)
return null; return null;
@ -336,7 +347,7 @@ public class SocialServiceImpl extends RemoteServiceServlet implements SocialSer
// add request header as in the documentation, @see https://developer.linkedin.com/documents/authentication // add request header as in the documentation, @see https://developer.linkedin.com/documents/authentication
request.addHeader("Authorization", "Bearer " + token); request.addHeader("Authorization", "Bearer " + token);
try { try {
_log.debug("Asking LinkedIn profile via http GET for " + getASLSession().getUsername()); logger.debug("Asking LinkedIn profile via http GET for " + getCurrentUser(this.getThreadLocalRequest()).getUsername());
HttpResponse httpResponse = httpClient.execute(request); HttpResponse httpResponse = httpClient.execute(request);
HttpEntity entity = httpResponse.getEntity(); HttpEntity entity = httpResponse.getEntity();
@ -345,14 +356,14 @@ public class SocialServiceImpl extends RemoteServiceServlet implements SocialSer
try { try {
String xmlResponse = IOUtils.toString(myInputStream, "UTF-8"); String xmlResponse = IOUtils.toString(myInputStream, "UTF-8");
//xmlResponse = testParsing(); //xmlResponse = testParsing();
_log.debug("LinkedIn xmlResponse: " + xmlResponse); logger.debug("LinkedIn xmlResponse: " + xmlResponse);
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(IOUtils.toInputStream(xmlResponse)); Document doc = dBuilder.parse(IOUtils.toInputStream(xmlResponse));
_log.debug("Parsing LinkedIn profile xmlResponse for " + getASLSession().getUsername()); logger.debug("Parsing LinkedIn profile xmlResponse for " + getCurrentUser(this.getThreadLocalRequest()).getUsername());
String headline = ""; String headline = "";
String summary = ""; String summary = "";
String location = ""; String location = "";
@ -380,7 +391,7 @@ public class SocialServiceImpl extends RemoteServiceServlet implements SocialSer
String positions = ""; String positions = "";
currValue = helper.evaluate("/person/positions/position"); currValue = helper.evaluate("/person/positions/position");
int positionsNo = currValue.size(); int positionsNo = currValue.size();
_log.debug("Number of positions: " + positions); logger.debug("Number of positions: " + positions);
if (positionsNo > 0) { if (positionsNo > 0) {
positions = (positionsNo > 1) ? "\n\nCurrent Positions:" : "\n\nCurrent Position:"; positions = (positionsNo > 1) ? "\n\nCurrent Positions:" : "\n\nCurrent Position:";
for (int i = 0; i < positionsNo; i++) { for (int i = 0; i < positionsNo; i++) {
@ -434,9 +445,9 @@ public class SocialServiceImpl extends RemoteServiceServlet implements SocialSer
summary += positions; summary += positions;
if (isWithinPortal()) { if (isWithinPortal()) {
_log.debug("LinkedIn Profile gotten correctly for " + getASLSession().getUsername() + " attempting to write into DB ..."); logger.debug("LinkedIn Profile gotten correctly for " + getCurrentUser(this.getThreadLocalRequest()).getUsername() + " attempting to write into DB ...");
com.liferay.portal.model.User user; com.liferay.portal.model.User user;
user = UserLocalServiceUtil.getUserByScreenName(SiteManagerUtil.getCompany().getCompanyId(), getASLSession().getUsername()); user = UserLocalServiceUtil.getUserByScreenName(SiteManagerUtil.getCompany().getCompanyId(), getCurrentUser(this.getThreadLocalRequest()).getUsername());
//headline //headline
if (headline.compareTo("") != 0) { if (headline.compareTo("") != 0) {
String checkedHeadline = headline; String checkedHeadline = headline;
@ -467,7 +478,7 @@ public class SocialServiceImpl extends RemoteServiceServlet implements SocialSer
if (pictureURL.compareTo("") != 0 && pictureURL.startsWith("http")) { if (pictureURL.compareTo("") != 0 && pictureURL.startsWith("http")) {
byte[] pictureData = getUserPictureFromURL(httpClient, pictureURL); byte[] pictureData = getUserPictureFromURL(httpClient, pictureURL);
if (pictureData != null) { if (pictureData != null) {
_log.debug("Updating Image Profile with this one: " + pictureURL); logger.debug("Updating Image Profile with this one: " + pictureURL);
UserLocalServiceUtil.updatePortrait(user.getUserId(), pictureData); UserLocalServiceUtil.updatePortrait(user.getUserId(), pictureData);
} }
} }
@ -479,7 +490,7 @@ public class SocialServiceImpl extends RemoteServiceServlet implements SocialSer
return publicProfileURL; return publicProfileURL;
else return null; else return null;
} else { } else {
_log.warn("Development Mode ON, not attempting to write into DB"); logger.warn("Development Mode ON, not attempting to write into DB");
return "fakePublicURL"; return "fakePublicURL";
} }
} }
@ -508,7 +519,7 @@ public class SocialServiceImpl extends RemoteServiceServlet implements SocialSer
try { try {
return IOUtils.toByteArray(httpClient.execute(request).getEntity().getContent()); return IOUtils.toByteArray(httpClient.execute(request).getEntity().getContent());
} catch (Exception e) { } catch (Exception e) {
_log.error("Could not get bytes from picture URL " + e.getMessage()); logger.error("Could not get bytes from picture URL " + e.getMessage());
e.printStackTrace(); e.printStackTrace();
return null; return null;
} }
@ -520,8 +531,8 @@ public class SocialServiceImpl extends RemoteServiceServlet implements SocialSer
* @return an hashmap containing the 3 info needed * @return an hashmap containing the 3 info needed
*/ */
private HashMap<String, String> getLinkedInUASInfo(){ private HashMap<String, String> getLinkedInUASInfo(){
String scope = getASLSession().getScope(); String scope = getCurrentContext(this.getThreadLocalRequest());
_log.info("Looking for a LinkedIn UAS in " + scope); logger.info("Looking for a LinkedIn UAS in " + scope);
String previousScope = ScopeProvider.instance.get(); String previousScope = ScopeProvider.instance.get();
ScopeProvider.instance.set(scope); ScopeProvider.instance.set(scope);
SimpleQuery query = queryFor(ServiceEndpoint.class); SimpleQuery query = queryFor(ServiceEndpoint.class);
@ -533,7 +544,7 @@ public class SocialServiceImpl extends RemoteServiceServlet implements SocialSer
ScopeProvider.instance.set(previousScope); ScopeProvider.instance.set(previousScope);
if (list.size() > 1) { if (list.size() > 1) {
_log.warn("Multiple LinkedIn-user-authorization Service Endpoints available in the scope, should be only one."); logger.warn("Multiple LinkedIn-user-authorization Service Endpoints available in the scope, should be only one.");
return null; return null;
} }
else if (list.size() == 1) { else if (list.size() == 1) {
@ -566,7 +577,7 @@ public class SocialServiceImpl extends RemoteServiceServlet implements SocialSer
* @return <code>true</code> if it is, <code>false</code> otherwise. * @return <code>true</code> if it is, <code>false</code> otherwise.
*/ */
private boolean isInfrastructureScope() { private boolean isInfrastructureScope() {
ScopeBean scope = new ScopeBean(getASLSession().getScope()); ScopeBean scope = new ScopeBean(getCurrentContext(this.getThreadLocalRequest()));
return scope.is(Type.INFRASTRUCTURE); return scope.is(Type.INFRASTRUCTURE);
} }
/** /**

View File

@ -1,16 +1,15 @@
package org.gcube.portlets.user.socialprofile.server.portlet; package org.gcube.portlets.user.socialprofile.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 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 * WfTemplatesPortlet Portlet Class
@ -21,7 +20,6 @@ import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
public class SocialProfilePortlet extends GenericPortlet { public class SocialProfilePortlet extends GenericPortlet {
public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
response.setContentType("text/html"); response.setContentType("text/html");
ScopeHelper.setContext(request);
PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/SocialProfile_view.jsp"); PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/SocialProfile_view.jsp");
dispatcher.include(request, response); dispatcher.include(request, response);
} }

View File

@ -77,7 +77,4 @@ public class UserContext implements Serializable {
public void setInfrastructure(boolean isInfrastructure) { public void setInfrastructure(boolean isInfrastructure) {
this.isInfrastructure = isInfrastructure; this.isInfrastructure = isInfrastructure;
} }
} }

View File

@ -1,19 +0,0 @@
log4j.rootLogger=DEBUG, A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
# Print the date in ISO 8601 format
log4j.appender.A1.layout.ConversionPattern=%d %-5p %c - %m%n
# Print only messages of level TRACE or above in the package org.gcube
log4j.logger.org.gcube=TRACE
log4j.logger.org.gcube.application.framework.core.session=INFO
log4j.logger.org.gcube.contentmanager=ERROR
log4j.logger.org.gcube.common.scope=ERROR
log4j.logger.org.gcube.contentmanagement=ERROR
log4j.logger.org.gcube.resources.discovery.icclient=ERROR
log4j.logger.org.gcube.common.clients=ERROR
log4j.logger.org.gcube.common.homelibrary.jcr=ERROR
log4j.logger.org.gcube.application.framework.accesslogger=ERROR
log4j.logger.org.apache.pdfbox.util.PDFStreamEngine=ERROR
log4j.logger.org.apache.http=INFO

View File

@ -8,13 +8,12 @@
<!-- inherits GCUBE Widgets --> <!-- inherits GCUBE Widgets -->
<inherits name='org.gcube.portlets.user.gcubewidgets.WidgetFactory' /> <inherits name='org.gcube.portlets.user.gcubewidgets.WidgetFactory' />
<inherits name='org.gcube.portlets.widgets.wsmail.WsMail_Widget' /> <inherits name='org.gcube.portlets.widgets.wsmail.WsMail_Widget' />
<inherits name='org.gcube.portlets.widgets.sessionchecker.SessionChecker' />
<inherits name='org.gcube.portal.databook.GCubeSocialNetworking' /> <inherits name='org.gcube.portal.databook.GCubeSocialNetworking' />
<inherits name="net.eliasbalasis.tibcopagebus4gwt.tibcopagebus4gwt" /> <inherits name="net.eliasbalasis.tibcopagebus4gwt.tibcopagebus4gwt" />
<inherits name="org.jsonmaker.gwt.Gwt_jsonmaker" /> <inherits name="org.jsonmaker.gwt.Gwt_jsonmaker" />
<inherits <inherits
name="net.eliasbalasis.tibcopagebus4gwt.testsubscriber.TestSubscriber" /> name="net.eliasbalasis.tibcopagebus4gwt.testsubscriber.TestSubscriber" />
<!-- Bootstrap import --> <!-- Bootstrap import -->
<inherits name="com.github.gwtbootstrap.Bootstrap" /> <inherits name="com.github.gwtbootstrap.Bootstrap" />

View File

@ -35,17 +35,6 @@
<url-pattern>/socialprofile/WorkspaceExplorerService</url-pattern> <url-pattern>/socialprofile/WorkspaceExplorerService</url-pattern>
</servlet-mapping> </servlet-mapping>
<servlet>
<servlet-name>checkServlet</servlet-name>
<servlet-class>org.gcube.portlets.widgets.sessionchecker.server.SessionCheckerServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>checkServlet</servlet-name>
<url-pattern>/socialprofile/checksession</url-pattern>
</servlet-mapping>
<!-- Default page to serve --> <!-- Default page to serve -->
<welcome-file-list> <welcome-file-list>
<welcome-file>SocialProfile.html</welcome-file> <welcome-file>SocialProfile.html</welcome-file>

View File

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