Refs #10188: Add a way to esplicitly set the scope in accounting-analytics
Task-Url: https://support.d4science.org/issues/10188 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-analytics@161933 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
3bd30063c0
commit
0dd016b6fa
|
@ -16,6 +16,7 @@ import org.gcube.accounting.analytics.UsageValue;
|
||||||
import org.gcube.accounting.analytics.exception.DuplicatedKeyFilterException;
|
import org.gcube.accounting.analytics.exception.DuplicatedKeyFilterException;
|
||||||
import org.gcube.accounting.analytics.exception.KeyException;
|
import org.gcube.accounting.analytics.exception.KeyException;
|
||||||
import org.gcube.accounting.analytics.exception.ValueException;
|
import org.gcube.accounting.analytics.exception.ValueException;
|
||||||
|
import org.gcube.accounting.datamodel.BasicUsageRecord;
|
||||||
import org.gcube.documentstore.records.AggregatedRecord;
|
import org.gcube.documentstore.records.AggregatedRecord;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
@ -26,6 +27,14 @@ public interface AccountingPersistenceBackendQuery {
|
||||||
|
|
||||||
public static final int KEY_VALUES_LIMIT = 25;
|
public static final int KEY_VALUES_LIMIT = 25;
|
||||||
|
|
||||||
|
public static String getScopeToQuery() {
|
||||||
|
String scope = AccountingPersistenceQueryFactory.getForcedScope().get();
|
||||||
|
if(scope == null) {
|
||||||
|
scope = BasicUsageRecord.getContextFromToken();
|
||||||
|
}
|
||||||
|
return scope;
|
||||||
|
}
|
||||||
|
|
||||||
public void prepareConnection(
|
public void prepareConnection(
|
||||||
AccountingPersistenceBackendQueryConfiguration configuration)
|
AccountingPersistenceBackendQueryConfiguration configuration)
|
||||||
throws Exception;
|
throws Exception;
|
||||||
|
|
|
@ -3,14 +3,33 @@
|
||||||
*/
|
*/
|
||||||
package org.gcube.accounting.analytics.persistence;
|
package org.gcube.accounting.analytics.persistence;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class AccountingPersistenceQueryFactory {
|
public class AccountingPersistenceQueryFactory {
|
||||||
|
|
||||||
|
private static final InheritableThreadLocal<String> forcedScope = new InheritableThreadLocal<String>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String initialValue() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to force the query in a certain scope without changing the current effective scope.
|
||||||
|
* Please note that is responsibility of the AccountingPersistenceBackendQuery implementation
|
||||||
|
* use the scope to query. The facility method getScopeToQuery() has been also created
|
||||||
|
*/
|
||||||
|
public static InheritableThreadLocal<String> getForcedScope() {
|
||||||
|
return forcedScope;
|
||||||
|
}
|
||||||
|
|
||||||
public static AccountingPersistenceQuery getInstance() {
|
public static AccountingPersistenceQuery getInstance() {
|
||||||
return AccountingPersistenceQuery.getInstance();
|
return AccountingPersistenceQuery.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue