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;
|
2016-03-16 13:29:03 +01:00
|
|
|
import java.util.SortedMap;
|
|
|
|
import java.util.SortedSet;
|
|
|
|
import java.util.TreeSet;
|
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;
|
2016-03-16 13:29:03 +01:00
|
|
|
import org.gcube.accounting.datamodel.UsageRecord;
|
2015-12-18 17:13:22 +01:00
|
|
|
import org.gcube.documentstore.records.AggregatedRecord;
|
2016-03-16 13:29:03 +01:00
|
|
|
import org.gcube.documentstore.records.Record;
|
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/
|
2016-03-16 13:29:03 +01:00
|
|
|
*
|
2015-07-08 15:24:32 +02:00
|
|
|
*/
|
2015-10-14 15:10:06 +02:00
|
|
|
public class AccountingPersistenceQuery {
|
|
|
|
|
|
|
|
private static final AccountingPersistenceQuery accountingPersistenceQuery;
|
2016-03-16 13:29:03 +01:00
|
|
|
|
|
|
|
private AccountingPersistenceQuery() {
|
|
|
|
}
|
|
|
|
|
2015-10-14 15:10:06 +02:00
|
|
|
static {
|
|
|
|
accountingPersistenceQuery = new AccountingPersistenceQuery();
|
|
|
|
}
|
2016-03-16 13:29:03 +01:00
|
|
|
|
|
|
|
protected static synchronized AccountingPersistenceQuery getInstance() {
|
2015-10-14 15:10:06 +02:00
|
|
|
return accountingPersistenceQuery;
|
|
|
|
}
|
2016-03-16 13:29:03 +01:00
|
|
|
|
|
|
|
public static SortedSet<String> getQuerableKeys(
|
|
|
|
@SuppressWarnings("rawtypes") AggregatedRecord instance)
|
|
|
|
throws Exception {
|
|
|
|
SortedSet<String> properties = new TreeSet<>(
|
|
|
|
instance.getRequiredFields());
|
|
|
|
|
|
|
|
properties.removeAll(instance.getAggregatedFields());
|
|
|
|
properties.removeAll(instance.getComputedFields());
|
|
|
|
properties.remove(Record.ID);
|
|
|
|
properties.remove(Record.CREATION_TIME);
|
|
|
|
properties.remove(Record.RECORD_TYPE);
|
|
|
|
properties.remove(UsageRecord.SCOPE);
|
|
|
|
|
|
|
|
return properties;
|
2015-07-08 17:28:33 +02:00
|
|
|
}
|
2016-03-16 13:29:03 +01:00
|
|
|
|
|
|
|
public static SortedSet<String> getQuerableKeys(
|
|
|
|
Class<? extends AggregatedRecord<?,?>> aggregatedRecordClass)
|
|
|
|
throws Exception {
|
|
|
|
AggregatedRecord<?,?> instance = aggregatedRecordClass.newInstance();
|
|
|
|
return getQuerableKeys(instance);
|
2015-10-14 15:10:06 +02:00
|
|
|
}
|
2016-03-16 13:29:03 +01:00
|
|
|
|
|
|
|
public Map<Calendar, Info> getTimeSeries(
|
|
|
|
Class<? extends AggregatedRecord<?,?>> aggregatedRecordClass,
|
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters)
|
|
|
|
throws Exception {
|
|
|
|
return AccountingPersistenceBackendQueryFactory.getInstance()
|
|
|
|
.getTimeSeries(aggregatedRecordClass, temporalConstraint,
|
|
|
|
filters);
|
2015-10-14 15:10:06 +02:00
|
|
|
}
|
2016-03-16 13:29:03 +01:00
|
|
|
|
|
|
|
public static SortedMap<Filter, Map<Calendar, Info>> getTopValues(
|
|
|
|
Class<? extends AggregatedRecord<?,?>> aggregatedRecordClass,
|
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters)
|
|
|
|
throws Exception {
|
|
|
|
return AccountingPersistenceBackendQueryFactory.getInstance()
|
|
|
|
.getTopValues(aggregatedRecordClass, temporalConstraint,
|
|
|
|
filters);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static SortedSet<Filter> getNextPossibleValues(
|
|
|
|
Class<? extends AggregatedRecord<?,?>> aggregatedRecordClass,
|
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters)
|
|
|
|
throws Exception {
|
|
|
|
return AccountingPersistenceBackendQueryFactory.getInstance()
|
|
|
|
.getNextPossibleValues(aggregatedRecordClass,
|
|
|
|
temporalConstraint, filters);
|
|
|
|
}
|
|
|
|
|
2015-09-29 16:25:58 +02:00
|
|
|
/**
|
|
|
|
* Close the connection to persistence
|
2016-03-16 13:29:03 +01:00
|
|
|
*
|
|
|
|
* @throws Exception
|
|
|
|
* if the close fails
|
2015-09-29 16:25:58 +02:00
|
|
|
*/
|
2015-10-14 15:10:06 +02:00
|
|
|
public void close() throws Exception {
|
|
|
|
AccountingPersistenceBackendQueryFactory.getInstance().close();
|
|
|
|
}
|
2016-03-16 13:29:03 +01:00
|
|
|
|
2015-07-08 15:24:32 +02:00
|
|
|
}
|