scope dependnt ready for testing

git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portlets/user/share-updates@73200 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2013-04-11 16:46:58 +00:00
parent be4409f90e
commit f6ce7a3562
8 changed files with 153 additions and 44 deletions

View File

@ -3,8 +3,8 @@ package org.gcube.portlets.user.shareupdates.client;
import org.gcube.portal.databook.shared.ClientFeed; import org.gcube.portal.databook.shared.ClientFeed;
import org.gcube.portal.databook.shared.FeedType; import org.gcube.portal.databook.shared.FeedType;
import org.gcube.portal.databook.shared.PrivacyLevel; 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.LinkPreview;
import org.gcube.portlets.user.shareupdates.shared.UserSettings;
import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; 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 { 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); 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); LinkPreview checkLink(String linkToCheck);
} }

View File

@ -3,8 +3,8 @@ package org.gcube.portlets.user.shareupdates.client;
import org.gcube.portal.databook.shared.ClientFeed; import org.gcube.portal.databook.shared.ClientFeed;
import org.gcube.portal.databook.shared.FeedType; import org.gcube.portal.databook.shared.FeedType;
import org.gcube.portal.databook.shared.PrivacyLevel; 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.LinkPreview;
import org.gcube.portlets.user.shareupdates.shared.UserSettings;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
@ -15,6 +15,8 @@ public interface ShareUpdateServiceAsync {
void share(String feedText, FeedType type, PrivacyLevel pLevel, void share(String feedText, FeedType type, PrivacyLevel pLevel,
String vreName, String linkTitle, String linkDesc, String url, String vreName, String linkTitle, String linkDesc, String url,
String urlThumbnail, String host, AsyncCallback<ClientFeed> callback); String urlThumbnail, String host, AsyncCallback<ClientFeed> callback);
void getUserInfo(AsyncCallback<UserInfo> callback);
void checkLink(String linkToCheck, AsyncCallback<LinkPreview> callback); void checkLink(String linkToCheck, AsyncCallback<LinkPreview> callback);
void getUserSettings(AsyncCallback<UserSettings> callback);
} }

View File

@ -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.ShareUpdateService;
import org.gcube.portlets.user.shareupdates.client.ShareUpdateServiceAsync; import org.gcube.portlets.user.shareupdates.client.ShareUpdateServiceAsync;
import org.gcube.portlets.user.shareupdates.shared.LinkPreview; import org.gcube.portlets.user.shareupdates.shared.LinkPreview;
import org.gcube.portlets.user.shareupdates.shared.UserSettings;
import org.jsonmaker.gwt.client.Jsonizer; import org.jsonmaker.gwt.client.Jsonizer;
import com.google.gwt.core.client.GWT; 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.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField; 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.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite; 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.Image;
import com.google.gwt.user.client.ui.ListBox; import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.Widget; import com.google.gwt.user.client.ui.Widget;
@ -59,38 +62,50 @@ public class ShareUpdateForm extends Composite {
public static ShareUpdateForm get() { public static ShareUpdateForm get() {
return singleton; return singleton;
} }
@UiField
HTMLPanel mainPanel;
UserInfo myUserInfo; UserInfo myUserInfo;
public ShareUpdateForm() { public ShareUpdateForm() {
initWidget(uiBinder.createAndBindUi(this)); initWidget(uiBinder.createAndBindUi(this));
singleton = this; singleton = this;
avatarImage.setUrl(loading); avatarImage.setUrl(loading);
shareTextArea.setText(SHARE_UPDATE_TEXT); shareTextArea.setText(SHARE_UPDATE_TEXT);
shareupdateService.getUserInfo(new AsyncCallback<UserInfo>() { shareupdateService.getUserSettings(new AsyncCallback<UserSettings>() {
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
avatarImage.setSize("60px", "60px"); avatarImage.setSize("60px", "60px");
avatarImage.setUrl(avatar_default); avatarImage.setUrl(avatar_default);
} }
public void onSuccess(UserInfo user) { public void onSuccess(UserSettings userSettings) {
myUserInfo = user; myUserInfo = userSettings.getUserInfo();
avatarImage.getElement().getParentElement().setAttribute("href", user.getAccountURL()); avatarImage.getElement().getParentElement().setAttribute("href", myUserInfo.getAccountURL());
avatarImage.setSize("60px", "60px"); avatarImage.setSize("60px", "60px");
avatarImage.setUrl(user.getAvatarId()); avatarImage.setUrl(myUserInfo.getAvatarId());
if (myUserInfo.getOwnVREs().size() > 1){ String singleVREName = "";
if (myUserInfo.getOwnVREs().size() > 1) {
privacyLevel.addItem("My VREs", PrivacyLevel.VRES.toString()); privacyLevel.addItem("My VREs", PrivacyLevel.VRES.toString());
for (String vreId : myUserInfo.getOwnVREs().keySet()) for (String vreId : myUserInfo.getOwnVREs().keySet())
privacyLevel.addItem(LISTBOX_LEVEL + myUserInfo.getOwnVREs().get(vreId), vreId); privacyLevel.addItem(LISTBOX_LEVEL + myUserInfo.getOwnVREs().get(vreId), vreId);
} }
else if (myUserInfo.getOwnVREs().size() == 1) else if (myUserInfo.getOwnVREs().size() == 1)
for (String vreId : myUserInfo.getOwnVREs().keySet()) for (String vreId : myUserInfo.getOwnVREs().keySet()) {
privacyLevel.addItem(LISTBOX_LEVEL + myUserInfo.getOwnVREs().get(vreId), vreId); singleVREName = myUserInfo.getOwnVREs().get(vreId);
privacyLevel.addItem(LISTBOX_LEVEL + singleVREName, vreId);
}
//privacyLevel.addItem("My Connections", PrivacyLevel.CONNECTION.toString()); //privacyLevel.addItem("My Connections", PrivacyLevel.CONNECTION.toString());
if (user.isAdmin()) if (myUserInfo.isAdmin() && userSettings.isInfrastructure())
privacyLevel.addItem("Anyone", PrivacyLevel.PORTAL.toString()); 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") @UiHandler("submitButton")
void onClick(ClickEvent e) { void onClick(ClickEvent e) {
shareupdateService.getUserInfo(new AsyncCallback<UserInfo>() { shareupdateService.getUserSettings(new AsyncCallback<UserSettings>() {
public void onFailure(Throwable caught) { 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."); 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) { public void onSuccess(UserSettings result) {
if (result.getUsername().equals("test.user")) { if (result.getUserInfo().getUsername().equals("test.user")) {
Window.alert("Your session has expired, please log out and login again"); Window.alert("Your session has expired, please log out and login again");
return; return;
} }
myUserInfo = result; myUserInfo = result.getUserInfo();
String toShare = shareTextArea.getText().trim(); String toShare = shareTextArea.getText().trim();
if (toShare.equals(SHARE_UPDATE_TEXT) || toShare.equals(ERROR_UPDATE_TEXT) || toShare.equals("")) { if (toShare.equals(SHARE_UPDATE_TEXT) || toShare.equals(ERROR_UPDATE_TEXT) || toShare.equals("")) {
shareTextArea.addStyleName("error"); shareTextArea.addStyleName("error");

View File

@ -1,12 +1,7 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent"> <!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder" <ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:m="urn:import:org.gcube.portlets.user.shareupdates.client.form"> xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:m="urn:import:org.gcube.portlets.user.shareupdates.client.form">
<ui:style> <g:HTMLPanel ui:field="mainPanel">
.important {
font-weight: bold;
}
</ui:style>
<g:HTMLPanel>
<table class="shareContainer"> <table class="shareContainer">
<tr> <tr>
<td width="60px;" align="middle"> <td width="60px;" align="middle">
@ -30,7 +25,8 @@
<td valign="middle" width="50%"> <td valign="middle" width="50%">
<div style="text-align: left; padding-top: 2px; color: #777;"> <div style="text-align: left; padding-top: 2px; color: #777;">
privacy level: privacy level:
<g:ListBox styleName="wizardListbox" ui:field="privacyLevel" /> <g:ListBox styleName="wizardListbox" ui:field="privacyLevel" visible="false"/>
<span id="staticPrivacyLevel"></span>
</div> </div>
</td> </td>
<td valign="middle"></td> <td valign="middle"></td>

View File

@ -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.metaseeker.MetaSeeker;
import org.gcube.portlets.user.shareupdates.server.opengraph.OpenGraph; import org.gcube.portlets.user.shareupdates.server.opengraph.OpenGraph;
import org.gcube.portlets.user.shareupdates.shared.LinkPreview; 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.GroupManager;
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayGroupManager; import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayGroupManager;
import org.gcube.vomanagement.usermanagement.model.GroupModel; 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); String user = (String) this.getThreadLocalRequest().getSession().getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
if (user == null) { if (user == null) {
_log.warn("USER IS NULL setting test.user and Running OUTSIDE PORTAL"); _log.warn("USER IS NULL setting test.user and Running OUTSIDE PORTAL");
user = "test.user"; //user = "test.user";
//user = "massimiliano.assante"; user = "massimiliano.assante";
SessionManager.getInstance().getASLSession(sessionID, user).setScope("/gcube/devsec/devVRE");
withinPortal = false; withinPortal = false;
} }
else { else {
@ -121,7 +123,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
if (withinPortal) { if (withinPortal) {
try { try {
UserInfo user = getUserFromSession(); UserInfo user = getUserSettings().getUserInfo();
email = user.getEmailaddress(); email = user.getEmailaddress();
fullName = user.getFullName(); fullName = user.getFullName();
thumbnailURL = user.getAvatarId(); thumbnailURL = user.getAvatarId();
@ -170,11 +172,11 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
return cf; return cf;
} }
private UserInfo getUserFromSession() { private UserSettings getUserSettingsFromSession() {
return (UserInfo) getASLSession().getAttribute(UserInfo.USER_INFO_ATTR); 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); getASLSession().setAttribute(UserInfo.USER_INFO_ATTR, user);
} }
private String replaceAmpersand(String toReplace) { 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 { try {
ASLSession session = getASLSession();
String username = getASLSession().getUsername(); String username = session.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";
@ -231,22 +235,27 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
ThemeDisplay themeDisplay = (ThemeDisplay) this.getThreadLocalRequest().getSession().getAttribute(WebKeys.THEME_DISPLAY); ThemeDisplay themeDisplay = (ThemeDisplay) this.getThreadLocalRequest().getSession().getAttribute(WebKeys.THEME_DISPLAY);
String accountURL = themeDisplay.getURLMyAccount().toString(); String accountURL = themeDisplay.getURLMyAccount().toString();
HashMap<String, String> vreNames = getUserVreNames(username); HashMap<String, String> 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; return toReturn;
} }
else { else {
_log.info("Returning test USER"); _log.info("Returning test USER");
HashMap<String, String> fakeVreNames = new HashMap<String, String>(); HashMap<String, String> fakeVreNames = new HashMap<String, String>();
fakeVreNames.put("1","devVRE"); fakeVreNames.put("/gcube/devsec/devVRE","devVRE");
// fakeVreNames.put("2", "devNext"); //fakeVreNames.put("/gcube/devNext/NexNext","NexNext");
return new UserInfo(getASLSession().getUsername(), fullName, thumbnailURL, email, "fakeAccountUrl", true, false, fakeVreNames);
UserInfo user = new UserInfo(getASLSession().getUsername(), fullName, thumbnailURL, email, "fakeAccountUrl", true, false, fakeVreNames);
return new UserSettings(user, 0, session.getScopeName(), isInfrastructureScope());
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); 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 * 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<String, String> getUserVreNames(String username) { private HashMap<String, String> getUserVreNames(String username) {
HashMap<String, String> toReturn = new HashMap<String, String>(); HashMap<String, String> toReturn = new HashMap<String, String>();
for (GroupModel vre : getUserVREs(username)) { if (isInfrastructureScope()) {
toReturn.put(vre.getGroupId(), vre.getGroupName()); 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; return toReturn;
} }
/** /**
@ -286,7 +303,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
return false; return false;
} }
} }
/** /**
* *
* @param rolename * @param rolename
@ -562,4 +579,12 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
System.out.println("Error" + e); System.out.println("Error" + e);
} }
} }
/**
* Indicates whether the scope is the whole infrastructure.
* @return <code>true</code> if it is, <code>false</code> otherwise.
*/
private boolean isInfrastructureScope() {
return getASLSession().getScope().isInfrastructure();
}
} }

View File

@ -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 + "]";
}
}

View File

@ -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 { .buttonDiv {
text-align: right; text-align: right;
padding-top: 2px; padding-top: 2px;

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB