From 0069f4f363399fdd7f05d4da15c0fc963fe6a3f6 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Thu, 13 Feb 2020 15:30:59 +0100 Subject: [PATCH] Fixed ScopeDescriptior initialization in AccountingDashboardHarvesterPlugin --- .../harvester/CatalogueAccessesHarvester.java | 6 ++- .../AccountingDataHarvesterPluginTest.java | 47 ++++++++----------- 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/src/main/java/org/gcube/dataharvest/harvester/CatalogueAccessesHarvester.java b/src/main/java/org/gcube/dataharvest/harvester/CatalogueAccessesHarvester.java index 086fb91..9282efb 100644 --- a/src/main/java/org/gcube/dataharvest/harvester/CatalogueAccessesHarvester.java +++ b/src/main/java/org/gcube/dataharvest/harvester/CatalogueAccessesHarvester.java @@ -38,6 +38,7 @@ import org.gcube.common.resources.gcore.ServiceEndpoint.Property; import org.gcube.common.resources.gcore.utils.Group; import org.gcube.common.resources.gcore.utils.XPathHelper; import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.common.scope.impl.ScopeBean; import org.gcube.dataharvest.datamodel.AnalyticsReportCredentials; import org.gcube.dataharvest.datamodel.CatalogueAccessesReportRow; import org.gcube.dataharvest.datamodel.HarvestedDataKey; @@ -125,7 +126,10 @@ public class CatalogueAccessesHarvester extends BasicHarvester { } } ScopeDescriptor scopeDescriptor = new ScopeDescriptor(); - scopeDescriptor.setName(dashboardContext); + ScopeBean scopeBean = new ScopeBean(dashboardContext); + scopeDescriptor.setId(dashboardContext); + scopeDescriptor.setName(scopeBean.name()); + AccountingRecord ar1 = new AccountingRecord(scopeDescriptor, instant, getDimension(HarvestedDataKey.CATALOGUE_ACCESSES), (long) catalogueTotalAccesses); AccountingRecord ar2 = new AccountingRecord(scopeDescriptor, instant, getDimension(HarvestedDataKey.CATALOGUE_DATASET_LIST_ACCESSES), (long) catalogueDatasetListAccesses); AccountingRecord ar3 = new AccountingRecord(scopeDescriptor, instant, getDimension(HarvestedDataKey.CATALOGUE_DATASET_ACCESSES), (long) catalogueDatasetAccesses); diff --git a/src/test/java/org/gcube/dataharvest/AccountingDataHarvesterPluginTest.java b/src/test/java/org/gcube/dataharvest/AccountingDataHarvesterPluginTest.java index 2cbd18b..2b050ab 100644 --- a/src/test/java/org/gcube/dataharvest/AccountingDataHarvesterPluginTest.java +++ b/src/test/java/org/gcube/dataharvest/AccountingDataHarvesterPluginTest.java @@ -40,7 +40,6 @@ import org.gcube.vremanagement.executor.api.types.Scheduling; import org.gcube.vremanagement.executor.client.SmartExecutorClient; import org.gcube.vremanagement.executor.client.SmartExecutorClientFactory; import org.junit.Assert; -import org.junit.Test; import org.quartz.CronExpression; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -731,40 +730,34 @@ public class AccountingDataHarvesterPluginTest extends ContextTest { } } - @Test + // @Test public void testCatalogueHarvester() { try { - //Utils.setContext(RESOURCE_CATALOGUE); - ContextTest.setContextByName(ROOT); - System.out.println("vaaa"); - + String context = "/gcube"; + ContextTest.setContextByName(context); + + AccountingDao dao = getAccountingDao(); + Date start = DateUtils.getStartCalendar(2020, Calendar.JANUARY, 1).getTime(); Date end = DateUtils.getStartCalendar(2020, Calendar.FEBRUARY, 1).getTime(); -// Date start = DateUtils.getPreviousPeriod(measureType, false).getTime(); -// Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1, false); + /* + * Date start = DateUtils.getPreviousPeriod(measureType, false).getTime(); + * Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1, false); + */ + + ScopeBean scopeBean = new ScopeBean(context); + logger.debug("FullName {} - Name {}", scopeBean.toString(), scopeBean.name()); -// AccountingDashboardHarvesterPlugin accountingDataHarvesterPlugin = new AccountingDashboardHarvesterPlugin(null); -// accountingDataHarvesterPlugin.getConfigParameters(); + CatalogueAccessesHarvester catalogueHarvester = new CatalogueAccessesHarvester(start, end); + List accountingRecords = catalogueHarvester.getAccountingRecords(); + for (AccountingRecord accountingRecord : accountingRecords) { + logger.debug("{}", accountingRecord); + } + logger.debug("{}", accountingRecords); -// ContextAuthorization contextAuthorization = new ContextAuthorization(); -// SortedSet contexts = contextAuthorization.getContexts(); -// -// for(String context : contexts) { - ScopeBean scopeBean = new ScopeBean(ROOT); - logger.debug("FullName {} - Name {}", scopeBean.toString(), scopeBean.name()); - - - ContextTest.setContextByName(ROOT); - CatalogueAccessesHarvester catalogueHarvester = new CatalogueAccessesHarvester(start, end); - List data = catalogueHarvester.getAccountingRecords(); - for (AccountingRecord accountingRecord : data) { - logger.debug("{}", accountingRecord); - } - logger.debug("{}", data); - -// } + dao.insertRecords(accountingRecords.toArray(new AccountingRecord[1])); } catch(Exception e) { logger.error("", e);