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:
parent
3630de9582
commit
f27b583949
|
@ -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;
|
||||
|
@ -80,23 +82,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
|
||||
public void launch(Map<String,Object> inputs) throws Exception {
|
||||
|
@ -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,14 +148,49 @@ public class AccountingDataHarvesterPlugin extends Plugin<DataHarvestPluginDecla
|
|||
|
||||
ArrayList<HarvestedData> data = new ArrayList<HarvestedData>();
|
||||
|
||||
|
||||
String initialToken = SecurityTokenProvider.instance.get();
|
||||
|
||||
for(String context : contexts) {
|
||||
// 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)
|
||||
SocialInteractionsHarvester socialHarvester = new SocialInteractionsHarvester(start, end);
|
||||
|
@ -183,10 +203,13 @@ public class AccountingDataHarvesterPlugin extends Plugin<DataHarvestPluginDecla
|
|||
try {
|
||||
// Collecting info on VRE users
|
||||
if(getVREUsers) {
|
||||
// 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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue