From c0cceaa9a62f1b60ce388da33419453084702aad Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Thu, 22 Oct 2015 12:58:31 +0000 Subject: [PATCH] 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 --- distro/changelog.xml | 3 +- .../user/joinvre/client/ui/RedirectPanel.java | 51 +++++++++++ .../joinvre/client/ui/RedirectPanel.ui.xml | 14 +++ .../user/joinvre/client/ui/VreThumbnail.java | 34 +++++--- .../user/joinvre/server/JoinServiceImpl.java | 41 +++++++-- .../server/portlet/JoinVREPortlet.java | 2 +- .../portlets/user/joinvre/shared/VRE.java | 30 ++++++- .../joinvre/shared/VRECustomAttributes.java | 86 +++++++++++++++++++ src/main/webapp/JoinVRE.css | 4 - src/main/webapp/WEB-INF/portlet.xml | 6 ++ 10 files changed, 242 insertions(+), 29 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/joinvre/client/ui/RedirectPanel.java create mode 100644 src/main/java/org/gcube/portlets/user/joinvre/client/ui/RedirectPanel.ui.xml create mode 100644 src/main/java/org/gcube/portlets/user/joinvre/shared/VRECustomAttributes.java diff --git a/distro/changelog.xml b/distro/changelog.xml index e613d89..4b72edf 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -1,9 +1,10 @@ + date="2015-10-22"> Refactored to support virtual groups and related descriptions through LR Custom Field Refactored with GWT Bootstrap, new look and feel + Added support for showing external hosted VREso, see Feature #755 diff --git a/src/main/java/org/gcube/portlets/user/joinvre/client/ui/RedirectPanel.java b/src/main/java/org/gcube/portlets/user/joinvre/client/ui/RedirectPanel.java new file mode 100644 index 0000000..0fdd490 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/joinvre/client/ui/RedirectPanel.java @@ -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 { + } + + @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,
" + 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(); + } +} diff --git a/src/main/java/org/gcube/portlets/user/joinvre/client/ui/RedirectPanel.ui.xml b/src/main/java/org/gcube/portlets/user/joinvre/client/ui/RedirectPanel.ui.xml new file mode 100644 index 0000000..daabe12 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/joinvre/client/ui/RedirectPanel.ui.xml @@ -0,0 +1,14 @@ + + + + + + + + Close + + + + \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/joinvre/client/ui/VreThumbnail.java b/src/main/java/org/gcube/portlets/user/joinvre/client/ui/VreThumbnail.java index 852a140..269bb82 100644 --- a/src/main/java/org/gcube/portlets/user/joinvre/client/ui/VreThumbnail.java +++ b/src/main/java/org/gcube/portlets/user/joinvre/client/ui/VreThumbnail.java @@ -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() { - @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() { + @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", ""); + } - }); + }); + } } diff --git a/src/main/java/org/gcube/portlets/user/joinvre/server/JoinServiceImpl.java b/src/main/java/org/gcube/portlets/user/joinvre/server/JoinServiceImpl.java index 7cf31a0..8f94faf 100644 --- a/src/main/java/org/gcube/portlets/user/joinvre/server/JoinServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/joinvre/server/JoinServiceImpl.java @@ -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(); - 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 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)); } } } diff --git a/src/main/java/org/gcube/portlets/user/joinvre/server/portlet/JoinVREPortlet.java b/src/main/java/org/gcube/portlets/user/joinvre/server/portlet/JoinVREPortlet.java index a66eb31..c826eeb 100644 --- a/src/main/java/org/gcube/portlets/user/joinvre/server/portlet/JoinVREPortlet.java +++ b/src/main/java/org/gcube/portlets/user/joinvre/server/portlet/JoinVREPortlet.java @@ -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"); diff --git a/src/main/java/org/gcube/portlets/user/joinvre/shared/VRE.java b/src/main/java/org/gcube/portlets/user/joinvre/shared/VRE.java index 4cf0675..3fe080e 100644 --- a/src/main/java/org/gcube/portlets/user/joinvre/shared/VRE.java +++ b/src/main/java/org/gcube/portlets/user/joinvre/shared/VRE.java @@ -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() { diff --git a/src/main/java/org/gcube/portlets/user/joinvre/shared/VRECustomAttributes.java b/src/main/java/org/gcube/portlets/user/joinvre/shared/VRECustomAttributes.java new file mode 100644 index 0000000..949fc73 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/joinvre/shared/VRECustomAttributes.java @@ -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; + } + +} diff --git a/src/main/webapp/JoinVRE.css b/src/main/webapp/JoinVRE.css index 2e9d4e1..d093a47 100644 --- a/src/main/webapp/JoinVRE.css +++ b/src/main/webapp/JoinVRE.css @@ -18,7 +18,3 @@ h1.portlet-title { h1 small { font-size:18px !important; } - -#wrapper { - width: 1220px !important; -} \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/portlet.xml b/src/main/webapp/WEB-INF/portlet.xml index 0e7ee9c..bdcd055 100644 --- a/src/main/webapp/WEB-INF/portlet.xml +++ b/src/main/webapp/WEB-INF/portlet.xml @@ -17,5 +17,11 @@ JoinVRE Portlet JoinVRE Portlet + + + portlet-setup-show-borders + true + +