diff --git a/src/main/java/org/gcube/portlets/user/shareupdates/client/ShareUpdateService.java b/src/main/java/org/gcube/portlets/user/shareupdates/client/ShareUpdateService.java index e07373c..d79fb9b 100644 --- a/src/main/java/org/gcube/portlets/user/shareupdates/client/ShareUpdateService.java +++ b/src/main/java/org/gcube/portlets/user/shareupdates/client/ShareUpdateService.java @@ -3,8 +3,8 @@ package org.gcube.portlets.user.shareupdates.client; import org.gcube.portal.databook.shared.ClientFeed; import org.gcube.portal.databook.shared.FeedType; import org.gcube.portal.databook.shared.PrivacyLevel; -import org.gcube.portal.databook.shared.UserInfo; import org.gcube.portlets.user.shareupdates.shared.LinkPreview; +import org.gcube.portlets.user.shareupdates.shared.UserSettings; import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; @@ -16,7 +16,7 @@ import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; public interface ShareUpdateService extends RemoteService { ClientFeed share(String feedText, FeedType type, PrivacyLevel pLevel, String vreName, String linkTitle, String linkDesc, String url, String urlThumbnail, String host); - UserInfo getUserInfo(); + UserSettings getUserSettings(); LinkPreview checkLink(String linkToCheck); } diff --git a/src/main/java/org/gcube/portlets/user/shareupdates/client/ShareUpdateServiceAsync.java b/src/main/java/org/gcube/portlets/user/shareupdates/client/ShareUpdateServiceAsync.java index af91dd6..5e77ec3 100644 --- a/src/main/java/org/gcube/portlets/user/shareupdates/client/ShareUpdateServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/shareupdates/client/ShareUpdateServiceAsync.java @@ -3,8 +3,8 @@ package org.gcube.portlets.user.shareupdates.client; import org.gcube.portal.databook.shared.ClientFeed; import org.gcube.portal.databook.shared.FeedType; import org.gcube.portal.databook.shared.PrivacyLevel; -import org.gcube.portal.databook.shared.UserInfo; import org.gcube.portlets.user.shareupdates.shared.LinkPreview; +import org.gcube.portlets.user.shareupdates.shared.UserSettings; import com.google.gwt.user.client.rpc.AsyncCallback; @@ -15,6 +15,8 @@ public interface ShareUpdateServiceAsync { void share(String feedText, FeedType type, PrivacyLevel pLevel, String vreName, String linkTitle, String linkDesc, String url, String urlThumbnail, String host, AsyncCallback callback); - void getUserInfo(AsyncCallback callback); + void checkLink(String linkToCheck, AsyncCallback callback); + + void getUserSettings(AsyncCallback callback); } diff --git a/src/main/java/org/gcube/portlets/user/shareupdates/client/form/ShareUpdateForm.java b/src/main/java/org/gcube/portlets/user/shareupdates/client/form/ShareUpdateForm.java index 99f06f2..39f1167 100644 --- a/src/main/java/org/gcube/portlets/user/shareupdates/client/form/ShareUpdateForm.java +++ b/src/main/java/org/gcube/portlets/user/shareupdates/client/form/ShareUpdateForm.java @@ -11,9 +11,11 @@ import org.gcube.portal.databook.shared.UserInfo; import org.gcube.portlets.user.shareupdates.client.ShareUpdateService; import org.gcube.portlets.user.shareupdates.client.ShareUpdateServiceAsync; import org.gcube.portlets.user.shareupdates.shared.LinkPreview; +import org.gcube.portlets.user.shareupdates.shared.UserSettings; import org.jsonmaker.gwt.client.Jsonizer; import com.google.gwt.core.client.GWT; +import com.google.gwt.dom.client.Document; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; @@ -22,6 +24,7 @@ import com.google.gwt.user.client.Window; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.Button; 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.ListBox; import com.google.gwt.user.client.ui.Widget; @@ -59,38 +62,50 @@ public class ShareUpdateForm extends Composite { public static ShareUpdateForm get() { return singleton; } - + @UiField + HTMLPanel mainPanel; UserInfo myUserInfo; public ShareUpdateForm() { initWidget(uiBinder.createAndBindUi(this)); singleton = this; - + avatarImage.setUrl(loading); shareTextArea.setText(SHARE_UPDATE_TEXT); - shareupdateService.getUserInfo(new AsyncCallback() { + shareupdateService.getUserSettings(new AsyncCallback() { public void onFailure(Throwable caught) { avatarImage.setSize("60px", "60px"); avatarImage.setUrl(avatar_default); } - public void onSuccess(UserInfo user) { - myUserInfo = user; - avatarImage.getElement().getParentElement().setAttribute("href", user.getAccountURL()); + public void onSuccess(UserSettings userSettings) { + myUserInfo = userSettings.getUserInfo(); + avatarImage.getElement().getParentElement().setAttribute("href", myUserInfo.getAccountURL()); avatarImage.setSize("60px", "60px"); - avatarImage.setUrl(user.getAvatarId()); - if (myUserInfo.getOwnVREs().size() > 1){ + avatarImage.setUrl(myUserInfo.getAvatarId()); + String singleVREName = ""; + if (myUserInfo.getOwnVREs().size() > 1) { privacyLevel.addItem("My VREs", PrivacyLevel.VRES.toString()); for (String vreId : myUserInfo.getOwnVREs().keySet()) privacyLevel.addItem(LISTBOX_LEVEL + myUserInfo.getOwnVREs().get(vreId), vreId); } else if (myUserInfo.getOwnVREs().size() == 1) - for (String vreId : myUserInfo.getOwnVREs().keySet()) - privacyLevel.addItem(LISTBOX_LEVEL + myUserInfo.getOwnVREs().get(vreId), vreId); + for (String vreId : myUserInfo.getOwnVREs().keySet()) { + singleVREName = myUserInfo.getOwnVREs().get(vreId); + privacyLevel.addItem(LISTBOX_LEVEL + singleVREName, vreId); + } + //privacyLevel.addItem("My Connections", PrivacyLevel.CONNECTION.toString()); - if (user.isAdmin()) + if (myUserInfo.isAdmin() && userSettings.isInfrastructure()) privacyLevel.addItem("Anyone", PrivacyLevel.PORTAL.toString()); + //change css if deployed in VRE scope + if (!userSettings.isInfrastructure()) { + mainPanel.addStyleName("framed"); + Document.get().getElementById("staticPrivacyLevel").setInnerText(singleVREName); + } + else + privacyLevel.setVisible(true); } }); } @@ -114,16 +129,16 @@ public class ShareUpdateForm extends Composite { @UiHandler("submitButton") void onClick(ClickEvent e) { - shareupdateService.getUserInfo(new AsyncCallback() { + shareupdateService.getUserSettings(new AsyncCallback() { public void onFailure(Throwable caught) { Window.alert("Ops! we encountered some problems delivering your message, server is not responding, please try again in a short while."); } - public void onSuccess(UserInfo result) { - if (result.getUsername().equals("test.user")) { + public void onSuccess(UserSettings result) { + if (result.getUserInfo().getUsername().equals("test.user")) { Window.alert("Your session has expired, please log out and login again"); return; } - myUserInfo = result; + myUserInfo = result.getUserInfo(); String toShare = shareTextArea.getText().trim(); if (toShare.equals(SHARE_UPDATE_TEXT) || toShare.equals(ERROR_UPDATE_TEXT) || toShare.equals("")) { shareTextArea.addStyleName("error"); diff --git a/src/main/java/org/gcube/portlets/user/shareupdates/client/form/ShareUpdateForm.ui.xml b/src/main/java/org/gcube/portlets/user/shareupdates/client/form/ShareUpdateForm.ui.xml index 1f53943..d4f9387 100644 --- a/src/main/java/org/gcube/portlets/user/shareupdates/client/form/ShareUpdateForm.ui.xml +++ b/src/main/java/org/gcube/portlets/user/shareupdates/client/form/ShareUpdateForm.ui.xml @@ -1,12 +1,7 @@ - - .important { - font-weight: bold; - } - - + diff --git a/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java b/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java index 3ff2911..57c0e14 100644 --- a/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java @@ -34,6 +34,7 @@ import org.gcube.portlets.user.shareupdates.client.ShareUpdateService; import org.gcube.portlets.user.shareupdates.server.metaseeker.MetaSeeker; import org.gcube.portlets.user.shareupdates.server.opengraph.OpenGraph; import org.gcube.portlets.user.shareupdates.shared.LinkPreview; +import org.gcube.portlets.user.shareupdates.shared.UserSettings; import org.gcube.vomanagement.usermanagement.GroupManager; import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayGroupManager; import org.gcube.vomanagement.usermanagement.model.GroupModel; @@ -97,8 +98,9 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar 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"; + //user = "test.user"; + user = "massimiliano.assante"; + SessionManager.getInstance().getASLSession(sessionID, user).setScope("/gcube/devsec/devVRE"); withinPortal = false; } else { @@ -121,7 +123,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar if (withinPortal) { try { - UserInfo user = getUserFromSession(); + UserInfo user = getUserSettings().getUserInfo(); email = user.getEmailaddress(); fullName = user.getFullName(); thumbnailURL = user.getAvatarId(); @@ -170,11 +172,11 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar return cf; } - private UserInfo getUserFromSession() { - return (UserInfo) getASLSession().getAttribute(UserInfo.USER_INFO_ATTR); + private UserSettings getUserSettingsFromSession() { + return (UserSettings) getASLSession().getAttribute(UserInfo.USER_INFO_ATTR); } - private void setUserInSession(UserInfo user) { + private void setUserSettingsInSession(UserSettings user) { getASLSession().setAttribute(UserInfo.USER_INFO_ATTR, user); } private String replaceAmpersand(String toReplace) { @@ -214,10 +216,12 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar } - public UserInfo getUserInfo() { + public UserSettings getUserSettings() { + if (getUserSettingsFromSession() != null) + return getUserSettingsFromSession(); try { - - String username = getASLSession().getUsername(); + ASLSession session = getASLSession(); + String username = session.getUsername(); String email = username+"@isti.cnr.it"; String fullName = username+" FULL"; String thumbnailURL = "images/Avatar_default.png"; @@ -231,22 +235,27 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar ThemeDisplay themeDisplay = (ThemeDisplay) this.getThreadLocalRequest().getSession().getAttribute(WebKeys.THEME_DISPLAY); String accountURL = themeDisplay.getURLMyAccount().toString(); HashMap vreNames = getUserVreNames(username); - UserInfo toReturn = new UserInfo(username, fullName, thumbnailURL, user.getEmailAddress(), accountURL, true, isAdmin(), vreNames); - setUserInSession(toReturn); + + UserInfo userInfo = new UserInfo(username, fullName, thumbnailURL, user.getEmailAddress(), accountURL, true, isAdmin(), vreNames); + UserSettings toReturn = new UserSettings(userInfo, 0, session.getScopeName(), isInfrastructureScope()); + setUserSettingsInSession(toReturn); + return toReturn; } else { _log.info("Returning test USER"); HashMap fakeVreNames = new HashMap(); - fakeVreNames.put("1","devVRE"); - // fakeVreNames.put("2", "devNext"); - return new UserInfo(getASLSession().getUsername(), fullName, thumbnailURL, email, "fakeAccountUrl", true, false, fakeVreNames); + 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 new UserSettings(user, 0, session.getScopeName(), isInfrastructureScope()); } } catch (Exception e) { e.printStackTrace(); } - return new UserInfo(); + return new UserSettings(); } /** * return the id as key and the names as value of the vre a user is subscribed to @@ -255,9 +264,17 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar */ private HashMap getUserVreNames(String username) { HashMap toReturn = new HashMap(); - for (GroupModel vre : getUserVREs(username)) { - toReturn.put(vre.getGroupId(), vre.getGroupName()); + if (isInfrastructureScope()) { + for (GroupModel vre : getUserVREs(username)) { + toReturn.put(vre.getGroupId(), vre.getGroupName()); + } + } else { + for (GroupModel vre : getUserVREs(username)) { + if (vre.getGroupName().compareTo(getASLSession().getGroupName())==0) + toReturn.put(vre.getGroupId(), vre.getGroupName()); + } } + return toReturn; } /** @@ -286,7 +303,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar return false; } } - + /** * * @param rolename @@ -562,4 +579,12 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar System.out.println("Error" + e); } } + + /** + * Indicates whether the scope is the whole infrastructure. + * @return true if it is, false otherwise. + */ + private boolean isInfrastructureScope() { + return getASLSession().getScope().isInfrastructure(); + } } diff --git a/src/main/java/org/gcube/portlets/user/shareupdates/shared/UserSettings.java b/src/main/java/org/gcube/portlets/user/shareupdates/shared/UserSettings.java new file mode 100644 index 0000000..6200aa8 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/shareupdates/shared/UserSettings.java @@ -0,0 +1,56 @@ +package org.gcube.portlets.user.shareupdates.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/webapp/ShareUpdates.css b/src/main/webapp/ShareUpdates.css index c59d99c..b0f1b6a 100644 --- a/src/main/webapp/ShareUpdates.css +++ b/src/main/webapp/ShareUpdates.css @@ -1,3 +1,18 @@ +.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; + width: 600px; +} + .buttonDiv { text-align: right; padding-top: 2px; 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
@@ -30,7 +25,8 @@
privacy level: - + +