diff --git a/src/main/java/org/gcube/dataharvest/AccountingDataHarvesterPlugin.java b/src/main/java/org/gcube/dataharvest/AccountingDataHarvesterPlugin.java index 37b8407..8a6d580 100644 --- a/src/main/java/org/gcube/dataharvest/AccountingDataHarvesterPlugin.java +++ b/src/main/java/org/gcube/dataharvest/AccountingDataHarvesterPlugin.java @@ -14,12 +14,7 @@ import org.gcube.common.scope.impl.ScopeBean; import org.gcube.common.scope.impl.ScopeBean.Type; import org.gcube.dataharvest.dao.DatabaseManager; import org.gcube.dataharvest.datamodel.HarvestedData; -import org.gcube.dataharvest.harvester.MethodInvocationHarvester; -import org.gcube.dataharvest.harvester.SocialInteractionsHarvester; -import org.gcube.dataharvest.harvester.VREUsersHarvester; -import org.gcube.dataharvest.harvester.sobigdata.DataMethodDownloadHarvester; -import org.gcube.dataharvest.harvester.sobigdata.ResourceCatalogueHarvester; -import org.gcube.dataharvest.harvester.sobigdata.TagMeMethodInvocationHarvester; +import org.gcube.dataharvest.harvester.VREAccessesHarvester; import org.gcube.dataharvest.utils.ContextAuthorization; import org.gcube.dataharvest.utils.DateUtils; import org.gcube.dataharvest.utils.MeasureType; @@ -150,8 +145,7 @@ public class AccountingDataHarvesterPlugin extends Plugin harvested = gAnalytics.getData(); - // data.addAll(harvested); + if(scopeBean.is(Type.VRE)) { + // Collecting Google Analytics Data for VREs Accesses + List harvested = vreAccessesHarvester.getData(); + data.addAll(harvested); + } } catch(Exception e) { logger.error("Error harvesting Social Interactions for {}", context, e); } - + /* try { // Collecting info on social (posts, replies and likes) SocialInteractionsHarvester socialHarvester = new SocialInteractionsHarvester(start, end); @@ -256,11 +254,13 @@ public class AccountingDataHarvesterPlugin extends Plugin vreAccesses; - public VREAccessesHarvester(Date start, Date end) throws ParseException { + public VREAccessesHarvester(Date start, Date end) throws Exception { super(start, end); - Calendar cal = Calendar.getInstance(); - cal.add(Calendar.MONTH, -1); - String infrastructureScope = "/d4science.research-infrastructures.eu"; - try { - vreAccesses = getAllAccesses(start, end, infrastructureScope); - } catch (Exception e) { - e.printStackTrace(); - } + vreAccesses = getAllAccesses(start, end); } @Override @@ -96,6 +90,9 @@ public class VREAccessesHarvester extends BasicHarvester { String context = org.gcube.dataharvest.utils.Utils.getCurrentContext(); ArrayList data = new ArrayList(); int measure = 0; + + ScopeBean scopeBean = new ScopeBean(context); + String[] splitContext = context.split("/"); if (splitContext.length > 3) { String lowerCasedContext = splitContext[3].toLowerCase(); @@ -106,8 +103,8 @@ public class VREAccessesHarvester extends BasicHarvester { if (splits.length > 2 && lowerCasedContext.compareTo(splits[2]) == 0) measure++; } - HarvestedData harvest = new HarvestedData(HarvestedDataKey.USERS, context, measure); - _log.debug(harvest.toString()); + HarvestedData harvest = new HarvestedData(HarvestedDataKey.ACCESSES, context, measure); + logger.debug(harvest.toString()); data.add(harvest); } return data; @@ -123,11 +120,11 @@ public class VREAccessesHarvester extends BasicHarvester { * VREAccessesReportRow [pagePath=/group/agroclimaticmodelling/administration, visitNumber=2] * VREAccessesReportRow [pagePath=/group/agroclimaticmodelling/agroclimaticmodelling, visitNumber=39] */ - private static List getAllAccesses(Date start, Date end, String infrastructureScope) throws Exception { + private static List getAllAccesses(Date start, Date end) throws Exception { DateRange dateRange = getDateRangeForAnalytics(start, end); System.out.println("getting accesses in this time range: " + dateRange.toPrettyString()); - AnalyticsReportCredentials credentialsFromD4S = getAuthorisedApplicationInfoFromIs(infrastructureScope); + AnalyticsReportCredentials credentialsFromD4S = getAuthorisedApplicationInfoFromIs(); AnalyticsReporting service = initializeAnalyticsReporting(credentialsFromD4S); HashMap responses = getReportResponses(service, credentialsFromD4S.getViewIds(), dateRange); List totalAccesses = new ArrayList<>(); @@ -176,7 +173,7 @@ public class VREAccessesHarvester extends BasicHarvester { Dimension pageTitle = new Dimension().setName("ga:pagePath"); for (String view : viewIDs) { - _log.info("Getting data from Google Analytics for viewid: "+ view); + logger.info("Getting data from Google Analytics for viewid: "+ view); // Create the ReportRequest object. ReportRequest request = new ReportRequest() .setViewId(view) @@ -216,7 +213,7 @@ public class VREAccessesHarvester extends BasicHarvester { List rows = report.getData().getRows(); if (rows == null) { - _log.warn("No data found for " + viewId); + logger.warn("No data found for " + viewId); } else for (ReportRow row: rows) { @@ -241,7 +238,7 @@ public class VREAccessesHarvester extends BasicHarvester { } } toReturn.add(var); - _log.debug(var.toString()); + logger.debug(var.toString()); } } } @@ -304,7 +301,7 @@ public class VREAccessesHarvester extends BasicHarvester { } catch (InvalidKeySpecException exception) { unexpectedException = exception; } - throw new IOException("Unexpected exception reading PKCS data"); + throw new IOException("Unexpected exception reading PKCS data", unexpectedException); } private static List getAnalyticsReportingConfigurationFromIS(String infrastructureScope) throws Exception { @@ -321,19 +318,19 @@ public class VREAccessesHarvester extends BasicHarvester { } /** * l + * @throws Exception */ - private static AnalyticsReportCredentials getAuthorisedApplicationInfoFromIs(String infrastructureScope) { + private static AnalyticsReportCredentials getAuthorisedApplicationInfoFromIs() throws Exception { AnalyticsReportCredentials reportCredentials = new AnalyticsReportCredentials(); - String context = infrastructureScope; - ScopeProvider.instance.set(context); + String context = org.gcube.dataharvest.utils.Utils.getCurrentContext(); try { - List list = getAnalyticsReportingConfigurationFromIS(infrastructureScope); + List list = getAnalyticsReportingConfigurationFromIS(context); if (list.size() > 1) { - _log.error("Too many Service Endpoints having name " + SERVICE_ENDPOINT_NAME +" in this scope having Category " + SERVICE_ENDPOINT_CATEGORY); + logger.error("Too many Service Endpoints having name " + SERVICE_ENDPOINT_NAME +" in this scope having Category " + SERVICE_ENDPOINT_CATEGORY); } else if (list.size() == 0){ - _log.warn("There is no Service Endpoint having name " + SERVICE_ENDPOINT_NAME +" and Category " + SERVICE_ENDPOINT_CATEGORY + " in this context: " + infrastructureScope); + logger.warn("There is no Service Endpoint having name " + SERVICE_ENDPOINT_NAME +" and Category " + SERVICE_ENDPOINT_CATEGORY + " in this context: " + context); } else { diff --git a/src/test/java/org/gcube/dataharvest/AccountingDataHarvesterPluginTest.java b/src/test/java/org/gcube/dataharvest/AccountingDataHarvesterPluginTest.java index 22ed43b..dd1fb1b 100644 --- a/src/test/java/org/gcube/dataharvest/AccountingDataHarvesterPluginTest.java +++ b/src/test/java/org/gcube/dataharvest/AccountingDataHarvesterPluginTest.java @@ -60,7 +60,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest { inputs.put(AccountingDataHarvesterPlugin.MEASURE_TYPE_INPUT_PARAMETER, measureType.name()); inputs.put(AccountingDataHarvesterPlugin.GET_VRE_USERS_INPUT_PARAMETER, false); inputs.put(AccountingDataHarvesterPlugin.RERUN_INPUT_PARAMETER, true); - inputs.put(AccountingDataHarvesterPlugin.DRY_RUN_INPUT_PARAMETER, false); + inputs.put(AccountingDataHarvesterPlugin.DRY_RUN_INPUT_PARAMETER, true); /* Calendar from = DateUtils.getStartCalendar(2018, Calendar.FEBRUARY, 1);