import profile from linkedIn completed, only picture is missing
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/social-profile@99446 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
1069bf8229
commit
d2eb9ab66f
|
@ -31,7 +31,7 @@ public class SocialProfile implements EntryPoint {
|
|||
if (isUserAuthZFromLinkedIn()) {
|
||||
String authorizationCode = checkLinkedInAuthZ();
|
||||
if (authorizationCode != null) {
|
||||
mainPanel.add(new OkAlert("Authorization OK! Please wait while we import from LinkedIn ... "));
|
||||
mainPanel.add(new OkAlert("Authorization OK! Please wait while we import from LinkedIn ... ", false));
|
||||
socialService.fetchUserProfile(authorizationCode, DisplayProfile.getRedirectURI(), new AsyncCallback<Boolean>() {
|
||||
@Override
|
||||
public void onSuccess(Boolean result) {
|
||||
|
@ -39,8 +39,11 @@ public class SocialProfile implements EntryPoint {
|
|||
mainPanel.clear();
|
||||
mainPanel.add(new ErrorAlert("Something went wrong while parsing your professional summary from LinkedIn, please report the issue."));
|
||||
}
|
||||
else
|
||||
Window.alert("funzia!");
|
||||
else {
|
||||
mainPanel.clear();
|
||||
mainPanel.add(new OkAlert("Your data have been imported successfully, anything you want to edit or add? Please use Edit Profile Manually.", true));
|
||||
displayProfile();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
|
@ -48,7 +51,7 @@ public class SocialProfile implements EntryPoint {
|
|||
mainPanel.add(new ErrorAlert("Something went wrong while communicating with LinkedIn service, please report us the issue."));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
} else {
|
||||
displayProfile();
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
package org.gcube.portlets.user.socialprofile.client.ui;
|
||||
|
||||
import org.gcube.portlets.user.gcubewidgets.client.elements.Span;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.dom.client.Element;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.uibinder.client.UiBinder;
|
||||
import com.google.gwt.uibinder.client.UiField;
|
||||
import com.google.gwt.uibinder.client.UiHandler;
|
||||
import com.google.gwt.user.client.ui.Composite;
|
||||
import com.google.gwt.user.client.ui.Label;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
|
||||
public class OkAlert extends Composite {
|
||||
|
@ -14,9 +19,17 @@ public class OkAlert extends Composite {
|
|||
interface OkAlertUiBinder extends UiBinder<Widget, OkAlert> {
|
||||
}
|
||||
@UiField Element message;
|
||||
public OkAlert(String message2Show) {
|
||||
@UiField Span handler;
|
||||
|
||||
public OkAlert(String message2Show, boolean removable) {
|
||||
initWidget(uiBinder.createAndBindUi(this));
|
||||
message.setInnerText(message2Show);
|
||||
message.setInnerHTML(message2Show);
|
||||
if (removable)
|
||||
handler.setHTML(" Close");
|
||||
}
|
||||
|
||||
@UiHandler("handler")
|
||||
void onCloseClick(ClickEvent e) {
|
||||
this.removeFromParent();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,19 +1,31 @@
|
|||
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
|
||||
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
|
||||
xmlns:g="urn:import:com.google.gwt.user.client.ui">
|
||||
xmlns:g="urn:import:com.google.gwt.user.client.ui"
|
||||
xmlns:m="urn:import:org.gcube.portlets.user.gcubewidgets.client.elements">
|
||||
<ui:style>
|
||||
.alert {
|
||||
border: 1px solid #D6E9C6;
|
||||
border-radius: 4px;
|
||||
border-radius: 4px;
|
||||
margin: 20px;
|
||||
padding: 15px;
|
||||
background-color: #DFF0D8;
|
||||
color: #3C763D;
|
||||
font-family: 'Helvetica Neue', Arial, sans-serif;
|
||||
font-size: 14px;
|
||||
padding: 15px;
|
||||
background-color: #DFF0D8;
|
||||
color: #3C763D;
|
||||
font-family: 'Helvetica Neue', Arial, sans-serif;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.profile-link {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.profile-link:hover {
|
||||
cursor: pointer;
|
||||
cursor: hand;
|
||||
text-decoration: underline;
|
||||
}
|
||||
</ui:style>
|
||||
<g:HTMLPanel styleName="{style.alert}">
|
||||
<g:HTMLPanel styleName="{style.alert}">
|
||||
<span ui:field="message"></span>
|
||||
<m:Span ui:field="handler" styleName="{style.profile-link}"></m:Span>
|
||||
</g:HTMLPanel>
|
||||
</ui:UiBinder>
|
|
@ -8,6 +8,9 @@ import java.util.LinkedList;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
|
@ -29,6 +32,7 @@ import org.json.simple.parser.ContainerFactory;
|
|||
import org.json.simple.parser.JSONParser;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
||||
import com.liferay.portal.kernel.util.WebKeys;
|
||||
|
@ -44,11 +48,6 @@ public class SocialServiceImpl extends RemoteServiceServlet implements SocialSer
|
|||
|
||||
private static final Logger _log = LoggerFactory.getLogger(SocialServiceImpl.class);
|
||||
|
||||
/**
|
||||
* used for debugging in eclipse
|
||||
*/
|
||||
private boolean withinPortal = false;
|
||||
|
||||
/**
|
||||
* the current ASLSession
|
||||
* @return the session
|
||||
|
@ -59,11 +58,7 @@ public class SocialServiceImpl extends RemoteServiceServlet implements SocialSer
|
|||
if (user == null) {
|
||||
_log.warn("USER IS NULL setting test.user and Running OUTSIDE PORTAL");
|
||||
user = getDevelopmentUser();
|
||||
withinPortal = false;
|
||||
}
|
||||
else {
|
||||
withinPortal = true;
|
||||
}
|
||||
}
|
||||
return SessionManager.getInstance().getASLSession(sessionID, user);
|
||||
}
|
||||
/**
|
||||
|
@ -75,6 +70,20 @@ public class SocialServiceImpl extends RemoteServiceServlet implements SocialSer
|
|||
//user = "massimiliano.assante";
|
||||
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;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public UserContext getUserContext(String userid) {
|
||||
if (userid == null || userid.equals("")) {
|
||||
|
@ -94,7 +103,7 @@ public class SocialServiceImpl extends RemoteServiceServlet implements SocialSer
|
|||
String email = username+"@isti.cnr.it";
|
||||
String fullName = username+" FULL";
|
||||
String thumbnailURL = "images/Avatar_default.png";
|
||||
if (withinPortal) {
|
||||
if (isWithinPortal()) {
|
||||
try {
|
||||
com.liferay.portal.model.UserModel user = UserLocalServiceUtil.getUserByScreenName(OrganizationsUtil.getCompany().getCompanyId(), username);
|
||||
thumbnailURL = "/image/user_male_portrait?img_id="+user.getPortraitId();
|
||||
|
@ -134,7 +143,7 @@ public class SocialServiceImpl extends RemoteServiceServlet implements SocialSer
|
|||
String fullName = username+" FULL";
|
||||
String thumbnailURL = "images/Avatar_default.png";
|
||||
|
||||
if (withinPortal) {
|
||||
if (isWithinPortal()) {
|
||||
|
||||
com.liferay.portal.model.UserModel user = UserLocalServiceUtil.getUserByScreenName(OrganizationsUtil.getCompany().getCompanyId(), username);
|
||||
thumbnailURL = "/image/user_male_portrait?img_id="+user.getPortraitId();
|
||||
|
@ -287,10 +296,10 @@ public class SocialServiceImpl extends RemoteServiceServlet implements SocialSer
|
|||
|
||||
|
||||
private boolean parseProfile(HttpClient httpClient, String token) {
|
||||
// HttpGet request = new HttpGet("https://api.linkedin.com/v1/people/~");
|
||||
|
||||
HttpGet request = new HttpGet("https://api.linkedin.com/v1/people/~:(id,first-name,last-name,headline,summary,location:(name),industry)");
|
||||
|
||||
// HttpGet request = new HttpGet("https://api.linkedin.com/v1/people/~");
|
||||
|
||||
HttpGet request = new HttpGet("https://api.linkedin.com/v1/people/~:(id,headline,summary,location:(name),industry)");
|
||||
|
||||
// add request header
|
||||
request.addHeader("Authorization", "Bearer " + token);
|
||||
try {
|
||||
|
@ -302,6 +311,55 @@ public class SocialServiceImpl extends RemoteServiceServlet implements SocialSer
|
|||
try {
|
||||
String xmlResponse = IOUtils.toString(myInputStream, "UTF-8");
|
||||
_log.debug("LinkedIn xmlResponse: " + xmlResponse);
|
||||
|
||||
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
|
||||
Document doc = dBuilder.parse(IOUtils.toInputStream(xmlResponse));
|
||||
|
||||
_log.debug("Parsing xmlResponse ... ");
|
||||
doc.getDocumentElement().normalize();
|
||||
|
||||
String headline = "";
|
||||
if (doc.getDocumentElement().getElementsByTagName("headline") != null && doc.getDocumentElement().getElementsByTagName("headline").getLength() > 0)
|
||||
headline = doc.getDocumentElement().getElementsByTagName("headline").item(0).getTextContent();
|
||||
|
||||
String summary = "";
|
||||
if (doc.getDocumentElement().getElementsByTagName("summary") != null && doc.getDocumentElement().getElementsByTagName("summary").getLength() > 0)
|
||||
summary = doc.getDocumentElement().getElementsByTagName("summary").item(0).getTextContent();
|
||||
|
||||
String location = "";
|
||||
if (doc.getDocumentElement().getElementsByTagName("name") != null && doc.getDocumentElement().getElementsByTagName("name").getLength() > 0)
|
||||
location = doc.getDocumentElement().getElementsByTagName("name").item(0).getTextContent();
|
||||
|
||||
String industry = "";
|
||||
if (doc.getDocumentElement().getElementsByTagName("industry") != null && doc.getDocumentElement().getElementsByTagName("industry").getLength() > 0)
|
||||
industry = doc.getDocumentElement().getElementsByTagName("industry").item(0).getTextContent();
|
||||
|
||||
System.out.println("headline: " + headline);
|
||||
System.out.println("summary: " + summary);
|
||||
System.out.println("location: " + location);
|
||||
System.out.println("industry: " + industry);
|
||||
|
||||
if (isWithinPortal()) {
|
||||
com.liferay.portal.model.User user;
|
||||
user = UserLocalServiceUtil.getUserByScreenName(OrganizationsUtil.getCompany().getCompanyId(), getASLSession().getUsername());
|
||||
//headline
|
||||
if (headline.compareTo("") != 0)
|
||||
user.setJobTitle(escapeHtml(headline));
|
||||
//location and industry
|
||||
if (location.compareTo("") != 0 && industry.compareTo("") != 0)
|
||||
user.setOpenId(escapeHtml(location + " | " + industry));
|
||||
else if (location.compareTo("") != 0 || industry.compareTo("") != 0)
|
||||
user.setOpenId(escapeHtml(location + industry));
|
||||
//summary
|
||||
if (summary.compareTo("") != 0)
|
||||
user.setComments(escapeHtml(summary));
|
||||
|
||||
return (UserLocalServiceUtil.updateUser(user) != null);
|
||||
} else {
|
||||
_log.warn("Development Mode ON, not attempting to write into DB");
|
||||
}
|
||||
|
||||
}
|
||||
finally {
|
||||
myInputStream.close();
|
||||
|
|
|
@ -77,4 +77,19 @@
|
|||
|
||||
.editImage:active {
|
||||
background: url(images/edit.png) 0px -32px no-repeat;
|
||||
}
|
||||
|
||||
|
||||
a.profile-link {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
a.profile-link,a.contact-link:visited {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
a.profile-link:hover {
|
||||
cursor: pointer;
|
||||
cursor: hand;
|
||||
text-decoration: underline;
|
||||
}
|
Loading…
Reference in New Issue