diff --git a/src/main/java/org/gcube/portlet/user/my_vres/client/MyVREsService.java b/src/main/java/org/gcube/portlet/user/my_vres/client/MyVREsService.java index 17adba8..4ea61a6 100644 --- a/src/main/java/org/gcube/portlet/user/my_vres/client/MyVREsService.java +++ b/src/main/java/org/gcube/portlet/user/my_vres/client/MyVREsService.java @@ -15,9 +15,6 @@ import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; public interface MyVREsService extends RemoteService { LinkedHashMap> getUserVREs(); - void loadLayout(String scope, String URL); - - String showMoreVREs(); - + String getSiteLandingPagePath(); } diff --git a/src/main/java/org/gcube/portlet/user/my_vres/client/MyVREsServiceAsync.java b/src/main/java/org/gcube/portlet/user/my_vres/client/MyVREsServiceAsync.java index 32222ef..eca5ddc 100644 --- a/src/main/java/org/gcube/portlet/user/my_vres/client/MyVREsServiceAsync.java +++ b/src/main/java/org/gcube/portlet/user/my_vres/client/MyVREsServiceAsync.java @@ -8,15 +8,10 @@ import org.gcube.portlet.user.my_vres.shared.VRE; import com.google.gwt.user.client.rpc.AsyncCallback; public interface MyVREsServiceAsync { - - - void loadLayout(String scope, String URL, AsyncCallback callback); void getUserVREs( AsyncCallback>> callback); - void showMoreVREs(AsyncCallback callback); - void getSiteLandingPagePath(AsyncCallback callback); } diff --git a/src/main/java/org/gcube/portlet/user/my_vres/client/VresPanel.java b/src/main/java/org/gcube/portlet/user/my_vres/client/VresPanel.java index 2232aee..0b169fb 100644 --- a/src/main/java/org/gcube/portlet/user/my_vres/client/VresPanel.java +++ b/src/main/java/org/gcube/portlet/user/my_vres/client/VresPanel.java @@ -9,7 +9,6 @@ import org.gcube.portlet.user.my_vres.shared.VRE; import com.google.gwt.core.client.GWT; import com.google.gwt.dom.client.Style.Unit; -import com.google.gwt.safehtml.shared.SafeHtml; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.FlowPanel; @@ -26,7 +25,6 @@ import com.google.gwt.user.client.ui.VerticalPanel; */ public class VresPanel extends Composite { public static final String loading = GWT.getModuleBaseURL() + "../images/loading.gif"; - private static final String ADD_OTHER = "Add More"; private final MyVREsServiceAsync myVREsService = GWT.create(MyVREsService.class); private FlowPanel flowPanel; private VerticalPanel mainPanel = new VerticalPanel(); @@ -86,7 +84,7 @@ public class VresPanel extends Composite { flowPanel.setWidth("100%"); flowPanel.setStyleName("flowPanel"); for (VRE vre: cachedVREs.get(cat)) { - ClickableVRE vreButton = new ClickableVRE(vre, myVREsService); + ClickableVRE vreButton = new ClickableVRE(vre); flowPanel.add(vreButton); } @@ -97,30 +95,11 @@ public class VresPanel extends Composite { if (! hasAtLeastOneVRE(cachedVREs)) { mainPanel.add(new NoVresPanel()); imagesPanel.clear(); - } else { - addMoreVREsButton(); - } + } } - private void addMoreVREsButton() { - SimplePanel catPanel = new SimplePanel(); - catPanel.setStyleName("category-panel"); - HTML categ = new HTML(ADD_OTHER); - categ.setStyleName("category-name"); - catPanel.add(categ); - - mainPanel.add(catPanel); - FlowPanel flowPanel = new FlowPanel(); - flowPanel.setWidth("100%"); - flowPanel.setStyleName("flowPanel"); - - ClickableVRE vreButton = new ClickableVRE(myVREsService); - flowPanel.add(vreButton); - - mainPanel.add(flowPanel); - } - + private boolean hasAtLeastOneVRE(LinkedHashMap> cachedVREs) { for (String cat : cachedVREs.keySet()) if (! cachedVREs.get(cat).isEmpty()) diff --git a/src/main/java/org/gcube/portlet/user/my_vres/client/widgets/ClickableVRE.java b/src/main/java/org/gcube/portlet/user/my_vres/client/widgets/ClickableVRE.java index 307354a..2d21da1 100644 --- a/src/main/java/org/gcube/portlet/user/my_vres/client/widgets/ClickableVRE.java +++ b/src/main/java/org/gcube/portlet/user/my_vres/client/widgets/ClickableVRE.java @@ -1,7 +1,5 @@ package org.gcube.portlet.user.my_vres.client.widgets; -import org.gcube.common.portal.GCubePortalConstants; -import org.gcube.portlet.user.my_vres.client.MyVREsServiceAsync; import org.gcube.portlet.user.my_vres.shared.VRE; import com.google.gwt.core.client.GWT; @@ -9,7 +7,6 @@ import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.Window.Location; -import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.Image; @@ -34,43 +31,20 @@ public class ClickableVRE extends HTML { public ClickableVRE() { super(); } - - public ClickableVRE(final MyVREsServiceAsync service) { + + public ClickableVRE(final VRE vre) { super.setPixelSize(WIDTH, HEIGHT); setPixelSize(WIDTH, HEIGHT); - imageWidth = WIDTH - 25; String html = ""; - html = "
"; - setHTML(html); - setStyleName("vreButton"); - - addClickHandler(new ClickHandler() { - public void onClick(ClickEvent event) { - String html = "
" + - "redirecting ..." + - "
"; - setHTML(html); - service.showMoreVREs(new AsyncCallback() { - @Override - public void onFailure(Throwable caught) { } - - @Override - public void onSuccess(String result) { - Location.assign(result+GCubePortalConstants.VRES_EXPLORE_FRIENDLY_URL); - } - }); - } - }); - } - - public ClickableVRE(final VRE vre, final MyVREsServiceAsync service) { - super.setPixelSize(WIDTH, HEIGHT); - setPixelSize(WIDTH, HEIGHT); + if (vre.getName() == null || vre.getName().compareTo("") == 0) { + html = "
"; + } else { + name = (vre.getName().length() > 15) ? vre.getName().substring(0, 13) + ".." : vre.getName(); + html = "
" +name + "
"; + } imageWidth = WIDTH - 12; - name = (vre.getName().length() > 15) ? vre.getName().substring(0, 13) + ".." : vre.getName(); imageUrl = vre.getImageURL(); this.setTitle("Enter"); - String html = "
" + name + "
"; html += "
" + "" + "
"; @@ -83,13 +57,13 @@ public class ClickableVRE extends HTML { "redirecting ..." + ""; setHTML(html); - Timer timer = new Timer() { - @Override - public void run() { + Timer timer = new Timer() { + @Override + public void run() { Location.assign(vre.getFriendlyURL()); - } - }; - timer.schedule(50); + } + }; + timer.schedule(50); } }); } diff --git a/src/main/java/org/gcube/portlet/user/my_vres/server/MyVREsServiceImpl.java b/src/main/java/org/gcube/portlet/user/my_vres/server/MyVREsServiceImpl.java index 5757c02..90dd6b7 100644 --- a/src/main/java/org/gcube/portlet/user/my_vres/server/MyVREsServiceImpl.java +++ b/src/main/java/org/gcube/portlet/user/my_vres/server/MyVREsServiceImpl.java @@ -17,33 +17,17 @@ import org.gcube.portlet.user.my_vres.client.MyVREsService; import org.gcube.portlet.user.my_vres.shared.UserBelonging; import org.gcube.portlet.user.my_vres.shared.VRE; import org.gcube.vomanagement.usermanagement.GroupManager; -import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; -import org.gcube.vomanagement.usermanagement.exception.VirtualGroupNotExistingException; import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager; import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager; -import org.gcube.vomanagement.usermanagement.model.CustomAttributeKeys; import org.gcube.vomanagement.usermanagement.model.GCubeGroup; import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.gcube.vomanagement.usermanagement.model.VirtualGroup; +import org.gcube.vomanagement.usermanagement.util.ManagementUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.gwt.user.server.rpc.RemoteServiceServlet; -import com.liferay.portal.kernel.exception.PortalException; -import com.liferay.portal.kernel.exception.SystemException; -import com.liferay.portal.kernel.util.StringBundler; -import com.liferay.portal.model.Group; -import com.liferay.portal.model.VirtualHost; -import com.liferay.portal.security.auth.PrincipalThreadLocal; -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.LayoutSetLocalServiceUtil; import com.liferay.portal.service.UserLocalServiceUtil; -import com.liferay.portal.service.VirtualHostLocalServiceUtil; -import com.liferay.portal.util.PortalUtil; -import com.liferay.portal.webserver.WebServerServletTokenUtil; /** * The server side implementation of the RPC service. @@ -57,6 +41,9 @@ public class MyVREsServiceImpl extends RemoteServiceServlet implements MyVREsSer * */ public static final String CACHED_VOS = "CACHED_VRES"; + + public static final String ADD_MORE_CATEGORY = "Add More"; + public static final String ADD_MORE_IMAGE_PATH= "images/More.png"; private ASLSession getASLSession() { String sessionID = this.getThreadLocalRequest().getSession().getId(); @@ -70,10 +57,7 @@ public class MyVREsServiceImpl extends RemoteServiceServlet implements MyVREsSer } return SessionManager.getInstance().getASLSession(sessionID, user); } - @Override - public String showMoreVREs() { - return PortalContext.getConfiguration().getSiteLandingPagePath(getThreadLocalRequest()); - } + @Override public String getSiteLandingPagePath() { String user = getASLSession().getUsername(); @@ -111,8 +95,8 @@ public class MyVREsServiceImpl extends RemoteServiceServlet implements MyVREsSer LinkedHashMap> toReturn = new LinkedHashMap>(); - long currentSiteGroupId = getSiteFromServletRequest(getThreadLocalRequest()).getGroupId(); - List currentSiteVGroups = getVirtualGroups(currentSiteGroupId); + + List currentSiteVGroups = ManagementUtils.getVirtualGroupsBySiteGroupId(ManagementUtils.getSiteGroupIdFromServletRequest(getThreadLocalRequest().getServerName())); for (VirtualGroup vg : currentSiteVGroups) { String gName = vg.getName(); ArrayList toCreate = new ArrayList(); @@ -162,6 +146,17 @@ public class MyVREsServiceImpl extends RemoteServiceServlet implements MyVREsSer ArrayList toSort = toReturn.get(cat); Collections.sort(toSort); } + HttpServletRequest request = getThreadLocalRequest(); + PortalContext context = PortalContext.getConfiguration(); + String gatewayURL = context.getGatewayURL(request); + String exploreURL = gatewayURL+context.getSiteLandingPagePath(request)+GCubePortalConstants.VRES_EXPLORE_FRIENDLY_URL; + VRE addMore = new VRE("", "", "", "", exploreURL, UserBelonging.BELONGING); + //add a fake category and addMoreVRE + ArrayList addMoreVREs = new ArrayList(); + addMoreVREs.add(addMore); + toReturn.put(ADD_MORE_CATEGORY, addMoreVREs); + + return toReturn; } @@ -170,25 +165,6 @@ public class MyVREsServiceImpl extends RemoteServiceServlet implements MyVREsSer return null; } } - - - /** - * - * @param scope - */ - public void loadLayout(String scope, String URL) { - _log.trace("Calling Load Layout..."); - HttpSession session = this.getThreadLocalRequest().getSession(); - ASLSession mysession = getASLSession(); - mysession.setAttribute("loadlayout", "true"); - session.setAttribute("loadLayout", "true"); - session.setAttribute("selectedVRE", scope); - mysession.logUserLogin(scope); - mysession.setScope(scope); - - _log.trace("User login logged to: " + scope); - } - /** * simply returns fake VREs for development purpose * @return @@ -261,72 +237,6 @@ public class MyVREsServiceImpl extends RemoteServiceServlet implements MyVREsSer return toReturn; } - /** - * read the list of virtual groups the current site (i-marine, services etc. ) should show up - * @param actualGroupId - * @return he list of virtual groups the current site (i-marine, services etc. ) should show up - * @throws GroupRetrievalFault - * @throws VirtualGroupNotExistingException - */ - private List getVirtualGroups(long actualGroupId) throws GroupRetrievalFault, VirtualGroupNotExistingException { - List toReturn = new ArrayList(); - try { - long userId = LiferayUserManager.getAdmin().getUserId(); - PrincipalThreadLocal.setName(userId); - PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(UserLocalServiceUtil.getUser(userId)); - PermissionThreadLocal.setPermissionChecker(permissionChecker); - Group site = GroupLocalServiceUtil.getGroup(actualGroupId); - _log.debug("Set Thread Permission done, getVirtual Group of " + site.getName()); - if (site.getExpandoBridge().getAttribute(CustomAttributeKeys.VIRTUAL_GROUP.getKeyName()) == null || site.getExpandoBridge().getAttribute(CustomAttributeKeys.VIRTUAL_GROUP.getKeyName()).equals("")) { - String warningMessage = String.format("Attribute %s not initialized.", CustomAttributeKeys.VIRTUAL_GROUP.getKeyName()); - _log.warn(warningMessage); - throw new VirtualGroupNotExistingException(warningMessage); - } else { - String[] values = (String[]) site.getExpandoBridge().getAttribute(CustomAttributeKeys.VIRTUAL_GROUP.getKeyName()); - VirtualGroup toAdd = new VirtualGroup(); - if (values != null && values.length > 0) { - for (int i = 0; i < values.length; i++) { - toAdd = new VirtualGroup(); - String[] splits = values[i].split("\\|"); - toAdd.setName(splits[0]); - toAdd.setDescription(splits[1]); - toReturn.add(toAdd); - _log.debug("VirtualGroup selected found for " + site.getName() + " -> " + toAdd.getName()); - } - } else { - toAdd.setName("NoVirtualGroupAssigned"); - toAdd.setDescription("NoVirtualGroupDescription"); - } - } - } catch (Exception e) { - e.printStackTrace(); - } - return toReturn; - } - /** - * - * @param request - * @return the current Group instance based on the request - * @throws PortalException - * @throws SystemException - */ - private Group getSiteFromServletRequest(final HttpServletRequest request) throws PortalException, SystemException { - String serverName = request.getServerName(); - _log.trace("currentHost is " + serverName); - Group site = null; - List vHosts = VirtualHostLocalServiceUtil.getVirtualHosts(0, VirtualHostLocalServiceUtil.getVirtualHostsCount()); - for (VirtualHost virtualHost : vHosts) { - _log.trace("Found " + virtualHost.getHostname()); - if (virtualHost.getHostname().compareTo("localhost") != 0 && - virtualHost.getLayoutSetId() != 0 && - virtualHost.getHostname().compareTo(serverName) == 0) { - long layoutSetId = virtualHost.getLayoutSetId(); - site = LayoutSetLocalServiceUtil.getLayoutSet(layoutSetId).getGroup(); - _log.trace("Found match! Your site is " + site.getName()); - return site; - } - } - return null; - } + } \ No newline at end of file