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-18 12:00:35 +02:00
|
|
|
import org.gcube.dataharvest.datamodel.HarvestedData;
|
2018-05-28 15:22:59 +02:00
|
|
|
import org.gcube.dataharvest.utils.DateUtils;
|
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
|
|
|
|
2018-05-28 15:22:59 +02:00
|
|
|
public Date start;
|
|
|
|
public Date end;
|
2018-05-17 17:21:08 +02:00
|
|
|
|
2018-05-11 17:50:37 +02:00
|
|
|
public BasicHarvester(Date start, Date end) throws ParseException {
|
2018-05-28 15:22:59 +02:00
|
|
|
this.start = start;
|
|
|
|
this.end = end;
|
|
|
|
|
|
|
|
logger.debug("Creating {} for the period {} {} ", this.getClass().getSimpleName(), DateUtils.format(start), DateUtils.format(end));
|
2018-05-11 17:50:37 +02:00
|
|
|
}
|
2018-05-18 14:17:54 +02:00
|
|
|
|
|
|
|
public static String getCurrentContext(String token) throws Exception {
|
2018-05-11 17:50:37 +02:00
|
|
|
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
|
|
|
|
String context = authorizationEntry.getContext();
|
|
|
|
logger.info("Context of token {} is {}", token, context);
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
2018-05-18 14:17:54 +02:00
|
|
|
public static void setContext(String token) throws Exception {
|
2018-05-11 17:50:37 +02:00
|
|
|
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:35 +02:00
|
|
|
public abstract List<HarvestedData> getData() throws Exception;
|
2018-05-11 17:50:37 +02:00
|
|
|
|
|
|
|
}
|