From 9d2b2e5010e43da74df3c6cdaef98fbf51dfea20 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Fri, 5 Jun 2020 10:05:45 +0200 Subject: [PATCH] Fixed integration of CoreServicesAccessesHarvester --- .../AccountingDashboardHarvesterPlugin.java | 7 ++++ .../AccountingDataHarvesterPluginTest.java | 42 ++++++++++--------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/gcube/dataharvest/AccountingDashboardHarvesterPlugin.java b/src/main/java/org/gcube/dataharvest/AccountingDashboardHarvesterPlugin.java index 506588d..3a64dc3 100644 --- a/src/main/java/org/gcube/dataharvest/AccountingDashboardHarvesterPlugin.java +++ b/src/main/java/org/gcube/dataharvest/AccountingDashboardHarvesterPlugin.java @@ -20,6 +20,7 @@ import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.scope.impl.ScopeBean; import org.gcube.common.scope.impl.ScopeBean.Type; import org.gcube.dataharvest.harvester.CatalogueAccessesHarvester; +import org.gcube.dataharvest.harvester.CoreServicesAccessesHarvester; import org.gcube.dataharvest.harvester.MethodInvocationHarvester; import org.gcube.dataharvest.harvester.SocialInteractionsHarvester; import org.gcube.dataharvest.harvester.VREAccessesHarvester; @@ -258,9 +259,15 @@ public class AccountingDashboardHarvesterPlugin extends Plugin harvested = catalogueHarvester.getAccountingRecords(); accountingRecords.addAll(harvested); + + CoreServicesAccessesHarvester coreServicesHarvester = new CoreServicesAccessesHarvester(start, end); + List records = coreServicesHarvester.getAccountingRecords(); + accountingRecords.addAll(records); + }catch (Exception e) { logger.error("Error harvesting {} for {}", CatalogueAccessesHarvester.class.getSimpleName(), context, e); } diff --git a/src/test/java/org/gcube/dataharvest/AccountingDataHarvesterPluginTest.java b/src/test/java/org/gcube/dataharvest/AccountingDataHarvesterPluginTest.java index fc40923..de9666e 100644 --- a/src/test/java/org/gcube/dataharvest/AccountingDataHarvesterPluginTest.java +++ b/src/test/java/org/gcube/dataharvest/AccountingDataHarvesterPluginTest.java @@ -90,7 +90,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest { } } - // @Test + @Test public void launch() { try { @@ -109,13 +109,13 @@ public class AccountingDataHarvesterPluginTest extends ContextTest { inputs.put(AccountingDashboardHarvesterPlugin.GET_VRE_USERS_INPUT_PARAMETER, true); inputs.put(AccountingDashboardHarvesterPlugin.RERUN_INPUT_PARAMETER, true); inputs.put(AccountingDashboardHarvesterPlugin.DRY_RUN_INPUT_PARAMETER, false); - inputs.put(AccountingDashboardHarvesterPlugin.PARTIAL_HARVESTING, true); + inputs.put(AccountingDashboardHarvesterPlugin.PARTIAL_HARVESTING, false); /* - Calendar from = DateUtils.getStartCalendar(2016, Calendar.SEPTEMBER, 1); + Calendar from = DateUtils.getStartCalendar(2020, Calendar.MAY, 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); + logger.trace("{} is {}", AccountingDashboardHarvesterPlugin.START_DATE_INPUT_PARAMETER, fromDate); + inputs.put(AccountingDashboardHarvesterPlugin.START_DATE_INPUT_PARAMETER, fromDate); */ accountingDataHarvesterPlugin.launch(inputs); @@ -738,27 +738,29 @@ public class AccountingDataHarvesterPluginTest extends ContextTest { String context = ROOT; //"/gcube"; ContextTest.setContextByName(context); - //AccountingDao dao = getAccountingDao(); + AccountingDao dao = getAccountingDao(); - Date start = DateUtils.getStartCalendar(2020, Calendar.JANUARY, 1).getTime(); - Date end = DateUtils.getStartCalendar(2020, Calendar.FEBRUARY, 1).getTime(); + Date start = DateUtils.getStartCalendar(2017, Calendar.MAY, 1).getTime(); + Date finalEnd = DateUtils.getStartCalendar(2020, Calendar.MAY, 1).getTime(); - /* - * Date start = DateUtils.getPreviousPeriod(measureType, false).getTime(); - * Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1, false); - */ + Date end = DateUtils.getEndDateFromStartDate(AggregationType.MONTHLY, start, 1, false); ScopeBean scopeBean = new ScopeBean(context); logger.debug("FullName {} - Name {}", scopeBean.toString(), scopeBean.name()); - - CoreServicesAccessesHarvester coreServicesHarvester = new CoreServicesAccessesHarvester(start, end); - List accountingRecords = coreServicesHarvester.getAccountingRecords(); - for (AccountingRecord accountingRecord : accountingRecords) { - logger.debug("{}", accountingRecord); + + while(end.before(finalEnd)) { + CoreServicesAccessesHarvester coreServicesHarvester = new CoreServicesAccessesHarvester(start, end); + List accountingRecords = coreServicesHarvester.getAccountingRecords(); + dao.insertRecords(accountingRecords.toArray(new AccountingRecord[1])); + + logger.debug("{} -> {} Data Inserted", DateUtils.format(start), DateUtils.format(end)); + logger.debug("---------------------------------------------------------------------------------------"); + + Thread.sleep(TimeUnit.SECONDS.toMillis(90)); + start = end; + end = DateUtils.getEndDateFromStartDate(AggregationType.MONTHLY, start, 1, false); } - logger.debug("{}", accountingRecords); - - //dao.insertRecords(accountingRecords.toArray(new AccountingRecord[1])); + } catch(Exception e) { logger.error("", e);