104 lines
3.7 KiB
Java
104 lines
3.7 KiB
Java
package org.gcube.portlets.user.accountingdashboard.server.is;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import org.gcube.portlets.user.accountingdashboard.shared.Constants;
|
|
import org.gcube.portlets.user.accountingdashboard.shared.exception.ServiceException;
|
|
import org.gcube.portlets.user.accountingdashboard.shared.is.InfraNode;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
/**
|
|
*
|
|
* @author Giancarlo Panichi
|
|
*
|
|
*
|
|
*/
|
|
public class BuildInfraNode {
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(BuildInfraNode.class);
|
|
|
|
public static InfraNode build(String scope) throws ServiceException {
|
|
|
|
InfraNode infraNode = null;
|
|
|
|
if (Constants.DEBUG_MODE) {
|
|
logger.info("AccountDashboard: use debug configuration for infra nodes.");
|
|
infraNode = useDefaultConfiguration();
|
|
} else {
|
|
AccountingDashboardConfigJAXB accountingDashboardConfigJAXB = null;
|
|
try {
|
|
accountingDashboardConfigJAXB = InformationSystemUtils.retrieveAccountingDashboardConfig(scope);
|
|
} catch (ServiceException e) {
|
|
logger.debug(e.getLocalizedMessage(), e);
|
|
}
|
|
|
|
if (accountingDashboardConfigJAXB != null) {
|
|
logger.info("AccountingDashboard: use configuration in scope: " + scope);
|
|
if (accountingDashboardConfigJAXB.isEnabledInfraNode()) {
|
|
logger.info("Infra Nodes configuration enabled in scope: " + scope);
|
|
InfraNodeJAXB infraNodeJAXB = accountingDashboardConfigJAXB.getBaseInfraNode();
|
|
logger.info("Infra Nodes configuration: " + infraNodeJAXB);
|
|
if (infraNodeJAXB != null) {
|
|
infraNode = new InfraNode(infraNodeJAXB.getScope(), infraNodeJAXB.getName(),
|
|
infraNodeJAXB.getDescription());
|
|
ArrayList<InfraNode> children = retrieveChildren(infraNodeJAXB);
|
|
infraNode.setChildren(children);
|
|
|
|
} else {
|
|
logger.info("Infra Nodes use default configuration for scope: " + scope);
|
|
infraNode = useDefaultConfiguration();
|
|
}
|
|
} else {
|
|
logger.info("Infra Nodes configuration disabled in scope: " + scope);
|
|
}
|
|
} else {
|
|
logger.info("AccountingDashboard: use infra nodes default configuration for scope: " + scope);
|
|
infraNode = useDefaultConfiguration();
|
|
}
|
|
}
|
|
|
|
logger.debug("AccountingDashboard: Infra Nodes configuration set: " + infraNode);
|
|
return infraNode;
|
|
}
|
|
|
|
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");
|
|
|
|
ArrayList<InfraNode> children = new ArrayList<InfraNode>();
|
|
children.add(infraNodeCatalogue);
|
|
children.add(infraNodeWorkspace);
|
|
children.add(infraNodeMessages);
|
|
infraNodeCoreServices.setChildren(children);
|
|
|
|
return infraNodeCoreServices;
|
|
}
|
|
|
|
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);
|
|
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);
|
|
}
|
|
|
|
}
|
|
|
|
}
|