Added support for showing external hosted VREso, see Feature #755

git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portlets/user/join-vre@119963 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2015-10-22 12:58:31 +00:00
parent 4efb764828
commit c0cceaa9a6
10 changed files with 242 additions and 29 deletions

View File

@ -1,9 +1,10 @@
<ReleaseNotes>
<Changeset component="org.gcube.portlets-user.join-vre.2.0.0"
date="2015-09-28">
date="2015-10-22">
<Change>Refactored to support virtual groups and related descriptions
through LR Custom Field</Change>
<Change>Refactored with GWT Bootstrap, new look and feel</Change>
<Change>Added support for showing external hosted VREso, see Feature #755</Change>
</Changeset>
<Changeset component="org.gcube.portlets-user.join-vre.1.1.0"
date="2015-04-28">

View File

@ -0,0 +1,51 @@
package org.gcube.portlets.user.joinvre.client.ui;
import org.gcube.portlets.user.joinvre.shared.VRE;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.Modal;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Widget;
public class RedirectPanel extends Composite {
private static InfoPanelUiBinder uiBinder = GWT.create(InfoPanelUiBinder.class);
interface InfoPanelUiBinder extends UiBinder<Widget, RedirectPanel> {
}
@UiField Modal m;
@UiField HTML description;
@UiField Button close;
@UiField Button link;
private VRE vre;
public RedirectPanel(VRE toDisplay) {
initWidget(uiBinder.createAndBindUi(this));
vre = toDisplay;
}
public void show() {
m.setTitle("Infrastructure Gateway notice for " + vre.getName());
description.setHTML("Dear user, <br/>" + vre.getName() + " is not hosted in this Gateway, "+
"if you wish to enter or to request access, please click to the link below. We will redirect you to the D4Science Gateway hosting it.");
link.setHref(vre.getUrl());
link.setTarget("_blank");
link.setText("Take me to " + vre.getName());
link.setBlock(true);
link.getElement().getStyle().setMarginTop(25, Unit.PX);
link.getElement().getStyle().setMarginBottom(15, Unit.PX);
m.show();
}
@UiHandler("close")
void handleClick(ClickEvent e) {
m.hide();
}
}

View File

@ -0,0 +1,14 @@
<!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:b="urn:import:com.github.gwtbootstrap.client.ui">
<g:HTMLPanel>
<b:Modal ui:field="m" title="My Modal" backdrop="STATIC"
keyboard="true" animation="true">
<g:HTML ui:field="description"></g:HTML>
<b:Button type="LINK" ui:field="link"></b:Button>
<b:ModalFooter>
<b:Button type="PRIMARY" ui:field="close">Close</b:Button>
</b:ModalFooter>
</b:Modal>
</g:HTMLPanel>
</ui:UiBinder>

View File

@ -43,7 +43,7 @@ public class VreThumbnail extends Composite {
vreName.setText(name);
if (vre.isUponRequest()) {
joinButton.setType(ButtonType.DEFAULT);
joinButton.setText("Request access");
joinButton.setText("Access");
} else {
joinButton.setType(ButtonType.PRIMARY);
joinButton.setText("Enter this VRE");
@ -53,21 +53,27 @@ public class VreThumbnail extends Composite {
@UiHandler("joinButton")
void handleClick(ClickEvent e) {
joinService.joinVRE(myVre.getId(), new AsyncCallback<Boolean>() {
@Override
public void onFailure(Throwable caught) {
String errorDescription = "Error while trying to join to"
+ myVre.getName() + " VRE. Please Try again later. "
+ "If the problem persist contact system administrator";
Window.alert(errorDescription);
}
if (myVre.isExternal()) {
RedirectPanel modal = new RedirectPanel(myVre);
modal.show();
}
else {
joinService.joinVRE(myVre.getId(), new AsyncCallback<Boolean>() {
@Override
public void onFailure(Throwable caught) {
String errorDescription = "Error while trying to join to"
+ myVre.getName() + " VRE. Please Try again later. "
+ "If the problem persist contact system administrator";
Window.alert(errorDescription);
}
@Override
public void onSuccess(Boolean result) {
Window.open("/group/data-e-infrastructure-gateway/join-new?orgid="+myVre.getId(), "_self", "");
}
@Override
public void onSuccess(Boolean result) {
Window.open("/group/data-e-infrastructure-gateway/join-new?orgid="+myVre.getId(), "_self", "");
}
});
});
}
}

View File

@ -17,6 +17,7 @@ import org.gcube.portlets.user.joinvre.client.JoinService;
import org.gcube.portlets.user.joinvre.shared.UserBelonging;
import org.gcube.portlets.user.joinvre.shared.VRE;
import org.gcube.portlets.user.joinvre.shared.VRECategory;
import org.gcube.portlets.user.joinvre.shared.VRECustomAttributes;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.liferay.portal.kernel.exception.PortalException;
@ -47,6 +48,8 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
private static Log _log = LogFactoryUtil.getLog(JoinServiceImpl.class);
private static final String REQUEST_BASED_GROUP = "Requestbasedgroup";
private static final String CATEGORY = "Virtualgroup";
private static final String IS_EXTERNAL = "Isexternal";
private static final String URL_IF_EXTERNAL = "Url";
/**
* the current ASLSession
@ -135,7 +138,7 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
devsecCategory = new VRECategory(2, "Sailing", "Sailing prod desc");
vres = new ArrayList<VRE>();
vres.add(new VRE(1, "PerformanceEvaluationInAquaculture", "devVRE VRE description", "http://placehold.it/200x100", "http://placehold.it/200x100", "/group/devVRE", UserBelonging.NOT_BELONGING, false));
vres.add(new VRE(1, "PerformanceEvaluationInAquaculture", "devVRE VRE description", "http://placehold.it/200x100", "http://placehold.it/200x100", "/group/devVRE", UserBelonging.NOT_BELONGING, false, true, "http://i-marine.d4science.org"));
vres.add(new VRE(2, "devmode", "devmode VRE description", "http://placehold.it/200x100", "https://placeholdit.imgix.net/~text?txtsize=19&txt=200%C3%97100&w=200&h=100", "/group/devmode", UserBelonging.NOT_BELONGING, true));
vres.add(new VRE(1, "StrategicInvestmentAnalysis", "devVRE VRE description", "", "https://placeholdit.imgix.net/~text?txtsize=19&txt=200%C3%97100&w=200&h=100", "/group/devVRE", UserBelonging.NOT_BELONGING, false));
vres.add(new VRE(2, "devmode2", "devmode VRE description", "http://placehold.it/200x100", "", "/group/devmode", UserBelonging.NOT_BELONGING, true));
@ -182,7 +185,9 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
}
public boolean requireAccessGrant(Organization organization) throws PortalException, SystemException {
public VRECustomAttributes getVRECustomAttr(Organization organization) throws PortalException, SystemException {
VRECustomAttributes toReturn = new VRECustomAttributes();
try {
long companyId = OrganizationsUtil.getCompany().getCompanyId();
_log.trace("Setting Thread Permission");
@ -193,15 +198,31 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
if (organization.getExpandoBridge().getAttribute(REQUEST_BASED_GROUP) == null || organization.getExpandoBridge().getAttribute(REQUEST_BASED_GROUP).equals("")) {
_log.trace(String.format("Attribute %s not initialized. In this case by default Access Grant is permitted", REQUEST_BASED_GROUP));
return true;
toReturn.setUponRequest(true);
} else {
String attributeValue = (String) organization.getExpandoBridge().getAttribute(REQUEST_BASED_GROUP);
return (attributeValue.compareTo("true") == 0);
toReturn.setUponRequest(attributeValue.compareTo("true") == 0);
}
if (organization.getExpandoBridge().getAttribute(IS_EXTERNAL) == null || organization.getExpandoBridge().getAttribute(IS_EXTERNAL).equals("")) {
_log.trace(String.format("Attribute %s not initialized. In this case by default we assume it is an internal VRE", IS_EXTERNAL));
toReturn.setExternal(false);
} else {
Boolean attributeValue = (Boolean) organization.getExpandoBridge().getAttribute(IS_EXTERNAL);
toReturn.setExternal(attributeValue);
if (attributeValue) { //we read the custom attr URL if and only if the VRE is External, in the other case is useless
String url = (String) organization.getExpandoBridge().getAttribute(URL_IF_EXTERNAL);
toReturn.setUrlIfAny(url);
}
}
} catch (Exception e) {
return false;
}
_log.error("Something went wrong when trying to read VRE Custom Attr, " + e);
return toReturn;
}
_log.trace("RETURNING VRECustomAttributes:\n" + toReturn.toString());
return toReturn;
}
@ -283,7 +304,11 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
String friendlyURL = vreGroup.getPathFriendlyURL(true, themeDisplay) + vreGroup.getFriendlyURL();
friendlyURL = String.format("%s%s", getPortalBasicUrl(), friendlyURL);
boolean requireAccessGrant = requireAccessGrant(vreOrganization);
VRECustomAttributes attrs = getVRECustomAttr(vreOrganization);
boolean requireAccessGrant = attrs.isUponRequest();
boolean isExternal = attrs.isExternal();
String urlIfAny = attrs.getUrlIfAny();
String catName = getCategory(vreOrganization);
String[] splits = catName.split("\\|");
@ -296,7 +321,7 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
}
if (toLookFor != null) {
ArrayList<VRE> toUpdate = toReturn.get(toLookFor);
toUpdate.add(new VRE(vreID,vreName, vreDescription, vreLogoURL, groupName,friendlyURL, UserBelonging.NOT_BELONGING, requireAccessGrant));
toUpdate.add(new VRE(vreID,vreName, vreDescription, vreLogoURL, groupName,friendlyURL, UserBelonging.NOT_BELONGING, requireAccessGrant, isExternal, urlIfAny));
}
}
}

View File

@ -36,7 +36,7 @@ public class JoinVREPortlet extends GenericPortlet {
} catch(Exception e){
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
request.getPortletSession().setAttribute(WebKeys.THEME_DISPLAY, themeDisplay, PortletSession.APPLICATION_SCOPE);
_log.error("The following exception is acceptable if the user is not logged.", e);
_log.error("The following exception is acceptable if the user is not logged.");
}
PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/JoinVRE_view.jsp");

View File

@ -11,7 +11,8 @@ public class VRE extends ResearchEnvironment implements Serializable, Comparable
protected boolean uponRequest;
protected long id;
protected boolean isExternal;
protected String url;
public VRE() {
super();
@ -33,6 +34,17 @@ public class VRE extends ResearchEnvironment implements Serializable, Comparable
super(vreName, description, imageURL, vomsGroupName, friendlyURL, userBelonging);
this.uponRequest = uponRequest;
this.id = id;
isExternal = false;
url = "";
}
public VRE(long id, String vreName, String description, String imageURL,
String vomsGroupName, String friendlyURL, UserBelonging userBelonging, boolean uponRequest, boolean isExternal, String url) {
super(vreName, description, imageURL, vomsGroupName, friendlyURL, userBelonging);
this.uponRequest = uponRequest;
this.id = id;
this.isExternal = isExternal;
this.url = url;
}
public boolean isUponRequest() {
@ -49,6 +61,22 @@ public class VRE extends ResearchEnvironment implements Serializable, Comparable
public void setId(long id) {
this.id = id;
}
public boolean isExternal() {
return isExternal;
}
public void setExternal(boolean isExternal) {
this.isExternal = isExternal;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
@Override
public String toString() {

View File

@ -0,0 +1,86 @@
package org.gcube.portlets.user.joinvre.shared;
public class VRECustomAttributes {
private boolean isUponRequest;
private boolean isExternal;
private String urlIfAny;
public VRECustomAttributes() {
super();
this.isUponRequest = false;
this.isExternal = false;
this.urlIfAny = "";
}
public VRECustomAttributes(boolean isUponRequest, boolean isExternal,
String urlIfAny) {
super();
this.isUponRequest = isUponRequest;
this.isExternal = isExternal;
this.urlIfAny = urlIfAny;
}
public boolean isUponRequest() {
return isUponRequest;
}
public void setUponRequest(boolean isUponRequest) {
this.isUponRequest = isUponRequest;
}
public boolean isExternal() {
return isExternal;
}
public void setExternal(boolean isExternal) {
this.isExternal = isExternal;
}
public String getUrlIfAny() {
return urlIfAny;
}
public void setUrlIfAny(String urlIfAny) {
this.urlIfAny = urlIfAny;
}
@Override
public String toString() {
return "VRECustomAttributes [isUponRequest=" + isUponRequest
+ ", isExternal=" + isExternal + ", urlIfAny=" + urlIfAny + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (isExternal ? 1231 : 1237);
result = prime * result + (isUponRequest ? 1231 : 1237);
result = prime * result
+ ((urlIfAny == null) ? 0 : urlIfAny.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
VRECustomAttributes other = (VRECustomAttributes) obj;
if (isExternal != other.isExternal)
return false;
if (isUponRequest != other.isUponRequest)
return false;
if (urlIfAny == null) {
if (other.urlIfAny != null)
return false;
} else if (!urlIfAny.equals(other.urlIfAny))
return false;
return true;
}
}

View File

@ -18,7 +18,3 @@ h1.portlet-title {
h1 small {
font-size:18px !important;
}
#wrapper {
width: 1220px !important;
}

View File

@ -17,5 +17,11 @@
<short-title>JoinVRE Portlet</short-title>
<keywords>JoinVRE Portlet</keywords>
</portlet-info>
<portlet-preferences>
<preference>
<name>portlet-setup-show-borders</name>
<value>true</value>
</preference>
</portlet-preferences>
</portlet>
</portlet-app>