Code redesign

Refs #11756: Refactor DataHArvesterPlugin to support scheduled execution from smart-executor 

Task-Url: https://support.d4science.org/issues/11756

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-dashboard-harvester-se-plugin@167646 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2018-05-21 14:23:14 +00:00
parent 559251fe2f
commit 72f29300c9
2 changed files with 33 additions and 10 deletions

View File

@ -61,7 +61,7 @@ public abstract class SoBigDataHarvester extends BasicHarvester {
return res.get(0);
}
protected SortedSet<String> getExcludedContexts() {
public SortedSet<String> getExcludedContexts() {
SortedSet<String> excludedContexts = new TreeSet<>();
GenericResource genericResource = getGenericResource();
@ -89,15 +89,36 @@ public abstract class SoBigDataHarvester extends BasicHarvester {
logger.info("The body of the {} does not contains any information to filter contexts.", GenericResource.class.getSimpleName());
}
Node node = nodeList.item(0).getChildNodes().item(1);
NodeList contexts = node.getChildNodes();
Element classNameElement = null;
for(int c=0; c<nodeList.getLength(); c++) {
Node node = nodeList.item(c);
if(node.getNodeType() == Node.ELEMENT_NODE) {
classNameElement = (Element) node;
}
}
for(int i=1; i<contexts.getLength()-1; i++){
Node context = contexts.item(i);
NodeList nList = context.getChildNodes();
if(nList.item(0)!=null) {
String contextToExclude = nList.item(0).getNodeValue();
excludedContexts.add(contextToExclude);
Element vresElement = null;
NodeList vresNodeList = classNameElement.getElementsByTagName("vres");
for(int c=0; c<vresNodeList.getLength(); c++) {
Node node = vresNodeList.item(c);
if(node.getNodeType() == Node.ELEMENT_NODE) {
vresElement = (Element) node;
}
}
NodeList vreNodeList = vresElement.getElementsByTagName("vre");
for(int c=0; c<vreNodeList.getLength(); c++) {
Node node = vreNodeList.item(c);
if(node.getNodeType() == Node.ELEMENT_NODE) {
Element vreElement = (Element) node;
NodeList nl = vreElement.getChildNodes();
for(int i=0; i<nl.getLength(); i++) {
Node n = nl.item(i);
if(n.getNodeType() == Node.TEXT_NODE) {
excludedContexts.add(n.getNodeValue());
}
}
}
}

View File

@ -137,9 +137,11 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
SortedSet<String> contexts = contextAuthorization.getContexts();
ResourceCatalogueHarvester resourceCatalogueHarvester = new ResourceCatalogueHarvester(start, end, contexts);
SortedSet<String> excludedContexts = resourceCatalogueHarvester.getExcludedContexts();
logger.info("Excluded contexts {}", excludedContexts);
SortedSet<String> validContexts = resourceCatalogueHarvester.getFilteredContexts();
logger.info("{}", validContexts);
logger.info("Valid Contexts {}", validContexts);
} catch(Exception e) {
logger.error("", e);