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();
GCubeUser currUser = pContext.getCurrentUser(request);
InfraNode infraNode=BuildInfraNode.build(infrastructureScope);
InfraNode infraNode = BuildInfraNode.build(infrastructureScope);
List<GCubeGroup> theGateways = new LiferayGroupManager().getGateways();
for (GCubeGroup gCubeGroup : theGateways) {
@ -109,13 +109,13 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
LinkedList<ScopeDescriptor> gatewayChildren = retrieveGatewayChildren(request, gCubeGroup.getGroupId(),
currUser);
if(infraNode!=null){
String currScope=portalContext.getCurrentScope(gCubeGroup.getGroupId()+"");
ScopeDescriptor infraNodeScopeDescriptor=createRelativeInfraNode(infraNode, currScope);
if(gatewayChildren!=null){
if (infraNode != null) {
String currScope = portalContext.getCurrentScope(gCubeGroup.getGroupId() + "");
ScopeDescriptor infraNodeScopeDescriptor = createRelativeInfraNode(infraNode, currScope);
if (gatewayChildren != null) {
gatewayChildren.addFirst(infraNodeScopeDescriptor);
} else {
gatewayChildren=new LinkedList<>();
gatewayChildren = new LinkedList<>();
gatewayChildren.add(infraNodeScopeDescriptor);
}
}
@ -126,31 +126,27 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
infraChildren.add(gatewayScopeDescriptor);
}
infra.setChildren(infraChildren);
return infra;
}
private ScopeDescriptor createRelativeInfraNode(InfraNode infraNode, String scope){
ScopeDescriptor scopeDescriptor=null;
if(infraNode!=null){
StringBuilder absoluteScope=new StringBuilder();
private ScopeDescriptor createRelativeInfraNode(InfraNode infraNode, String scope) {
StringBuilder absoluteScope = new StringBuilder();
absoluteScope.append(scope);
absoluteScope.append("/");
absoluteScope.append(infraNode.getScope());
scopeDescriptor=new ScopeDescriptor(infraNode.getName(), absoluteScope.toString());
if(infraNode.getChildren()!=null&&!infraNode.getChildren().isEmpty()){
LinkedList<ScopeDescriptor> childsDescriptor=new LinkedList<>();
for(InfraNode child:infraNode.getChildren()){
ScopeDescriptor childScopeDescriptor=createRelativeInfraNode(child, absoluteScope.toString());
childsDescriptor.add(childScopeDescriptor);
ScopeDescriptor scopeDescriptor = new ScopeDescriptor(infraNode.getName(), absoluteScope.toString());
if (infraNode.getChildren() != null && !infraNode.getChildren().isEmpty()) {
LinkedList<ScopeDescriptor> childsScopeDescriptor = new LinkedList<>();
for (InfraNode child : infraNode.getChildren()) {
ScopeDescriptor childScopeDescriptor = createRelativeInfraNode(child, absoluteScope.toString());
childsScopeDescriptor.add(childScopeDescriptor);
}
scopeDescriptor.setChildren(childsDescriptor);
}
}
return scopeDescriptor;
scopeDescriptor.setChildren(childsScopeDescriptor);
}
return scopeDescriptor;
}
private ScopeDescriptor recreateTreeForPortalContext(HttpServletRequest request)
throws Exception, PortalException, SystemException {
@ -160,19 +156,19 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
PortalContext pContext = PortalContext.getConfiguration();
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;
rootChildren = retrieveGatewayChildren(request, currentSiteGroupId, currUser);
if(infraNode!=null){
ScopeDescriptor infraNodeScopeDescriptor=createRelativeInfraNode(infraNode, currScope);
if(rootChildren!=null){
if (infraNode != null) {
ScopeDescriptor infraNodeScopeDescriptor = createRelativeInfraNode(infraNode, currScope);
if (rootChildren != null) {
rootChildren.addFirst(infraNodeScopeDescriptor);
} else {
rootChildren=new LinkedList<>();
rootChildren = new LinkedList<>();
rootChildren.add(infraNodeScopeDescriptor);
}
}
@ -186,7 +182,7 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
private LinkedList<ScopeDescriptor> retrieveGatewayChildren(HttpServletRequest request, long currentSiteGroupId,
GCubeUser currUser) throws Exception, PortalException, SystemException {
logger.info("Retrieve Gateway Children: currentSiteGroupId="+currentSiteGroupId);
logger.info("Retrieve Gateway Children: currentSiteGroupId=" + currentSiteGroupId);
// PARSE TREE
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());
LinkedList<ScopeDescriptor> rootChildren = new LinkedList<>();
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);
public static InfraNode build(String scope) throws ServiceException {
logger.info("Build Infra Nodes");
InfraNode infraNode = null;
if (Constants.DEBUG_MODE) {
@ -42,8 +42,10 @@ public class BuildInfraNode {
if (infraNodeJAXB != null) {
infraNode = new InfraNode(infraNodeJAXB.getScope(), infraNodeJAXB.getName(),
infraNodeJAXB.getDescription());
if (infraNodeJAXB.getChildren() != null && !infraNodeJAXB.getChildren().isEmpty()) {
ArrayList<InfraNode> children = retrieveChildren(infraNodeJAXB);
infraNode.setChildren(children);
}
} else {
logger.info("Infra Nodes use default configuration for scope: " + scope);
@ -64,9 +66,9 @@ public class BuildInfraNode {
private static InfraNode useDefaultConfiguration() {
InfraNode infraNodeCoreServices = new InfraNode("CoreServices", "Core Services");
InfraNode infraNodeCatalogue = new InfraNode("CoreServices/Catalogue", "Catalogue");
InfraNode infraNodeWorkspace = new InfraNode("CoreServices/Workspace", "Workspace");
InfraNode infraNodeMessages = new InfraNode("CoreServices/Messages", "Messages");
InfraNode infraNodeCatalogue = new InfraNode("Catalogue", "Catalogue");
InfraNode infraNodeWorkspace = new InfraNode("Workspace", "Workspace");
InfraNode infraNodeMessages = new InfraNode("Messages", "Messages");
ArrayList<InfraNode> children = new ArrayList<InfraNode>();
children.add(infraNodeCatalogue);
@ -79,23 +81,22 @@ public class BuildInfraNode {
private static ArrayList<InfraNode> retrieveChildren(InfraNodeJAXB infraNodeJAXB) throws ServiceException {
try {
if (infraNodeJAXB.getChildren() == null || infraNodeJAXB.getChildren().isEmpty()) {
return null;
} else {
ArrayList<InfraNode> children = new ArrayList<>();
for (InfraNodeJAXB childJAXB : infraNodeJAXB.getChildren()) {
InfraNode child = new InfraNode(childJAXB.getScope(), childJAXB.getName(),
childJAXB.getDescription());
ArrayList<InfraNode> childrenOfChild = retrieveChildren(infraNodeJAXB);
InfraNode child = new InfraNode(childJAXB.getScope(), childJAXB.getName(), childJAXB.getDescription());
if (childJAXB.getChildren() != null && !childJAXB.getChildren().isEmpty()) {
ArrayList<InfraNode> childrenOfChild = retrieveChildren(childJAXB);
child.setChildren(childrenOfChild);
}
children.add(child);
}
return children;
}
} catch (Throwable e) {
logger.error("Ivalid infra nodes configuration: " + e.getLocalizedMessage(), e);
throw new ServiceException("Ivalid infra nodes configuration: " + e.getLocalizedMessage(), e);
logger.error("Ivalid infra nodes configuration. Error retrieving children for infra nodes: "
+ 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.getTree();
assertTrue("Success", true);
assertTrue(true);
} catch (Throwable e) {
logger.error(e.getLocalizedMessage(), e);
fail("Error:" + e.getLocalizedMessage());
@ -35,7 +35,7 @@ public class AccountingServiceTest extends TestCase {
}
} else {
assertTrue("Success", true);
assertTrue(true);
}
}
@ -44,7 +44,7 @@ public class AccountingServiceTest extends TestCase {
if (Constants.TEST_ENABLE) {
try {
assertTrue("Success", true);
assertTrue(true);
} catch (Throwable e) {
logger.error(e.getLocalizedMessage(), e);
@ -53,7 +53,7 @@ public class AccountingServiceTest extends TestCase {
}
} else {
assertTrue("Success", true);
assertTrue(true);
}
}

View File

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

View File

@ -3,11 +3,15 @@
*/
package org.gcube.portlets.user.accountingdashboard;
import java.io.File;
import java.io.StringWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import javax.xml.bind.JAXBContext;
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.BuildInfraNode;
@ -58,20 +62,22 @@ public class ISTest extends TestCase {
logger.debug("Test Enabled");
try {
logger.info("Check Marshalling");
InfraNodeJAXB infraNodeCoreServices = new InfraNodeJAXB();
infraNodeCoreServices.setScope("CoreServices");
infraNodeCoreServices.setName("Core Services");
InfraNodeJAXB infraNodeCatalogue = new InfraNodeJAXB();
infraNodeCatalogue.setScope("CoreServices/Catalogue");
infraNodeCatalogue.setScope("Catalogue");
infraNodeCatalogue.setName("Catalogue");
InfraNodeJAXB infraNodeWorkspace = new InfraNodeJAXB();
infraNodeWorkspace.setScope("CoreServices/Workspace");
infraNodeWorkspace.setScope("Workspace");
infraNodeWorkspace.setName("Workspace");
InfraNodeJAXB infraNodeMessages = new InfraNodeJAXB();
infraNodeMessages.setScope("CoreServices/Messages");
infraNodeMessages.setScope("Messages");
infraNodeMessages.setName("Messages");
ArrayList<InfraNodeJAXB> children = new ArrayList<>();
@ -80,7 +86,7 @@ public class ISTest extends TestCase {
children.add(infraNodeMessages);
infraNodeCoreServices.setChildren(children);
AccountingDashboardConfigJAXB config=new AccountingDashboardConfigJAXB();
AccountingDashboardConfigJAXB config = new AccountingDashboardConfigJAXB();
config.setEnabledInfraNode(true);
config.setBaseInfraNode(infraNodeCoreServices);
@ -97,6 +103,18 @@ public class ISTest extends TestCase {
// Verify XML Content
String xmlContent = sw.toString();
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);
} catch (Throwable e) {

View File

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