From f27b583949849479c55c5f48f53d064a053bc852 Mon Sep 17 00:00:00 2001 From: "luca.frosini" Date: Wed, 13 Jun 2018 17:39:01 +0000 Subject: [PATCH] Added logic to avoid harvesting of VRE users for VO and logic to harvest VRE Accesses git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-dashboard-harvester-se-plugin@169180 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../AccountingDataHarvesterPlugin.java | 69 ++++++++++++------- 1 file changed, 46 insertions(+), 23 deletions(-) diff --git a/src/main/java/org/gcube/dataharvest/AccountingDataHarvesterPlugin.java b/src/main/java/org/gcube/dataharvest/AccountingDataHarvesterPlugin.java index dea5380..37b8407 100644 --- a/src/main/java/org/gcube/dataharvest/AccountingDataHarvesterPlugin.java +++ b/src/main/java/org/gcube/dataharvest/AccountingDataHarvesterPlugin.java @@ -10,6 +10,8 @@ import java.util.Properties; import java.util.SortedSet; 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.dao.DatabaseManager; import org.gcube.dataharvest.datamodel.HarvestedData; import org.gcube.dataharvest.harvester.MethodInvocationHarvester; @@ -79,23 +81,6 @@ public class AccountingDataHarvesterPlugin extends Plugin contextAuthorization = new InheritableThreadLocal() { - - @Override - protected ContextAuthorization initialValue() { - try { - return new ContextAuthorization(); - } catch(Exception e) { - throw new RuntimeException("Unable to instantiate ContextAuthorization"); - } - } - }; - - public static InheritableThreadLocal getContextAuthorization() { - return contextAuthorization; - } /** {@inheritDoc} */ @Override @@ -155,7 +140,7 @@ public class AccountingDataHarvesterPlugin extends Plugin data = new ArrayList(); - String initialToken = SecurityTokenProvider.instance.get(); + + // GAnalytics gAnalytics = null + Object gAnalytics = null; for(String context : contexts) { - // Setting the token for the context Utils.setContext(contextAuthorization.getTokenForContext(context)); + + ScopeBean scopeBean = new ScopeBean(context); + + if(gAnalytics == null) { + + if(scopeBean.is(Type.INFRASTRUCTURE)) { + // gAnalytics = new GAnalytics(); + }else { + // 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())); + + // gAnalytics = new GAnalytics(); + + // Setting back token for the context + Utils.setContext(contextAuthorization.getTokenForContext(context)); + } + + } + try { + // Collecting Google Analytics Data for VREs Accesses + // List harvested = gAnalytics.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) @@ -183,9 +203,12 @@ public class AccountingDataHarvesterPlugin extends Plugin harvested = vreUsersHarvester.getData(); - data.addAll(harvested); + // Harvesting Users only for VREs (not for VO and ROOT which is the sum of the children contexts) + if(scopeBean.is(Type.VRE)) { + VREUsersHarvester vreUsersHarvester = new VREUsersHarvester(start, end); + List harvested = vreUsersHarvester.getData(); + data.addAll(harvested); + } } } catch(Exception e) { logger.error("Error harvesting Context Users for {}", context, e);