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

@ -5,12 +5,12 @@ package org.gcube.dataharvest.dao;
* @author Luca Frosini (ISTI - CNR)
*/
public class DaoException extends Exception {
/**
* Generated Serial Version UID
*/
private static final long serialVersionUID = -6302570066137502483L;
public DaoException() {
super();
}
@ -18,9 +18,9 @@ public class DaoException extends Exception {
public DaoException(String message) {
super(message);
}
public DaoException(String message, Throwable throwable) {
super(message, throwable);
}
}

View File

@ -4,49 +4,48 @@ package org.gcube.dataharvest.dao;
* @author Eric Perrone (ISTI - CNR)
* @author Luca Frosini (ISTI - CNR)
*/
public class DatabaseConnectionData {
protected String uri;
protected String user;
protected String password;
public DatabaseConnectionData() {
this.uri = null;
this.user = null;
this.password = null;
}
public DatabaseConnectionData(String uri, String user, String password) {
this.uri = uri;
this.user = user;
this.password = password;
}
public String getURI() {
return uri;
}
public void setURI(String uri) {
this.uri = uri;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public String toString() {
return this.getClass().getSimpleName() + " [uri =" + uri + ", user=" + user + ", password=" + password + "]";

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,15 +59,16 @@ 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();
SimpleQuery query = ICFactory.queryFor(ServiceEndpoint.class);
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);
@ -75,7 +77,7 @@ public class DatabaseParameterRetriever {
}
Group<AccessPoint> accessPoints = serviceEndpoints.get(0).profile().accessPoints();
for(AccessPoint accessPoint : accessPoints) {
if(accessPoint.name().compareTo(className) == 0) {
uri = accessPoint.address();
@ -98,7 +100,7 @@ public class DatabaseParameterRetriever {
checkParameter(username, "Username", localDB);
checkParameter(password, "Password", localDB);
return new DatabaseConnectionData(uri, username, password);
}
}

View File

@ -3,8 +3,12 @@ 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
*/
@ -22,7 +26,7 @@ public class HarvestedData implements Serializable {
public static int SOCIAL_LIKES = 10;
public static int METHOD_INVOCATIONS = 11;
public static int VISUAL_TOOLS = 12;
private int dataType;
private String context;
private long measure;
@ -39,49 +43,48 @@ public class HarvestedData implements Serializable {
this.measure = measure;
this.day = day;
}
public HarvestedData(int dataType, String context, long measure) {
this.dataType = dataType;
this.context = context;
this.measure = measure;
}
public void setDataType(int dataType) {
this.dataType = dataType;
}
public void setContext(String context) {
this.context = context;
}
public void setMeasure(long measure) {
this.measure = measure;
}
public void setDay(Date day) {
this.day = day;
}
public int getDataType() {
return dataType;
}
public String getContext() {
return context;
}
public long getMeasure() {
return measure;
}
public Date getDay() {
return day;
}
@Override
public String toString() {
return "Harvest [context=" + context + ", dataType=" + dataType + ", measure=" + measure + "]";
}
}

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,15 +14,18 @@ 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 {
super(start, end);
}
@Override
public List<HarvestedData> getData() throws Exception {
String context = Utils.getCurrentContext();
@ -33,12 +36,12 @@ 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;
}
}
private int get() throws MalformedURLException, IOException {
int userNumber = 0;
// la seguente stringa deve essere letta dinamicamente
@ -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,16 +22,20 @@ 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);
private int count = 0;
public DataMethodDownloadHarvester(Date start, Date end) throws ParseException {
super(start, end);
}
@Override
public List<HarvestedData> getData() throws Exception {
String context = Utils.getCurrentContext();
@ -42,18 +46,19 @@ public class DataMethodDownloadHarvester extends BasicHarvester {
count = 0;
HomeManager manager = HomeLibrary.getHomeManagerFactory().getHomeManager();
String user = getVREName(context) + "-Manager";
@SuppressWarnings("deprecation")
Home home = manager.getHome(user);
JCRWorkspace ws = (JCRWorkspace) home.getWorkspace();
JCRWorkspaceItem item = (JCRWorkspaceItem) ws
.getItemByPath("/Workspace/MySpecialFolders/" + getVREName(context));
logger.debug("Analyzing " + context + " from " + startDate.toString() + " to " + endDate.toString());
logger.error("Before getStats()");
getStats(item, startDate, endDate);
logger.error("After getStats()");
@ -62,58 +67,58 @@ 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) {
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;
default:
break;
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++;
}
break;
default:
break;
}
}
} catch (Exception e) {
} catch(Exception e) {
logger.error("DataMethodDownloadHarvester: " + e.getLocalizedMessage());
throw new InternalErrorException(e.getLocalizedMessage());
}
}
}
private static String getVREName(String vre) {
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, "-");
return newName;
}
}

View File

@ -22,14 +22,18 @@ 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);
public MethodInvocationHarvester(Date start, Date end) throws ParseException {
super(start, end);
}
@Override
public List<HarvestedData> getData() throws Exception {
try {
@ -42,39 +46,39 @@ public class MethodInvocationHarvester extends BasicHarvester {
end.setTime(endDate);
TemporalConstraint temporalConstraint = new TemporalConstraint(start.getTimeInMillis(),
end.getTimeInMillis(), AggregationMode.MONTHLY);
List<Filter> filters = new ArrayList<>();
filters.add(new Filter(ServiceUsageRecord.CALLED_METHOD, "tag"));
List<String> contexts = new ArrayList<>();
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());
}
}
}
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);
throw x;
}
}
}

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) {
@ -166,5 +170,5 @@ public class ResourceCatalogueHarvester extends BasicHarvester {
break;
}
}
}

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
@ -54,18 +54,19 @@ public class ContextAuthorization {
this.tokenToContext = new HashMap<>();
retrieveContextsAndTokens();
}
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,14 +9,17 @@ 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);
public static TimeZone UTC_TIMEZONE = TimeZone.getTimeZone("UTC");
public static final String DATETIME_PATTERN = "yyyy-MM-dd HH:mm:ss.SSS Z";
public static final DateFormat DEFAULT_DATE_FORMAT;
public static final String LAUNCH_DATE_FORMAT_PATTERN = "yyyy-MM-dd";
public static final DateFormat LAUNCH_DATE_FORMAT;
@ -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,14 +19,20 @@ 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";
private boolean testMode = false;
private Date dateFrom, dateTo;
public static void main(String[] args) {
Harvester harvester = new Harvester();
try {
@ -37,115 +43,115 @@ public class Harvester {
//ArrayList<Integer> list = harvester.getSubTree(17);
//harvester.createSocialReports(list);
System.out.println("End.");
} catch (Exception e) {
} catch(Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public Harvester() {
testMode = false;
}
public void setDateFrom(Date dateFrom) {
this.dateFrom = dateFrom;
}
public void setDateTo(Date dateTo) {
this.dateTo = dateTo;
}
public void setTestMode(boolean testMode) {
this.testMode = testMode;
}
public Date getDateFrom() {
return dateFrom;
}
public Date getDateTo() {
return dateTo;
}
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());
}
}
public void runAll() {
try {
// collecting info on VRE users
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());
}
try {
// collecting info on Res. Catalogue (Dataset, Application,
// Deliverables, Methods)
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());
}
try {
// collecting info on Data/Method download
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());
}
try {
// collecting info on social (posts, replies and likes)
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());
}
try {
// collecting info on method invocation
MethodInvocationHarvester methodInvocationHarvester = new MethodInvocationHarvester(dateFrom, dateTo);
List<HarvestedData> res = methodInvocationHarvester.getData();
logger.debug("{}", res);
// insertMonthlyData((Date) dateFrom, (Date) dateTo, res);
} catch (Exception x) {
} catch(Exception x) {
logger.error(x.getLocalizedMessage());
}
}
private void insertMonthlyData(Date from, Date to, List<HarvestedData> data) {
Dao dao = null;
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());
}
}
}
}
private Dao dbConnect() throws DaoException {
DatabaseParameterRetriever dde = new DatabaseParameterRetriever();
//dde.setTestMode(testMode);
@ -155,70 +161,70 @@ public class Harvester {
dao.connect(dcd.getURI(), dcd.getUser(), dcd.getPassword());
return dao;
}
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);
}
}
}
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();
}
protected ArrayList<Integer> getSubTree(int root) {
Dao dao = null;
try {
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());
}
}
}
}
protected void createSocialReports(ArrayList<Integer> ids) {
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,13 +16,12 @@ 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";
protected static final String PROPERTIES_FILENAME = "token.properties";
private static final String GCUBE_DEVNEXT_VARNAME = "GCUBE_DEVNEXT";
public static final String GCUBE_DEVNEXT;
@ -51,16 +47,19 @@ 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);
}
GCUBE = properties.getProperty(GCUBE_VARNAME);
GCUBE_DEVNEXT = properties.getProperty(GCUBE_DEVNEXT_VARNAME);
@ -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;
}
}