almost ready, only notification to VRE-Manager missing

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/gcube-loggedin@99903 82a268e6-3cf1-43bd-a215-b396298e98cf
master
Massimiliano Assante 10 years ago
parent 85dcf48b51
commit f455fc70f4

@ -1,7 +1,10 @@
package org.gcube.portlets.user.gcubeloggedin.client;
import org.gcube.portal.custom.communitymanager.OrganizationsUtil;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.gcube.portlets.user.gcubeloggedin.client.ui.AboutView;
import org.gcube.portlets.user.gcubeloggedin.shared.VObject;
import org.gcube.portlets.user.gcubeloggedin.shared.VREClient;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
@ -10,6 +13,11 @@ import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.liferay.portal.model.User;
import com.liferay.portal.security.permission.PermissionChecker;
import com.liferay.portal.security.permission.PermissionCheckerFactoryUtil;
import com.liferay.portal.security.permission.PermissionThreadLocal;
import com.liferay.portal.service.UserLocalServiceUtil;
/**
* Entry point classes define <code>onModuleLoad()</code>.
@ -39,6 +47,7 @@ public class GCubeLoggedin implements EntryPoint {
public void onFailure(Throwable caught) { }
public void onSuccess(VObject result) {
main_panel.clear();
main_panel.add(new AboutView(result, loggedinService));
}
@ -57,4 +66,6 @@ public class GCubeLoggedin implements EntryPoint {
"</td></tr>"+
"</table></center>" ;
}
}

@ -3,6 +3,7 @@ package org.gcube.portlets.user.gcubeloggedin.client.ui;
import org.gcube.portlets.user.gcubeloggedin.client.LoggedinServiceAsync;
import org.gcube.portlets.user.gcubeloggedin.client.UIConstants;
import org.gcube.portlets.user.gcubeloggedin.shared.VObject;
import org.gcube.portlets.user.gcubeloggedin.shared.VREClient;
import org.gcube.portlets.widgets.sessionchecker.client.CheckSession;
import com.google.gwt.core.client.GWT;
@ -44,12 +45,15 @@ public class AboutView extends Composite {
initWidget(uiBinder.createAndBindUi(this));
this.loggedinService = loggedinService;
description.setHTML("<img class=\"imageVRE\" src=\"" + vobj.getImageURL() + "\" />" + vobj.getDescription());
leaveButton.getElement().getStyle().setBackgroundColor("#F2DEDE");
leaveButton.getElement().getStyle().setBorderColor("#EBCCD1");
leaveButton.getElement().getStyle().setColor("#A94440");
wa = new WarningAlert("Are you sure you want to leave this group? "
+ "By leaving this group you will no longer receive updates and loose the workspace folder related to the group.", this);
if (vobj instanceof VREClient && !vobj.isMandatory()) {
leaveButton.getElement().getStyle().setBackgroundColor("#F2DEDE");
leaveButton.getElement().getStyle().setBorderColor("#EBCCD1");
leaveButton.getElement().getStyle().setColor("#A94440");
wa = new WarningAlert("Are you sure you want to leave this group? "
+ "By leaving this group you will no longer receive updates and lose the workspace folder related to the group.", this);
} else
htmlPanel.remove(leaveButton);
}
@UiHandler("backButton")
@ -66,11 +70,11 @@ public class AboutView extends Composite {
@UiHandler("leaveButton")
void onUnsubscribe(ClickEvent e) {
htmlPanel.add(wa);
}
protected void abandonGroup() {
htmlPanel.remove(wa);
final HTML loading = getLoadingHTML();
@ -91,19 +95,19 @@ public class AboutView extends Composite {
}
});
}
/**
*
* @return
*/
private HTML getLoadingHTML() {
return new HTML(
"<center><table border='0'>"+
"<tr>"+
"<td>"+
"<img src='" + UIConstants.LOADING_IMAGE + "'>"+
"</td></tr>"+
"</table></center>") ;
"<center><table border='0'>"+
"<tr>"+
"<td>"+
"<img src='" + UIConstants.LOADING_IMAGE + "'>"+
"</td></tr>"+
"</table></center>") ;
}
}

@ -21,22 +21,26 @@ import org.gcube.portlets.user.gcubeloggedin.shared.VObject.UserBelongingClient;
import org.gcube.portlets.user.gcubeloggedin.shared.VREClient;
import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.UserManager;
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayGroupManager;
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayUserManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.liferay.portal.kernel.bean.BeanLocatorException;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.servlet.ImageServletTokenUtil;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.model.Group;
import com.liferay.portal.model.Organization;
import com.liferay.portal.model.User;
import com.liferay.portal.security.permission.PermissionChecker;
import com.liferay.portal.security.permission.PermissionCheckerFactoryUtil;
import com.liferay.portal.security.permission.PermissionThreadLocal;
import com.liferay.portal.service.GroupLocalServiceUtil;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.theme.ThemeDisplay;
/**
@ -46,37 +50,54 @@ import com.liferay.portal.theme.ThemeDisplay;
public class LoggedinServiceImpl extends RemoteServiceServlet implements LoggedinService {
private static final Logger _log = LoggerFactory.getLogger(LoggedinServiceImpl.class);
private boolean isDeployed = true;
private static final String MANDATORY_GROUP = "Mandatory";
private static final String REQUEST_BASED_GROUP = "Requestbasedgroup";
/**
* the current ASLSession
* @return .
*/
private ASLSession getASLSession() {
isDeployed = true;
String sessionID = this.getThreadLocalRequest().getSession().getId();
String user = (String) this.getThreadLocalRequest().getSession().getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
if (user == null) {
_log.warn("LOGGEDIN PORTLET: USER IS NULL \n\n SESSION ID READ: " +sessionID );
user = "test.user";
_log.warn("session ID= *" + sessionID + "* user= *" + user + "*" );
isDeployed = false;
}
return SessionManager.getInstance().getASLSession(sessionID, user);
}
/**
*
* @return true if you're running into the portal, false if in development
*/
private boolean isWithinPortal() {
try {
UserLocalServiceUtil.getService();
return true;
}
catch (com.liferay.portal.kernel.bean.BeanLocatorException ex) {
_log.trace("Development Mode ON");
return false;
}
}
/**
* return the current selected VRE
*/
public VObject getSelectedRE() {
ASLSession aslSession = getASLSession();
if (! isDeployed) {
String username = aslSession.getUsername();
if (! isWithinPortal()) {
return new VREClient("Test", "", "" +
"Fishery and Aquaculture Resources Management (FARM) Virtual Organisation</b> The FARM Virtual Organisation is the <b><i>dynamic group of individuals</i></b> and/or <b><i>institutions</i></b> defined around a set of <b><i>sharing rules</i></b> in which <b><i>resource providers</i></b> and <b><i>consumers</i></b> specify clearly and carefully just what is shared, who is allowed to share, and the conditions under which sharing occurs to serve the needs of the <b><i>Fisheries and Aquaculture Resources Management</i></b>. This VO is conceived to support various application scenarios arising in the FARM Community including the production of Fisheries and Aquaculture Country Profiles, the management of catch statistics including harmonisation, the dynamic generation of biodiversity maps and species distribution maps. This Virtual Organisation currently consists of:<ul> <li> approximately <b><i>13 gCube nodes</i></b>, i.e. machines dedicated to run the gCube system;</li> <li> approximately <b><i>89 running instances</i></b>, i.e. running gCube services supporting the operation of the infrastructure;</li> <li> approximately <b><i>25 collections</i></b>, i.e. set of D4Science Information Objects including Earth images, AquaMaps, Graphs on catch statistics;</li> <li> approximately <b><i>66 metadata collections</i></b>, i.e. set of Metadata Objects describing the Information Objects through various features and schemas;</li> <li> approximately <b><i>58 other resources</i></b> including transformation programs, index types, etc.</li></ul></div>" +
"", "", "", UserBelongingClient.BELONGING);
"", "", "", UserBelongingClient.BELONGING, false, true);
}
_log.trace("getting Selected Research Environment");
HttpSession session = this.getThreadLocalRequest().getSession();
ThemeDisplay themeDisplay = (ThemeDisplay) this.getThreadLocalRequest().getSession().getAttribute(WebKeys.THEME_DISPLAY);
Organization currOrg = (Organization) session.getAttribute("CURR_RE_NAME");
@ -98,9 +119,91 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi
//set the description for the vre
if (currOrg.getComments() != null)
desc = currOrg.getComments();
VREClient vre = new VREClient(name, "", desc, logoURL, "", UserBelongingClient.BELONGING);
VREClient vre = new VREClient(name, "", desc, logoURL, "", UserBelongingClient.BELONGING, isEnabled(username, currOrg, MANDATORY_GROUP), isEnabled(username, currOrg, REQUEST_BASED_GROUP));
return vre;
}
private Boolean isEnabled(String username, Organization currOrg, String attrToCheck) {
Boolean isEnabled = false;
if (username.compareTo("test.user") == 0) {
_log.warn("Found test.user maybe you are in dev mode, returning ... ");
return true;
}
try {
long companyId = OrganizationsUtil.getCompany().getCompanyId();
_log.trace("Setting Thread Permission");
User user = UserLocalServiceUtil.getUserByScreenName(companyId, ScopeHelper.getAdministratorUsername());
PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user, false);
PermissionThreadLocal.setPermissionChecker(permissionChecker);
_log.trace("Setting Permission ok!");
User currentUser = OrganizationsUtil.validateUser(username);
if (currOrg.getExpandoBridge().getAttribute(attrToCheck) == null || currOrg.getExpandoBridge().getAttribute(attrToCheck).equals("")) {
_log.trace("Attribute " + attrToCheck + " must be initialized");
setOrgCustomAttribute(username, currOrg, attrToCheck);
isEnabled = true;
}
else {
String currVal = (String) currOrg.getExpandoBridge().getAttribute(attrToCheck);
isEnabled = (currVal.compareTo("true") == 0);
}
_log.trace("Setting Thread Permission back to regular");
permissionChecker = PermissionCheckerFactoryUtil.create(currentUser, false);
PermissionThreadLocal.setPermissionChecker(permissionChecker);
_log.trace("Setting Permission ok! returning ...");
System.out.println(" returning *********** isEnabled=" + isEnabled);
return isEnabled;
} catch (BeanLocatorException ex) {
ex.printStackTrace();
_log.warn("Could not read the property " + attrToCheck + " from LR DB, maybe you are in dev mode, returning true");
return true;
}
catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
*
* @param username
* @param attribute2Set
*/
private void setOrgCustomAttribute(String username, Organization currOrg, String attribute2Set) {
User currUser = null;
if (username.compareTo("test.user") == 0) {
_log.warn("Found Test User, returning ... ");
return;
}
try {
long companyId = OrganizationsUtil.getCompany().getCompanyId();
_log.trace("Setting Thread Permission");
User user = UserLocalServiceUtil.getUserByScreenName(companyId, ScopeHelper.getAdministratorUsername());
PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user, false);
PermissionThreadLocal.setPermissionChecker(permissionChecker);
_log.trace("Setting Permission ok!");
_log.debug("Creating and Setting custom attribute for colName " + attribute2Set + " to " +true);
//add the custom attrs
currUser = UserLocalServiceUtil.getUserByScreenName(companyId, username);
if (! currOrg.getExpandoBridge().hasAttribute(attribute2Set))
currOrg.getExpandoBridge().addAttribute(attribute2Set);
currOrg.getExpandoBridge().setAttribute(attribute2Set, "true");
_log.trace("setAttribute true");
_log.trace("Setting Thread Permission back to regular");
permissionChecker = PermissionCheckerFactoryUtil.create(currUser, false);
PermissionThreadLocal.setPermissionChecker(permissionChecker);
}
catch (Exception e) {
e.printStackTrace();
}
}
/**
* The Default Community is a community where all portal user belong to
@ -180,7 +283,7 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi
try {
userM.dismissUserFromGroup(getCurrentGroupID(), userM.getUserId(username));
removeUserFromHLGroup(username, getASLSession().getScope());
return getPortalBasicUrl();
return getDefaultCommunityURL();
} catch (Exception e) {
e.printStackTrace();
return null;

@ -8,12 +8,9 @@ import java.util.List;
* @author massi
*
*/
@SuppressWarnings("serial")
public class VOClient extends VObject implements Comparable<VOClient>, Serializable {
/**
*
*/
private static final long serialVersionUID = -8851330991617092921L;
private boolean isRoot;
private List<VREClient> vres;
@ -26,7 +23,7 @@ public class VOClient extends VObject implements Comparable<VOClient>, Serializa
String imageURL,
String friendlyURL,
UserBelongingClient userBelonging) {
super(name, groupName, description, imageURL, friendlyURL, userBelonging);
super(name, groupName, description, imageURL, friendlyURL, userBelonging, true, true);
// TODO Auto-generated constructor stub
}
@ -38,7 +35,7 @@ public class VOClient extends VObject implements Comparable<VOClient>, Serializa
String friendlyURL,
UserBelongingClient userBelonging,
boolean isRoot, List<VREClient> vres) {
super(name, groupName, description, imageURL, friendlyURL, userBelonging);
super(name, groupName, description, imageURL, friendlyURL, userBelonging, true, true);
this.isRoot = isRoot;
this.vres = vres;
}

@ -3,13 +3,9 @@ package org.gcube.portlets.user.gcubeloggedin.shared;
import java.io.Serializable;
@SuppressWarnings("serial")
public class VObject implements Serializable {
/**
*
*/
private static final long serialVersionUID = 59621631728865981L;
public enum UserBelongingClient {
BELONGING, NOT_BELONGING, PENDING
}
@ -19,24 +15,29 @@ public class VObject implements Serializable {
private String description;
private String imageURL;
private String friendlyURL;
private boolean mandatory;
private boolean uponRequest;
private UserBelongingClient userBelonging;
public VObject() {
super();
// TODO Auto-generated constructor stub
}
public VObject(String name, String groupName, String description, String imageURL, String friendlyURL,
UserBelongingClient userBelonging) {
super();
public VObject(String name, String groupName, String description,
String imageURL, String friendlyURL, UserBelongingClient userBelonging, boolean mandatory,
boolean uponRequest) {
this.name = name;
this.groupName = groupName;
this.description = description;
this.imageURL = imageURL;
this.friendlyURL = friendlyURL;
this.mandatory = mandatory;
this.uponRequest = uponRequest;
this.userBelonging = userBelonging;
}
public String getName() {
return name;
}
@ -75,5 +76,21 @@ public class VObject implements Serializable {
public void setFriendlyURL(String friendlyURL) {
this.friendlyURL = friendlyURL;
}
public boolean isMandatory() {
return mandatory;
}
public void setMandatory(boolean mandatory) {
this.mandatory = mandatory;
}
public boolean isUponRequest() {
return uponRequest;
}
public void setUponRequest(boolean uponRequest) {
this.uponRequest = uponRequest;
}
}

@ -5,21 +5,17 @@ package org.gcube.portlets.user.gcubeloggedin.shared;
* @author massi
*
*/
@SuppressWarnings("serial")
public class VREClient extends VObject {
/**
*
*/
private static final long serialVersionUID = -4608871177709997781L;
public VREClient() {
super();
// TODO Auto-generated constructor stub
}
public VREClient(String name, String groupName, String description, String imageURL, String friendlyURL,
UserBelongingClient userBelonging) {
super(name, groupName, description, imageURL, friendlyURL, userBelonging);
UserBelongingClient userBelonging, boolean isMandatory, boolean isUponRequest) {
super(name, groupName, description, imageURL, friendlyURL, userBelonging, isMandatory, isUponRequest);
// TODO Auto-generated constructor stub
}

Loading…
Cancel
Save