diff --git a/pom.xml b/pom.xml index e1e50ab..83984b6 100644 --- a/pom.xml +++ b/pom.xml @@ -63,6 +63,12 @@ [1.4.0,1.6.0] provided + + org.gcube.portlets.user + gcube-widgets + [1.4.0-SNAPSHOT, 2.0.0-SNAPSHOT) + provided + org.gcube.portal custom-portal-handler diff --git a/src/main/java/org/gcube/portlets/user/socialprofile/client/SocialService.java b/src/main/java/org/gcube/portlets/user/socialprofile/client/SocialService.java index 874eb85..6f12307 100644 --- a/src/main/java/org/gcube/portlets/user/socialprofile/client/SocialService.java +++ b/src/main/java/org/gcube/portlets/user/socialprofile/client/SocialService.java @@ -1,5 +1,7 @@ package org.gcube.portlets.user.socialprofile.client; +import org.gcube.portal.databook.shared.UserInfo; + import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; @@ -8,5 +10,5 @@ import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; */ @RemoteServiceRelativePath("greet") public interface SocialService extends RemoteService { - + UserInfo getUserInfo(); } diff --git a/src/main/java/org/gcube/portlets/user/socialprofile/client/SocialServiceAsync.java b/src/main/java/org/gcube/portlets/user/socialprofile/client/SocialServiceAsync.java index 5fd7918..87a9196 100644 --- a/src/main/java/org/gcube/portlets/user/socialprofile/client/SocialServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/socialprofile/client/SocialServiceAsync.java @@ -1,7 +1,11 @@ package org.gcube.portlets.user.socialprofile.client; +import org.gcube.portal.databook.shared.UserInfo; + import com.google.gwt.user.client.rpc.AsyncCallback; public interface SocialServiceAsync { + + void getUserInfo(AsyncCallback callback); } 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 882329d..e741969 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 @@ -1,12 +1,15 @@ package org.gcube.portlets.user.socialprofile.client.ui; +import org.gcube.portal.databook.shared.UserInfo; import org.gcube.portlets.user.socialprofile.client.SocialService; import org.gcube.portlets.user.socialprofile.client.SocialServiceAsync; import com.google.gwt.core.client.GWT; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; +import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.HTMLPanel; import com.google.gwt.user.client.ui.Image; import com.google.gwt.user.client.ui.Widget; @@ -17,13 +20,38 @@ public class DisplayProfile extends Composite { interface DisplayProfileUiBinder extends UiBinder { } - + public static final String avatar_default = GWT.getModuleBaseURL() + "../images/Avatar_default.png"; + public static final String loading = GWT.getModuleBaseURL() + "../images/avatarLoader.gif"; + private final SocialServiceAsync socialService = GWT.create(SocialService.class); + @UiField HTMLPanel mainPanel; @UiField Image avatarImage; + + private UserInfo myUserInfo; + public DisplayProfile() { initWidget(uiBinder.createAndBindUi(this)); + avatarImage.setUrl(loading); + mainPanel.addStyleName("framed"); + + socialService.getUserInfo(new AsyncCallback() { + + @Override + public void onSuccess(UserInfo result) { + myUserInfo = result; + avatarImage.getElement().getParentElement().setAttribute("href", myUserInfo.getAccountURL()); + avatarImage.setSize("60px", "60px"); + avatarImage.setUrl(myUserInfo.getAvatarId()); + } + + @Override + public void onFailure(Throwable caught) { + avatarImage.setSize("120px", "120px"); + avatarImage.setUrl(avatar_default); + } + }); } } 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 596e5b8..eba542a 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 @@ -1,19 +1,20 @@ - + - diff --git a/src/main/java/org/gcube/portlets/user/socialprofile/server/SocialServiceImpl.java b/src/main/java/org/gcube/portlets/user/socialprofile/server/SocialServiceImpl.java index 046d66b..fbf542e 100644 --- a/src/main/java/org/gcube/portlets/user/socialprofile/server/SocialServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/socialprofile/server/SocialServiceImpl.java @@ -1,14 +1,90 @@ package org.gcube.portlets.user.socialprofile.server; +import java.util.HashMap; + +import org.gcube.application.framework.core.session.ASLSession; +import org.gcube.application.framework.core.session.SessionManager; +import org.gcube.common.core.utils.logging.GCUBEClientLog; +import org.gcube.portal.custom.communitymanager.OrganizationsUtil; +import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; +import org.gcube.portal.databook.shared.UserInfo; import org.gcube.portlets.user.socialprofile.client.SocialService; -import org.gcube.portlets.user.socialprofile.shared.FieldVerifier; + import com.google.gwt.user.server.rpc.RemoteServiceServlet; +import com.liferay.portal.kernel.util.WebKeys; +import com.liferay.portal.service.UserLocalServiceUtil; +import com.liferay.portal.theme.ThemeDisplay; /** * The server side implementation of the RPC service. */ @SuppressWarnings("serial") public class SocialServiceImpl extends RemoteServiceServlet implements SocialService { + /** + * + */ + private static GCUBEClientLog _log = new GCUBEClientLog(SocialServiceImpl.class); + + /** + * used for debugging in eclipse + */ + private boolean withinPortal = false; + + /** + * 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 = "test.user"; +// user = "massimiliano.assante"; +// SessionManager.getInstance().getASLSession(sessionID, user).setScope("/gcube/devsec/devVRE"); + withinPortal = false; + } + else { + withinPortal = true; + } + return SessionManager.getInstance().getASLSession(sessionID, user); + } + + @Override + public UserInfo getUserInfo() { + try { + ASLSession session = getASLSession(); + String username = session.getUsername(); + String email = username+"@isti.cnr.it"; + String fullName = username+" FULL"; + String thumbnailURL = "images/Avatar_default.png"; - + if (withinPortal) { + + com.liferay.portal.model.UserModel user = UserLocalServiceUtil.getUserByScreenName(OrganizationsUtil.getCompany().getCompanyId(), username); + thumbnailURL = "/image/user_male_portrait?img_id="+user.getPortraitId(); + fullName = user.getFirstName() + " " + user.getLastName(); + email = user.getEmailAddress(); + ThemeDisplay themeDisplay = (ThemeDisplay) this.getThreadLocalRequest().getSession().getAttribute(WebKeys.THEME_DISPLAY); + String accountURL = themeDisplay.getURLMyAccount().toString(); + HashMap vreNames = new HashMap(); + + UserInfo userInfo = new UserInfo(username, fullName, thumbnailURL, user.getEmailAddress(), accountURL, true, false, vreNames); + return userInfo; + } + else { + _log.info("Returning test USER"); + HashMap fakeVreNames = new HashMap(); + fakeVreNames.put("/gcube/devsec/devVRE","devVRE"); + //fakeVreNames.put("/gcube/devNext/NexNext","NexNext"); + + UserInfo user = new UserInfo(getASLSession().getUsername(), fullName, thumbnailURL, email, "fakeAccountUrl", true, false, fakeVreNames); + return (user); + } + + } catch (Exception e) { + e.printStackTrace(); + } + return new UserInfo(); + } } diff --git a/src/main/java/org/gcube/portlets/user/socialprofile/shared/FieldVerifier.java b/src/main/java/org/gcube/portlets/user/socialprofile/shared/FieldVerifier.java deleted file mode 100644 index a2ebb57..0000000 --- a/src/main/java/org/gcube/portlets/user/socialprofile/shared/FieldVerifier.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.gcube.portlets.user.socialprofile.shared; - -/** - *

- * FieldVerifier validates that the name the user enters is valid. - *

- *

- * This class is in the shared packing because we use it in both - * the client code and on the server. On the client, we verify that the name is - * valid before sending an RPC request so the user doesn't have to wait for a - * network round trip to get feedback. On the server, we verify that the name is - * correct to ensure that the input is correct regardless of where the RPC - * originates. - *

- *

- * When creating a class that is used on both the client and the server, be sure - * that all code is translatable and does not use native JavaScript. Code that - * is note translatable (such as code that interacts with a database or the file - * system) cannot be compiled into client side JavaScript. Code that uses native - * JavaScript (such as Widgets) cannot be run on the server. - *

- */ -public class FieldVerifier { - - /** - * Verifies that the specified name is valid for our service. - * - * In this example, we only require that the name is at least four - * characters. In your application, you can use more complex checks to ensure - * that usernames, passwords, email addresses, URLs, and other fields have the - * proper syntax. - * - * @param name the name to validate - * @return true if valid, false if invalid - */ - public static boolean isValidName(String name) { - if (name == null) { - return false; - } - return name.length() > 3; - } -} diff --git a/src/main/java/org/gcube/portlets/user/socialprofile/shared/UserSettings.java b/src/main/java/org/gcube/portlets/user/socialprofile/shared/UserSettings.java new file mode 100644 index 0000000..de520f7 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/socialprofile/shared/UserSettings.java @@ -0,0 +1,56 @@ +package org.gcube.portlets.user.socialprofile.shared; + +import java.io.Serializable; + +import org.gcube.portal.databook.shared.UserInfo; + +@SuppressWarnings("serial") +public class UserSettings implements Serializable { + private UserInfo userInfo; + private int refreshingTimeInMillis; + private String currentScope; + boolean isInfrastructure; + public UserSettings() { + super(); + } + public UserSettings(UserInfo userInfo, int refreshingTimeInMillis, + String currentScope, boolean isInfrastructure) { + super(); + this.userInfo = userInfo; + this.refreshingTimeInMillis = refreshingTimeInMillis; + this.currentScope = currentScope; + this.isInfrastructure = isInfrastructure; + } + public UserInfo getUserInfo() { + return userInfo; + } + public void setUserInfo(UserInfo userInfo) { + this.userInfo = userInfo; + } + public int getRefreshingTimeInMillis() { + return refreshingTimeInMillis; + } + public void setRefreshingTimeInMillis(int refreshingTimeInMillis) { + this.refreshingTimeInMillis = refreshingTimeInMillis; + } + public String getCurrentScope() { + return currentScope; + } + public void setCurrentScope(String currentScope) { + this.currentScope = currentScope; + } + public boolean isInfrastructure() { + return isInfrastructure; + } + public void setInfrastructure(boolean isInfrastructure) { + this.isInfrastructure = isInfrastructure; + } + @Override + public String toString() { + return "UserSettings [userInfo=" + userInfo + + ", refreshingTimeInMillis=" + refreshingTimeInMillis + + ", currentScope=" + currentScope + ", isInfrastructure=" + + isInfrastructure + "]"; + } + +} 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 ec47f27..c6b033c 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 @@ -1,15 +1,18 @@ - - + + - + + + + + + - - - - - - + + + diff --git a/src/main/webapp/SocialProfile.css b/src/main/webapp/SocialProfile.css index e69de29..423d0fb 100644 --- a/src/main/webapp/SocialProfile.css +++ b/src/main/webapp/SocialProfile.css @@ -0,0 +1,28 @@ +.framed { + margin: 0 0 10px; + padding: 10px; + margin: 0px 5px; + background: #FFF url(images/vre_bg_gray.png) repeat-x left bottom; + border-radius: 6px !important; + -moz-border-radius: 6px !important; + -webkit-border-radius: 6px !important; + border: 1px solid #DBDBDB; +} + +.user-photo { + display: block; + padding: 2px; + border: 1px solid #E6E6E6; +} + +.full-name { + font-family: Helvetica, Arial, sans-serif; + font-size: 24px; + font-weight: bold; +} + +.headline { + font-family: Helvetica, Arial, sans-serif; + font-size: 16px; + color: red; +} \ No newline at end of file diff --git a/src/main/webapp/images/Avatar_default.png b/src/main/webapp/images/Avatar_default.png new file mode 100644 index 0000000..2a6c844 Binary files /dev/null and b/src/main/webapp/images/Avatar_default.png differ diff --git a/src/main/webapp/images/avatarLoader.gif b/src/main/webapp/images/avatarLoader.gif new file mode 100644 index 0000000..4c4d825 Binary files /dev/null and b/src/main/webapp/images/avatarLoader.gif differ diff --git a/src/main/webapp/images/vre_bg_gray.png b/src/main/webapp/images/vre_bg_gray.png new file mode 100644 index 0000000..31cb923 Binary files /dev/null and b/src/main/webapp/images/vre_bg_gray.png differ
- + +
- SSSSSS +
Massimiliano Assante
+
Researcher