2018-05-11 17:50:37 +02:00
|
|
|
package org.gcube.dataharvest.harvester;
|
|
|
|
|
|
|
|
import java.text.ParseException;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.gcube.common.authorization.client.Constants;
|
|
|
|
import org.gcube.common.authorization.library.AuthorizationEntry;
|
|
|
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
2018-05-16 15:08:25 +02:00
|
|
|
import org.gcube.dataharvest.datamodel.Harvest;
|
2018-05-11 17:50:37 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2018-05-18 12:00:10 +02:00
|
|
|
public abstract class BasicHarvester {
|
2018-05-17 17:21:08 +02:00
|
|
|
|
2018-05-11 17:50:37 +02:00
|
|
|
private static Logger logger = LoggerFactory.getLogger(BasicHarvester.class);
|
2018-05-17 17:21:08 +02:00
|
|
|
|
|
|
|
public Date startDate;
|
|
|
|
public Date endDate;
|
|
|
|
|
2018-05-18 12:00:10 +02:00
|
|
|
|
2018-05-11 17:50:37 +02:00
|
|
|
|
|
|
|
public BasicHarvester(Date start, Date end) throws ParseException {
|
|
|
|
startDate = start;
|
|
|
|
endDate = end;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getCurrentContext(String token) throws Exception{
|
|
|
|
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
|
|
|
|
String context = authorizationEntry.getContext();
|
|
|
|
logger.info("Context of token {} is {}", token, context);
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void setContext(String token) throws Exception{
|
|
|
|
SecurityTokenProvider.instance.set(token);
|
|
|
|
ScopeProvider.instance.set(getCurrentContext(token));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getCurrentContext() throws Exception {
|
|
|
|
String token = SecurityTokenProvider.instance.get();
|
|
|
|
return getCurrentContext(token);
|
|
|
|
}
|
|
|
|
|
2018-05-18 12:00:10 +02:00
|
|
|
public abstract List<Harvest> getData() throws Exception;
|
2018-05-11 17:50:37 +02:00
|
|
|
|
|
|
|
}
|