From 0ad6871bb1da9f40ac27096fd6b22d803afb6de2 Mon Sep 17 00:00:00 2001 From: "fabio.sinibaldi" Date: Fri, 6 Jul 2018 10:30:27 +0000 Subject: [PATCH] git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/accounting-dashboard@169699 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../accounting/PortalContextTreeProvider.java | 156 ++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 src/main/java/org/gcube/portlets/user/accountingdashboard/server/accounting/PortalContextTreeProvider.java diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/server/accounting/PortalContextTreeProvider.java b/src/main/java/org/gcube/portlets/user/accountingdashboard/server/accounting/PortalContextTreeProvider.java new file mode 100644 index 0000000..56f2c37 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/server/accounting/PortalContextTreeProvider.java @@ -0,0 +1,156 @@ +package org.gcube.portlets.user.accountingdashboard.server.accounting; + +import javax.servlet.http.HttpServletRequest; + +import org.gcube.data.access.accounting.summary.access.impl.ContextTreeProvider; +import org.gcube.data.access.accounting.summary.access.model.ScopeDescriptor; +import org.gcube.vomanagement.usermanagement.GroupManager; +import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; +import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; +import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager; +import org.gcube.vomanagement.usermanagement.model.GCubeGroup; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class PortalContextTreeProvider implements ContextTreeProvider { + + + private static GroupManager groupsManager; + + + static { + groupsManager = new LiferayGroupManager(); + } + + + + @Override + public ScopeDescriptor getTree(Object context) throws Exception { +// if(context == null) throw new Exception("Unable to get tree, Request is null."); +// if(!(context instanceof HttpServletRequest)) throw new Exception("Invalid request object : "+context); +// HttpServletRequest request=(HttpServletRequest) context; + + // PARSE TREE + + GCubeGroup rootGroupVO = groupsManager.getRootVO(); + + return asScopeDescriptor(rootGroupVO); + } + + private ScopeDescriptor asScopeDescriptor(GCubeGroup group) throws UserManagementSystemException, GroupRetrievalFault { + ScopeDescriptor toReturn=new ScopeDescriptor(group.getGroupName(),groupsManager.getInfrastructureScope(group.getGroupId())); + for(GCubeGroup child:group.getChildren()) { + toReturn.getChildren().add(asScopeDescriptor(child)); + } + return toReturn; + } + +// +// +// /** +// * +// * @return the Virtual groups with their VREs in the order estabilished in the LR Control Panel +// * @throws SystemException +// * @throws PortalException +// */ +// private LinkedHashMap> getPortalSitesMappedToVRE(HttpServletRequest request) throws Exception { +// +// Group site=getSiteFromServletRequest(request); +// +// ScopeDescriptor root=new ScopeDescriptor(site.getDescriptiveName(),site.getUuid()); +// +// LinkedList groups=new LinkedList<>(); +// +// long currentSiteGroupId = site.getGroupId(); +// +//// List currentSiteVGroups = groupsManager.getVirtualGroups(currentSiteGroupId); +//// +//// for (VirtualGroup vg : currentSiteVGroups) { +//// ScopeDescriptor groupDescriptor=new ScopeDescriptor(vg.getName(),); +//// VRECategory cat = new VRECategory(1L, vg.getName(), vg.getDescription()); +//// toReturn.put(cat, toCreate); +//// } +// +// GCubeGroup rootGroupVO = groupsManager.getRootVO(); +//// +//// try { +//// log.debug("root: " + rootGroupVO.getGroupName() ); +//// } catch (NullPointerException e) { +//// log.error("Cannot find root organziation, please check gcube-data.properties file in $CATALINA_HOME/conf folder, unless your installing the Bundle"); +//// return toReturn; +//// } +//// PortalContext pContext = PortalContext.getConfiguration(); +//// +//// List currUserGroups = new ArrayList(); +//// GCubeUser currUser = pContext.getCurrentUser(request); +//// if (currUser != null) { +//// currUserGroups = groupsManager.listGroupsByUser(currUser.getUserId()); +//// } +// +// //for each root sub organizations (VO) +// for (GCubeGroup vOrg : rootGroupVO.getChildren()) { +// for (GCubeGroup vreSite : vOrg.getChildren()) { +// long vreID = vreSite.getGroupId(); +// String vreName = vreSite.getGroupName(); +// String vreDescription = vreSite.getDescription(); +// +// String groupName = groupsManager.getInfrastructureScope(vreSite.getGroupId()); +// +// List vreGroups = groupsManager.getVirtualGroups(vreID); +// for (VirtualGroup vreGroup : vreGroups) { +// for (VRECategory vre : toReturn.keySet()) { +// if (vre.getName().compareTo(vreGroup.getName())==0) { +// ArrayList toUpdate = toReturn.get(vre); +// UserBelonging belongs = UserBelonging.NOT_BELONGING; +// VRE toAdd = new VRE(vreID,vreName, vreDescription, vreLogoURL, groupName, friendlyURL, belongs, getVREMembershipType(vreSite.getMembershipType())); +//// if (GroupLocalServiceUtil.getGroup(vreID).getPublicLayoutsPageCount() > 0) { +//// String publicURL = PREFIX_PUBLIC_URL+vreSite.getFriendlyURL(); +//// toAdd.setPublicURL(publicURL); +//// } +//// if (currUser != null) { +//// //check if the user belongs to it +//// if (currUserGroups.contains(vreSite)) { +//// toAdd.setUserBelonging(UserBelonging.BELONGING); +//// } +//// else if (checkPending(currUser.getUsername(), vreSite.getGroupId())) +//// toAdd.setUserBelonging(UserBelonging.PENDING); +//// } +// toUpdate.add(toAdd); +// } +// } +// } +// } +// } +// +// //sort the vres in the groups +// for (VRECategory cat : toReturn.keySet()) { +// ArrayList toSort = toReturn.get(cat); +// Collections.sort(toSort); +// } +// return toReturn; +// } +// +// +// +// +// +// private Group getSiteFromServletRequest(final HttpServletRequest request) throws PortalException, SystemException { +// String serverName = request.getServerName(); +// log.debug("currentHost is " + serverName); +// Group site = null; +// List vHosts = VirtualHostLocalServiceUtil.getVirtualHosts(0, VirtualHostLocalServiceUtil.getVirtualHostsCount()); +// for (VirtualHost virtualHost : vHosts) { +// log.debug("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.debug("Found match! Your site is " + site.getName()); +// return site; +// } +// } +// return null; +// } +}