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);