diff --git a/.classpath b/.classpath
index 90dd282..88b20b3 100644
--- a/.classpath
+++ b/.classpath
@@ -1,12 +1,12 @@
-
+
-
+
@@ -50,5 +50,5 @@
-
+
diff --git a/.gitignore b/.gitignore
index b83d222..30c3a67 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
/target/
+/test.log
diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component
index 062f4a2..7848b88 100644
--- a/.settings/org.eclipse.wst.common.component
+++ b/.settings/org.eclipse.wst.common.component
@@ -1,5 +1,5 @@
-
+
diff --git a/changelog.xml b/changelog.xml
index 0fe8a45..2da21e7 100644
--- a/changelog.xml
+++ b/changelog.xml
@@ -1,5 +1,11 @@
-
+
+ Updated to support accounting data visualization at the
+ infrastructure level [ticket #17847]
+
+
First Release
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 9c2c9f2..c4a4408 100644
--- a/pom.xml
+++ b/pom.xml
@@ -13,7 +13,7 @@
4.0.0
org.gcube.portlets.user
accounting-dashboard
- 1.0.0-SNAPSHOT
+ 1.1.0-SNAPSHOT
war
accounting-dashboard
diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/server/AccountingDashboardServiceImpl.java b/src/main/java/org/gcube/portlets/user/accountingdashboard/server/AccountingDashboardServiceImpl.java
index d7fc439..ef56017 100644
--- a/src/main/java/org/gcube/portlets/user/accountingdashboard/server/AccountingDashboardServiceImpl.java
+++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/server/AccountingDashboardServiceImpl.java
@@ -105,7 +105,11 @@ public class AccountingDashboardServiceImpl extends RemoteServiceServlet impleme
if (scopeBean.is(Type.VRE)) {
return AccountingServiceType.CurrentScope;
} else {
- return AccountingServiceType.PortalContex;
+ if (scopeBean.is(Type.VO)) {
+ return AccountingServiceType.PortalContex;
+ } else {
+ return AccountingServiceType.Infrastructure;
+ }
}
} catch (Throwable e) {
logger.error("getAccountingContext(): " + e.getLocalizedMessage(), e);
diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/server/accounting/AccountingService.java b/src/main/java/org/gcube/portlets/user/accountingdashboard/server/accounting/AccountingService.java
index 72de97a..a6e07f9 100644
--- a/src/main/java/org/gcube/portlets/user/accountingdashboard/server/accounting/AccountingService.java
+++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/server/accounting/AccountingService.java
@@ -48,7 +48,11 @@ public class AccountingService {
break;
case PortalContex:
logger.debug("AccountingService: PortalContext");
- dao = AccountingDao.get(new PortalContextTreeProvider());
+ dao = AccountingDao.get(new PortalContextTreeProvider(accountingServiceType));
+ break;
+ case Infrastructure:
+ logger.debug("AccountingService: Infrastructure");
+ dao = AccountingDao.get(new PortalContextTreeProvider(accountingServiceType));
break;
default:
logger.debug("AccountingService: CurrentScope");
diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/server/accounting/AccountingServiceType.java b/src/main/java/org/gcube/portlets/user/accountingdashboard/server/accounting/AccountingServiceType.java
index 81f59ff..7570943 100644
--- a/src/main/java/org/gcube/portlets/user/accountingdashboard/server/accounting/AccountingServiceType.java
+++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/server/accounting/AccountingServiceType.java
@@ -7,6 +7,6 @@ package org.gcube.portlets.user.accountingdashboard.server.accounting;
*/
public enum AccountingServiceType {
- PortalContex, CurrentScope;
+ Infrastructure, PortalContex, CurrentScope;
}
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
index 33ce4df..1785b79 100644
--- 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
@@ -9,10 +9,10 @@ import java.util.Map.Entry;
import javax.servlet.http.HttpServletRequest;
-import org.gcube.common.portal.GCubePortalConstants;
-import org.gcube.common.portal.PortalContext;
import org.gcube.accounting.accounting.summary.access.impl.ContextTreeProvider;
import org.gcube.accounting.accounting.summary.access.model.ScopeDescriptor;
+import org.gcube.common.portal.GCubePortalConstants;
+import org.gcube.common.portal.PortalContext;
import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
@@ -28,11 +28,21 @@ import com.liferay.portal.model.VirtualHost;
import com.liferay.portal.service.LayoutSetLocalServiceUtil;
import com.liferay.portal.service.VirtualHostLocalServiceUtil;
+/**
+ *
+ * @author Giancarlo Panichi
+ *
+ */
public class PortalContextTreeProvider implements ContextTreeProvider {
private static GroupManager groupsManager;
- private static Logger log = LoggerFactory.getLogger(PortalContextTreeProvider.class);
+ private static Logger logger = LoggerFactory.getLogger(PortalContextTreeProvider.class);
+ private AccountingServiceType accountingServiceType;
+
+ public PortalContextTreeProvider(AccountingServiceType accountingServiceType) {
+ this.accountingServiceType = accountingServiceType;
+ }
static {
groupsManager = new LiferayGroupManager();
@@ -44,12 +54,93 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
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
- LinkedHashMap> gatewayTree = getPortalSitesMappedToVRE(request);
+ if (accountingServiceType == null) {
+ logger.error("Invalid AccountingServiceType requested: null");
+ }
- log.debug("Parsing tree from gateway. Size {} ", gatewayTree.size());
+ ScopeDescriptor root = null;
+ switch (accountingServiceType) {
+ case CurrentScope:
+ logger.debug("AccountingService: CurrentScope");
+ break;
+ case PortalContex:
+ logger.debug("AccountingService: PortalContext");
+ root = recreateTreeForPortalContext(request);
+ break;
+ case Infrastructure:
+ logger.debug("AccountingService: Infrastructure");
+ root = recreateTreeForInfrastructure(request);
+ break;
+ default:
+ logger.debug("AccountingService: CurrentScope");
+ break;
+
+ }
+
+ return root;
+ }
+
+ private ScopeDescriptor recreateTreeForInfrastructure(HttpServletRequest request)
+ throws Exception, PortalException, SystemException {
+ ScopeDescriptor infra = null;
+ PortalContext portalContext = PortalContext.getConfiguration();
+ String infrastructureName = portalContext.getInfrastructureName();
+ String infrastructureScope = portalContext.getCurrentScope(request);
+ infra = new ScopeDescriptor(infrastructureName, infrastructureScope);
+
+ LinkedList infraChildren = new LinkedList<>();
+ PortalContext pContext = PortalContext.getConfiguration();
+ GCubeUser currUser = pContext.getCurrentUser(request);
+
+ List theGateways = new LiferayGroupManager().getGateways();
+ for (GCubeGroup gCubeGroup : theGateways) {
+ logger.debug("Gateway: [id=" + gCubeGroup.getGroupId() + ", name=" + gCubeGroup.getGroupName() + "]");
+ }
+ for (GCubeGroup gCubeGroup : theGateways) {
+ logger.debug("Gateway: [id=" + gCubeGroup.getGroupId() + ", name=" + gCubeGroup.getGroupName() + "]");
+
+ LinkedList gatewayChildren = retrieveGatewayChildren(request, gCubeGroup.getGroupId(),
+ currUser);
+ ScopeDescriptor gatewayScopeDescriptor = new ScopeDescriptor(gCubeGroup.getGroupName(),
+ gCubeGroup.getGroupId() + "");
+ gatewayScopeDescriptor.setChildren(gatewayChildren);
+ infraChildren.add(gatewayScopeDescriptor);
+ }
+
+ infra.setChildren(infraChildren);
+ return infra;
+ }
+
+ private ScopeDescriptor recreateTreeForPortalContext(HttpServletRequest request)
+ throws Exception, PortalException, SystemException {
+ ScopeDescriptor root;
+
+ long currentSiteGroupId = getSiteFromServletRequest(request).getGroupId();
+
+ PortalContext pContext = PortalContext.getConfiguration();
+ GCubeUser currUser = pContext.getCurrentUser(request);
+
+ LinkedList rootChildren = null;
+ rootChildren = retrieveGatewayChildren(request, currentSiteGroupId, currUser);
+
+ Group rootGroup = getSiteFromServletRequest(request);
+ root = new ScopeDescriptor(rootGroup.getDescriptiveName(), rootGroup.getGroupId() + "");
+ root.setChildren(rootChildren);
+ logger.debug("TREE IS {} ", root);
+ return root;
+ }
+
+ private LinkedList retrieveGatewayChildren(HttpServletRequest request, long currentSiteGroupId,
+ GCubeUser currUser) throws Exception, PortalException, SystemException {
+
+ // PARSE TREE
+ LinkedHashMap> gatewayTree = getPortalSitesMappedToVRE(currUser,
+ currentSiteGroupId);
+
+ logger.debug("Parsing tree from gateway. Size {} ", gatewayTree.size());
LinkedList rootChildren = new LinkedList<>();
for (Entry> entry : gatewayTree.entrySet()) {
@@ -59,12 +150,7 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
rootChildren.add(rootChild);
}
- Group rootGroup = getSiteFromServletRequest(request);
- ScopeDescriptor root = new ScopeDescriptor(rootGroup.getDescriptiveName(), rootGroup.getGroupId() + "");
- root.setChildren(rootChildren);
- log.debug("TREE IS {} ", root);
-
- return root;
+ return rootChildren;
}
/**
@@ -74,12 +160,11 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
* @throws SystemException
* @throws PortalException
*/
- private LinkedHashMap> getPortalSitesMappedToVRE(HttpServletRequest request)
- throws Exception {
+ private LinkedHashMap> getPortalSitesMappedToVRE(GCubeUser currUser,
+ long currentSiteGroupId) throws Exception {
LinkedHashMap> toReturn = new LinkedHashMap>();
- long currentSiteGroupId = getSiteFromServletRequest(request).getGroupId();
List currentSiteVGroups = groupsManager.getVirtualGroups(currentSiteGroupId);
for (VirtualGroup vg : currentSiteVGroups) {
@@ -91,17 +176,16 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
GCubeGroup rootGroupVO = groupsManager.getRootVO();
try {
- log.debug("root: " + rootGroupVO.getGroupName());
+ logger.debug("root: " + rootGroupVO.getGroupName());
} catch (NullPointerException e) {
- log.error(
+ logger.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();
@SuppressWarnings("unused")
List currUserGroups = new ArrayList();
- GCubeUser currUser = pContext.getCurrentUser(request);
+
if (currUser != null) {
currUserGroups = groupsManager.listGroupsByUser(currUser.getUserId());
}
@@ -124,29 +208,7 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
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()));
VRE toAdd = new VRE(vreName, vreDescription, vreID, friendlyURL, infraScope);
- // 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);
}
}
@@ -164,17 +226,17 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
private Group getSiteFromServletRequest(final HttpServletRequest request) throws PortalException, SystemException {
String serverName = request.getServerName();
- log.debug("currentHost is " + serverName);
+ logger.debug("currentHost is " + serverName);
Group site = null;
List vHosts = VirtualHostLocalServiceUtil.getVirtualHosts(0,
VirtualHostLocalServiceUtil.getVirtualHostsCount());
for (VirtualHost virtualHost : vHosts) {
- log.debug("Found " + virtualHost.getHostname());
+ logger.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());
+ logger.debug("Found match! Your site is " + site.getName());
return site;
}
}