accounting-dashboard-harves.../src/main/java/org/gcube/dataharvest/harvester/sobigdata/SoBigDataHarvester.java

70 lines
2.1 KiB
Java

package org.gcube.dataharvest.harvester.sobigdata;
import java.text.ParseException;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import org.gcube.common.resources.gcore.GenericResource;
import org.gcube.dataharvest.harvester.BasicHarvester;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.gcube.resources.discovery.icclient.ICFactory;
public abstract class SoBigDataHarvester extends BasicHarvester {
public static final String SO_BIG_DATA_CONTEXT = "/d4science.research-infrastructures.eu/SoBigData";
protected SortedSet<String> contexts;
public SoBigDataHarvester(Date start, Date end) throws ParseException {
super(start, end);
}
public SortedSet<String> getContexts() {
return contexts;
}
public void setContexts(SortedSet<String> contexts) {
// Adding trailing slash to SO_BIG_DATA_CONTEXT to avoid to get VO
this.contexts = getSoBigDataContexts(contexts, SO_BIG_DATA_CONTEXT + "/");
}
public static String SECONDARY_TYPE_FORMAT = "$resource/Profile/SecondaryType/text() eq '%1s'";
public static String NAME_FORMAT = "$resource/Profile/Name/text() eq '%1s'";
public static String SECONDARY_TYPE = "ExcludingVREs";
public static String NAME = "AccountingHarvesters";
protected SimpleQuery getFilteringGenericResource() {
return ICFactory.queryFor(GenericResource.class)
.addCondition(String.format(SECONDARY_TYPE_FORMAT, SECONDARY_TYPE))
.addCondition(String.format(NAME_FORMAT, NAME));
}
protected void getExcludedContexts(){
SimpleQuery simpleQuery = getFilteringGenericResource();
List<String> res = ICFactory.client().submit(simpleQuery);
}
protected boolean filterContext(String context) {
return false;
}
protected SortedSet<String> getSoBigDataContexts(Set<String> contexts, String base){
SortedSet<String> filteredContext = new TreeSet<>();
for(String context : contexts) {
if(context.startsWith(SO_BIG_DATA_CONTEXT)){
if(!filterContext(context)) {
filteredContext.add(context);
}
}
}
return filteredContext;
}
}