ref 17847: Updated to support accounting data visualization at the

infrastructure level
This commit is contained in:
Giancarlo Panichi 2019-10-22 19:04:25 +02:00
parent 7406fa24c3
commit 6d43214019
9 changed files with 130 additions and 53 deletions

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry including="**/*.java" kind="src" output="target/accounting-dashboard-1.0.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<classpathentry including="**/*.java" kind="src" output="target/accounting-dashboard-1.1.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/accounting-dashboard-1.0.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<classpathentry excluding="**" kind="src" output="target/accounting-dashboard-1.1.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
@ -50,5 +50,5 @@
</classpathentry>
<classpathentry kind="lib" path="/home/giancarlo/gwt/gwt-2.8.2/validation-api-1.0.0.GA.jar" sourcepath="/home/giancarlo/gwt/gwt-2.8.2/validation-api-1.0.0.GA-sources.jar"/>
<classpathentry kind="lib" path="/home/giancarlo/gwt/gwt-2.8.2/validation-api-1.0.0.GA-sources.jar"/>
<classpathentry kind="output" path="target/accounting-dashboard-1.0.0-SNAPSHOT/WEB-INF/classes"/>
<classpathentry kind="output" path="target/accounting-dashboard-1.1.0-SNAPSHOT/WEB-INF/classes"/>
</classpath>

1
.gitignore vendored
View File

@ -1 +1,2 @@
/target/
/test.log

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="accounting-dashboard-1.0.0-SNAPSHOT">
<wb-module deploy-name="accounting-dashboard-1.1.0-SNAPSHOT">
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>

View File

@ -1,5 +1,11 @@
<ReleaseNotes>
<Changeset component="org.gcube.portlets.user.accounting-dashboard.1-0-0" date="2018-08-01">
<Changeset component="org.gcube.portlets.user.accounting-dashboard.1-1-0"
date="2019-10-01">
<Change>Updated to support accounting data visualization at the
infrastructure level [ticket #17847]</Change>
</Changeset>
<Changeset component="org.gcube.portlets.user.accounting-dashboard.1-0-0"
date="2018-08-01">
<Change>First Release</Change>
</Changeset>
</ReleaseNotes>

View File

@ -13,7 +13,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.gcube.portlets.user</groupId>
<artifactId>accounting-dashboard</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>accounting-dashboard</name>

View File

@ -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);

View File

@ -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");

View File

@ -7,6 +7,6 @@ package org.gcube.portlets.user.accountingdashboard.server.accounting;
*/
public enum AccountingServiceType {
PortalContex, CurrentScope;
Infrastructure, PortalContex, CurrentScope;
}

View File

@ -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<VRECategory, ArrayList<VRE>> 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<ScopeDescriptor> infraChildren = new LinkedList<>();
PortalContext pContext = PortalContext.getConfiguration();
GCubeUser currUser = pContext.getCurrentUser(request);
List<GCubeGroup> 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<ScopeDescriptor> 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<ScopeDescriptor> 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<ScopeDescriptor> retrieveGatewayChildren(HttpServletRequest request, long currentSiteGroupId,
GCubeUser currUser) throws Exception, PortalException, SystemException {
// PARSE TREE
LinkedHashMap<VRECategory, ArrayList<VRE>> gatewayTree = getPortalSitesMappedToVRE(currUser,
currentSiteGroupId);
logger.debug("Parsing tree from gateway. Size {} ", gatewayTree.size());
LinkedList<ScopeDescriptor> rootChildren = new LinkedList<>();
for (Entry<VRECategory, ArrayList<VRE>> 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<VRECategory, ArrayList<VRE>> getPortalSitesMappedToVRE(HttpServletRequest request)
throws Exception {
private LinkedHashMap<VRECategory, ArrayList<VRE>> getPortalSitesMappedToVRE(GCubeUser currUser,
long currentSiteGroupId) throws Exception {
LinkedHashMap<VRECategory, ArrayList<VRE>> toReturn = new LinkedHashMap<VRECategory, ArrayList<VRE>>();
long currentSiteGroupId = getSiteFromServletRequest(request).getGroupId();
List<VirtualGroup> 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<GCubeGroup> currUserGroups = new ArrayList<GCubeGroup>();
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<VRE> 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<VirtualHost> 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;
}
}