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:
parent
be4409f90e
commit
f6ce7a3562
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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<ClientFeed> callback);
|
||||
void getUserInfo(AsyncCallback<UserInfo> callback);
|
||||
|
||||
void checkLink(String linkToCheck, AsyncCallback<LinkPreview> callback);
|
||||
|
||||
void getUserSettings(AsyncCallback<UserSettings> callback);
|
||||
}
|
||||
|
|
|
@ -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<UserInfo>() {
|
||||
shareupdateService.getUserSettings(new AsyncCallback<UserSettings>() {
|
||||
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<UserInfo>() {
|
||||
shareupdateService.getUserSettings(new AsyncCallback<UserSettings>() {
|
||||
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");
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
<!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:m="urn:import:org.gcube.portlets.user.shareupdates.client.form">
|
||||
<ui:style>
|
||||
.important {
|
||||
font-weight: bold;
|
||||
}
|
||||
</ui:style>
|
||||
<g:HTMLPanel>
|
||||
<g:HTMLPanel ui:field="mainPanel">
|
||||
<table class="shareContainer">
|
||||
<tr>
|
||||
<td width="60px;" align="middle">
|
||||
|
@ -30,7 +25,8 @@
|
|||
<td valign="middle" width="50%">
|
||||
<div style="text-align: left; padding-top: 2px; color: #777;">
|
||||
privacy level:
|
||||
<g:ListBox styleName="wizardListbox" ui:field="privacyLevel" />
|
||||
<g:ListBox styleName="wizardListbox" ui:field="privacyLevel" visible="false"/>
|
||||
<span id="staticPrivacyLevel"></span>
|
||||
</div>
|
||||
</td>
|
||||
<td valign="middle"></td>
|
||||
|
|
|
@ -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<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;
|
||||
}
|
||||
else {
|
||||
_log.info("Returning test USER");
|
||||
HashMap<String, String> fakeVreNames = new HashMap<String, String>();
|
||||
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<String, String> getUserVreNames(String username) {
|
||||
HashMap<String, String> toReturn = new HashMap<String, String>();
|
||||
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 <code>true</code> if it is, <code>false</code> otherwise.
|
||||
*/
|
||||
private boolean isInfrastructureScope() {
|
||||
return getASLSession().getScope().isInfrastructure();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 2.7 KiB |
Loading…
Reference in New Issue