refs #166: Create accouting-analytics library
https://support.d4science.org/issues/166 Implementing Library git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-analytics@117097 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
5103f831ca
commit
b8ff04c497
|
@ -3,10 +3,28 @@
|
||||||
*/
|
*/
|
||||||
package org.gcube.accounting.analytics.persistence;
|
package org.gcube.accounting.analytics.persistence;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.gcube.accounting.analytics.Filter;
|
||||||
|
import org.gcube.accounting.analytics.Info;
|
||||||
|
import org.gcube.accounting.analytics.TemporalConstraint;
|
||||||
|
import org.gcube.accounting.datamodel.UsageRecord;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class AccountingPersistenceQuery {
|
public abstract class AccountingPersistenceQuery {
|
||||||
|
|
||||||
|
protected abstract void prepareConnection(AccountingPersistenceQueryConfiguration configuration) throws Exception;
|
||||||
|
|
||||||
|
protected abstract List<Info> reallyQuery(Class<? extends UsageRecord> usageRecordType,
|
||||||
|
TemporalConstraint temporalConstraint, List<Filter> filters) throws Exception;
|
||||||
|
|
||||||
|
public List<Info> query(Class<? extends UsageRecord> usageRecordType,
|
||||||
|
TemporalConstraint temporalConstraint, List<Filter> filters) throws Exception{
|
||||||
|
return reallyQuery(usageRecordType, temporalConstraint, filters);
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void close() throws Exception;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
*/
|
*/
|
||||||
package org.gcube.accounting.analytics.persistence;
|
package org.gcube.accounting.analytics.persistence;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
import org.gcube.accounting.persistence.AccountingPersistenceConfiguration;
|
import org.gcube.accounting.persistence.AccountingPersistenceConfiguration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -13,5 +15,15 @@ public class AccountingPersistenceQueryConfiguration extends AccountingPersisten
|
||||||
|
|
||||||
protected final String SERVICE_ENDPOINT_NAME = "PersistenceQuery";
|
protected final String SERVICE_ENDPOINT_NAME = "PersistenceQuery";
|
||||||
|
|
||||||
|
public AccountingPersistenceQueryConfiguration(){
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public AccountingPersistenceQueryConfiguration(URI uri, String username, String password){
|
||||||
|
super(uri, username, password);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AccountingPersistenceQueryConfiguration(String persistenceClassName) throws Exception{
|
||||||
|
super(persistenceClassName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package org.gcube.accounting.analytics;
|
package org.gcube.accounting.analytics.persistence;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -9,7 +9,6 @@ import java.util.ServiceLoader;
|
||||||
|
|
||||||
import org.gcube.accounting.analytics.exception.NoAvailableScopeException;
|
import org.gcube.accounting.analytics.exception.NoAvailableScopeException;
|
||||||
import org.gcube.accounting.analytics.exception.NoUsableAccountingPersistenceQueryFound;
|
import org.gcube.accounting.analytics.exception.NoUsableAccountingPersistenceQueryFound;
|
||||||
import org.gcube.accounting.analytics.persistence.AccountingPersistenceQuery;
|
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -17,24 +16,24 @@ import org.slf4j.LoggerFactory;
|
||||||
/**
|
/**
|
||||||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||||
*/
|
*/
|
||||||
public abstract class ResourceRecordQueryFactory {
|
public abstract class AccountingPersistenceQueryFactory {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(ResourceRecordQueryFactory.class);
|
private static Logger logger = LoggerFactory.getLogger(AccountingPersistenceQueryFactory.class);
|
||||||
|
|
||||||
private static Map<String, ResourceRecordQuery> resourceRecordQueries;
|
private static Map<String, AccountingPersistenceQuery> accountingPersistenceQueries;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
resourceRecordQueries = new HashMap<String, ResourceRecordQuery>();
|
accountingPersistenceQueries = new HashMap<String, AccountingPersistenceQuery>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized static ResourceRecordQuery getInstance() throws NoAvailableScopeException, NoUsableAccountingPersistenceQueryFound {
|
public synchronized static AccountingPersistenceQuery getInstance() throws NoAvailableScopeException, NoUsableAccountingPersistenceQueryFound {
|
||||||
String scope = ScopeProvider.instance.get();
|
String scope = ScopeProvider.instance.get();
|
||||||
if(scope==null){
|
if(scope==null){
|
||||||
new NoAvailableScopeException();
|
new NoAvailableScopeException();
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourceRecordQuery resourceRecordQuery = resourceRecordQueries.get(scope);
|
AccountingPersistenceQuery accountingPersistenceQuery = accountingPersistenceQueries.get(scope);
|
||||||
if(resourceRecordQuery==null){
|
if(accountingPersistenceQuery==null){
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ServiceLoader<AccountingPersistenceQuery> serviceLoader = ServiceLoader.load(AccountingPersistenceQuery.class);
|
ServiceLoader<AccountingPersistenceQuery> serviceLoader = ServiceLoader.load(AccountingPersistenceQuery.class);
|
||||||
|
@ -43,11 +42,9 @@ public abstract class ResourceRecordQueryFactory {
|
||||||
String foundClassName = found.getClass().getSimpleName();
|
String foundClassName = found.getClass().getSimpleName();
|
||||||
logger.debug("Testing {}", foundClassName);
|
logger.debug("Testing {}", foundClassName);
|
||||||
|
|
||||||
//AccountingPersistenceQueryConfiguration configuration = AccountingPersistenceQueryConfiguration.getConfiguration(foundClassName);
|
AccountingPersistenceQueryConfiguration configuration = new AccountingPersistenceQueryConfiguration(foundClassName);
|
||||||
//found.prepareConnection(configuration);
|
found.prepareConnection(configuration);
|
||||||
|
accountingPersistenceQuery = found;
|
||||||
resourceRecordQuery = new ResourceRecordQuery(found);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.debug(String.format("%s not initialized correctly. It will not be used", found.getClass().getSimpleName()));
|
logger.debug(String.format("%s not initialized correctly. It will not be used", found.getClass().getSimpleName()));
|
||||||
|
@ -57,18 +54,18 @@ public abstract class ResourceRecordQueryFactory {
|
||||||
throw new NoUsableAccountingPersistenceQueryFound();
|
throw new NoUsableAccountingPersistenceQueryFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(resourceRecordQuery==null){
|
if(accountingPersistenceQuery==null){
|
||||||
throw new NoUsableAccountingPersistenceQueryFound();
|
throw new NoUsableAccountingPersistenceQueryFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
resourceRecordQueries.put(scope, resourceRecordQuery);
|
accountingPersistenceQueries.put(scope, accountingPersistenceQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
return resourceRecordQuery;
|
return accountingPersistenceQuery;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected ResourceRecordQueryFactory(){
|
protected AccountingPersistenceQueryFactory(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue