diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 0591777..940e556 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -4,15 +4,6 @@ - - uses - - - uses - - - uses - diff --git a/pom.xml b/pom.xml index 8565dfd..53b785f 100644 --- a/pom.xml +++ b/pom.xml @@ -98,6 +98,12 @@ portal-service provided + + junit + junit + 4.8.1 + test + javax.portlet portlet-api diff --git a/src/main/java/OkAlert.ui.xml b/src/main/java/OkAlert.ui.xml new file mode 100644 index 0000000..8479193 --- /dev/null +++ b/src/main/java/OkAlert.ui.xml @@ -0,0 +1,13 @@ + + + + .important { + font-weight: bold; + } + + + Hello, + + + \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/socialprofile/client/SocialProfile.java b/src/main/java/org/gcube/portlets/user/socialprofile/client/SocialProfile.java index 1c3d0d2..ed6625b 100644 --- a/src/main/java/org/gcube/portlets/user/socialprofile/client/SocialProfile.java +++ b/src/main/java/org/gcube/portlets/user/socialprofile/client/SocialProfile.java @@ -4,6 +4,8 @@ import org.gcube.portal.databook.client.GCubeSocialNetworking; import org.gcube.portal.databook.client.util.Encoder; import org.gcube.portlets.user.socialprofile.client.ui.DisplayProfile; import org.gcube.portlets.user.socialprofile.client.ui.DisplaySummary; +import org.gcube.portlets.user.socialprofile.client.ui.ErrorAlert; +import org.gcube.portlets.user.socialprofile.client.ui.OkAlert; import org.gcube.portlets.user.socialprofile.shared.UserContext; import com.google.gwt.core.client.EntryPoint; @@ -17,12 +19,16 @@ import com.google.gwt.user.client.ui.VerticalPanel; * Entry point classes define onModuleLoad(). */ public class SocialProfile implements EntryPoint { + private final SocialServiceAsync socialService = GWT.create(SocialService.class); private VerticalPanel mainPanel = new VerticalPanel(); private DisplayProfile dispProfile = new DisplayProfile(); public void onModuleLoad() { + if (isUserAuthZFromLinkedIn()) { + checkLinkedInAuthZ(); + } socialService.getUserContext(getUserToShowId(), new AsyncCallback() { @Override public void onSuccess(UserContext result) { @@ -43,6 +49,18 @@ public class SocialProfile implements EntryPoint { RootPanel.get("SocialProfileDiv").add(mainPanel); } + private void checkLinkedInAuthZ() { + if (Window.Location.getParameter("error") != null) { + mainPanel.add(new ErrorAlert()); + } else { + String code = Window.Location.getParameter("code"); + String controlSequence = Window.Location.getParameter("state"); + GWT.log("key="+code+" state="+controlSequence); + GWT.log("state="+controlSequence); + mainPanel.add(new OkAlert()); + } + } + /** * decode the userid from the location param * @return the decoded (base64) userid @@ -54,4 +72,13 @@ public class SocialProfile implements EntryPoint { String encodedUserId = Window.Location.getParameter(encodedOid); return Encoder.decode(encodedUserId); } + /** + * + * @return true if either the user + */ + private boolean isUserAuthZFromLinkedIn() { + if (Window.Location.getParameter("error") != null || Window.Location.getParameter("code") != null) + return true; + return false; + } } diff --git a/src/main/java/org/gcube/portlets/user/socialprofile/client/ui/DisplayProfile.java b/src/main/java/org/gcube/portlets/user/socialprofile/client/ui/DisplayProfile.java index c55428d..112d37c 100644 --- a/src/main/java/org/gcube/portlets/user/socialprofile/client/ui/DisplayProfile.java +++ b/src/main/java/org/gcube/portlets/user/socialprofile/client/ui/DisplayProfile.java @@ -17,6 +17,7 @@ import com.google.gwt.event.dom.client.ClickHandler; 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.Random; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.Window.Location; import com.google.gwt.user.client.rpc.AsyncCallback; @@ -66,6 +67,8 @@ public class DisplayProfile extends Composite { @UiField Button messageButton; @UiField Button editButton; + @UiField Button importButton; + private String currHeadLine; private String currInstitution; @@ -122,6 +125,22 @@ public class DisplayProfile extends Composite { } }); + importButton.setVisible(true); + importButton.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + String OAUTH2_SERVICE = "https://www.linkedin.com/uas/oauth2/authorization?response_type=code"; + String D4S_APP_ID = "77n7r4c9nwuwk2"; + String controlSequence = getRandomString(); + String url = OAUTH2_SERVICE + "" + + "&client_id="+D4S_APP_ID + + "&state="+controlSequence + + "&redirect_uri="+Location.getHref(); + + Location.assign(url); + } + }); + } else { //its someone else String head = (result.getHeadline() == null || result.getHeadline().compareTo("") == 0) ? "" : result.getHeadline(); String isti = (result.getInstitution() == null || result.getInstitution().compareTo("") == 0) ? "" : result.getInstitution(); @@ -293,4 +312,13 @@ public class DisplayProfile extends Composite { } + + private String getRandomString() { + StringBuilder sb = new StringBuilder(); + for (int i=0;i<20;i++) { + sb.append('a'+Random.nextInt(26)); + } + return sb.toString(); + } + } diff --git a/src/main/java/org/gcube/portlets/user/socialprofile/client/ui/DisplayProfile.ui.xml b/src/main/java/org/gcube/portlets/user/socialprofile/client/ui/DisplayProfile.ui.xml index fc98ef3..c432ba2 100644 --- a/src/main/java/org/gcube/portlets/user/socialprofile/client/ui/DisplayProfile.ui.xml +++ b/src/main/java/org/gcube/portlets/user/socialprofile/client/ui/DisplayProfile.ui.xml @@ -60,7 +60,8 @@
Private Message - Edit Professional Background + Import from LinkedIn + Edit Profile Manually
diff --git a/src/main/java/org/gcube/portlets/user/socialprofile/client/ui/ErrorAlert.java b/src/main/java/org/gcube/portlets/user/socialprofile/client/ui/ErrorAlert.java new file mode 100644 index 0000000..bd793e5 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/socialprofile/client/ui/ErrorAlert.java @@ -0,0 +1,21 @@ +package org.gcube.portlets.user.socialprofile.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.uibinder.client.UiBinder; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.Widget; + +public class ErrorAlert extends Composite { + + private static ErrorAlertUiBinder uiBinder = GWT + .create(ErrorAlertUiBinder.class); + + interface ErrorAlertUiBinder extends UiBinder { + } + public ErrorAlert() { + initWidget(uiBinder.createAndBindUi(this)); + } + public ErrorAlert(String firstName) { + initWidget(uiBinder.createAndBindUi(this)); + } +} diff --git a/src/main/java/org/gcube/portlets/user/socialprofile/client/ui/ErrorAlert.ui.xml b/src/main/java/org/gcube/portlets/user/socialprofile/client/ui/ErrorAlert.ui.xml new file mode 100644 index 0000000..eb65370 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/socialprofile/client/ui/ErrorAlert.ui.xml @@ -0,0 +1,17 @@ + + + + .alert { + border: 1px solid #EBCCD1; + border-radius: 4px; + margin: 20px; + padding: 15px; + background-color: #F2DEDE; + color: #A94440; + } + + + Import Error: it seems you denied our request to import from LinkedIn. If this is not the case please report the issue. + + \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/socialprofile/client/ui/OkAlert.java b/src/main/java/org/gcube/portlets/user/socialprofile/client/ui/OkAlert.java new file mode 100644 index 0000000..05e6e98 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/socialprofile/client/ui/OkAlert.java @@ -0,0 +1,19 @@ +package org.gcube.portlets.user.socialprofile.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.uibinder.client.UiBinder; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.Widget; + +public class OkAlert extends Composite { + + private static OkAlertUiBinder uiBinder = GWT.create(OkAlertUiBinder.class); + + interface OkAlertUiBinder extends UiBinder { + } + + public OkAlert() { + initWidget(uiBinder.createAndBindUi(this)); + } + +} diff --git a/src/main/java/org/gcube/portlets/user/socialprofile/client/ui/OkAlert.ui.xml b/src/main/java/org/gcube/portlets/user/socialprofile/client/ui/OkAlert.ui.xml new file mode 100644 index 0000000..1623a88 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/socialprofile/client/ui/OkAlert.ui.xml @@ -0,0 +1,17 @@ + + + + .alert { + border: 1px solid #D6E9C6; + border-radius: 4px; + margin: 20px; + padding: 15px; + background-color: #DFF0D8; + color: #3C763D; + } + + + Import operation completed successfully. + + \ No newline at end of file diff --git a/src/main/resources/org/gcube/portlets/user/socialprofile/SocialProfile.gwt.xml b/src/main/resources/org/gcube/portlets/user/socialprofile/SocialProfile.gwt.xml index c877752..7f47007 100644 --- a/src/main/resources/org/gcube/portlets/user/socialprofile/SocialProfile.gwt.xml +++ b/src/main/resources/org/gcube/portlets/user/socialprofile/SocialProfile.gwt.xml @@ -3,7 +3,7 @@ - + diff --git a/src/test/java/org/gcube/portlets/user/socialprofile/client/GwtTestSocialProfile.java b/src/test/java/org/gcube/portlets/user/socialprofile/client/GwtTestSocialProfile.java deleted file mode 100644 index c6ab4ab..0000000 --- a/src/test/java/org/gcube/portlets/user/socialprofile/client/GwtTestSocialProfile.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.gcube.portlets.user.socialprofile.client; - -import com.google.gwt.junit.client.GWTTestCase; - -/** - * GWT JUnit integration tests must extend GWTTestCase. - * Using "GwtTest*" naming pattern exclude them from running with - * surefire during the test phase. - * - * If you run the tests using the Maven command line, you will have to - * navigate with your browser to a specific url given by Maven. - * See http://mojo.codehaus.org/gwt-maven-plugin/user-guide/testing.html - * for details. - */ -public class GwtTestSocialProfile extends GWTTestCase { - - /** - * Must refer to a valid module that sources this class. - */ - public String getModuleName() { - return "org.gcube.portlets.user.socialprofile.SocialProfileJUnit"; - } - - /** - * Tests the FieldVerifier. - */ - public void testFieldVerifier() { - - } - - /** - * This test will send a request to the server using the greetServer method in - * GreetingService and verify the response. - */ - public void testGreetingService() { - - } - - -}