diff --git a/src/main/java/org/gcube/dataharvest/AccountingDashboardHarvesterPlugin.java b/src/main/java/org/gcube/dataharvest/AccountingDashboardHarvesterPlugin.java index 2f1627d..548972f 100644 --- a/src/main/java/org/gcube/dataharvest/AccountingDashboardHarvesterPlugin.java +++ b/src/main/java/org/gcube/dataharvest/AccountingDashboardHarvesterPlugin.java @@ -112,7 +112,7 @@ public class AccountingDashboardHarvesterPlugin extends Plugin { return scopeDescriptors.get().get(context); } - protected static final InheritableThreadLocal> scopeDescriptors = new InheritableThreadLocal>() { + public static final InheritableThreadLocal> scopeDescriptors = new InheritableThreadLocal>() { @Override protected Map initialValue() { diff --git a/src/test/java/org/gcube/dataharvest/AccountingDataHarvesterJupyterTest.java b/src/test/java/org/gcube/dataharvest/AccountingDataHarvesterJupyterTest.java index 342128e..6ab1b6d 100644 --- a/src/test/java/org/gcube/dataharvest/AccountingDataHarvesterJupyterTest.java +++ b/src/test/java/org/gcube/dataharvest/AccountingDataHarvesterJupyterTest.java @@ -8,18 +8,19 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.SortedSet; +import java.util.TreeSet; import org.gcube.accounting.accounting.summary.access.AccountingDao; import org.gcube.accounting.accounting.summary.access.model.ScopeDescriptor; import org.gcube.accounting.accounting.summary.access.model.internal.Dimension; import org.gcube.accounting.accounting.summary.access.model.update.AccountingRecord; import org.gcube.common.authorization.client.exceptions.ObjectNotFound; +import org.gcube.common.scope.impl.ScopeBean; import org.gcube.dataharvest.harvester.JupyterAccessesHarvester; import org.gcube.dataharvest.utils.AggregationType; import org.gcube.dataharvest.utils.ContextAuthorization; import org.gcube.dataharvest.utils.ContextTest; import org.gcube.dataharvest.utils.DateUtils; -import org.junit.Ignore; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -69,16 +70,30 @@ public class AccountingDataHarvesterJupyterTest extends ContextTest { starts.add(DateUtils.getStartCalendar(2021, Calendar.FEBRUARY, 1).getTime()); starts.add(DateUtils.getStartCalendar(2021, Calendar.MARCH, 1).getTime()); starts.add(DateUtils.getStartCalendar(2021, Calendar.APRIL, 1).getTime()); - //starts.add(DateUtils.getStartCalendar(2021, Calendar.MAY, 1).getTime()); + starts.add(DateUtils.getStartCalendar(2021, Calendar.MAY, 1).getTime()); - AggregationType measureType = AggregationType.MONTHLY; ContextAuthorization contextAuthorization = new ContextAuthorization(); + SortedSet contexts = contextAuthorization.getContexts(); + /* + SortedSet contexts = new TreeSet<>(); + contexts.add("/d4science.research-infrastructures.eu/D4OS/Blue-CloudLab"); + contexts.add("/d4science.research-infrastructures.eu/D4OS/Zoo-Phytoplankton_EOV"); + contexts.add("/d4science.research-infrastructures.eu/D4OS/MarineEnvironmentalIndicators"); + */ List accountingRecords = new ArrayList<>(); + Set scopeDescriptorSet = dao.getContexts(); + Map scopeDescriptorMap = new HashMap<>(); + for (ScopeDescriptor scopeDescriptor : scopeDescriptorSet) { + scopeDescriptorMap.put(scopeDescriptor.getId(), scopeDescriptor); + } + AccountingDashboardHarvesterPlugin.scopeDescriptors.set(scopeDescriptorMap); + + for (Date start : starts) { Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1, false); @@ -88,6 +103,15 @@ public class AccountingDataHarvesterJupyterTest extends ContextTest { for(String context : contexts) { ContextTest.setContext(contextAuthorization.getTokenForContext(context)); + ScopeBean scopeBean = new ScopeBean(context); + + ScopeDescriptor actualScopeDescriptor = scopeDescriptorMap.get(context); + if (actualScopeDescriptor == null) { + actualScopeDescriptor = new ScopeDescriptor(scopeBean.name(), context); + } + + AccountingDashboardHarvesterPlugin.scopeDescriptor.set(actualScopeDescriptor); + List harvested = jupyterAccessesHarvester.getAccountingRecords(); accountingRecords.addAll(harvested); }