2018-05-16 15:08:25 +02:00
|
|
|
package org.gcube.dataharvest;
|
|
|
|
|
2018-11-12 16:30:20 +01:00
|
|
|
import java.time.Instant;
|
2018-06-14 14:50:42 +02:00
|
|
|
import java.util.ArrayList;
|
2018-06-14 16:19:25 +02:00
|
|
|
import java.util.Calendar;
|
2018-05-18 18:24:53 +02:00
|
|
|
import java.util.Date;
|
2018-05-16 15:08:25 +02:00
|
|
|
import java.util.HashMap;
|
2018-05-22 12:05:30 +02:00
|
|
|
import java.util.LinkedHashMap;
|
2018-05-18 18:24:53 +02:00
|
|
|
import java.util.List;
|
2018-05-16 15:08:25 +02:00
|
|
|
import java.util.Map;
|
2018-06-18 15:15:12 +02:00
|
|
|
import java.util.Properties;
|
2018-09-04 11:13:16 +02:00
|
|
|
import java.util.Set;
|
2018-05-21 15:37:57 +02:00
|
|
|
import java.util.SortedSet;
|
2018-05-22 12:05:30 +02:00
|
|
|
import java.util.TreeSet;
|
2018-06-18 15:44:10 +02:00
|
|
|
import java.util.concurrent.TimeUnit;
|
2018-05-16 15:08:25 +02:00
|
|
|
|
2018-09-04 11:13:16 +02:00
|
|
|
import org.gcube.accounting.accounting.summary.access.AccountingDao;
|
2018-11-12 16:30:20 +01:00
|
|
|
import org.gcube.accounting.accounting.summary.access.model.ScopeDescriptor;
|
2018-09-04 11:13:16 +02:00
|
|
|
import org.gcube.accounting.accounting.summary.access.model.internal.Dimension;
|
|
|
|
import org.gcube.accounting.accounting.summary.access.model.update.AccountingRecord;
|
2018-05-22 12:05:30 +02:00
|
|
|
import org.gcube.common.scope.impl.ScopeBean;
|
2018-06-14 14:50:42 +02:00
|
|
|
import org.gcube.common.scope.impl.ScopeBean.Type;
|
2018-11-12 16:30:20 +01:00
|
|
|
import org.gcube.dataharvest.datamodel.HarvestedDataKey;
|
2018-05-18 18:33:28 +02:00
|
|
|
import org.gcube.dataharvest.harvester.MethodInvocationHarvester;
|
2018-07-05 18:25:05 +02:00
|
|
|
import org.gcube.dataharvest.harvester.SocialInteractionsHarvester;
|
2018-06-14 14:50:42 +02:00
|
|
|
import org.gcube.dataharvest.harvester.VREAccessesHarvester;
|
2018-06-18 15:15:12 +02:00
|
|
|
import org.gcube.dataharvest.harvester.VREUsersHarvester;
|
2018-05-24 17:10:45 +02:00
|
|
|
import org.gcube.dataharvest.harvester.sobigdata.DataMethodDownloadHarvester;
|
2018-05-21 12:51:17 +02:00
|
|
|
import org.gcube.dataharvest.harvester.sobigdata.ResourceCatalogueHarvester;
|
2018-05-18 18:24:53 +02:00
|
|
|
import org.gcube.dataharvest.harvester.sobigdata.TagMeMethodInvocationHarvester;
|
2018-06-18 15:15:12 +02:00
|
|
|
import org.gcube.dataharvest.utils.AggregationType;
|
2018-06-14 14:50:42 +02:00
|
|
|
import org.gcube.dataharvest.utils.ContextAuthorization;
|
2018-05-18 14:17:54 +02:00
|
|
|
import org.gcube.dataharvest.utils.ContextTest;
|
2018-05-18 18:24:53 +02:00
|
|
|
import org.gcube.dataharvest.utils.DateUtils;
|
2018-06-14 14:50:42 +02:00
|
|
|
import org.gcube.dataharvest.utils.Utils;
|
2018-05-22 12:05:30 +02:00
|
|
|
import org.gcube.resourcemanagement.support.server.managers.context.ContextManager;
|
2018-12-05 09:52:19 +01:00
|
|
|
import org.gcube.vremanagement.executor.api.rest.SmartExecutor;
|
|
|
|
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
|
|
|
|
import org.gcube.vremanagement.executor.client.SmartExecutorClientFactory;
|
|
|
|
import org.junit.Assert;
|
2018-05-16 15:08:25 +02:00
|
|
|
import org.junit.Test;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2018-05-18 14:17:54 +02:00
|
|
|
public class AccountingDataHarvesterPluginTest extends ContextTest {
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-05-16 15:08:25 +02:00
|
|
|
private static Logger logger = LoggerFactory.getLogger(AccountingDataHarvesterPluginTest.class);
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-05-28 15:22:59 +02:00
|
|
|
public static final String SO_BIG_DATA_CONTEXT = "/d4science.research-infrastructures.eu/SoBigData";
|
|
|
|
|
2018-11-12 16:30:20 +01:00
|
|
|
|
2018-09-04 11:20:11 +02:00
|
|
|
public static SortedSet<String> getContexts() throws Exception {
|
2018-05-28 15:22:59 +02:00
|
|
|
SortedSet<String> contexts = new TreeSet<>();
|
|
|
|
LinkedHashMap<String,ScopeBean> map = ContextManager.readContexts();
|
|
|
|
for(String scope : map.keySet()) {
|
|
|
|
try {
|
|
|
|
String context = map.get(scope).toString();
|
|
|
|
contexts.add(context);
|
2018-09-04 11:20:11 +02:00
|
|
|
} catch(Exception e) {
|
2018-05-28 15:22:59 +02:00
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return contexts;
|
|
|
|
}
|
|
|
|
|
2018-09-04 11:20:11 +02:00
|
|
|
// @Test
|
2018-09-04 11:13:16 +02:00
|
|
|
public void getDimensions() {
|
|
|
|
try {
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-09-04 11:13:16 +02:00
|
|
|
Utils.setContext(ROOT);
|
|
|
|
|
|
|
|
AccountingDao dao = AccountingDao.get();
|
|
|
|
|
|
|
|
Set<Dimension> dimensionSet = dao.getDimensions();
|
|
|
|
for(Dimension d : dimensionSet) {
|
|
|
|
logger.debug("{} - {} - {} - {}", d.getId(), d.getGroup(), d.getAggregatedMeasure(), d.getLabel());
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.info("End.");
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-09-04 11:13:16 +02:00
|
|
|
} catch(Exception e) {
|
|
|
|
logger.error("", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-04 11:14:40 +02:00
|
|
|
// @Test
|
2018-05-28 16:39:13 +02:00
|
|
|
public void launch() {
|
2018-05-16 15:08:25 +02:00
|
|
|
try {
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-06-18 15:15:12 +02:00
|
|
|
Utils.setContext(ROOT);
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-05-16 15:08:25 +02:00
|
|
|
DataHarvestPluginDeclaration dataHarvestPluginDeclaration = new DataHarvestPluginDeclaration();
|
2018-06-14 18:17:22 +02:00
|
|
|
|
2018-05-21 15:37:57 +02:00
|
|
|
AccountingDataHarvesterPlugin accountingDataHarvesterPlugin = new AccountingDataHarvesterPlugin(
|
|
|
|
dataHarvestPluginDeclaration);
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-05-17 16:04:22 +02:00
|
|
|
Map<String,Object> inputs = new HashMap<>();
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-06-14 18:17:22 +02:00
|
|
|
AggregationType aggregationType = AggregationType.MONTHLY;
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-06-14 18:17:22 +02:00
|
|
|
inputs.put(AccountingDataHarvesterPlugin.MEASURE_TYPE_INPUT_PARAMETER, aggregationType.name());
|
2018-07-05 18:25:05 +02:00
|
|
|
inputs.put(AccountingDataHarvesterPlugin.GET_VRE_USERS_INPUT_PARAMETER, true);
|
2018-05-17 16:04:22 +02:00
|
|
|
inputs.put(AccountingDataHarvesterPlugin.RERUN_INPUT_PARAMETER, true);
|
2018-09-04 11:13:16 +02:00
|
|
|
inputs.put(AccountingDataHarvesterPlugin.DRY_RUN_INPUT_PARAMETER, true);
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-06-14 18:19:10 +02:00
|
|
|
/*
|
|
|
|
Calendar from = DateUtils.getStartCalendar(2016, Calendar.SEPTEMBER, 1);
|
|
|
|
String fromDate = DateUtils.LAUNCH_DATE_FORMAT.format(from.getTime());
|
|
|
|
logger.trace("{} is {}", AccountingDataHarvesterPlugin.START_DATE_INPUT_PARAMETER, fromDate);
|
|
|
|
inputs.put(AccountingDataHarvesterPlugin.START_DATE_INPUT_PARAMETER, fromDate);
|
|
|
|
*/
|
|
|
|
|
|
|
|
accountingDataHarvesterPlugin.launch(inputs);
|
|
|
|
|
|
|
|
logger.info("End.");
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-06-14 18:19:10 +02:00
|
|
|
} catch(Exception e) {
|
|
|
|
logger.error("", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-05 09:52:19 +01:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void launchPluginOnSmartExecutor() {
|
|
|
|
try {
|
|
|
|
|
|
|
|
Utils.setContext(ROOT);
|
|
|
|
|
|
|
|
SmartExecutor smartExecutor = SmartExecutorClientFactory.create(DataHarvestPluginDeclaration.NAME);
|
|
|
|
Assert.assertNotNull(smartExecutor);
|
|
|
|
|
|
|
|
Map<String,Object> inputs = new HashMap<>();
|
|
|
|
|
|
|
|
AggregationType aggregationType = AggregationType.MONTHLY;
|
|
|
|
|
|
|
|
inputs.put(AccountingDataHarvesterPlugin.MEASURE_TYPE_INPUT_PARAMETER, aggregationType.name());
|
|
|
|
inputs.put(AccountingDataHarvesterPlugin.GET_VRE_USERS_INPUT_PARAMETER, true);
|
|
|
|
inputs.put(AccountingDataHarvesterPlugin.RERUN_INPUT_PARAMETER, true);
|
|
|
|
inputs.put(AccountingDataHarvesterPlugin.DRY_RUN_INPUT_PARAMETER, true);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Calendar from = DateUtils.getStartCalendar(2016, Calendar.SEPTEMBER, 1);
|
|
|
|
String fromDate = DateUtils.LAUNCH_DATE_FORMAT.format(from.getTime());
|
|
|
|
logger.trace("{} is {}", AccountingDataHarvesterPlugin.START_DATE_INPUT_PARAMETER, fromDate);
|
|
|
|
inputs.put(AccountingDataHarvesterPlugin.START_DATE_INPUT_PARAMETER, fromDate);
|
|
|
|
*/
|
|
|
|
|
|
|
|
LaunchParameter launchParameter = new LaunchParameter(DataHarvestPluginDeclaration.NAME, inputs);
|
|
|
|
smartExecutor.launch(launchParameter);
|
|
|
|
|
|
|
|
logger.info("End.");
|
|
|
|
|
|
|
|
} catch(Exception e) {
|
|
|
|
logger.error("", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-05 18:25:05 +02:00
|
|
|
// @Test
|
2018-06-14 18:19:10 +02:00
|
|
|
public void launchOldData() {
|
|
|
|
try {
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-06-18 15:15:12 +02:00
|
|
|
Utils.setContext(ROOT);
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-06-14 18:19:10 +02:00
|
|
|
DataHarvestPluginDeclaration dataHarvestPluginDeclaration = new DataHarvestPluginDeclaration();
|
|
|
|
|
|
|
|
AccountingDataHarvesterPlugin accountingDataHarvesterPlugin = new AccountingDataHarvesterPlugin(
|
|
|
|
dataHarvestPluginDeclaration);
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-06-14 18:19:10 +02:00
|
|
|
Map<String,Object> inputs = new HashMap<>();
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-06-14 18:19:10 +02:00
|
|
|
AggregationType aggregationType = AggregationType.MONTHLY;
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-06-14 18:19:10 +02:00
|
|
|
inputs.put(AccountingDataHarvesterPlugin.MEASURE_TYPE_INPUT_PARAMETER, aggregationType.name());
|
2018-06-18 15:15:12 +02:00
|
|
|
inputs.put(AccountingDataHarvesterPlugin.GET_VRE_USERS_INPUT_PARAMETER, true);
|
2018-06-14 18:19:10 +02:00
|
|
|
inputs.put(AccountingDataHarvesterPlugin.RERUN_INPUT_PARAMETER, true);
|
2018-06-18 15:15:12 +02:00
|
|
|
inputs.put(AccountingDataHarvesterPlugin.DRY_RUN_INPUT_PARAMETER, false);
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-06-14 18:17:22 +02:00
|
|
|
Calendar from = DateUtils.getStartCalendar(2016, Calendar.SEPTEMBER, 1);
|
|
|
|
|
2018-09-04 11:20:11 +02:00
|
|
|
Calendar runbeforeDate = DateUtils.getStartCalendar(2018, Calendar.JUNE, 1);
|
2018-05-29 11:08:24 +02:00
|
|
|
|
2018-06-14 18:17:22 +02:00
|
|
|
while(from.before(runbeforeDate)) {
|
|
|
|
String fromDate = DateUtils.LAUNCH_DATE_FORMAT.format(from.getTime());
|
|
|
|
logger.trace("{} is {}", AccountingDataHarvesterPlugin.START_DATE_INPUT_PARAMETER, fromDate);
|
|
|
|
inputs.put(AccountingDataHarvesterPlugin.START_DATE_INPUT_PARAMETER, fromDate);
|
2018-06-18 15:15:12 +02:00
|
|
|
accountingDataHarvesterPlugin.launch(inputs);
|
2018-06-14 18:17:22 +02:00
|
|
|
from.add(aggregationType.getCalendarField(), 1);
|
|
|
|
}
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-05-16 15:08:25 +02:00
|
|
|
logger.info("End.");
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-05-21 15:37:57 +02:00
|
|
|
} catch(Exception e) {
|
2018-05-17 16:04:22 +02:00
|
|
|
logger.error("", e);
|
2018-05-16 15:08:25 +02:00
|
|
|
}
|
|
|
|
}
|
2018-06-14 14:50:42 +02:00
|
|
|
|
2018-06-18 15:15:12 +02:00
|
|
|
// @Test
|
|
|
|
public void launchOldDataVREAccessesHarvester() {
|
|
|
|
try {
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-06-18 15:15:12 +02:00
|
|
|
Utils.setContext(ROOT);
|
2018-09-04 11:20:11 +02:00
|
|
|
// AccountingDao dao = AccountingDao.get();
|
2018-06-18 15:15:12 +02:00
|
|
|
|
|
|
|
DataHarvestPluginDeclaration dataHarvestPluginDeclaration = new DataHarvestPluginDeclaration();
|
|
|
|
|
|
|
|
AccountingDataHarvesterPlugin accountingDataHarvesterPlugin = new AccountingDataHarvesterPlugin(
|
|
|
|
dataHarvestPluginDeclaration);
|
|
|
|
Properties properties = accountingDataHarvesterPlugin.getConfigParameters();
|
|
|
|
AccountingDataHarvesterPlugin.getProperties().set(properties);
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-06-18 15:15:12 +02:00
|
|
|
ContextAuthorization contextAuthorization = new ContextAuthorization();
|
|
|
|
SortedSet<String> contexts = contextAuthorization.getContexts();
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-06-18 15:15:12 +02:00
|
|
|
AggregationType aggregationType = AggregationType.MONTHLY;
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-06-18 15:44:10 +02:00
|
|
|
Calendar from = DateUtils.getStartCalendar(2018, Calendar.APRIL, 1);
|
2018-06-18 15:15:12 +02:00
|
|
|
|
2018-09-04 11:20:11 +02:00
|
|
|
Calendar runbeforeDate = DateUtils.getStartCalendar(2018, Calendar.JUNE, 1);
|
2018-06-18 15:15:12 +02:00
|
|
|
|
|
|
|
while(from.before(runbeforeDate)) {
|
|
|
|
Date start = from.getTime();
|
|
|
|
Date end = DateUtils.getEndDateFromStartDate(aggregationType, start, 1);
|
|
|
|
|
|
|
|
logger.debug("Harvesting from {} to {}", DateUtils.format(start), DateUtils.format(end));
|
|
|
|
|
2018-09-04 11:13:16 +02:00
|
|
|
ArrayList<AccountingRecord> accountingRecords = new ArrayList<>();
|
2018-06-18 15:15:12 +02:00
|
|
|
|
|
|
|
VREAccessesHarvester vreAccessesHarvester = null;
|
|
|
|
|
|
|
|
for(String context : contexts) {
|
|
|
|
// Setting the token for the context
|
|
|
|
Utils.setContext(contextAuthorization.getTokenForContext(context));
|
|
|
|
|
|
|
|
ScopeBean scopeBean = new ScopeBean(context);
|
|
|
|
|
|
|
|
if(vreAccessesHarvester == null) {
|
|
|
|
|
|
|
|
if(scopeBean.is(Type.INFRASTRUCTURE)) {
|
|
|
|
vreAccessesHarvester = new VREAccessesHarvester(start, end);
|
2018-09-04 11:20:11 +02:00
|
|
|
} else {
|
2018-06-18 15:15:12 +02:00
|
|
|
// This code should be never used because the scopes are sorted by fullname
|
|
|
|
|
|
|
|
ScopeBean parent = scopeBean.enclosingScope();
|
|
|
|
while(!parent.is(Type.INFRASTRUCTURE)) {
|
|
|
|
parent = scopeBean.enclosingScope();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setting back token for the context
|
|
|
|
Utils.setContext(contextAuthorization.getTokenForContext(parent.toString()));
|
|
|
|
|
|
|
|
vreAccessesHarvester = new VREAccessesHarvester(start, end);
|
|
|
|
|
|
|
|
// Setting back token for the context
|
|
|
|
Utils.setContext(contextAuthorization.getTokenForContext(context));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2018-09-04 11:20:11 +02:00
|
|
|
if(context.startsWith(AccountingDataHarvesterPlugin.SO_BIG_DATA_VO)
|
|
|
|
&& start.before(DateUtils.getStartCalendar(2018, Calendar.APRIL, 1).getTime())) {
|
|
|
|
logger.info("Not Harvesting VREs Accesses for {} from {} to {}", context,
|
|
|
|
DateUtils.format(start), DateUtils.format(end));
|
2018-06-18 15:15:12 +02:00
|
|
|
} else {
|
|
|
|
// Collecting Google Analytics Data for VREs Accesses
|
2018-09-04 11:13:16 +02:00
|
|
|
List<AccountingRecord> harvested = vreAccessesHarvester.getAccountingRecords();
|
|
|
|
accountingRecords.addAll(harvested);
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-06-18 15:15:12 +02:00
|
|
|
}
|
|
|
|
} catch(Exception e) {
|
|
|
|
logger.error("Error harvesting Social Interactions for {}", context, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-04 11:20:11 +02:00
|
|
|
logger.debug("Harvest Measures from {} to {} are {}", DateUtils.format(start), DateUtils.format(end),
|
|
|
|
accountingRecords);
|
2018-06-18 15:15:12 +02:00
|
|
|
Utils.setContext(ROOT);
|
2018-09-04 11:13:16 +02:00
|
|
|
|
2018-09-04 11:20:11 +02:00
|
|
|
// dao.insertRecords(accountingRecords.toArray(new AccountingRecord[1]));
|
2018-06-18 15:15:12 +02:00
|
|
|
|
2018-06-18 15:44:10 +02:00
|
|
|
Thread.sleep(TimeUnit.SECONDS.toMillis(10));
|
|
|
|
|
2018-06-18 15:15:12 +02:00
|
|
|
from.add(aggregationType.getCalendarField(), 1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Utils.setContext(ROOT);
|
|
|
|
|
|
|
|
} catch(Exception e) {
|
|
|
|
logger.error("", e);
|
|
|
|
}
|
2018-09-04 11:20:11 +02:00
|
|
|
|
|
|
|
logger.info("End.");
|
2018-06-18 15:15:12 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-06-14 18:17:22 +02:00
|
|
|
// @Test
|
2018-06-14 14:50:42 +02:00
|
|
|
public void testScopeBean() throws Exception {
|
2018-06-18 15:15:12 +02:00
|
|
|
Utils.setContext(ROOT);
|
2018-06-14 14:50:42 +02:00
|
|
|
SortedSet<String> contexts = getContexts();
|
2018-06-14 18:17:22 +02:00
|
|
|
|
|
|
|
AggregationType aggregationType = AggregationType.MONTHLY;
|
|
|
|
|
|
|
|
Date start = DateUtils.getStartCalendar(2018, Calendar.MARCH, 1).getTime();
|
|
|
|
// start = DateUtils.getPreviousPeriod(measureType).getTime();
|
|
|
|
Date end = DateUtils.getEndDateFromStartDate(aggregationType, start, 1);
|
|
|
|
|
|
|
|
logger.info("\n\n\n");
|
|
|
|
|
2018-06-14 14:50:42 +02:00
|
|
|
for(String context : contexts) {
|
|
|
|
ScopeBean scopeBean = new ScopeBean(context);
|
2018-06-14 18:17:22 +02:00
|
|
|
// logger.debug("FullName {} - Name {}", scopeBean.toString(), scopeBean.name());
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
if(scopeBean.is(Type.VRE) && start.equals(DateUtils.getPreviousPeriod(aggregationType).getTime())) {
|
|
|
|
logger.info("Harvesting (VRE Users) for {} from {} to {}", context, DateUtils.format(start),
|
|
|
|
DateUtils.format(end));
|
2018-09-04 11:20:11 +02:00
|
|
|
} else {
|
2018-06-14 18:17:22 +02:00
|
|
|
logger.info("--- Not Harvesting (VRE Users) for {} from {} to {}", context, DateUtils.format(start),
|
|
|
|
DateUtils.format(end));
|
|
|
|
}
|
|
|
|
|
2018-09-04 11:20:11 +02:00
|
|
|
if((context.startsWith(AccountingDataHarvesterPlugin.SO_BIG_DATA_VO)
|
|
|
|
|| context.startsWith(AccountingDataHarvesterPlugin.SO_BIG_DATA_EU_VRE)
|
2018-06-14 18:17:22 +02:00
|
|
|
|| context.startsWith(AccountingDataHarvesterPlugin.SO_BIG_DATA_IT_VRE))
|
|
|
|
&& start.before(DateUtils.getStartCalendar(2018, Calendar.APRIL, 1).getTime())) {
|
2018-09-04 11:20:11 +02:00
|
|
|
logger.info("--- Not Harvesting (SoBigData Check) for {} from {} to {}", context,
|
|
|
|
DateUtils.format(start), DateUtils.format(end));
|
2018-06-14 18:17:22 +02:00
|
|
|
} else {
|
|
|
|
logger.info("Harvesting (SoBigData Check) for {} from {} to {}", context, DateUtils.format(start),
|
|
|
|
DateUtils.format(end));
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch(Exception e) {
|
|
|
|
logger.error("Error harvesting Social Interactions for {}", context, e);
|
|
|
|
}
|
|
|
|
|
2018-06-14 14:50:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-07-05 18:25:05 +02:00
|
|
|
// @Test
|
2018-06-14 14:50:42 +02:00
|
|
|
public void testVREAccessesHarvester() {
|
|
|
|
try {
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-06-18 15:15:12 +02:00
|
|
|
Utils.setContext(ROOT);
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-06-14 18:17:22 +02:00
|
|
|
AggregationType measureType = AggregationType.MONTHLY;
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-06-14 14:50:42 +02:00
|
|
|
// Date start = DateUtils.getStartCalendar(2015, Calendar.FEBRUARY, 1).getTime();
|
|
|
|
// Date end = DateUtils.getStartCalendar(2019, Calendar.FEBRUARY, 1).getTime();
|
|
|
|
|
|
|
|
Date start = DateUtils.getPreviousPeriod(measureType).getTime();
|
|
|
|
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1);
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-06-14 14:50:42 +02:00
|
|
|
AccountingDataHarvesterPlugin accountingDataHarvesterPlugin = new AccountingDataHarvesterPlugin(null);
|
|
|
|
accountingDataHarvesterPlugin.getConfigParameters();
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-06-14 14:50:42 +02:00
|
|
|
ContextAuthorization contextAuthorization = new ContextAuthorization();
|
2018-06-14 15:30:07 +02:00
|
|
|
SortedSet<String> contexts = contextAuthorization.getContexts();
|
2018-06-14 14:50:42 +02:00
|
|
|
|
|
|
|
VREAccessesHarvester vreAccessesHarvester = null;
|
|
|
|
|
2018-09-04 11:13:16 +02:00
|
|
|
ArrayList<AccountingRecord> accountingRecords = new ArrayList<>();
|
2018-06-14 14:50:42 +02:00
|
|
|
|
|
|
|
for(String context : contexts) {
|
|
|
|
// Setting the token for the context
|
|
|
|
Utils.setContext(contextAuthorization.getTokenForContext(context));
|
|
|
|
|
|
|
|
ScopeBean scopeBean = new ScopeBean(context);
|
|
|
|
|
|
|
|
if(vreAccessesHarvester == null) {
|
|
|
|
|
|
|
|
if(scopeBean.is(Type.INFRASTRUCTURE)) {
|
|
|
|
vreAccessesHarvester = new VREAccessesHarvester(start, end);
|
2018-09-04 11:20:11 +02:00
|
|
|
} else {
|
2018-06-14 14:50:42 +02:00
|
|
|
// This code should be never used because the scopes are sorted by fullname
|
|
|
|
|
|
|
|
ScopeBean parent = scopeBean.enclosingScope();
|
|
|
|
while(!parent.is(Type.INFRASTRUCTURE)) {
|
|
|
|
parent = scopeBean.enclosingScope();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setting back token for the context
|
|
|
|
Utils.setContext(contextAuthorization.getTokenForContext(parent.toString()));
|
|
|
|
|
|
|
|
vreAccessesHarvester = new VREAccessesHarvester(start, end);
|
|
|
|
|
|
|
|
// Setting back token for the context
|
|
|
|
Utils.setContext(contextAuthorization.getTokenForContext(context));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2018-09-04 11:20:11 +02:00
|
|
|
if(context.startsWith(AccountingDataHarvesterPlugin.SO_BIG_DATA_VO)
|
|
|
|
&& start.before(DateUtils.getStartCalendar(2018, Calendar.APRIL, 1).getTime())) {
|
|
|
|
logger.info("Not Harvesting VREs Accesses for {} from {} to {}", context,
|
|
|
|
DateUtils.format(start), DateUtils.format(end));
|
2018-06-14 16:19:25 +02:00
|
|
|
} else {
|
|
|
|
// Collecting Google Analytics Data for VREs Accesses
|
2018-09-04 11:13:16 +02:00
|
|
|
List<AccountingRecord> harvested = vreAccessesHarvester.getAccountingRecords();
|
|
|
|
accountingRecords.addAll(harvested);
|
2018-06-14 16:19:25 +02:00
|
|
|
}
|
2018-06-14 14:50:42 +02:00
|
|
|
} catch(Exception e) {
|
|
|
|
logger.error("Error harvesting Social Interactions for {}", context, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-04 11:13:16 +02:00
|
|
|
logger.debug("{}", accountingRecords);
|
2018-06-14 14:50:42 +02:00
|
|
|
|
|
|
|
} catch(Exception e) {
|
|
|
|
logger.error("", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-05 18:25:05 +02:00
|
|
|
// @Test
|
|
|
|
public void testSocialInteraction() {
|
|
|
|
try {
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-07-05 18:25:05 +02:00
|
|
|
Utils.setContext(ROOT);
|
2018-09-04 11:20:11 +02:00
|
|
|
// AccountingDao dao = AccountingDao.get();
|
2018-07-05 18:25:05 +02:00
|
|
|
|
|
|
|
DataHarvestPluginDeclaration dataHarvestPluginDeclaration = new DataHarvestPluginDeclaration();
|
|
|
|
|
|
|
|
AccountingDataHarvesterPlugin accountingDataHarvesterPlugin = new AccountingDataHarvesterPlugin(
|
|
|
|
dataHarvestPluginDeclaration);
|
|
|
|
Properties properties = accountingDataHarvesterPlugin.getConfigParameters();
|
|
|
|
AccountingDataHarvesterPlugin.getProperties().set(properties);
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-07-05 18:25:05 +02:00
|
|
|
ContextAuthorization contextAuthorization = new ContextAuthorization();
|
|
|
|
|
|
|
|
SortedSet<String> contexts = new TreeSet<>();
|
|
|
|
contexts.add("/d4science.research-infrastructures.eu/D4Research");
|
|
|
|
contexts.add("/d4science.research-infrastructures.eu/FARM/WECAFC-FIRMS");
|
|
|
|
contexts.add("/d4science.research-infrastructures.eu/gCubeApps/BlueBridgeProject");
|
|
|
|
contexts.add("/d4science.research-infrastructures.eu/gCubeApps/Parthenos");
|
|
|
|
contexts.add("/d4science.research-infrastructures.eu/gCubeApps/ScalableDataMining");
|
|
|
|
contexts.add("/d4science.research-infrastructures.eu/gCubeApps/gCube");
|
|
|
|
|
|
|
|
AggregationType aggregationType = AggregationType.MONTHLY;
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-07-05 18:25:05 +02:00
|
|
|
Calendar from = DateUtils.getStartCalendar(2018, Calendar.JUNE, 1);
|
|
|
|
Date start = from.getTime();
|
|
|
|
Date end = DateUtils.getEndDateFromStartDate(aggregationType, start, 1);
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-07-05 18:25:05 +02:00
|
|
|
logger.debug("Harvesting Social Interaction from {} to {}", DateUtils.format(start), DateUtils.format(end));
|
|
|
|
|
2018-09-04 11:13:16 +02:00
|
|
|
ArrayList<AccountingRecord> accountingRecords = new ArrayList<>();
|
2018-07-05 18:25:05 +02:00
|
|
|
|
|
|
|
for(String context : contexts) {
|
|
|
|
// Setting the token for the context
|
|
|
|
Utils.setContext(contextAuthorization.getTokenForContext(context));
|
|
|
|
try {
|
|
|
|
// Collecting info on social (posts, replies and likes)
|
|
|
|
logger.info("Going to harvest Social Interactions for {}", context);
|
|
|
|
SocialInteractionsHarvester socialHarvester = new SocialInteractionsHarvester(start, end);
|
2018-09-04 11:13:16 +02:00
|
|
|
List<AccountingRecord> harvested = socialHarvester.getAccountingRecords();
|
|
|
|
accountingRecords.addAll(harvested);
|
2018-07-05 18:25:05 +02:00
|
|
|
} catch(Exception e) {
|
|
|
|
logger.error("Error harvesting Social Interactions for {}", context, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-04 11:20:11 +02:00
|
|
|
logger.debug("Harvest Measures from {} to {} are {}", DateUtils.format(start), DateUtils.format(end),
|
|
|
|
accountingRecords);
|
|
|
|
Utils.setContext(ROOT);
|
|
|
|
// dao.insertRecords(accountingRecords.toArray(new AccountingRecord[1]));
|
2018-07-05 18:25:05 +02:00
|
|
|
|
|
|
|
} catch(Exception e) {
|
|
|
|
logger.error("", e);
|
|
|
|
}
|
2018-09-04 11:20:11 +02:00
|
|
|
|
|
|
|
logger.info("End.");
|
2018-07-05 18:25:05 +02:00
|
|
|
|
|
|
|
}
|
2018-06-14 14:50:42 +02:00
|
|
|
|
2018-07-05 18:25:05 +02:00
|
|
|
// @Test
|
2018-05-18 18:33:28 +02:00
|
|
|
public void testMethodInvocation() {
|
|
|
|
try {
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-06-18 15:15:12 +02:00
|
|
|
Utils.setContext(StockAssessment);
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-06-14 18:17:22 +02:00
|
|
|
AggregationType measureType = AggregationType.MONTHLY;
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-05-18 18:33:28 +02:00
|
|
|
Date start = DateUtils.getPreviousPeriod(measureType).getTime();
|
|
|
|
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1);
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-05-18 18:33:28 +02:00
|
|
|
MethodInvocationHarvester methodInvocationHarvester = new MethodInvocationHarvester(start, end);
|
2018-09-04 11:20:11 +02:00
|
|
|
List<AccountingRecord> accountingRecords = methodInvocationHarvester.getAccountingRecords();
|
|
|
|
|
|
|
|
logger.debug("{}", accountingRecords);
|
2018-09-04 11:13:16 +02:00
|
|
|
|
2018-05-21 15:37:57 +02:00
|
|
|
} catch(Exception e) {
|
2018-05-18 18:33:28 +02:00
|
|
|
logger.error("", e);
|
|
|
|
}
|
|
|
|
}
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-07-05 18:25:05 +02:00
|
|
|
// @Test
|
2018-05-18 18:33:28 +02:00
|
|
|
public void testTagMeMethodInvocation() {
|
2018-05-18 18:24:53 +02:00
|
|
|
try {
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-06-18 15:15:12 +02:00
|
|
|
Utils.setContext(TAGME);
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-06-14 18:17:22 +02:00
|
|
|
AggregationType measureType = AggregationType.MONTHLY;
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-05-18 18:24:53 +02:00
|
|
|
Date start = DateUtils.getPreviousPeriod(measureType).getTime();
|
|
|
|
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1);
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-05-18 18:24:53 +02:00
|
|
|
TagMeMethodInvocationHarvester methodInvocationHarvester = new TagMeMethodInvocationHarvester(start, end);
|
2018-09-04 11:20:11 +02:00
|
|
|
List<AccountingRecord> accountingRecords = methodInvocationHarvester.getAccountingRecords();
|
|
|
|
|
|
|
|
logger.debug("{}", accountingRecords);
|
|
|
|
|
2018-05-21 15:37:57 +02:00
|
|
|
} catch(Exception e) {
|
2018-05-18 18:24:53 +02:00
|
|
|
logger.error("", e);
|
|
|
|
}
|
|
|
|
}
|
2018-06-18 15:15:12 +02:00
|
|
|
|
|
|
|
// @Test
|
|
|
|
public void testGetVREUsersForSpecificVRE() {
|
|
|
|
try {
|
|
|
|
Utils.setContext(ROOT);
|
|
|
|
|
|
|
|
DataHarvestPluginDeclaration dataHarvestPluginDeclaration = new DataHarvestPluginDeclaration();
|
|
|
|
AccountingDataHarvesterPlugin accountingDataHarvesterPlugin = new AccountingDataHarvesterPlugin(
|
|
|
|
dataHarvestPluginDeclaration);
|
|
|
|
Properties properties = accountingDataHarvesterPlugin.getConfigParameters();
|
|
|
|
AccountingDataHarvesterPlugin.getProperties().set(properties);
|
|
|
|
|
2018-09-04 11:20:11 +02:00
|
|
|
// AccountingDao dao = AccountingDao.get();
|
2018-06-18 15:15:12 +02:00
|
|
|
|
|
|
|
ContextAuthorization contextAuthorization = new ContextAuthorization();
|
2018-09-04 11:20:11 +02:00
|
|
|
Utils.setContext(contextAuthorization
|
|
|
|
.getTokenForContext("/d4science.research-infrastructures.eu/SoBigData/SportsDataScience"));
|
|
|
|
|
2018-06-18 15:15:12 +02:00
|
|
|
AggregationType measureType = AggregationType.MONTHLY;
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-06-18 15:15:12 +02:00
|
|
|
Date start = DateUtils.getPreviousPeriod(measureType).getTime();
|
|
|
|
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1);
|
|
|
|
|
|
|
|
VREUsersHarvester vreUsersHarvester = new VREUsersHarvester(start, end);
|
2018-09-04 11:13:16 +02:00
|
|
|
List<AccountingRecord> harvested = vreUsersHarvester.getAccountingRecords();
|
|
|
|
|
2018-06-18 15:15:12 +02:00
|
|
|
logger.info("Harvested Data from {} to {} : {}", DateUtils.format(start), DateUtils.format(end), harvested);
|
|
|
|
|
|
|
|
org.gcube.dataharvest.utils.Utils.setContext(ROOT);
|
2018-09-04 11:20:11 +02:00
|
|
|
// dao.insertRecords(accountingRecords.toArray(new AccountingRecord[1]));
|
2018-06-18 15:15:12 +02:00
|
|
|
|
|
|
|
} catch(Exception e) {
|
|
|
|
logger.error("", e);
|
|
|
|
}
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-06-18 15:15:12 +02:00
|
|
|
}
|
|
|
|
|
2018-07-05 18:25:05 +02:00
|
|
|
// @Test
|
2018-05-24 12:49:53 +02:00
|
|
|
public void testFilteringGenericResource() {
|
2018-05-21 12:51:17 +02:00
|
|
|
try {
|
2018-06-18 15:15:12 +02:00
|
|
|
Utils.setContext(RESOURCE_CATALOGUE);
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-06-14 18:17:22 +02:00
|
|
|
AggregationType measureType = AggregationType.MONTHLY;
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-05-21 12:51:17 +02:00
|
|
|
Date start = DateUtils.getPreviousPeriod(measureType).getTime();
|
|
|
|
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1);
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-05-28 15:22:59 +02:00
|
|
|
SortedSet<String> contexts = getContexts();
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-05-24 12:49:53 +02:00
|
|
|
AccountingDataHarvesterPlugin accountingDataHarvesterPlugin = new AccountingDataHarvesterPlugin(null);
|
|
|
|
accountingDataHarvesterPlugin.getConfigParameters();
|
2018-09-04 11:20:11 +02:00
|
|
|
|
|
|
|
ResourceCatalogueHarvester resourceCatalogueHarvester = new ResourceCatalogueHarvester(start, end,
|
|
|
|
contexts);
|
|
|
|
SortedSet<String> validContexts = resourceCatalogueHarvester.getValidContexts(contexts,
|
|
|
|
SO_BIG_DATA_CONTEXT + "/");
|
2018-05-28 12:00:15 +02:00
|
|
|
logger.info("Valid Contexts {}", validContexts);
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-05-21 15:37:57 +02:00
|
|
|
} catch(Exception e) {
|
2018-05-21 12:51:17 +02:00
|
|
|
logger.error("", e);
|
|
|
|
}
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-05-21 12:51:17 +02:00
|
|
|
}
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-07-05 18:25:05 +02:00
|
|
|
// @Test
|
2018-05-24 12:49:53 +02:00
|
|
|
public void testResourceCatalogueHarvester() {
|
2018-05-21 15:37:57 +02:00
|
|
|
try {
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-06-18 15:15:12 +02:00
|
|
|
Utils.setContext(RESOURCE_CATALOGUE);
|
2018-05-28 12:00:15 +02:00
|
|
|
|
2018-06-14 18:17:22 +02:00
|
|
|
AggregationType measureType = AggregationType.MONTHLY;
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-05-28 16:03:31 +02:00
|
|
|
// Date start = DateUtils.getStartCalendar(2015, Calendar.FEBRUARY, 1).getTime();
|
|
|
|
// Date end = DateUtils.getStartCalendar(2019, Calendar.FEBRUARY, 1).getTime();
|
|
|
|
|
2018-05-28 15:22:59 +02:00
|
|
|
Date start = DateUtils.getPreviousPeriod(measureType).getTime();
|
2018-05-24 17:10:45 +02:00
|
|
|
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1);
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-05-24 17:10:45 +02:00
|
|
|
AccountingDataHarvesterPlugin accountingDataHarvesterPlugin = new AccountingDataHarvesterPlugin(null);
|
|
|
|
accountingDataHarvesterPlugin.getConfigParameters();
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-05-28 15:22:59 +02:00
|
|
|
SortedSet<String> contexts = getContexts();
|
2018-05-28 12:00:15 +02:00
|
|
|
|
2018-09-04 11:20:11 +02:00
|
|
|
ResourceCatalogueHarvester resourceCatalogueHarvester = new ResourceCatalogueHarvester(start, end,
|
|
|
|
contexts);
|
2018-09-04 11:13:16 +02:00
|
|
|
List<AccountingRecord> data = resourceCatalogueHarvester.getAccountingRecords();
|
|
|
|
|
2018-05-28 12:00:15 +02:00
|
|
|
logger.debug("{}", data);
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-05-24 17:10:45 +02:00
|
|
|
} catch(Exception e) {
|
|
|
|
logger.error("", e);
|
|
|
|
}
|
|
|
|
}
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-11-12 16:30:20 +01:00
|
|
|
// @Test
|
2018-05-24 17:10:45 +02:00
|
|
|
public void testDataMethodDownloadHarvester() {
|
|
|
|
try {
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-06-18 15:15:12 +02:00
|
|
|
Utils.setContext(RESOURCE_CATALOGUE);
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-06-14 18:17:22 +02:00
|
|
|
AggregationType measureType = AggregationType.MONTHLY;
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-05-28 16:03:31 +02:00
|
|
|
// Date start = DateUtils.getStartCalendar(2015, Calendar.FEBRUARY, 1).getTime();
|
|
|
|
// Date end = DateUtils.getStartCalendar(2019, Calendar.FEBRUARY, 1).getTime();
|
|
|
|
|
2018-05-28 15:22:59 +02:00
|
|
|
Date start = DateUtils.getPreviousPeriod(measureType).getTime();
|
2018-05-28 12:00:15 +02:00
|
|
|
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1);
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-05-24 12:49:53 +02:00
|
|
|
AccountingDataHarvesterPlugin accountingDataHarvesterPlugin = new AccountingDataHarvesterPlugin(null);
|
|
|
|
accountingDataHarvesterPlugin.getConfigParameters();
|
2018-09-04 11:20:11 +02:00
|
|
|
|
2018-05-28 15:22:59 +02:00
|
|
|
SortedSet<String> contexts = getContexts();
|
2018-05-28 12:00:15 +02:00
|
|
|
|
2018-09-04 11:20:11 +02:00
|
|
|
DataMethodDownloadHarvester dataMethodDownloadHarvester = new DataMethodDownloadHarvester(start, end,
|
|
|
|
contexts);
|
2018-09-04 11:13:16 +02:00
|
|
|
List<AccountingRecord> data = dataMethodDownloadHarvester.getAccountingRecords();
|
|
|
|
|
2018-05-28 12:00:15 +02:00
|
|
|
logger.debug("{}", data);
|
|
|
|
|
2018-05-21 15:37:57 +02:00
|
|
|
} catch(Exception e) {
|
|
|
|
logger.error("", e);
|
|
|
|
}
|
|
|
|
}
|
2018-06-14 14:50:42 +02:00
|
|
|
|
2018-11-12 16:30:20 +01:00
|
|
|
|
|
|
|
public static final String E_LEARNING_AREA_VRE = "/d4science.research-infrastructures.eu/SoBigData/E-Learning_Area";
|
|
|
|
|
|
|
|
// @Test
|
|
|
|
public void addMissingVREAccesses() {
|
|
|
|
try {
|
|
|
|
|
|
|
|
Utils.setContext(ROOT);
|
|
|
|
|
|
|
|
DataHarvestPluginDeclaration dataHarvestPluginDeclaration = new DataHarvestPluginDeclaration();
|
|
|
|
AccountingDataHarvesterPlugin adhp = new AccountingDataHarvesterPlugin(dataHarvestPluginDeclaration);
|
|
|
|
Properties properties = adhp.getConfigParameters();
|
|
|
|
AccountingDataHarvesterPlugin.getProperties().set(properties);
|
|
|
|
|
|
|
|
ContextAuthorization contextAuthorization = new ContextAuthorization();
|
|
|
|
|
|
|
|
// DatabaseManager dbaseManager = new DatabaseManager();
|
|
|
|
AccountingDao dao = AccountingDao.get();
|
|
|
|
|
|
|
|
Set<ScopeDescriptor> scopeDescriptorSet = dao.getContexts();
|
|
|
|
Map<String,ScopeDescriptor> scopeDescriptorMap = new HashMap<>();
|
|
|
|
for(ScopeDescriptor scopeDescriptor : scopeDescriptorSet) {
|
|
|
|
scopeDescriptorMap.put(scopeDescriptor.getId(), scopeDescriptor);
|
|
|
|
}
|
|
|
|
AccountingDataHarvesterPlugin.scopeDescriptors.set(scopeDescriptorMap);
|
|
|
|
|
|
|
|
|
|
|
|
Set<Dimension> dimensionSet = dao.getDimensions();
|
|
|
|
Map<String,Dimension> dimensionMap = new HashMap<>();
|
|
|
|
for(Dimension dimension : dimensionSet) {
|
|
|
|
dimensionMap.put(dimension.getId(), dimension);
|
|
|
|
}
|
|
|
|
|
|
|
|
AccountingDataHarvesterPlugin.dimensions.set(dimensionMap);
|
|
|
|
|
|
|
|
// ArrayList<HarvestedData> data = new ArrayList<HarvestedData>();
|
|
|
|
ArrayList<AccountingRecord> accountingRecords = new ArrayList<AccountingRecord>();
|
|
|
|
|
|
|
|
String context = E_LEARNING_AREA_VRE;
|
|
|
|
|
|
|
|
// Setting the token for the context
|
|
|
|
Utils.setContext(contextAuthorization.getTokenForContext(context));
|
|
|
|
|
|
|
|
|
|
|
|
ScopeBean scopeBean = new ScopeBean(context);
|
|
|
|
ScopeDescriptor scopeDescriptor = new ScopeDescriptor(scopeBean.name(), context);
|
|
|
|
|
|
|
|
Dimension dimension = AccountingDataHarvesterPlugin.getDimension(HarvestedDataKey.ACCESSES.getKey());
|
|
|
|
|
|
|
|
Calendar calendar = DateUtils.getStartCalendar(2018, Calendar.JULY, 1);
|
|
|
|
calendar.set(Calendar.DAY_OF_MONTH, 15);
|
|
|
|
|
|
|
|
Map<Integer, Integer> monthValues = new HashMap<>();
|
|
|
|
monthValues.put(Calendar.JULY, 54);
|
|
|
|
monthValues.put(Calendar.AUGUST, 23);
|
|
|
|
monthValues.put(Calendar.SEPTEMBER, 127);
|
|
|
|
monthValues.put(Calendar.OCTOBER, 192);
|
|
|
|
|
|
|
|
for(Integer month : monthValues.keySet()) {
|
|
|
|
calendar.set(Calendar.MONTH, month);
|
|
|
|
Instant instant = calendar.toInstant();
|
|
|
|
|
|
|
|
AccountingRecord ar = new AccountingRecord(scopeDescriptor, instant, dimension, (long) monthValues.get(month));
|
|
|
|
logger.debug("{} : {}", ar.getDimension().getId(), ar.getMeasure());
|
|
|
|
accountingRecords.add(ar);
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.trace("{}", accountingRecords);
|
|
|
|
dao.insertRecords(accountingRecords.toArray(new AccountingRecord[1]));
|
|
|
|
|
|
|
|
} catch(Exception e) {
|
|
|
|
logger.error("", e);
|
|
|
|
}
|
|
|
|
}
|
2018-05-16 15:08:25 +02:00
|
|
|
}
|