2015-07-08 15:24:32 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package org.gcube.accounting.analytics.persistence;
|
|
|
|
|
2015-07-21 16:33:36 +02:00
|
|
|
import java.util.Calendar;
|
2015-07-08 17:28:33 +02:00
|
|
|
import java.util.List;
|
2015-07-21 16:33:36 +02:00
|
|
|
import java.util.Map;
|
2015-09-08 17:04:56 +02:00
|
|
|
import java.util.Set;
|
2015-07-08 17:28:33 +02:00
|
|
|
|
|
|
|
import org.gcube.accounting.analytics.Filter;
|
|
|
|
import org.gcube.accounting.analytics.Info;
|
|
|
|
import org.gcube.accounting.analytics.TemporalConstraint;
|
2015-12-18 17:13:22 +01:00
|
|
|
import org.gcube.documentstore.records.AggregatedRecord;
|
2015-07-08 17:28:33 +02:00
|
|
|
|
2015-07-08 15:24:32 +02:00
|
|
|
/**
|
|
|
|
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
|
|
|
*
|
|
|
|
*/
|
2015-10-14 15:10:06 +02:00
|
|
|
public class AccountingPersistenceQuery {
|
|
|
|
|
|
|
|
private static final AccountingPersistenceQuery accountingPersistenceQuery;
|
|
|
|
|
|
|
|
private AccountingPersistenceQuery(){}
|
2015-07-08 17:28:33 +02:00
|
|
|
|
2015-10-14 15:10:06 +02:00
|
|
|
static {
|
|
|
|
accountingPersistenceQuery = new AccountingPersistenceQuery();
|
|
|
|
}
|
2015-09-07 11:13:20 +02:00
|
|
|
|
2015-10-14 15:10:06 +02:00
|
|
|
protected static synchronized AccountingPersistenceQuery getInstance(){
|
|
|
|
return accountingPersistenceQuery;
|
|
|
|
}
|
2015-07-08 17:28:33 +02:00
|
|
|
|
|
|
|
|
2015-09-08 17:04:56 +02:00
|
|
|
/**
|
|
|
|
* Query the persistence obtaining a Map where the date is the key and
|
|
|
|
* the #Info is the value. The result is relative to an Usage Record Type,
|
|
|
|
* respect a TemporalConstraint and can be applied one or more filters.
|
2015-12-18 17:13:22 +01:00
|
|
|
* @param recordClass the Usage Record Type of interest
|
2015-09-08 17:04:56 +02:00
|
|
|
* @param temporalConstraint the TemporalConstraint (interval and aggregation)
|
|
|
|
* @param filters the filter for the query. If null or empty string get all
|
|
|
|
* data. The filters are evaluated in the order the are presented and are
|
|
|
|
* considered in AND
|
|
|
|
* @return the Map containing for each date in the required interval the
|
|
|
|
* requested data
|
|
|
|
* @throws Exception if fails
|
|
|
|
*/
|
2015-12-18 17:13:22 +01:00
|
|
|
public Map<Calendar, Info> query(@SuppressWarnings("rawtypes") Class<? extends AggregatedRecord> recordClass,
|
2015-07-08 17:28:33 +02:00
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters) throws Exception{
|
2015-12-18 17:13:22 +01:00
|
|
|
return AccountingPersistenceBackendQueryFactory.getInstance().query(recordClass, temporalConstraint, filters);
|
2015-07-08 17:28:33 +02:00
|
|
|
}
|
|
|
|
|
2015-09-08 17:04:56 +02:00
|
|
|
/**
|
|
|
|
* Return the list of key valid for queries a certain usage record type
|
2015-12-18 17:13:22 +01:00
|
|
|
* @param recordClass the usage record type
|
2015-09-08 17:04:56 +02:00
|
|
|
* @return a set containing the list of key
|
|
|
|
* @throws Exception if fails
|
|
|
|
*/
|
2015-12-18 17:13:22 +01:00
|
|
|
public Set<String> getKeys(@SuppressWarnings("rawtypes") Class<? extends AggregatedRecord> recordClass) throws Exception {
|
|
|
|
return AccountingPersistenceBackendQueryFactory.getInstance().getKeys(recordClass);
|
2015-10-14 15:10:06 +02:00
|
|
|
}
|
2015-09-08 17:04:56 +02:00
|
|
|
|
2015-10-01 17:35:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the list of possible values for a key for a certain usage record type
|
|
|
|
* @param usageRecordType the usage record type
|
|
|
|
* @param key the key
|
|
|
|
* @return a set containing the list of possible values
|
|
|
|
* @throws Exception if fails
|
|
|
|
*/
|
2015-12-18 17:13:22 +01:00
|
|
|
public Set<String> getPossibleValuesForKey(@SuppressWarnings("rawtypes") Class<? extends AggregatedRecord> usageRecordType, String key) throws Exception {
|
2015-10-14 15:10:06 +02:00
|
|
|
return AccountingPersistenceBackendQueryFactory.getInstance().getPossibleValuesForKey(usageRecordType, key);
|
|
|
|
}
|
2015-10-01 17:35:09 +02:00
|
|
|
|
2015-09-29 16:25:58 +02:00
|
|
|
/**
|
|
|
|
* Close the connection to persistence
|
|
|
|
* @throws Exception if the close fails
|
|
|
|
*/
|
2015-10-14 15:10:06 +02:00
|
|
|
public void close() throws Exception {
|
|
|
|
AccountingPersistenceBackendQueryFactory.getInstance().close();
|
|
|
|
}
|
2015-10-01 17:35:09 +02:00
|
|
|
|
2015-07-08 15:24:32 +02:00
|
|
|
}
|