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 java.util.SortedSet;
|
||||||
|
|
||||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
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.dao.DatabaseManager;
|
||||||
import org.gcube.dataharvest.datamodel.HarvestedData;
|
import org.gcube.dataharvest.datamodel.HarvestedData;
|
||||||
import org.gcube.dataharvest.harvester.MethodInvocationHarvester;
|
import org.gcube.dataharvest.harvester.MethodInvocationHarvester;
|
||||||
|
@ -80,23 +82,6 @@ public class AccountingDataHarvesterPlugin extends Plugin<DataHarvestPluginDecla
|
||||||
return properties;
|
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} */
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public void launch(Map<String,Object> inputs) throws Exception {
|
public void launch(Map<String,Object> inputs) throws Exception {
|
||||||
|
@ -155,7 +140,7 @@ public class AccountingDataHarvesterPlugin extends Plugin<DataHarvestPluginDecla
|
||||||
Properties properties = getConfigParameters();
|
Properties properties = getConfigParameters();
|
||||||
getProperties().set(properties);
|
getProperties().set(properties);
|
||||||
|
|
||||||
ContextAuthorization contextAuthorization = AccountingDataHarvesterPlugin.contextAuthorization.get();
|
ContextAuthorization contextAuthorization = new ContextAuthorization();
|
||||||
|
|
||||||
DatabaseManager dbaseManager = new DatabaseManager();
|
DatabaseManager dbaseManager = new DatabaseManager();
|
||||||
|
|
||||||
|
@ -163,14 +148,49 @@ public class AccountingDataHarvesterPlugin extends Plugin<DataHarvestPluginDecla
|
||||||
|
|
||||||
ArrayList<HarvestedData> data = new ArrayList<HarvestedData>();
|
ArrayList<HarvestedData> data = new ArrayList<HarvestedData>();
|
||||||
|
|
||||||
|
|
||||||
String initialToken = SecurityTokenProvider.instance.get();
|
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
|
// Setting the token for the context
|
||||||
Utils.setContext(contextAuthorization.getTokenForContext(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 {
|
try {
|
||||||
// Collecting info on social (posts, replies and likes)
|
// Collecting info on social (posts, replies and likes)
|
||||||
SocialInteractionsHarvester socialHarvester = new SocialInteractionsHarvester(start, end);
|
SocialInteractionsHarvester socialHarvester = new SocialInteractionsHarvester(start, end);
|
||||||
|
@ -183,9 +203,12 @@ public class AccountingDataHarvesterPlugin extends Plugin<DataHarvestPluginDecla
|
||||||
try {
|
try {
|
||||||
// Collecting info on VRE users
|
// Collecting info on VRE users
|
||||||
if(getVREUsers) {
|
if(getVREUsers) {
|
||||||
VREUsersHarvester vreUsersHarvester = new VREUsersHarvester(start, end);
|
// Harvesting Users only for VREs (not for VO and ROOT which is the sum of the children contexts)
|
||||||
List<HarvestedData> harvested = vreUsersHarvester.getData();
|
if(scopeBean.is(Type.VRE)) {
|
||||||
data.addAll(harvested);
|
VREUsersHarvester vreUsersHarvester = new VREUsersHarvester(start, end);
|
||||||
|
List<HarvestedData> harvested = vreUsersHarvester.getData();
|
||||||
|
data.addAll(harvested);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
logger.error("Error harvesting Context Users for {}", context, e);
|
logger.error("Error harvesting Context Users for {}", context, e);
|
||||||
|
|
Loading…
Reference in New Issue