ref 18291: Modify the Accounting Dashboard portlet to support the Core

Services Category per gateway

https://support.d4science.org/issues/18291

Fixed the creation of the tree
This commit is contained in:
Giancarlo Panichi 2020-01-21 11:28:33 +01:00
parent 8726e63ad7
commit e140afebe4
6 changed files with 92 additions and 78 deletions

View File

@ -97,7 +97,7 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
PortalContext pContext = PortalContext.getConfiguration(); PortalContext pContext = PortalContext.getConfiguration();
GCubeUser currUser = pContext.getCurrentUser(request); GCubeUser currUser = pContext.getCurrentUser(request);
InfraNode infraNode=BuildInfraNode.build(infrastructureScope); InfraNode infraNode = BuildInfraNode.build(infrastructureScope);
List<GCubeGroup> theGateways = new LiferayGroupManager().getGateways(); List<GCubeGroup> theGateways = new LiferayGroupManager().getGateways();
for (GCubeGroup gCubeGroup : theGateways) { for (GCubeGroup gCubeGroup : theGateways) {
@ -109,13 +109,13 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
LinkedList<ScopeDescriptor> gatewayChildren = retrieveGatewayChildren(request, gCubeGroup.getGroupId(), LinkedList<ScopeDescriptor> gatewayChildren = retrieveGatewayChildren(request, gCubeGroup.getGroupId(),
currUser); currUser);
if(infraNode!=null){ if (infraNode != null) {
String currScope=portalContext.getCurrentScope(gCubeGroup.getGroupId()+""); String currScope = portalContext.getCurrentScope(gCubeGroup.getGroupId() + "");
ScopeDescriptor infraNodeScopeDescriptor=createRelativeInfraNode(infraNode, currScope); ScopeDescriptor infraNodeScopeDescriptor = createRelativeInfraNode(infraNode, currScope);
if(gatewayChildren!=null){ if (gatewayChildren != null) {
gatewayChildren.addFirst(infraNodeScopeDescriptor); gatewayChildren.addFirst(infraNodeScopeDescriptor);
} else { } else {
gatewayChildren=new LinkedList<>(); gatewayChildren = new LinkedList<>();
gatewayChildren.add(infraNodeScopeDescriptor); gatewayChildren.add(infraNodeScopeDescriptor);
} }
} }
@ -126,32 +126,28 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
infraChildren.add(gatewayScopeDescriptor); infraChildren.add(gatewayScopeDescriptor);
} }
infra.setChildren(infraChildren); infra.setChildren(infraChildren);
return infra; return infra;
} }
private ScopeDescriptor createRelativeInfraNode(InfraNode infraNode, String scope){ private ScopeDescriptor createRelativeInfraNode(InfraNode infraNode, String scope) {
ScopeDescriptor scopeDescriptor=null; StringBuilder absoluteScope = new StringBuilder();
if(infraNode!=null){ absoluteScope.append(scope);
StringBuilder absoluteScope=new StringBuilder(); absoluteScope.append("/");
absoluteScope.append(scope); absoluteScope.append(infraNode.getScope());
absoluteScope.append("/"); ScopeDescriptor scopeDescriptor = new ScopeDescriptor(infraNode.getName(), absoluteScope.toString());
absoluteScope.append(infraNode.getScope()); if (infraNode.getChildren() != null && !infraNode.getChildren().isEmpty()) {
scopeDescriptor=new ScopeDescriptor(infraNode.getName(), absoluteScope.toString()); LinkedList<ScopeDescriptor> childsScopeDescriptor = new LinkedList<>();
if(infraNode.getChildren()!=null&&!infraNode.getChildren().isEmpty()){ for (InfraNode child : infraNode.getChildren()) {
LinkedList<ScopeDescriptor> childsDescriptor=new LinkedList<>(); ScopeDescriptor childScopeDescriptor = createRelativeInfraNode(child, absoluteScope.toString());
for(InfraNode child:infraNode.getChildren()){ childsScopeDescriptor.add(childScopeDescriptor);
ScopeDescriptor childScopeDescriptor=createRelativeInfraNode(child, absoluteScope.toString());
childsDescriptor.add(childScopeDescriptor);
}
scopeDescriptor.setChildren(childsDescriptor);
} }
scopeDescriptor.setChildren(childsScopeDescriptor);
} }
return scopeDescriptor; return scopeDescriptor;
} }
private ScopeDescriptor recreateTreeForPortalContext(HttpServletRequest request) private ScopeDescriptor recreateTreeForPortalContext(HttpServletRequest request)
throws Exception, PortalException, SystemException { throws Exception, PortalException, SystemException {
ScopeDescriptor root; ScopeDescriptor root;
@ -160,19 +156,19 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
PortalContext pContext = PortalContext.getConfiguration(); PortalContext pContext = PortalContext.getConfiguration();
GCubeUser currUser = pContext.getCurrentUser(request); GCubeUser currUser = pContext.getCurrentUser(request);
String currScope=pContext.getCurrentScope(currentSiteGroupId+""); String currScope = pContext.getCurrentScope(currentSiteGroupId + "");
InfraNode infraNode=BuildInfraNode.build(currScope); InfraNode infraNode = BuildInfraNode.build(currScope);
LinkedList<ScopeDescriptor> rootChildren = null; LinkedList<ScopeDescriptor> rootChildren = null;
rootChildren = retrieveGatewayChildren(request, currentSiteGroupId, currUser); rootChildren = retrieveGatewayChildren(request, currentSiteGroupId, currUser);
if(infraNode!=null){ if (infraNode != null) {
ScopeDescriptor infraNodeScopeDescriptor=createRelativeInfraNode(infraNode, currScope); ScopeDescriptor infraNodeScopeDescriptor = createRelativeInfraNode(infraNode, currScope);
if(rootChildren!=null){ if (rootChildren != null) {
rootChildren.addFirst(infraNodeScopeDescriptor); rootChildren.addFirst(infraNodeScopeDescriptor);
} else { } else {
rootChildren=new LinkedList<>(); rootChildren = new LinkedList<>();
rootChildren.add(infraNodeScopeDescriptor); rootChildren.add(infraNodeScopeDescriptor);
} }
} }
@ -186,7 +182,7 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
private LinkedList<ScopeDescriptor> retrieveGatewayChildren(HttpServletRequest request, long currentSiteGroupId, private LinkedList<ScopeDescriptor> retrieveGatewayChildren(HttpServletRequest request, long currentSiteGroupId,
GCubeUser currUser) throws Exception, PortalException, SystemException { GCubeUser currUser) throws Exception, PortalException, SystemException {
logger.info("Retrieve Gateway Children: currentSiteGroupId="+currentSiteGroupId); logger.info("Retrieve Gateway Children: currentSiteGroupId=" + currentSiteGroupId);
// PARSE TREE // PARSE TREE
LinkedHashMap<VRECategory, ArrayList<VRE>> gatewayTree = getPortalSitesMappedToVRE(currUser, LinkedHashMap<VRECategory, ArrayList<VRE>> gatewayTree = getPortalSitesMappedToVRE(currUser,
@ -194,7 +190,6 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
logger.debug("Parsing tree from gateway. Size {} ", gatewayTree.size()); logger.debug("Parsing tree from gateway. Size {} ", gatewayTree.size());
LinkedList<ScopeDescriptor> rootChildren = new LinkedList<>(); LinkedList<ScopeDescriptor> rootChildren = new LinkedList<>();
for (Entry<VRECategory, ArrayList<VRE>> entry : gatewayTree.entrySet()) { for (Entry<VRECategory, ArrayList<VRE>> entry : gatewayTree.entrySet()) {

View File

@ -19,7 +19,7 @@ public class BuildInfraNode {
private static Logger logger = LoggerFactory.getLogger(BuildInfraNode.class); private static Logger logger = LoggerFactory.getLogger(BuildInfraNode.class);
public static InfraNode build(String scope) throws ServiceException { public static InfraNode build(String scope) throws ServiceException {
logger.info("Build Infra Nodes");
InfraNode infraNode = null; InfraNode infraNode = null;
if (Constants.DEBUG_MODE) { if (Constants.DEBUG_MODE) {
@ -42,8 +42,10 @@ public class BuildInfraNode {
if (infraNodeJAXB != null) { if (infraNodeJAXB != null) {
infraNode = new InfraNode(infraNodeJAXB.getScope(), infraNodeJAXB.getName(), infraNode = new InfraNode(infraNodeJAXB.getScope(), infraNodeJAXB.getName(),
infraNodeJAXB.getDescription()); infraNodeJAXB.getDescription());
ArrayList<InfraNode> children = retrieveChildren(infraNodeJAXB); if (infraNodeJAXB.getChildren() != null && !infraNodeJAXB.getChildren().isEmpty()) {
infraNode.setChildren(children); ArrayList<InfraNode> children = retrieveChildren(infraNodeJAXB);
infraNode.setChildren(children);
}
} else { } else {
logger.info("Infra Nodes use default configuration for scope: " + scope); logger.info("Infra Nodes use default configuration for scope: " + scope);
@ -64,9 +66,9 @@ public class BuildInfraNode {
private static InfraNode useDefaultConfiguration() { private static InfraNode useDefaultConfiguration() {
InfraNode infraNodeCoreServices = new InfraNode("CoreServices", "Core Services"); InfraNode infraNodeCoreServices = new InfraNode("CoreServices", "Core Services");
InfraNode infraNodeCatalogue = new InfraNode("CoreServices/Catalogue", "Catalogue"); InfraNode infraNodeCatalogue = new InfraNode("Catalogue", "Catalogue");
InfraNode infraNodeWorkspace = new InfraNode("CoreServices/Workspace", "Workspace"); InfraNode infraNodeWorkspace = new InfraNode("Workspace", "Workspace");
InfraNode infraNodeMessages = new InfraNode("CoreServices/Messages", "Messages"); InfraNode infraNodeMessages = new InfraNode("Messages", "Messages");
ArrayList<InfraNode> children = new ArrayList<InfraNode>(); ArrayList<InfraNode> children = new ArrayList<InfraNode>();
children.add(infraNodeCatalogue); children.add(infraNodeCatalogue);
@ -79,23 +81,22 @@ public class BuildInfraNode {
private static ArrayList<InfraNode> retrieveChildren(InfraNodeJAXB infraNodeJAXB) throws ServiceException { private static ArrayList<InfraNode> retrieveChildren(InfraNodeJAXB infraNodeJAXB) throws ServiceException {
try { try {
if (infraNodeJAXB.getChildren() == null || infraNodeJAXB.getChildren().isEmpty()) { ArrayList<InfraNode> children = new ArrayList<>();
return null; for (InfraNodeJAXB childJAXB : infraNodeJAXB.getChildren()) {
} else { InfraNode child = new InfraNode(childJAXB.getScope(), childJAXB.getName(), childJAXB.getDescription());
ArrayList<InfraNode> children = new ArrayList<>(); if (childJAXB.getChildren() != null && !childJAXB.getChildren().isEmpty()) {
for (InfraNodeJAXB childJAXB : infraNodeJAXB.getChildren()) { ArrayList<InfraNode> childrenOfChild = retrieveChildren(childJAXB);
InfraNode child = new InfraNode(childJAXB.getScope(), childJAXB.getName(),
childJAXB.getDescription());
ArrayList<InfraNode> childrenOfChild = retrieveChildren(infraNodeJAXB);
child.setChildren(childrenOfChild); child.setChildren(childrenOfChild);
children.add(child);
} }
return children; children.add(child);
} }
return children;
} catch (Throwable e) { } catch (Throwable e) {
logger.error("Ivalid infra nodes configuration: " + e.getLocalizedMessage(), e); logger.error("Ivalid infra nodes configuration. Error retrieving children for infra nodes: "
throw new ServiceException("Ivalid infra nodes configuration: " + e.getLocalizedMessage(), e); + e.getLocalizedMessage(), e);
throw new ServiceException("Ivalid infra nodes configuration. Error retrieving children for infra nodes: "
+ e.getLocalizedMessage(), e);
} }
} }

View File

@ -27,7 +27,7 @@ public class AccountingServiceTest extends TestCase {
AccountingService accountingService = new AccountingService(AccountingServiceType.CurrentScope); AccountingService accountingService = new AccountingService(AccountingServiceType.CurrentScope);
// accountingService.getTree(); // accountingService.getTree();
assertTrue("Success", true); assertTrue(true);
} catch (Throwable e) { } catch (Throwable e) {
logger.error(e.getLocalizedMessage(), e); logger.error(e.getLocalizedMessage(), e);
fail("Error:" + e.getLocalizedMessage()); fail("Error:" + e.getLocalizedMessage());
@ -35,7 +35,7 @@ public class AccountingServiceTest extends TestCase {
} }
} else { } else {
assertTrue("Success", true); assertTrue(true);
} }
} }
@ -44,7 +44,7 @@ public class AccountingServiceTest extends TestCase {
if (Constants.TEST_ENABLE) { if (Constants.TEST_ENABLE) {
try { try {
assertTrue("Success", true); assertTrue(true);
} catch (Throwable e) { } catch (Throwable e) {
logger.error(e.getLocalizedMessage(), e); logger.error(e.getLocalizedMessage(), e);
@ -53,7 +53,7 @@ public class AccountingServiceTest extends TestCase {
} }
} else { } else {
assertTrue("Success", true); assertTrue(true);
} }
} }

View File

@ -123,7 +123,7 @@ public class ColorTest extends TestCase {
logger.debug("HTML Color green: " + htmlSingleColorBuilder.toString()); logger.debug("HTML Color green: " + htmlSingleColorBuilder.toString());
assertTrue("Success", true); assertTrue(true);
} catch (Throwable e) { } catch (Throwable e) {
logger.error(e.getLocalizedMessage(), e); logger.error(e.getLocalizedMessage(), e);
fail("Error:" + e.getLocalizedMessage()); fail("Error:" + e.getLocalizedMessage());
@ -131,7 +131,7 @@ public class ColorTest extends TestCase {
} }
} else { } else {
assertTrue("Success", true); assertTrue(true);
} }
} }

View File

@ -3,11 +3,15 @@
*/ */
package org.gcube.portlets.user.accountingdashboard; package org.gcube.portlets.user.accountingdashboard;
import java.io.File;
import java.io.StringWriter; import java.io.StringWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller; import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import org.gcube.portlets.user.accountingdashboard.server.is.AccountingDashboardConfigJAXB; import org.gcube.portlets.user.accountingdashboard.server.is.AccountingDashboardConfigJAXB;
import org.gcube.portlets.user.accountingdashboard.server.is.BuildInfraNode; import org.gcube.portlets.user.accountingdashboard.server.is.BuildInfraNode;
@ -58,20 +62,22 @@ public class ISTest extends TestCase {
logger.debug("Test Enabled"); logger.debug("Test Enabled");
try { try {
logger.info("Check Marshalling");
InfraNodeJAXB infraNodeCoreServices = new InfraNodeJAXB(); InfraNodeJAXB infraNodeCoreServices = new InfraNodeJAXB();
infraNodeCoreServices.setScope("CoreServices"); infraNodeCoreServices.setScope("CoreServices");
infraNodeCoreServices.setName("Core Services"); infraNodeCoreServices.setName("Core Services");
InfraNodeJAXB infraNodeCatalogue = new InfraNodeJAXB(); InfraNodeJAXB infraNodeCatalogue = new InfraNodeJAXB();
infraNodeCatalogue.setScope("CoreServices/Catalogue"); infraNodeCatalogue.setScope("Catalogue");
infraNodeCatalogue.setName("Catalogue"); infraNodeCatalogue.setName("Catalogue");
InfraNodeJAXB infraNodeWorkspace = new InfraNodeJAXB(); InfraNodeJAXB infraNodeWorkspace = new InfraNodeJAXB();
infraNodeWorkspace.setScope("CoreServices/Workspace"); infraNodeWorkspace.setScope("Workspace");
infraNodeWorkspace.setName("Workspace"); infraNodeWorkspace.setName("Workspace");
InfraNodeJAXB infraNodeMessages = new InfraNodeJAXB(); InfraNodeJAXB infraNodeMessages = new InfraNodeJAXB();
infraNodeMessages.setScope("CoreServices/Messages"); infraNodeMessages.setScope("Messages");
infraNodeMessages.setName("Messages"); infraNodeMessages.setName("Messages");
ArrayList<InfraNodeJAXB> children = new ArrayList<>(); ArrayList<InfraNodeJAXB> children = new ArrayList<>();
@ -80,7 +86,7 @@ public class ISTest extends TestCase {
children.add(infraNodeMessages); children.add(infraNodeMessages);
infraNodeCoreServices.setChildren(children); infraNodeCoreServices.setChildren(children);
AccountingDashboardConfigJAXB config=new AccountingDashboardConfigJAXB(); AccountingDashboardConfigJAXB config = new AccountingDashboardConfigJAXB();
config.setEnabledInfraNode(true); config.setEnabledInfraNode(true);
config.setBaseInfraNode(infraNodeCoreServices); config.setBaseInfraNode(infraNodeCoreServices);
@ -97,6 +103,18 @@ public class ISTest extends TestCase {
// Verify XML Content // Verify XML Content
String xmlContent = sw.toString(); String xmlContent = sw.toString();
logger.debug(xmlContent); logger.debug(xmlContent);
logger.info("Check Unmarshalling");
Path path = Files.createTempFile("AccountingDashboardConfig", ".xml");
File file = path.toFile();
jaxbMarshaller.marshal(config, file);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
AccountingDashboardConfigJAXB configUnmarshalled = (AccountingDashboardConfigJAXB) jaxbUnmarshaller
.unmarshal(file);
logger.debug("Config unmarshallded: " + configUnmarshalled);
file.delete();
logger.info("Success!");
assertTrue(true); assertTrue(true);
} catch (Throwable e) { } catch (Throwable e) {

View File

@ -22,7 +22,7 @@ public class ServiceTest extends TestCase {
try { try {
assertTrue("Success", true); assertTrue(true);
} catch (Throwable e) { } catch (Throwable e) {
logger.error(e.getLocalizedMessage(), e); logger.error(e.getLocalizedMessage(), e);
fail("Error:" + e.getLocalizedMessage()); fail("Error:" + e.getLocalizedMessage());
@ -30,7 +30,7 @@ public class ServiceTest extends TestCase {
} }
} else { } else {
assertTrue("Success", true); assertTrue(true);
} }
} }