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
This commit is contained in:
Luca Frosini 2018-06-13 17:39:01 +00:00
parent 3630de9582
commit f27b583949
1 changed files with 46 additions and 23 deletions

View File

@ -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<DataHarvestPluginDecla
}
return properties;
}
private static final InheritableThreadLocal<ContextAuthorization> contextAuthorization = new InheritableThreadLocal<ContextAuthorization>() {
@Override
protected ContextAuthorization initialValue() {
try {
return new ContextAuthorization();
} catch(Exception e) {
throw new RuntimeException("Unable to instantiate ContextAuthorization");
}
}
};
public static InheritableThreadLocal<ContextAuthorization> getContextAuthorization() {
return contextAuthorization;
}
/** {@inheritDoc} */
@Override
@ -155,7 +140,7 @@ public class AccountingDataHarvesterPlugin extends Plugin<DataHarvestPluginDecla
Properties properties = getConfigParameters();
getProperties().set(properties);
ContextAuthorization contextAuthorization = AccountingDataHarvesterPlugin.contextAuthorization.get();
ContextAuthorization contextAuthorization = new ContextAuthorization();
DatabaseManager dbaseManager = new DatabaseManager();
@ -163,13 +148,48 @@ public class AccountingDataHarvesterPlugin extends Plugin<DataHarvestPluginDecla
ArrayList<HarvestedData> data = new ArrayList<HarvestedData>();
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<HarvestedData> 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<DataHarvestPluginDecla
try {
// Collecting info on VRE users
if(getVREUsers) {
VREUsersHarvester vreUsersHarvester = new VREUsersHarvester(start, end);
List<HarvestedData> 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<HarvestedData> harvested = vreUsersHarvester.getData();
data.addAll(harvested);
}
}
} catch(Exception e) {
logger.error("Error harvesting Context Users for {}", context, e);