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@167596 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2018-05-18 12:17:54 +00:00
parent a91ece8a0f
commit 9db4794c16
23 changed files with 239 additions and 589 deletions

View File

@ -24,6 +24,10 @@ import org.gcube.vremanagement.executor.plugin.Plugin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Eric Perrone (ISTI - CNR)
* @author Luca Frosini (ISTI - CNR)
*/
public class AccountingDataHarvesterPlugin extends Plugin<DataHarvestPluginDeclaration> {
private static Logger logger = LoggerFactory.getLogger(AccountingDataHarvesterPlugin.class);
@ -70,15 +74,6 @@ public class AccountingDataHarvesterPlugin extends Plugin<DataHarvestPluginDecla
}
private static final InheritableThreadLocal<ContextAuthorization> contextAuthorization = new InheritableThreadLocal<ContextAuthorization>() {
@Override
protected ContextAuthorization initialValue() {
return null;
}
};
/** {@inheritDoc} */
@Override
public void launch(Map<String,Object> inputs) throws Exception {

View File

@ -9,9 +9,14 @@ import org.gcube.vremanagement.executor.plugin.PluginDeclaration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Eric Perrone (ISTI - CNR)
* @author Luca Frosini (ISTI - CNR)
*/
public class DataHarvestPluginDeclaration implements PluginDeclaration {
private static Logger logger = LoggerFactory.getLogger(DataHarvestPluginDeclaration.class);
public static final String NAME = "AccountingDataHarvester";
public static final String DESCRIPTION = "Data Harvest for Accounting Summary Dashboard";
public static final String VERSION = "1.0.0";

View File

@ -15,6 +15,10 @@ import org.postgresql.util.PSQLException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Eric Perrone (ISTI - CNR)
* @author Luca Frosini (ISTI - CNR)
*/
public class Dao {
private Connection conn = null;
private static Logger logger = LoggerFactory.getLogger(Dao.class);

View File

@ -4,7 +4,6 @@ package org.gcube.dataharvest.dao;
* @author Eric Perrone (ISTI - CNR)
* @author Luca Frosini (ISTI - CNR)
*/
public class DatabaseConnectionData {
protected String uri;

View File

@ -7,6 +7,10 @@ import org.gcube.dataharvest.datamodel.HarvestedData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Eric Perrone (ISTI - CNR)
* @author Luca Frosini (ISTI - CNR)
*/
public class DatabaseManager {
private static Logger logger = LoggerFactory.getLogger(DatabaseManager.class);

View File

@ -39,8 +39,9 @@ public class DatabaseParameterRetriever {
}
protected void checkParameter(String parameter, String parameterName, boolean localDB) throws DaoException {
if(parameter ==null || parameter.isEmpty()) {
throw new DaoException("DB " + parameterName + " cannot be null nor empty. Please check your " + (localDB ? "local configuration." : "ServiceEndpoint"));
if(parameter == null || parameter.isEmpty()) {
throw new DaoException("DB " + parameterName + " cannot be null nor empty. Please check your "
+ (localDB ? "local configuration." : "ServiceEndpoint"));
}
}
@ -58,7 +59,7 @@ public class DatabaseParameterRetriever {
uri = properties.getProperty(DB_URI);
username = properties.getProperty(DB_USERNAME);
password = properties.getProperty(DB_PASSWORD);
}else {
} else {
try {
String className = this.getClass().getSimpleName();
@ -66,7 +67,8 @@ public class DatabaseParameterRetriever {
query.addCondition(
String.format("$resource/Profile/Category/text() eq '%s'", SERVICE_ENDPOINT_CATEGORY));
query.addCondition(String.format("$resource/Profile/Name/text() eq '%s'", SERVICE_ENDPOINT_NAME));
query.addCondition(String.format("$resource/Profile/AccessPoint/Interface/Endpoint/@EntryName eq '%s'", className));
query.addCondition(String.format("$resource/Profile/AccessPoint/Interface/Endpoint/@EntryName eq '%s'",
className));
DiscoveryClient<ServiceEndpoint> client = ICFactory.clientFor(ServiceEndpoint.class);
List<ServiceEndpoint> serviceEndpoints = client.submit(query);

View File

@ -3,7 +3,11 @@ package org.gcube.dataharvest.datamodel;
import java.util.Date;
import java.io.Serializable;
public class HarvestedData implements Serializable {
/**
* @author Eric Perrone (ISTI - CNR)
* @author Luca Frosini (ISTI - CNR)
*/
public class HarvestedData implements Serializable {
/**
* Generated Serial Version UID
@ -46,7 +50,6 @@ public class HarvestedData implements Serializable {
this.measure = measure;
}
public void setDataType(int dataType) {
this.dataType = dataType;
}

View File

@ -19,22 +19,19 @@ public abstract class BasicHarvester {
public Date startDate;
public Date endDate;
public BasicHarvester(Date start, Date end) throws ParseException {
startDate = start;
endDate = end;
}
public static String getCurrentContext(String token) throws Exception{
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{
public static void setContext(String token) throws Exception {
SecurityTokenProvider.instance.set(token);
ScopeProvider.instance.set(getCurrentContext(token));
}

View File

@ -15,6 +15,10 @@ import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Eric Perrone (ISTI - CNR)
* @author Luca Frosini (ISTI - CNR)
*/
public class SocialHarvester extends BasicHarvester {
private static Logger logger = LoggerFactory.getLogger(SocialHarvester.class);

View File

@ -14,9 +14,12 @@ import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Eric Perrone (ISTI - CNR)
* @author Luca Frosini (ISTI - CNR)
*/
public class VreUsersHarvester extends BasicHarvester {
private static Logger logger = LoggerFactory.getLogger(VreUsersHarvester.class);
public VreUsersHarvester(Date start, Date end) throws ParseException {
@ -33,8 +36,8 @@ public class VreUsersHarvester extends BasicHarvester {
ArrayList<HarvestedData> data = new ArrayList<HarvestedData>();
data.add(harvest);
return data;
} catch (Exception e) {
logger.error("Error Haversting Context Users for context {}", context, e);
} catch(Exception e) {
logger.error("Error Haversting Context Users for context {}", context, e);
throw e;
}
}
@ -46,7 +49,7 @@ public class VreUsersHarvester extends BasicHarvester {
String token = SecurityTokenProvider.instance.get();
JSONObject jsonObject = new JSONObject(Utils.getJson(url + token));
Boolean success = (Boolean) jsonObject.get("success");
if (success == false) {
if(success == false) {
String message = "get-all-usernames returned an error. token: " + token;
logger.error(message);
throw new IOException(message);

View File

@ -22,6 +22,10 @@ import org.gcube.dataharvest.utils.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Eric Perrone (ISTI - CNR)
* @author Luca Frosini (ISTI - CNR)
*/
public class DataMethodDownloadHarvester extends BasicHarvester {
private static Logger logger = LoggerFactory.getLogger(DataMethodDownloadHarvester.class);
@ -45,6 +49,7 @@ public class DataMethodDownloadHarvester extends BasicHarvester {
String user = getVREName(context) + "-Manager";
@SuppressWarnings("deprecation")
Home home = manager.getHome(user);
JCRWorkspace ws = (JCRWorkspace) home.getWorkspace();
@ -62,43 +67,43 @@ public class DataMethodDownloadHarvester extends BasicHarvester {
logger.debug(harvest.toString());
return data;
} catch (Exception e) {
} catch(Exception e) {
logger.error("Error Harvesting Data Methods Download for context {}", context, e);
throw e;
}
}
private void getStats(WorkspaceItem root, Date start, Date end) throws InternalErrorException {
List<? extends WorkspaceItem> children;
if (root.isFolder()) {
if(root.isFolder()) {
children = root.getChildren();
for (WorkspaceItem child : children)
for(WorkspaceItem child : children)
getStats(child, start, end);
} else {
try {
List<AccountingEntry> accounting = root.getAccounting();
for (AccountingEntry entry : accounting) {
for(AccountingEntry entry : accounting) {
switch (entry.getEntryType()) {
case CREATE:
case UPDATE:
case READ:
Calendar calendar = entry.getDate();
if (calendar.after(Utils.dateToCalendar(start)) && calendar.before(Utils.dateToCalendar(end))) {
count++;
}
switch(entry.getEntryType()) {
case CREATE:
case UPDATE:
case READ:
Calendar calendar = entry.getDate();
if(calendar.after(Utils.dateToCalendar(start))
&& calendar.before(Utils.dateToCalendar(end))) {
count++;
}
break;
break;
default:
break;
default:
break;
}
}
} catch (Exception e) {
} catch(Exception e) {
logger.error("DataMethodDownloadHarvester: " + e.getLocalizedMessage());
throw new InternalErrorException(e.getLocalizedMessage());
}
@ -109,7 +114,7 @@ public class DataMethodDownloadHarvester extends BasicHarvester {
Validate.notNull(vre, "scope must be not null");
String newName;
if (vre.startsWith(JCRRepository.PATH_SEPARATOR))
if(vre.startsWith(JCRRepository.PATH_SEPARATOR))
newName = vre.replace(JCRRepository.PATH_SEPARATOR, "-").substring(1);
else
newName = vre.replace(JCRRepository.PATH_SEPARATOR, "-");

View File

@ -22,6 +22,10 @@ import org.gcube.dataharvest.harvester.BasicHarvester;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Eric Perrone (ISTI - CNR)
* @author Luca Frosini (ISTI - CNR)
*/
public class MethodInvocationHarvester extends BasicHarvester {
private static Logger logger = LoggerFactory.getLogger(MethodInvocationHarvester.class);
@ -50,15 +54,15 @@ public class MethodInvocationHarvester extends BasicHarvester {
contexts.add("/d4science.research-infrastructures.eu/SoBigData/TagMe");
logger.debug("MethodInvocationHarvester::getData()::getContextTimeSeries");
SortedMap<Filter, SortedMap<Calendar, Info>> result = accountingPersistenceQuery.getContextTimeSeries(
SortedMap<Filter,SortedMap<Calendar,Info>> result = accountingPersistenceQuery.getContextTimeSeries(
AggregatedServiceUsageRecord.class, temporalConstraint, filters, contexts, true);
if (result == null) {
if(result == null) {
logger.error("No data found.");
} else {
Set<Filter> ks = result.keySet();
if (ks != null) {
if(ks != null) {
Iterator<Filter> ksi = ks.iterator();
while (ksi.hasNext()) {
while(ksi.hasNext()) {
// System.out.println("" + ksi.next().toString());
logger.debug("Filter: " + ksi.next().toString());
}
@ -66,10 +70,10 @@ public class MethodInvocationHarvester extends BasicHarvester {
}
return data;
} catch (Exception x) {
} catch(Exception x) {
StackTraceElement[] ste = x.getStackTrace();
String errorMessage = "MethodInvocationHarvester: " + x.getLocalizedMessage();
for (StackTraceElement s : ste) {
for(StackTraceElement s : ste) {
errorMessage += "\n" + s.toString();
}
logger.error(errorMessage);

View File

@ -16,6 +16,10 @@ import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Eric Perrone (ISTI - CNR)
* @author Luca Frosini (ISTI - CNR)
*/
public class ResourceCatalogueHarvester extends BasicHarvester {
private static Logger logger = LoggerFactory.getLogger(ResourceCatalogueHarvester.class);
@ -91,8 +95,8 @@ public class ResourceCatalogueHarvester extends BasicHarvester {
JSONObject response = jsonObject.getJSONObject("response");
int numFound = response.getInt("numFound");
HarvestedData h = new HarvestedData(dataType, "/d4science.research-infrastructures.eu/SoBigData/ResourceCatalogue",
numFound);
HarvestedData h = new HarvestedData(dataType,
"/d4science.research-infrastructures.eu/SoBigData/ResourceCatalogue", numFound);
logger.debug(h.toString());
data.add(h);
if(numFound > 0) {

View File

@ -20,6 +20,9 @@ import org.gcube.resourcemanagement.support.server.managers.scope.ScopeManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class ContextAuthorization {
private static Logger logger = LoggerFactory.getLogger(ContextAuthorization.class);
@ -36,15 +39,12 @@ public class ContextAuthorization {
/**
* Contains Context full name as key and Token as Value
*/
protected Map<String, String> contextToToken;
protected Map<String,String> contextToToken;
/**
* Contains Token as key and Context full name as Value
*/
protected Map<String, String> tokenToContext;
protected Map<String,String> tokenToContext;
/**
* Contains Properties used to generate tokens
@ -57,15 +57,16 @@ public class ContextAuthorization {
public File getVOFile() {
try {
String voFileName = AccountingDataHarvesterPlugin.getProperties().get().getProperty(VO_FILE, DEFAULT_VO_FILENAME);
URL url = ContextAuthorization.class.getClassLoader().getResource(voFileName);
String voFileName = AccountingDataHarvesterPlugin.getProperties().get().getProperty(VO_FILE,
DEFAULT_VO_FILENAME);
URL url = ContextAuthorization.class.getClassLoader().getResource(voFileName);
File voFile = new File(url.toURI());
logger.trace("VO file is {}", voFile);
if(!voFile.exists()) {
throw new Exception("No VO file found. Unable to continue without it");
}
return voFile;
}catch (Exception e) {
} catch(Exception e) {
throw new RuntimeException(e);
}
}
@ -78,23 +79,25 @@ public class ContextAuthorization {
Properties properties = AccountingDataHarvesterPlugin.getProperties().get();
LinkedHashMap<String, ScopeBean> map = ScopeManager.readScopes(getVOFile().getAbsolutePath());
LinkedHashMap<String,ScopeBean> map = ScopeManager.readScopes(getVOFile().getAbsolutePath());
for(String scope : map.keySet()) {
try {
String context = map.get(scope).toString();
System.out.println("Going to generate Token for Context " + context);
logger.info("Going to generate Token for Context {}", context);
UserInfo userInfo = new UserInfo(properties.getProperty(USERNAME, DEFAULT_USERNAME), new ArrayList<>());
UserInfo userInfo = new UserInfo(properties.getProperty(USERNAME, DEFAULT_USERNAME),
new ArrayList<>());
String userToken = authorizationService().generateUserToken(userInfo, context);
SecurityTokenProvider.instance.set(userToken);
String generatedToken = authorizationService().generateExternalServiceToken(properties.getProperty(SERVICE_NAME, DEFAULT_SERVICE_NAME));
String generatedToken = authorizationService()
.generateExternalServiceToken(properties.getProperty(SERVICE_NAME, DEFAULT_SERVICE_NAME));
logger.trace("Token for Context {} is {}", context, generatedToken);
contextToToken.put(context, generatedToken);
tokenToContext.put(generatedToken, context);
}catch (Exception e) {
} catch(Exception e) {
logger.error("Error while elaborating {}", scope, e);
throw e;
} finally {
@ -102,7 +105,7 @@ public class ContextAuthorization {
}
}
} catch (Exception ex) {
} catch(Exception ex) {
throw ex;
} finally {
SecurityTokenProvider.instance.set(initialToken);
@ -117,10 +120,8 @@ public class ContextAuthorization {
return tokenToContext.get(token);
}
public SortedSet<String> getContexts(){
public SortedSet<String> getContexts() {
return new TreeSet<String>(contextToToken.keySet());
}
}

View File

@ -9,6 +9,9 @@ import java.util.TimeZone;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class DateUtils {
private static Logger logger = LoggerFactory.getLogger(DateUtils.class);
@ -30,13 +33,13 @@ public class DateUtils {
UTC_DATE_FORMAT = getUTCDateFormat(UTC_DATE_FORMAT_PATTERN);
}
public static DateFormat getUTCDateFormat(String pattern){
public static DateFormat getUTCDateFormat(String pattern) {
DateFormat dateFormat = new SimpleDateFormat(pattern);
dateFormat.setTimeZone(UTC_TIMEZONE);
return dateFormat;
}
public static Calendar getUTCCalendarInstance(){
public static Calendar getUTCCalendarInstance() {
return Calendar.getInstance(UTC_TIMEZONE);
}
@ -47,12 +50,12 @@ public class DateUtils {
case YEARLY:
now.add(Calendar.YEAR, -1);
now.set(Calendar.MONTH, Calendar.JANUARY);
now.set(Calendar.DAY_OF_MONTH,1);
now.set(Calendar.DAY_OF_MONTH, 1);
break;
case MONTHLY:
now.add(Calendar.MONTH, -1);
now.set(Calendar.DAY_OF_MONTH,1);
now.set(Calendar.DAY_OF_MONTH, 1);
break;
case DAILY:
@ -72,8 +75,7 @@ public class DateUtils {
}
public static Calendar getStartCalendar(int year, int month, int day){
public static Calendar getStartCalendar(int year, int month, int day) {
Calendar aggregationStartCalendar = getUTCCalendarInstance();
aggregationStartCalendar.set(Calendar.YEAR, year);
aggregationStartCalendar.set(Calendar.MONTH, month);

View File

@ -4,7 +4,6 @@ import java.text.DateFormat;
import java.util.Calendar;
/**
* @author Alessandro Pieve (ISTI - CNR)
* @author Luca Frosini (ISTI - CNR)
*/
public enum MeasureType {

View File

@ -19,6 +19,10 @@ import org.gcube.common.scope.api.ScopeProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Eric Perrone (ISTI - CNR)
* @author Luca Frosini (ISTI - CNR)
*/
public class Utils {
private static Logger logger = LoggerFactory.getLogger(Utils.class);

View File

@ -6,12 +6,12 @@ import java.util.Map;
import org.gcube.dataharvest.utils.DateUtils;
import org.gcube.dataharvest.utils.MeasureType;
import org.gcube.dataharvest.utils.ScopedTest;
import org.gcube.dataharvest.utils.ContextTest;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class AccountingDataHarvesterPluginTest extends ScopedTest {
public class AccountingDataHarvesterPluginTest extends ContextTest {
private static Logger logger = LoggerFactory.getLogger(AccountingDataHarvesterPluginTest.class);

View File

@ -19,8 +19,14 @@ import org.gcube.dataharvest.harvester.sobigdata.ResourceCatalogueHarvester;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Eric Perrone (ISTI - CNR)
* @author Luca Frosini (ISTI - CNR)
*/
public class Harvester {
private static Logger logger = LoggerFactory.getLogger(Harvester.class);
public static final String PARAMETER_FROM = "from";
public static final String PARAMETER_TO = "to";
public static final String TEST = "test";
@ -38,7 +44,7 @@ public class Harvester {
//harvester.createSocialReports(list);
System.out.println("End.");
} catch (Exception e) {
} catch(Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
@ -71,10 +77,10 @@ public class Harvester {
public void runOne(BasicHarvester harvester) {
try {
List<HarvestedData> data = harvester.getData();
if (data != null) {
if(data != null) {
insertMonthlyData((Date) dateFrom, (Date) dateTo, data);
}
} catch (Exception x) {
} catch(Exception x) {
logger.error(x.getLocalizedMessage());
}
}
@ -85,7 +91,7 @@ public class Harvester {
VreUsersHarvester vreUsersHarvester = new VreUsersHarvester(dateFrom, dateTo);
List<HarvestedData> users = vreUsersHarvester.getData();
insertMonthlyData((Date) dateFrom, (Date) dateTo, users);
} catch (Exception x) {
} catch(Exception x) {
logger.error(x.getLocalizedMessage());
}
@ -95,7 +101,7 @@ public class Harvester {
ResourceCatalogueHarvester resourceCatalogueHarvester = new ResourceCatalogueHarvester(dateFrom, dateTo);
List<HarvestedData> res = resourceCatalogueHarvester.getData();
insertMonthlyData((Date) dateFrom, (Date) dateTo, res);
} catch (Exception x) {
} catch(Exception x) {
logger.error(x.getLocalizedMessage());
}
@ -104,7 +110,7 @@ public class Harvester {
DataMethodDownloadHarvester dataMethodDownloadHarvester = new DataMethodDownloadHarvester(dateFrom, dateTo);
List<HarvestedData> res = dataMethodDownloadHarvester.getData();
insertMonthlyData((Date) dateFrom, (Date) dateTo, res);
} catch (Exception x) {
} catch(Exception x) {
logger.error(x.getLocalizedMessage());
}
@ -113,7 +119,7 @@ public class Harvester {
SocialHarvester socialHarvester = new SocialHarvester(dateFrom, dateTo);
List<HarvestedData> res = socialHarvester.getData();
insertMonthlyData((Date) dateFrom, (Date) dateTo, res);
} catch (Exception x) {
} catch(Exception x) {
logger.error(x.getLocalizedMessage());
}
@ -123,7 +129,7 @@ public class Harvester {
List<HarvestedData> res = methodInvocationHarvester.getData();
logger.debug("{}", res);
// insertMonthlyData((Date) dateFrom, (Date) dateTo, res);
} catch (Exception x) {
} catch(Exception x) {
logger.error(x.getLocalizedMessage());
}
}
@ -133,13 +139,13 @@ public class Harvester {
try {
dao = dbConnect();
dao.insertMonthlyMeasure(data, from, to, false);
} catch (Exception e) {
} catch(Exception e) {
logger.error(e.getLocalizedMessage());
} finally {
if (dao != null) {
if(dao != null) {
try {
dao.disconnect();
} catch (DaoException e) {
} catch(DaoException e) {
logger.error(e.getLocalizedMessage());
}
}
@ -158,16 +164,16 @@ public class Harvester {
private void processParameterArray(String[] args) throws Exception {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
for (int i = 0; i < args.length; i++) {
if (args[i].startsWith(PARAMETER_FROM)) {
for(int i = 0; i < args.length; i++) {
if(args[i].startsWith(PARAMETER_FROM)) {
String from = getArgValue(args[i]);
dateFrom = formatter.parse(from);
System.out.println(dateFrom.toString());
} else if (args[i].startsWith(PARAMETER_TO)) {
} else if(args[i].startsWith(PARAMETER_TO)) {
String to = getArgValue(args[i]);
dateTo = formatter.parse(to);
System.out.println(dateTo.toString());
} else if (args[i].toLowerCase().startsWith(TEST)) {
} else if(args[i].toLowerCase().startsWith(TEST)) {
testMode = true;
System.out.println("Test: " + testMode);
}
@ -177,7 +183,7 @@ public class Harvester {
private String getArgValue(String arg) throws Exception {
String[] tokens = arg.split("=");
if (tokens.length != 2)
if(tokens.length != 2)
throw new Exception("Argument must be in the format 'name=value'.");
return tokens[1].trim();
}
@ -188,14 +194,14 @@ public class Harvester {
dao = dbConnect();
ArrayList<Integer> subTree = dao.getSubTree(root);
return subTree;
} catch (Exception e) {
} catch(Exception e) {
logger.error(e.getLocalizedMessage());
return null;
} finally {
if (dao != null) {
if(dao != null) {
try {
dao.disconnect();
} catch (DaoException e) {
} catch(DaoException e) {
logger.error(e.getLocalizedMessage());
}
}
@ -206,15 +212,15 @@ public class Harvester {
Dao dao = null;
try {
dao = dbConnect();
for (Integer contextId : ids)
for(Integer contextId : ids)
dao.createSocialReport(contextId, 2018);
} catch (Exception e) {
} catch(Exception e) {
logger.error(e.getLocalizedMessage());
} finally {
if (dao != null) {
if(dao != null) {
try {
dao.disconnect();
} catch (DaoException e) {
} catch(DaoException e) {
logger.error(e.getLocalizedMessage());
}
}

View File

@ -9,7 +9,10 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ContextAuthorizationTest extends ScopedTest {
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class ContextAuthorizationTest extends ContextTest {
private static Logger logger = LoggerFactory.getLogger(ContextAuthorizationTest.class);

View File

@ -7,9 +7,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.gcube.common.authorization.client.Constants;
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
import org.gcube.common.authorization.library.AuthorizationEntry;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.junit.AfterClass;
@ -19,11 +16,10 @@ import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*
*/
public class ScopedTest {
public class ContextTest {
private static final Logger logger = LoggerFactory.getLogger(ScopedTest.class);
private static final Logger logger = LoggerFactory.getLogger(ContextTest.class);
protected static final String PROPERTIES_FILENAME = "token.properties";
@ -51,13 +47,16 @@ public class ScopedTest {
public static final String TAGME;
static {
logger.trace("Retrieving Tokens from {}", PROPERTIES_FILENAME);
Properties properties = new Properties();
InputStream input = ScopedTest.class.getClassLoader().getResourceAsStream(PROPERTIES_FILENAME);
InputStream input = ContextTest.class.getClassLoader().getResourceAsStream(PROPERTIES_FILENAME);
try {
// load the properties file
properties.load(input);
} catch (IOException e) {
} catch(IOException e) {
throw new RuntimeException(e);
}
@ -77,12 +76,12 @@ public class ScopedTest {
}
@BeforeClass
public static void beforeClass() throws Exception{
public static void beforeClass() throws Exception {
Utils.setContext(DEFAULT_TEST_SCOPE);
}
@AfterClass
public static void afterClass() throws Exception{
public static void afterClass() throws Exception {
SecurityTokenProvider.instance.reset();
ScopeProvider.instance.reset();
}

View File

@ -1,393 +0,0 @@
package org.gcube.dataharvest.utils;
public class DataFiller {
protected static String[] data10 = {
"/d4science.research-infrastructures.eu/FARM/AlieiaVRE","12",
"/d4science.research-infrastructures.eu/D4Research/AnalyticsLab","83",
"/d4science.research-infrastructures.eu/FARM/Aquabiotech","8",
"/d4science.research-infrastructures.eu/gCubeApps/AquacultureAtlasGeneration","26",
"/d4science.research-infrastructures.eu/gCubeApps/AquacultureTrainingLab","71",
"/d4science.research-infrastructures.eu/FARM/ARDAG_Aquaculture","5",
"/d4science.research-infrastructures.eu/D4Research/BOBLME_HilsaAWG","3",
"/d4science.research-infrastructures.eu/gCubeApps/BiodiversityLab","374",
"/d4science.research-infrastructures.eu/gCubeApps/BiOnym","112",
"/d4science.research-infrastructures.eu/gCubeApps/BlueCommons","37",
"/d4science.research-infrastructures.eu/D4Research/Blue-Datathon","44",
"/d4science.research-infrastructures.eu/gCubeApps/BlueUptake","36",
"/d4science.research-infrastructures.eu/gCubeApps/BlueBRIDGE-EAB","19",
"/d4science.research-infrastructures.eu/gCubeApps/BlueBridgeProject","100",
"/d4science.research-infrastructures.eu/gCubeApps/BlueBRIDGE-PSC","10",
"/d4science.research-infrastructures.eu/D4Research/BlueBRIDGEReview","15",
"/d4science.research-infrastructures.eu/D4Research/DRuMFISH","27",
"/d4science.research-infrastructures.eu/FARM/EllinikaPsariaVRE","11",
"/d4science.research-infrastructures.eu/FARM/ForkysVRE","12",
"/d4science.research-infrastructures.eu/gCubeApps/FAO_TunaAtlas","0",
"/d4science.research-infrastructures.eu/FARM/GALAXIDI","6",
"/d4science.research-infrastructures.eu/FARM/GRSF","13",
"/d4science.research-infrastructures.eu/FARM/GRSF_Admin","28",
"/d4science.research-infrastructures.eu/gCubeApps/ICCAT_BFT-E","37",
"/d4science.research-infrastructures.eu/D4Research/ICES_AbundanceEstimationFromAcoustic","36",
"/d4science.research-infrastructures.eu/gCubeApps/ICES_DALSA","27",
"/d4science.research-infrastructures.eu/gCubeApps/ICES_DASC","17",
"/d4science.research-infrastructures.eu/gCubeApps/ICES_FIACO","28",
"/d4science.research-infrastructures.eu/D4Research/ICES_IntroStockAssessment","34",
"/d4science.research-infrastructures.eu/gCubeApps/ICES_TCRE","30",
"/d4science.research-infrastructures.eu/D4Research/ICES_MSE","27",
"/d4science.research-infrastructures.eu/D4Research/ICES_MSY","84",
"/d4science.research-infrastructures.eu/gCubeApps/ICES_StockAssessmentAdvanced","26",
"/d4science.research-infrastructures.eu/gCubeApps/ICES_TCSSM","29",
"/d4science.research-infrastructures.eu/FARM/iLKNAK_Aquaculture","5",
"/d4science.research-infrastructures.eu/D4Research/InfraTraining","10",
"/d4science.research-infrastructures.eu/D4Research/IOTC_SS3","31",
"/d4science.research-infrastructures.eu/gCubeApps/iSearch","56",
"/d4science.research-infrastructures.eu/FARM/MARKELLOS_Aquaculture","5",
"/d4science.research-infrastructures.eu/gCubeApps/PerformanceEvaluationInAquaculture","27",
"/d4science.research-infrastructures.eu/gCubeApps/ProtectedAreaImpactMaps","30",
"/d4science.research-infrastructures.eu/gCubeApps/RPrototypingLab","99",
"/d4science.research-infrastructures.eu/gCubeApps/RStudioLab","68",
"/d4science.research-infrastructures.eu/gCubeApps/ScalableDataMining","152",
"/d4science.research-infrastructures.eu/gCubeApps/SIASPA","19",
"/d4science.research-infrastructures.eu/gCubeApps/StockAssessment","62",
"/d4science.research-infrastructures.eu/gCubeApps/StrategicInvestmentAnalysis","26",
"/d4science.research-infrastructures.eu/FARM/STRATOS_AQUACULTURES","6",
"/d4science.research-infrastructures.eu/gCubeApps/TabularDataLab","182",
"/d4science.research-infrastructures.eu/gCubeApps/FAO_TunaAtlas","38",
"/d4science.research-infrastructures.eu/FARM/VME-DB","18",
"/d4science.research-infrastructures.eu/FARM/WECAFC-FIRMS","20"
};
protected static String[] data11 = {
"/d4science.research-infrastructures.eu/FARM/AlieiaVRE","12",
"/d4science.research-infrastructures.eu/D4Research/AnalyticsLab","93",
"/d4science.research-infrastructures.eu/FARM/Aquabiotech","8",
"/d4science.research-infrastructures.eu/gCubeApps/AquacultureAtlasGeneration","26",
"/d4science.research-infrastructures.eu/gCubeApps/AquacultureTrainingLab","136",
"/d4science.research-infrastructures.eu/FARM/ARDAG_Aquaculture","6",
"/d4science.research-infrastructures.eu/D4Research/BOBLME_HilsaAWG","3",
"/d4science.research-infrastructures.eu/gCubeApps/BiodiversityLab","387",
"/d4science.research-infrastructures.eu/gCubeApps/BiOnym","116",
"/d4science.research-infrastructures.eu/gCubeApps/BlueCommons","35",
"/d4science.research-infrastructures.eu/D4Research/Blue-Datathon","45",
"/d4science.research-infrastructures.eu/gCubeApps/BlueUptake","33",
"/d4science.research-infrastructures.eu/gCubeApps/BlueBRIDGE-EAB","22",
"/d4science.research-infrastructures.eu/gCubeApps/BlueBridgeProject","98",
"/d4science.research-infrastructures.eu/gCubeApps/BlueBRIDGE-PSC","10",
"/d4science.research-infrastructures.eu/D4Research/BlueBRIDGEReview","15",
"/d4science.research-infrastructures.eu/D4Research/DRuMFISH","27",
"/d4science.research-infrastructures.eu/FARM/EllinikaPsariaVRE","11",
"/d4science.research-infrastructures.eu/FARM/ForkysVRE","12",
"/d4science.research-infrastructures.eu/gCubeApps/FAO_TunaAtlas","0",
"/d4science.research-infrastructures.eu/FARM/GALAXIDI","4",
"/d4science.research-infrastructures.eu/FARM/GRSF","13",
"/d4science.research-infrastructures.eu/FARM/GRSF_Admin","28",
"/d4science.research-infrastructures.eu/gCubeApps/ICCAT_BFT-E","37",
"/d4science.research-infrastructures.eu/D4Research/ICES_AbundanceEstimationFromAcoustic","36",
"/d4science.research-infrastructures.eu/gCubeApps/ICES_DALSA","27",
"/d4science.research-infrastructures.eu/gCubeApps/ICES_DASC","17",
"/d4science.research-infrastructures.eu/gCubeApps/ICES_FIACO","28",
"/d4science.research-infrastructures.eu/D4Research/ICES_IntroStockAssessment","34",
"/d4science.research-infrastructures.eu/gCubeApps/ICES_TCRE","31",
"/d4science.research-infrastructures.eu/D4Research/ICES_MSE","27",
"/d4science.research-infrastructures.eu/D4Research/ICES_MSY","84",
"/d4science.research-infrastructures.eu/gCubeApps/ICES_StockAssessmentAdvanced","26",
"/d4science.research-infrastructures.eu/gCubeApps/ICES_TCSSM","29",
"/d4science.research-infrastructures.eu/FARM/iLKNAK_Aquaculture","6",
"/d4science.research-infrastructures.eu/D4Research/InfraTraining","10",
"/d4science.research-infrastructures.eu/D4Research/IOTC_SS3","34",
"/d4science.research-infrastructures.eu/gCubeApps/iSearch","58",
"/d4science.research-infrastructures.eu/FARM/MARKELLOS_Aquaculture","5",
"/d4science.research-infrastructures.eu/gCubeApps/PerformanceEvaluationInAquaculture","27",
"/d4science.research-infrastructures.eu/gCubeApps/ProtectedAreaImpactMaps","56",
"/d4science.research-infrastructures.eu/gCubeApps/RPrototypingLab","110",
"/d4science.research-infrastructures.eu/gCubeApps/RStudioLab","73",
"/d4science.research-infrastructures.eu/gCubeApps/ScalableDataMining","161",
"/d4science.research-infrastructures.eu/gCubeApps/SIASPA","22",
"/d4science.research-infrastructures.eu/gCubeApps/StockAssessment","63",
"/d4science.research-infrastructures.eu/gCubeApps/StrategicInvestmentAnalysis","26",
"/d4science.research-infrastructures.eu/FARM/STRATOS_AQUACULTURES","5",
"/d4science.research-infrastructures.eu/gCubeApps/TabularDataLab","186",
"/d4science.research-infrastructures.eu/gCubeApps/FAO_TunaAtlas","40",
"/d4science.research-infrastructures.eu/FARM/VME-DB","18",
"/d4science.research-infrastructures.eu/FARM/WECAFC-FIRMS","20"
};
protected static String[] data12 = {
"/d4science.research-infrastructures.eu/FARM/AlieiaVRE","12",
"/d4science.research-infrastructures.eu/D4Research/AnalyticsLab","99",
"/d4science.research-infrastructures.eu/FARM/Aquabiotech","8",
"/d4science.research-infrastructures.eu/gCubeApps/AquacultureAtlasGeneration","28",
"/d4science.research-infrastructures.eu/gCubeApps/AquacultureTrainingLab","273",
"/d4science.research-infrastructures.eu/FARM/ARDAG_Aquaculture","6",
"/d4science.research-infrastructures.eu/D4Research/BOBLME_HilsaAWG","3",
"/d4science.research-infrastructures.eu/gCubeApps/BiodiversityLab","392",
"/d4science.research-infrastructures.eu/gCubeApps/BiOnym","118",
"/d4science.research-infrastructures.eu/gCubeApps/BlueCommons","35",
"/d4science.research-infrastructures.eu/D4Research/Blue-Datathon","45",
"/d4science.research-infrastructures.eu/gCubeApps/BlueUptake","33",
"/d4science.research-infrastructures.eu/gCubeApps/BlueBRIDGE-EAB","22",
"/d4science.research-infrastructures.eu/gCubeApps/BlueBridgeProject","98",
"/d4science.research-infrastructures.eu/gCubeApps/BlueBRIDGE-PSC","10",
"/d4science.research-infrastructures.eu/D4Research/BlueBRIDGEReview","15",
"/d4science.research-infrastructures.eu/D4Research/DRuMFISH","27",
"/d4science.research-infrastructures.eu/FARM/EllinikaPsariaVRE","11",
"/d4science.research-infrastructures.eu/FARM/ForkysVRE","12",
"/d4science.research-infrastructures.eu/gCubeApps/FAO_TunaAtlas","0",
"/d4science.research-infrastructures.eu/FARM/GALAXIDI","4",
"/d4science.research-infrastructures.eu/FARM/GRSF","13",
"/d4science.research-infrastructures.eu/FARM/GRSF_Admin","30",
"/d4science.research-infrastructures.eu/gCubeApps/ICCAT_BFT-E","37",
"/d4science.research-infrastructures.eu/D4Research/ICES_AbundanceEstimationFromAcoustic","36",
"/d4science.research-infrastructures.eu/gCubeApps/ICES_DALSA","27",
"/d4science.research-infrastructures.eu/gCubeApps/ICES_DASC","17",
"/d4science.research-infrastructures.eu/gCubeApps/ICES_FIACO","28",
"/d4science.research-infrastructures.eu/D4Research/ICES_IntroStockAssessment","34",
"/d4science.research-infrastructures.eu/gCubeApps/ICES_TCRE","31",
"/d4science.research-infrastructures.eu/D4Research/ICES_MSE","27",
"/d4science.research-infrastructures.eu/D4Research/ICES_MSY","84",
"/d4science.research-infrastructures.eu/gCubeApps/ICES_StockAssessmentAdvanced","26",
"/d4science.research-infrastructures.eu/gCubeApps/ICES_TCSSM","29",
"/d4science.research-infrastructures.eu/FARM/iLKNAK_Aquaculture","6",
"/d4science.research-infrastructures.eu/D4Research/InfraTraining","10",
"/d4science.research-infrastructures.eu/D4Research/IOTC_SS3","36",
"/d4science.research-infrastructures.eu/gCubeApps/iSearch","59",
"/d4science.research-infrastructures.eu/FARM/MARKELLOS_Aquaculture","6",
"/d4science.research-infrastructures.eu/gCubeApps/PerformanceEvaluationInAquaculture","27",
"/d4science.research-infrastructures.eu/gCubeApps/ProtectedAreaImpactMaps","57",
"/d4science.research-infrastructures.eu/gCubeApps/RPrototypingLab","114",
"/d4science.research-infrastructures.eu/gCubeApps/RStudioLab","74",
"/d4science.research-infrastructures.eu/gCubeApps/ScalableDataMining","164",
"/d4science.research-infrastructures.eu/gCubeApps/SIASPA","26",
"/d4science.research-infrastructures.eu/gCubeApps/StockAssessment","63",
"/d4science.research-infrastructures.eu/gCubeApps/StrategicInvestmentAnalysis","26",
"/d4science.research-infrastructures.eu/FARM/STRATOS_AQUACULTURES","5",
"/d4science.research-infrastructures.eu/gCubeApps/TabularDataLab","188",
"/d4science.research-infrastructures.eu/gCubeApps/FAO_TunaAtlas","40",
"/d4science.research-infrastructures.eu/FARM/VME-DB","18",
"/d4science.research-infrastructures.eu/FARM/WECAFC-FIRMS","20"
};
public static String[] data01 = {
"/d4science.research-infrastructures.eu/FARM/AlieiaVRE","12",
"/d4science.research-infrastructures.eu/D4Research/AnalyticsLab","103",
"/d4science.research-infrastructures.eu/FARM/Aquabiotech","8",
"/d4science.research-infrastructures.eu/gCubeApps/AquacultureAtlasGeneration","35",
"/d4science.research-infrastructures.eu/gCubeApps/AquacultureTrainingLab","278",
"/d4science.research-infrastructures.eu/FARM/ARDAG_Aquaculture","6",
"/d4science.research-infrastructures.eu/D4Research/BOBLME_HilsaAWG","3",
"/d4science.research-infrastructures.eu/gCubeApps/BiodiversityLab","400",
"/d4science.research-infrastructures.eu/gCubeApps/BiOnym","121",
"/d4science.research-infrastructures.eu/gCubeApps/BlueCommons","35",
"/d4science.research-infrastructures.eu/D4Research/Blue-Datathon","45",
"/d4science.research-infrastructures.eu/gCubeApps/BlueUptake","33",
"/d4science.research-infrastructures.eu/gCubeApps/BlueBRIDGE-EAB","22",
"/d4science.research-infrastructures.eu/gCubeApps/BlueBridgeProject","99",
"/d4science.research-infrastructures.eu/gCubeApps/BlueBRIDGE-PSC","10",
"/d4science.research-infrastructures.eu/D4Research/BlueBRIDGEReview","15",
"/d4science.research-infrastructures.eu/D4Research/DRuMFISH","27",
"/d4science.research-infrastructures.eu/FARM/EllinikaPsariaVRE","11",
"/d4science.research-infrastructures.eu/FARM/ForkysVRE","12",
"/d4science.research-infrastructures.eu/gCubeApps/FAO_TunaAtlas","5",
"/d4science.research-infrastructures.eu/FARM/GALAXIDI","4",
"/d4science.research-infrastructures.eu/FARM/GRSF","13",
"/d4science.research-infrastructures.eu/FARM/GRSF_Admin","31",
"/d4science.research-infrastructures.eu/gCubeApps/ICCAT_BFT-E","38",
"/d4science.research-infrastructures.eu/D4Research/ICES_AbundanceEstimationFromAcoustic","36",
"/d4science.research-infrastructures.eu/gCubeApps/ICES_DALSA","27",
"/d4science.research-infrastructures.eu/gCubeApps/ICES_DASC","17",
"/d4science.research-infrastructures.eu/gCubeApps/ICES_FIACO","28",
"/d4science.research-infrastructures.eu/D4Research/ICES_IntroStockAssessment","34",
"/d4science.research-infrastructures.eu/gCubeApps/ICES_TCRE","31",
"/d4science.research-infrastructures.eu/D4Research/ICES_MSE","27",
"/d4science.research-infrastructures.eu/D4Research/ICES_MSY","84",
"/d4science.research-infrastructures.eu/gCubeApps/ICES_StockAssessmentAdvanced","26",
"/d4science.research-infrastructures.eu/gCubeApps/ICES_TCSSM","29",
"/d4science.research-infrastructures.eu/FARM/iLKNAK_Aquaculture","6",
"/d4science.research-infrastructures.eu/D4Research/InfraTraining","10",
"/d4science.research-infrastructures.eu/D4Research/IOTC_SS3","37",
"/d4science.research-infrastructures.eu/gCubeApps/iSearch","59",
"/d4science.research-infrastructures.eu/FARM/MARKELLOS_Aquaculture","6",
"/d4science.research-infrastructures.eu/gCubeApps/PerformanceEvaluationInAquaculture","27",
"/d4science.research-infrastructures.eu/gCubeApps/ProtectedAreaImpactMaps","68",
"/d4science.research-infrastructures.eu/gCubeApps/RPrototypingLab","123",
"/d4science.research-infrastructures.eu/gCubeApps/RStudioLab","80",
"/d4science.research-infrastructures.eu/gCubeApps/ScalableDataMining","167",
"/d4science.research-infrastructures.eu/gCubeApps/SIASPA","31",
"/d4science.research-infrastructures.eu/gCubeApps/StockAssessment","63",
"/d4science.research-infrastructures.eu/gCubeApps/StrategicInvestmentAnalysis","26",
"/d4science.research-infrastructures.eu/FARM/STRATOS_AQUACULTURES","5",
"/d4science.research-infrastructures.eu/gCubeApps/TabularDataLab","191",
"/d4science.research-infrastructures.eu/gCubeApps/FAO_TunaAtlas","44",
"/d4science.research-infrastructures.eu/FARM/VME-DB","18",
"/d4science.research-infrastructures.eu/FARM/WECAFC-FIRMS","20",
};
public static String[] data02 = {
"/d4science.research-infrastructures.eu/FARM/AlieiaVRE","12",
"/d4science.research-infrastructures.eu/D4Research/AnalyticsLab","106",
"/d4science.research-infrastructures.eu/FARM/Aquabiotech","8",
"/d4science.research-infrastructures.eu/gCubeApps/AquacultureAtlasGeneration","35",
"/d4science.research-infrastructures.eu/gCubeApps/AquacultureTrainingLab","279",
"/d4science.research-infrastructures.eu/FARM/ARDAG_Aquaculture","6",
"/d4science.research-infrastructures.eu/D4Research/BOBLME_HilsaAWG","3",
"/d4science.research-infrastructures.eu/gCubeApps/BiodiversityLab","402",
"/d4science.research-infrastructures.eu/gCubeApps/BiOnym","124",
"/d4science.research-infrastructures.eu/gCubeApps/BlueCommons","35",
"/d4science.research-infrastructures.eu/D4Research/Blue-Datathon","45",
"/d4science.research-infrastructures.eu/gCubeApps/BlueUptake","33",
"/d4science.research-infrastructures.eu/gCubeApps/BlueBRIDGE-EAB","26",
"/d4science.research-infrastructures.eu/gCubeApps/BlueBridgeProject","99",
"/d4science.research-infrastructures.eu/gCubeApps/BlueBRIDGE-PSC","10",
"/d4science.research-infrastructures.eu/D4Research/BlueBRIDGEReview","15",
"/d4science.research-infrastructures.eu/D4Research/DRuMFISH","27",
"/d4science.research-infrastructures.eu/FARM/EllinikaPsariaVRE","11",
"/d4science.research-infrastructures.eu/FARM/ForkysVRE","12",
"/d4science.research-infrastructures.eu/gCubeApps/FAO_TunaAtlas","5",
"/d4science.research-infrastructures.eu/FARM/GALAXIDI","4",
"/d4science.research-infrastructures.eu/FARM/GRSF","13",
"/d4science.research-infrastructures.eu/FARM/GRSF_Admin","32",
"/d4science.research-infrastructures.eu/gCubeApps/ICCAT_BFT-E","38",
"/d4science.research-infrastructures.eu/D4Research/ICES_AbundanceEstimationFromAcoustic","36",
"/d4science.research-infrastructures.eu/gCubeApps/ICES_DALSA","27",
"/d4science.research-infrastructures.eu/gCubeApps/ICES_DASC","17",
"/d4science.research-infrastructures.eu/gCubeApps/ICES_FIACO","28",
"/d4science.research-infrastructures.eu/D4Research/ICES_IntroStockAssessment","34",
"/d4science.research-infrastructures.eu/gCubeApps/ICES_TCRE","31",
"/d4science.research-infrastructures.eu/D4Research/ICES_MSE","27",
"/d4science.research-infrastructures.eu/D4Research/ICES_MSY","84",
"/d4science.research-infrastructures.eu/gCubeApps/ICES_StockAssessmentAdvanced","26",
"/d4science.research-infrastructures.eu/gCubeApps/ICES_TCSSM","29",
"/d4science.research-infrastructures.eu/FARM/iLKNAK_Aquaculture","6",
"/d4science.research-infrastructures.eu/D4Research/InfraTraining","10",
"/d4science.research-infrastructures.eu/D4Research/IOTC_SS3","38",
"/d4science.research-infrastructures.eu/gCubeApps/iSearch","60",
"/d4science.research-infrastructures.eu/FARM/MARKELLOS_Aquaculture","6",
"/d4science.research-infrastructures.eu/gCubeApps/PerformanceEvaluationInAquaculture","27",
"/d4science.research-infrastructures.eu/gCubeApps/ProtectedAreaImpactMaps","71",
"/d4science.research-infrastructures.eu/gCubeApps/RPrototypingLab","127",
"/d4science.research-infrastructures.eu/gCubeApps/RStudioLab","81",
"/d4science.research-infrastructures.eu/gCubeApps/ScalableDataMining","171",
"/d4science.research-infrastructures.eu/gCubeApps/SIASPA","32",
"/d4science.research-infrastructures.eu/gCubeApps/StockAssessment","63",
"/d4science.research-infrastructures.eu/gCubeApps/StrategicInvestmentAnalysis","26",
"/d4science.research-infrastructures.eu/FARM/STRATOS_AQUACULTURES","5",
"/d4science.research-infrastructures.eu/gCubeApps/TabularDataLab","193",
"/d4science.research-infrastructures.eu/gCubeApps/FAO_TunaAtlas","49",
"/d4science.research-infrastructures.eu/FARM/VME-DB","18",
"/d4science.research-infrastructures.eu/FARM/WECAFC-FIRMS","24"
};
public static String[] data03 = {
"/d4science.research-infrastructures.eu/FARM/AlieiaVRE","12",
"/d4science.research-infrastructures.eu/D4Research/AnalyticsLab","107",
"/d4science.research-infrastructures.eu/FARM/Aquabiotech","8",
"/d4science.research-infrastructures.eu/gCubeApps/AquacultureAtlasGeneration","35",
"/d4science.research-infrastructures.eu/gCubeApps/AquacultureTrainingLab","278",
"/d4science.research-infrastructures.eu/FARM/ARDAG_Aquaculture","6",
"/d4science.research-infrastructures.eu/D4Research/BOBLME_HilsaAWG","3",
"/d4science.research-infrastructures.eu/gCubeApps/BiodiversityLab","403",
"/d4science.research-infrastructures.eu/gCubeApps/BiOnym","124",
"/d4science.research-infrastructures.eu/gCubeApps/BlueCommons","35",
"/d4science.research-infrastructures.eu/D4Research/Blue-Datathon","45",
"/d4science.research-infrastructures.eu/gCubeApps/BlueUptake","33",
"/d4science.research-infrastructures.eu/gCubeApps/BlueBRIDGE-EAB","26",
"/d4science.research-infrastructures.eu/gCubeApps/BlueBridgeProject","99",
"/d4science.research-infrastructures.eu/gCubeApps/BlueBRIDGE-PSC","10",
"/d4science.research-infrastructures.eu/D4Research/BlueBRIDGEReview","15",
"/d4science.research-infrastructures.eu/D4Research/DRuMFISH","27",
"/d4science.research-infrastructures.eu/FARM/EllinikaPsariaVRE","11",
"/d4science.research-infrastructures.eu/FARM/ForkysVRE","12",
"/d4science.research-infrastructures.eu/gCubeApps/FAO_TunaAtlas","5",
"/d4science.research-infrastructures.eu/FARM/GALAXIDI","4",
"/d4science.research-infrastructures.eu/FARM/GRSF","13",
"/d4science.research-infrastructures.eu/FARM/GRSF_Admin","32",
"/d4science.research-infrastructures.eu/gCubeApps/ICCAT_BFT-E","38",
"/d4science.research-infrastructures.eu/D4Research/ICES_AbundanceEstimationFromAcoustic","36",
"/d4science.research-infrastructures.eu/gCubeApps/ICES_DALSA","27",
"/d4science.research-infrastructures.eu/gCubeApps/ICES_DASC","17",
"/d4science.research-infrastructures.eu/gCubeApps/ICES_FIACO","28",
"/d4science.research-infrastructures.eu/D4Research/ICES_IntroStockAssessment","34",
"/d4science.research-infrastructures.eu/gCubeApps/ICES_TCRE","32",
"/d4science.research-infrastructures.eu/D4Research/ICES_MSE","29",
"/d4science.research-infrastructures.eu/D4Research/ICES_MSY","84",
"/d4science.research-infrastructures.eu/gCubeApps/ICES_StockAssessmentAdvanced","26",
"/d4science.research-infrastructures.eu/gCubeApps/ICES_TCSSM","29",
"/d4science.research-infrastructures.eu/FARM/iLKNAK_Aquaculture","6",
"/d4science.research-infrastructures.eu/D4Research/InfraTraining","10",
"/d4science.research-infrastructures.eu/D4Research/IOTC_SS3","38",
"/d4science.research-infrastructures.eu/gCubeApps/iSearch","61",
"/d4science.research-infrastructures.eu/FARM/MARKELLOS_Aquaculture","6",
"/d4science.research-infrastructures.eu/gCubeApps/PerformanceEvaluationInAquaculture","27",
"/d4science.research-infrastructures.eu/gCubeApps/ProtectedAreaImpactMaps","71",
"/d4science.research-infrastructures.eu/gCubeApps/RPrototypingLab","127",
"/d4science.research-infrastructures.eu/gCubeApps/RStudioLab","81",
"/d4science.research-infrastructures.eu/gCubeApps/ScalableDataMining","171",
"/d4science.research-infrastructures.eu/gCubeApps/SIASPA","32",
"/d4science.research-infrastructures.eu/gCubeApps/StockAssessment","63",
"/d4science.research-infrastructures.eu/gCubeApps/StrategicInvestmentAnalysis","26",
"/d4science.research-infrastructures.eu/FARM/STRATOS_AQUACULTURES","5",
"/d4science.research-infrastructures.eu/gCubeApps/TabularDataLab","191",
"/d4science.research-infrastructures.eu/gCubeApps/FAO_TunaAtlas","49",
"/d4science.research-infrastructures.eu/FARM/VME-DB","18",
"/d4science.research-infrastructures.eu/FARM/WECAFC-FIRMS","24"
};
public static String[] data04 = {
"/d4science.research-infrastructures.eu/FARM/CWP_Secretariat", "8"
};
public static String[] vals = {
"2017", "1", "0", "2", "80",
"2017", "2", "0", "2", "80",
"2017", "3", "0", "2", "80",
"2017", "4", "0", "2", "80",
"2017", "5", "0", "2", "80",
"2017", "6", "0", "2", "80",
"2017", "7", "4", "2", "80",
"2017", "8", "4", "2", "80",
"2017", "9", "4", "2", "80",
"2017", "10", "4", "2", "80",
"2017", "11", "4", "2", "80",
"2017", "12", "4", "2", "80",
"2018", "1", "4", "2", "80",
"2018", "2", "4", "2", "80",
"2018", "3", "4", "2", "80"
};
public static void main(String[] args) {
// for(int i=0; i<data03.length; i+=2) {
// String insert = "insert into monthly_measure (year, month, measure, measure_type_id, context_id, day) " +
// "values(2018,3," + data03[i+1] + ",2,(select id from context where dname='" + data03[i] + "'),'2018-03-01');";
// System.out.println(insert);
// }
insertMeasures();
}
private static void insertMeasures() {
String im = "insert into monthly_measure (year, month, measure, measure_type_id, context_id, day) values ";
String val = "(%Y, %M, %m, %T, %C, '%D')";
for(int i=0; i<vals.length; i+=5) {
String item = new String(val);
item = item.replace("%Y", vals[i]);
item = item.replace("%M", vals[i+1]);
item = item.replace("%m", vals[i+2]);
item = item.replace("%T", vals[i+3]);
item = item.replace("%C", vals[i+4]);
item = item.replace("%D", getDay(vals[i], vals[i+1]));
im += item + ",";
}
im = im.substring(0, im.length()-1);
System.out.println(im);
}
private static String getDay(String year, String month) {
String day = year + "-";
if(month.length() < 2)
day += "0" + month + "-01";
else day += month + "-01";
return day;
}
}