ref 18291: Modify the Accounting Dashboard portlet to support the Core
Services Category per gateway https://support.d4science.org/issues/18291 Added IS support
This commit is contained in:
parent
52cc4ad7c9
commit
8726e63ad7
|
@ -13,6 +13,8 @@ import org.gcube.accounting.accounting.summary.access.impl.ContextTreeProvider;
|
||||||
import org.gcube.accounting.accounting.summary.access.model.ScopeDescriptor;
|
import org.gcube.accounting.accounting.summary.access.model.ScopeDescriptor;
|
||||||
import org.gcube.common.portal.GCubePortalConstants;
|
import org.gcube.common.portal.GCubePortalConstants;
|
||||||
import org.gcube.common.portal.PortalContext;
|
import org.gcube.common.portal.PortalContext;
|
||||||
|
import org.gcube.portlets.user.accountingdashboard.server.is.BuildInfraNode;
|
||||||
|
import org.gcube.portlets.user.accountingdashboard.shared.is.InfraNode;
|
||||||
import org.gcube.vomanagement.usermanagement.GroupManager;
|
import org.gcube.vomanagement.usermanagement.GroupManager;
|
||||||
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
|
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
|
||||||
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
|
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
|
||||||
|
@ -95,6 +97,8 @@ 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);
|
||||||
|
|
||||||
List<GCubeGroup> theGateways = new LiferayGroupManager().getGateways();
|
List<GCubeGroup> theGateways = new LiferayGroupManager().getGateways();
|
||||||
for (GCubeGroup gCubeGroup : theGateways) {
|
for (GCubeGroup gCubeGroup : theGateways) {
|
||||||
logger.debug("Gateway: [id=" + gCubeGroup.getGroupId() + ", name=" + gCubeGroup.getGroupName() + "]");
|
logger.debug("Gateway: [id=" + gCubeGroup.getGroupId() + ", name=" + gCubeGroup.getGroupName() + "]");
|
||||||
|
@ -104,16 +108,50 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
|
||||||
|
|
||||||
LinkedList<ScopeDescriptor> gatewayChildren = retrieveGatewayChildren(request, gCubeGroup.getGroupId(),
|
LinkedList<ScopeDescriptor> gatewayChildren = retrieveGatewayChildren(request, gCubeGroup.getGroupId(),
|
||||||
currUser);
|
currUser);
|
||||||
|
|
||||||
|
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.add(infraNodeScopeDescriptor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ScopeDescriptor gatewayScopeDescriptor = new ScopeDescriptor(gCubeGroup.getGroupName(),
|
ScopeDescriptor gatewayScopeDescriptor = new ScopeDescriptor(gCubeGroup.getGroupName(),
|
||||||
gCubeGroup.getGroupId() + "");
|
gCubeGroup.getGroupId() + "");
|
||||||
gatewayScopeDescriptor.setChildren(gatewayChildren);
|
gatewayScopeDescriptor.setChildren(gatewayChildren);
|
||||||
infraChildren.add(gatewayScopeDescriptor);
|
infraChildren.add(gatewayScopeDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
infra.setChildren(infraChildren);
|
infra.setChildren(infraChildren);
|
||||||
return infra;
|
return infra;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ScopeDescriptor createRelativeInfraNode(InfraNode infraNode, String scope){
|
||||||
|
ScopeDescriptor scopeDescriptor=null;
|
||||||
|
if(infraNode!=null){
|
||||||
|
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.setChildren(childsDescriptor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return scopeDescriptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private ScopeDescriptor recreateTreeForPortalContext(HttpServletRequest request)
|
private ScopeDescriptor recreateTreeForPortalContext(HttpServletRequest request)
|
||||||
throws Exception, PortalException, SystemException {
|
throws Exception, PortalException, SystemException {
|
||||||
ScopeDescriptor root;
|
ScopeDescriptor root;
|
||||||
|
@ -122,10 +160,23 @@ 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+"");
|
||||||
|
|
||||||
|
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){
|
||||||
|
ScopeDescriptor infraNodeScopeDescriptor=createRelativeInfraNode(infraNode, currScope);
|
||||||
|
if(rootChildren!=null){
|
||||||
|
rootChildren.addFirst(infraNodeScopeDescriptor);
|
||||||
|
} else {
|
||||||
|
rootChildren=new LinkedList<>();
|
||||||
|
rootChildren.add(infraNodeScopeDescriptor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Group rootGroup = getSiteFromServletRequest(request);
|
Group rootGroup = getSiteFromServletRequest(request);
|
||||||
root = new ScopeDescriptor(rootGroup.getDescriptiveName(), rootGroup.getGroupId() + "");
|
root = new ScopeDescriptor(rootGroup.getDescriptiveName(), rootGroup.getGroupId() + "");
|
||||||
root.setChildren(rootChildren);
|
root.setChildren(rootChildren);
|
||||||
|
@ -135,6 +186,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);
|
||||||
|
|
||||||
// PARSE TREE
|
// PARSE TREE
|
||||||
LinkedHashMap<VRECategory, ArrayList<VRE>> gatewayTree = getPortalSitesMappedToVRE(currUser,
|
LinkedHashMap<VRECategory, ArrayList<VRE>> gatewayTree = getPortalSitesMappedToVRE(currUser,
|
||||||
|
@ -142,14 +194,15 @@ 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()) {
|
||||||
ScopeDescriptor rootChild = new ScopeDescriptor(entry.getKey().name, entry.getKey().categoryID + "");
|
ScopeDescriptor rootChild = new ScopeDescriptor(entry.getKey().name, entry.getKey().categoryID + "");
|
||||||
for (VRE vre : entry.getValue())
|
for (VRE vre : entry.getValue())
|
||||||
rootChild.getChildren().add(new ScopeDescriptor(vre.name, vre.scope));
|
rootChild.getChildren().add(new ScopeDescriptor(vre.name, vre.scope));
|
||||||
rootChildren.add(rootChild);
|
rootChildren.add(rootChild);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rootChildren;
|
return rootChildren;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
package org.gcube.portlets.user.accountingdashboard.server.is;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlAccessType;
|
||||||
|
import javax.xml.bind.annotation.XmlAccessorType;
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Giancarlo Panichi
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
@XmlRootElement(name = "config")
|
||||||
|
@XmlAccessorType(XmlAccessType.FIELD)
|
||||||
|
public class AccountingDashboardConfigJAXB {
|
||||||
|
|
||||||
|
@XmlElement
|
||||||
|
private boolean enabledInfraNode;
|
||||||
|
|
||||||
|
@XmlElement
|
||||||
|
private InfraNodeJAXB baseInfraNode;
|
||||||
|
|
||||||
|
public boolean isEnabledInfraNode() {
|
||||||
|
return enabledInfraNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnabledInfraNode(boolean enabledInfraNode) {
|
||||||
|
this.enabledInfraNode = enabledInfraNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InfraNodeJAXB getBaseInfraNode() {
|
||||||
|
return baseInfraNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBaseInfraNode(InfraNodeJAXB baseInfraNode) {
|
||||||
|
this.baseInfraNode = baseInfraNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "AccountingDashboardConfigJAXB [enabledInfraNode=" + enabledInfraNode + ", baseInfraNode="
|
||||||
|
+ baseInfraNode + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,103 @@
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,94 @@
|
||||||
|
package org.gcube.portlets.user.accountingdashboard.server.is;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.gcube.common.resources.gcore.GenericResource;
|
||||||
|
import org.gcube.common.resources.gcore.ScopeGroup;
|
||||||
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
|
import org.gcube.portlets.user.accountingdashboard.shared.Constants;
|
||||||
|
import org.gcube.portlets.user.accountingdashboard.shared.exception.ServiceException;
|
||||||
|
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||||
|
import org.gcube.resources.discovery.client.impl.JAXBParser;
|
||||||
|
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||||
|
import org.gcube.resources.discovery.icclient.ICFactory;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Giancarlo Panichi
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class InformationSystemUtils {
|
||||||
|
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(InformationSystemUtils.class);
|
||||||
|
|
||||||
|
public static AccountingDashboardConfigJAXB retrieveAccountingDashboardConfig(String scope) throws ServiceException {
|
||||||
|
try {
|
||||||
|
|
||||||
|
if (scope == null || scope.length() == 0)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
ScopeProvider.instance.set(scope);
|
||||||
|
logger.debug("Retrieve Infra Node configuration in scope: " + scope);
|
||||||
|
|
||||||
|
SimpleQuery query = ICFactory.queryFor(GenericResource.class);
|
||||||
|
query.addCondition(
|
||||||
|
"$resource/Profile/SecondaryType/text() eq '" + Constants.ACCOUNTING__DASHBOARD_CATEGORY + "'")
|
||||||
|
.addCondition("$resource/Profile/Name/text() eq '" + Constants.ACCOUNTING_DASHBOARD_NAME + "'")
|
||||||
|
.setResult("$resource");
|
||||||
|
|
||||||
|
DiscoveryClient<GenericResource> client = ICFactory.clientFor(GenericResource.class);
|
||||||
|
List<GenericResource> accountingResources = client.submit(query);
|
||||||
|
logger.debug("Resources: " + accountingResources);
|
||||||
|
|
||||||
|
AccountingDashboardConfigJAXB accountingDashboardConfigJAXB = null;
|
||||||
|
|
||||||
|
for (GenericResource genericResource : accountingResources) {
|
||||||
|
if (genericResource.scopes() != null) {
|
||||||
|
ScopeGroup<String> scopes = genericResource.scopes();
|
||||||
|
Iterator<String> iterator = scopes.iterator();
|
||||||
|
String scopeFound = null;
|
||||||
|
boolean found = false;
|
||||||
|
while (iterator.hasNext() && !found) {
|
||||||
|
scopeFound = iterator.next();
|
||||||
|
if (scopeFound.compareTo(scope) == 0) {
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (found) {
|
||||||
|
try {
|
||||||
|
JAXBParser<AccountingDashboardConfigJAXB> parser = new JAXBParser<AccountingDashboardConfigJAXB>(AccountingDashboardConfigJAXB.class);
|
||||||
|
logger.debug("Body: " + genericResource.profile().bodyAsString());
|
||||||
|
accountingDashboardConfigJAXB = (AccountingDashboardConfigJAXB) parser.parse(genericResource.profile().bodyAsString());
|
||||||
|
logger.debug("Nodes: " + accountingDashboardConfigJAXB);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
String error = "Error in discovery Accounting Dashboard config in scope "
|
||||||
|
+ scope + ". " + "Resource parsing failed!";
|
||||||
|
logger.error(error);
|
||||||
|
logger.error(
|
||||||
|
"Error {resource=" + genericResource + ", error=" + e.getLocalizedMessage() + "}");
|
||||||
|
logger.error(e.getLocalizedMessage(), e);
|
||||||
|
throw new ServiceException(error, e);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return accountingDashboardConfigJAXB;
|
||||||
|
|
||||||
|
} catch (ServiceException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (Throwable e) {
|
||||||
|
String error = "Error in discovery Accounting Dashboard config in scope: " + scope;
|
||||||
|
logger.error(error,e);
|
||||||
|
throw new ServiceException(error, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,72 @@
|
||||||
|
package org.gcube.portlets.user.accountingdashboard.server.is;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlAccessType;
|
||||||
|
import javax.xml.bind.annotation.XmlAccessorType;
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||||
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Giancarlo Panichi
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
@XmlRootElement(name = "node")
|
||||||
|
@XmlAccessorType(XmlAccessType.FIELD)
|
||||||
|
public class InfraNodeJAXB {
|
||||||
|
@XmlElement
|
||||||
|
private String scope;
|
||||||
|
|
||||||
|
@XmlElement
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@XmlElement(name = "description", required = false)
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
@XmlElementWrapper(name = "children", required = false)
|
||||||
|
@XmlElement(name = "node", required = false)
|
||||||
|
private List<InfraNodeJAXB> children;
|
||||||
|
|
||||||
|
public String getScope() {
|
||||||
|
return scope;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScope(String scope) {
|
||||||
|
this.scope = scope;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<InfraNodeJAXB> getChildren() {
|
||||||
|
return children;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChildren(List<InfraNodeJAXB> children) {
|
||||||
|
this.children = children;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "InfraNodeJAXB [scope=" + scope + ", name=" + name + ", description=" + description + ", children="
|
||||||
|
+ children + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -29,9 +29,11 @@ public class Constants {
|
||||||
public static final String CURR_GROUP_ID = "CURR_GROUP_ID";
|
public static final String CURR_GROUP_ID = "CURR_GROUP_ID";
|
||||||
public static final String CURR_USER_ID = "CURR_USER_ID";
|
public static final String CURR_USER_ID = "CURR_USER_ID";
|
||||||
|
|
||||||
|
|
||||||
// Service
|
// Service
|
||||||
public static final int CLIENT_MONITOR_PERIODMILLIS = 2000;
|
public static final int CLIENT_MONITOR_PERIODMILLIS = 2000;
|
||||||
|
|
||||||
|
// IS Resource
|
||||||
|
public static final String ACCOUNTING_DASHBOARD_NAME = "AccountingDashboard";
|
||||||
|
public static final String ACCOUNTING__DASHBOARD_CATEGORY = "AccountingProfile";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
package org.gcube.portlets.user.accountingdashboard.shared.is;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class InfraNode implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 2238683459962419017L;
|
||||||
|
private String scope;
|
||||||
|
private String name;
|
||||||
|
private String description;
|
||||||
|
private ArrayList<InfraNode> children;
|
||||||
|
|
||||||
|
public InfraNode() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public InfraNode(String scope, String name) {
|
||||||
|
super();
|
||||||
|
this.scope = scope;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InfraNode(String scope, String name, String description) {
|
||||||
|
super();
|
||||||
|
this.scope = scope;
|
||||||
|
this.name = name;
|
||||||
|
this.description=description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InfraNode(String scope, String name, String description, ArrayList<InfraNode> children) {
|
||||||
|
super();
|
||||||
|
this.scope = scope;
|
||||||
|
this.name = name;
|
||||||
|
this.description = description;
|
||||||
|
this.children = children;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getScope() {
|
||||||
|
return scope;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScope(String scope) {
|
||||||
|
this.scope = scope;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<InfraNode> getChildren() {
|
||||||
|
return children;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChildren(ArrayList<InfraNode> children) {
|
||||||
|
this.children = children;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "InfraNode [scope=" + scope + ", name=" + name + ", description=" + description + ", children="
|
||||||
|
+ children + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,112 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.portlets.user.accountingdashboard;
|
||||||
|
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import javax.xml.bind.JAXBContext;
|
||||||
|
import javax.xml.bind.Marshaller;
|
||||||
|
|
||||||
|
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.InfraNodeJAXB;
|
||||||
|
import org.gcube.portlets.user.accountingdashboard.shared.Constants;
|
||||||
|
import org.gcube.portlets.user.accountingdashboard.shared.is.InfraNode;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Giancarlo Panichi
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class ISTest extends TestCase {
|
||||||
|
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(ISTest.class);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAccountingDashboardResource() {
|
||||||
|
if (Constants.TEST_ENABLE) {
|
||||||
|
logger.debug("Test Enabled");
|
||||||
|
|
||||||
|
try {
|
||||||
|
logger.debug("Scope: " + Constants.DEFAULT_SCOPE);
|
||||||
|
InfraNode infraNode = BuildInfraNode.build(Constants.DEFAULT_SCOPE);
|
||||||
|
logger.debug("Infra Node: " + infraNode);
|
||||||
|
assertTrue(true);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error(e.getLocalizedMessage(), e);
|
||||||
|
assertTrue("Error searching the resource!", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
logger.debug("Test Disabled");
|
||||||
|
assertTrue(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInfraNodeMarshaller() {
|
||||||
|
if (Constants.TEST_ENABLE) {
|
||||||
|
logger.debug("Test Enabled");
|
||||||
|
|
||||||
|
try {
|
||||||
|
InfraNodeJAXB infraNodeCoreServices = new InfraNodeJAXB();
|
||||||
|
infraNodeCoreServices.setScope("CoreServices");
|
||||||
|
infraNodeCoreServices.setName("Core Services");
|
||||||
|
|
||||||
|
InfraNodeJAXB infraNodeCatalogue = new InfraNodeJAXB();
|
||||||
|
infraNodeCatalogue.setScope("CoreServices/Catalogue");
|
||||||
|
infraNodeCatalogue.setName("Catalogue");
|
||||||
|
|
||||||
|
InfraNodeJAXB infraNodeWorkspace = new InfraNodeJAXB();
|
||||||
|
infraNodeWorkspace.setScope("CoreServices/Workspace");
|
||||||
|
infraNodeWorkspace.setName("Workspace");
|
||||||
|
|
||||||
|
InfraNodeJAXB infraNodeMessages = new InfraNodeJAXB();
|
||||||
|
infraNodeMessages.setScope("CoreServices/Messages");
|
||||||
|
infraNodeMessages.setName("Messages");
|
||||||
|
|
||||||
|
ArrayList<InfraNodeJAXB> children = new ArrayList<>();
|
||||||
|
children.add(infraNodeCatalogue);
|
||||||
|
children.add(infraNodeWorkspace);
|
||||||
|
children.add(infraNodeMessages);
|
||||||
|
infraNodeCoreServices.setChildren(children);
|
||||||
|
|
||||||
|
AccountingDashboardConfigJAXB config=new AccountingDashboardConfigJAXB();
|
||||||
|
config.setEnabledInfraNode(true);
|
||||||
|
config.setBaseInfraNode(infraNodeCoreServices);
|
||||||
|
|
||||||
|
JAXBContext jaxbContext = JAXBContext.newInstance(AccountingDashboardConfigJAXB.class);
|
||||||
|
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
|
||||||
|
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
|
||||||
|
|
||||||
|
// Print XML String to Console
|
||||||
|
StringWriter sw = new StringWriter();
|
||||||
|
|
||||||
|
// Write XML to StringWriter
|
||||||
|
jaxbMarshaller.marshal(config, sw);
|
||||||
|
|
||||||
|
// Verify XML Content
|
||||||
|
String xmlContent = sw.toString();
|
||||||
|
logger.debug(xmlContent);
|
||||||
|
assertTrue(true);
|
||||||
|
|
||||||
|
} catch (Throwable e) {
|
||||||
|
logger.error(e.getLocalizedMessage(), e);
|
||||||
|
assertTrue("Error in InfraNode Marshal!", false);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logger.debug("Test Disabled");
|
||||||
|
assertTrue(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue