2015-07-08 15:24:32 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package org.gcube.accounting.analytics.persistence;
|
|
|
|
|
2016-03-16 17:30:26 +01:00
|
|
|
import java.util.ArrayList;
|
2015-07-21 16:33:36 +02:00
|
|
|
import java.util.Calendar;
|
2016-03-16 17:30:26 +01:00
|
|
|
import java.util.Iterator;
|
2015-07-08 17:28:33 +02:00
|
|
|
import java.util.List;
|
2016-03-16 17:30:26 +01:00
|
|
|
import java.util.Map;
|
2016-03-16 13:29:03 +01:00
|
|
|
import java.util.SortedMap;
|
|
|
|
import java.util.SortedSet;
|
2016-06-28 15:00:55 +02:00
|
|
|
import java.util.TreeMap;
|
2017-05-05 17:01:23 +02:00
|
|
|
import java.util.TreeSet;
|
2015-07-08 17:28:33 +02:00
|
|
|
|
2016-03-24 18:59:34 +01:00
|
|
|
import javax.activity.InvalidActivityException;
|
|
|
|
|
2015-07-08 17:28:33 +02:00
|
|
|
import org.gcube.accounting.analytics.Filter;
|
|
|
|
import org.gcube.accounting.analytics.Info;
|
2016-03-16 15:53:59 +01:00
|
|
|
import org.gcube.accounting.analytics.NumberedFilter;
|
2015-07-08 17:28:33 +02:00
|
|
|
import org.gcube.accounting.analytics.TemporalConstraint;
|
2016-11-15 11:21:51 +01:00
|
|
|
import org.gcube.accounting.analytics.UsageValue;
|
2016-03-24 18:59:34 +01:00
|
|
|
import org.gcube.accounting.analytics.exception.DuplicatedKeyFilterException;
|
|
|
|
import org.gcube.accounting.analytics.exception.KeyException;
|
|
|
|
import org.gcube.accounting.analytics.exception.ValueException;
|
2017-05-05 17:01:23 +02:00
|
|
|
import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord;
|
|
|
|
import org.gcube.accounting.datamodel.aggregation.AggregatedStorageStatusRecord;
|
2016-03-16 15:53:59 +01:00
|
|
|
import org.gcube.accounting.datamodel.aggregation.AggregatedStorageUsageRecord;
|
2015-12-18 17:13:22 +01:00
|
|
|
import org.gcube.documentstore.records.AggregatedRecord;
|
2016-03-16 17:30:26 +01:00
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
2015-07-08 17:28:33 +02:00
|
|
|
|
2015-07-08 15:24:32 +02:00
|
|
|
/**
|
2016-10-12 14:09:44 +02:00
|
|
|
* @author Luca Frosini (ISTI - CNR)
|
2016-03-16 13:29:03 +01:00
|
|
|
*
|
2015-07-08 15:24:32 +02:00
|
|
|
*/
|
2016-03-24 18:59:34 +01:00
|
|
|
public class AccountingPersistenceQuery implements AccountingPersistenceBackendQuery {
|
2015-10-14 15:10:06 +02:00
|
|
|
|
|
|
|
private static final AccountingPersistenceQuery accountingPersistenceQuery;
|
2016-03-16 13:29:03 +01:00
|
|
|
|
2016-03-16 17:30:26 +01:00
|
|
|
public static final int DEFAULT_LIMIT_RESULT_NUMBER = 5;
|
2016-06-28 15:00:55 +02:00
|
|
|
|
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
|
|
|
|
2016-09-19 12:54:05 +02:00
|
|
|
@Deprecated
|
2016-03-16 13:29:03 +01:00
|
|
|
public static SortedSet<String> getQuerableKeys(
|
|
|
|
@SuppressWarnings("rawtypes") AggregatedRecord instance)
|
2016-06-28 15:00:55 +02:00
|
|
|
throws Exception {
|
2016-09-19 12:54:05 +02:00
|
|
|
return instance.getQuerableKeys();
|
2015-07-08 17:28:33 +02:00
|
|
|
}
|
2016-03-16 13:29:03 +01:00
|
|
|
|
|
|
|
public static SortedSet<String> getQuerableKeys(
|
2016-03-17 12:16:30 +01:00
|
|
|
Class<? extends AggregatedRecord<?,?>> clz)
|
2016-06-28 15:00:55 +02:00
|
|
|
throws Exception {
|
2016-03-17 12:16:30 +01:00
|
|
|
AggregatedRecord<?,?> instance = clz.newInstance();
|
2017-05-05 17:01:23 +02:00
|
|
|
|
|
|
|
//limit filterky for accounting storage status (used from portlet accounting for tad space)
|
|
|
|
if (clz.equals(AggregatedStorageStatusRecord.class)){
|
|
|
|
SortedSet<String> storageStatus= new TreeSet<>();
|
|
|
|
storageStatus.add(AggregatedStorageStatusRecord.CONSUMER_ID);
|
|
|
|
storageStatus.add(AggregatedStorageStatusRecord.DATA_SERVICEID);
|
|
|
|
return storageStatus;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
return instance.getQuerableKeys();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-10-14 15:10:06 +02:00
|
|
|
}
|
2016-06-28 15:00:55 +02:00
|
|
|
|
2016-03-24 18:59:34 +01:00
|
|
|
public static String getDefaultOrderingProperties(
|
|
|
|
Class<? extends AggregatedRecord<?, ?>> clz){
|
2016-03-17 12:16:30 +01:00
|
|
|
if(clz.isAssignableFrom(AggregatedStorageUsageRecord.class)){
|
2016-03-16 15:53:59 +01:00
|
|
|
return AggregatedStorageUsageRecord.DATA_VOLUME;
|
|
|
|
}
|
|
|
|
return AggregatedRecord.OPERATION_COUNT;
|
|
|
|
}
|
2016-06-28 15:00:55 +02:00
|
|
|
|
2016-03-16 17:30:26 +01:00
|
|
|
protected static JSONObject getPaddingJSONObject(
|
|
|
|
Map<Calendar, Info> unpaddedResults) throws JSONException {
|
|
|
|
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
2016-06-28 15:00:55 +02:00
|
|
|
//verify data consistency
|
|
|
|
if (unpaddedResults.size()!=0){
|
|
|
|
Info auxInfo = new ArrayList<Info>(unpaddedResults.values()).get(0);
|
|
|
|
JSONObject auxJsonObject = auxInfo.getValue();
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
Iterator<String> keys = auxJsonObject.keys();
|
|
|
|
while (keys.hasNext()) {
|
|
|
|
String key = keys.next();
|
|
|
|
jsonObject.put(key, 0);
|
|
|
|
}
|
2016-03-16 17:30:26 +01:00
|
|
|
}
|
|
|
|
return jsonObject;
|
|
|
|
}
|
2016-06-28 15:00:55 +02:00
|
|
|
|
2016-03-16 17:30:26 +01:00
|
|
|
/**
|
|
|
|
* Pad the data
|
|
|
|
*
|
|
|
|
* @param unpaddedData
|
|
|
|
* the data to be pad
|
|
|
|
* @param temporalConstraint
|
|
|
|
* temporalConstraint the temporal interval and the granularity
|
|
|
|
* of the data to pad
|
|
|
|
* @return the data padded taking in account the TemporalConstraint
|
|
|
|
* @throws Exception
|
|
|
|
* if fails
|
|
|
|
*/
|
|
|
|
public static SortedMap<Calendar, Info> padMap(
|
|
|
|
SortedMap<Calendar, Info> unpaddedData,
|
|
|
|
TemporalConstraint temporalConstraint) throws Exception {
|
2016-06-28 15:00:55 +02:00
|
|
|
|
2016-03-16 17:30:26 +01:00
|
|
|
JSONObject jsonObject = getPaddingJSONObject(unpaddedData);
|
|
|
|
SortedSet<Calendar> sequence = temporalConstraint.getCalendarSequence();
|
|
|
|
for (Calendar progressTime : sequence) {
|
|
|
|
Info info = unpaddedData.get(progressTime);
|
|
|
|
if (info == null) {
|
|
|
|
info = new Info(progressTime, jsonObject);
|
|
|
|
unpaddedData.put(progressTime, info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return unpaddedData;
|
|
|
|
}
|
2016-06-28 15:00:55 +02:00
|
|
|
|
2016-03-24 18:59:34 +01:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
public SortedMap<Calendar, Info> getTimeSeries(
|
|
|
|
Class<? extends AggregatedRecord<?,?>> clz,
|
2016-06-28 15:00:55 +02:00
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters)
|
|
|
|
throws DuplicatedKeyFilterException, KeyException, ValueException,
|
|
|
|
Exception {
|
|
|
|
|
2016-03-24 18:59:34 +01:00
|
|
|
return this.getTimeSeries(clz, temporalConstraint, filters, false);
|
|
|
|
}
|
2016-06-28 15:00:55 +02:00
|
|
|
|
2016-03-17 12:05:17 +01:00
|
|
|
public SortedMap<Calendar, Info> getTimeSeries(
|
2016-03-17 12:16:30 +01:00
|
|
|
Class<? extends AggregatedRecord<?,?>> clz,
|
2016-06-28 15:00:55 +02:00
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters,
|
|
|
|
boolean pad) throws DuplicatedKeyFilterException, KeyException,
|
|
|
|
ValueException, Exception {
|
2016-03-17 12:05:17 +01:00
|
|
|
SortedMap<Calendar, Info> ret =
|
|
|
|
AccountingPersistenceBackendQueryFactory.getInstance()
|
2016-03-17 12:16:30 +01:00
|
|
|
.getTimeSeries(clz, temporalConstraint,
|
2016-03-17 12:05:17 +01:00
|
|
|
filters);
|
2016-06-28 15:00:55 +02:00
|
|
|
|
|
|
|
if(ret==null){
|
|
|
|
ret = new TreeMap<>();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-17 12:05:17 +01:00
|
|
|
if(pad){
|
|
|
|
ret = padMap(ret, temporalConstraint);
|
|
|
|
}
|
2016-06-28 15:00:55 +02:00
|
|
|
|
2016-03-17 12:05:17 +01:00
|
|
|
return ret;
|
|
|
|
}
|
2017-02-03 12:18:14 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public SortedMap<Calendar, Info> getNoContextTimeSeries(
|
|
|
|
Class<? extends AggregatedRecord<?,?>> clz,
|
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters)
|
|
|
|
throws DuplicatedKeyFilterException, KeyException, ValueException,
|
|
|
|
Exception {
|
|
|
|
|
|
|
|
return this.getNoContextTimeSeries(clz, temporalConstraint, filters, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public SortedMap<Calendar, Info> getNoContextTimeSeries(
|
|
|
|
Class<? extends AggregatedRecord<?,?>> clz,
|
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters,
|
|
|
|
boolean pad) throws DuplicatedKeyFilterException, KeyException,
|
|
|
|
ValueException, Exception {
|
|
|
|
SortedMap<Calendar, Info> ret =
|
|
|
|
AccountingPersistenceBackendQueryFactory.getInstance()
|
|
|
|
.getNoContextTimeSeries(clz, temporalConstraint,
|
|
|
|
filters);
|
|
|
|
|
|
|
|
if(ret==null){
|
|
|
|
ret = new TreeMap<>();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(pad){
|
|
|
|
ret = padMap(ret, temporalConstraint);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-03-17 12:05:17 +01:00
|
|
|
|
|
|
|
public SortedMap<NumberedFilter, SortedMap<Calendar, Info>> getTopValues(
|
2016-03-24 18:59:34 +01:00
|
|
|
Class<? extends AggregatedRecord<?, ?>> clz,
|
2016-06-28 15:00:55 +02:00
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters,
|
|
|
|
String topKey, String orderingProperty, boolean pad, int limit)
|
|
|
|
throws DuplicatedKeyFilterException, KeyException, ValueException,
|
|
|
|
Exception {
|
2016-03-23 11:09:27 +01:00
|
|
|
SortedMap<NumberedFilter, SortedMap<Calendar, Info>> got;
|
2016-06-28 15:00:55 +02:00
|
|
|
|
2016-03-16 17:30:26 +01:00
|
|
|
if(orderingProperty==null){
|
2016-03-17 12:16:30 +01:00
|
|
|
orderingProperty = getDefaultOrderingProperties(clz);
|
2016-03-16 17:30:26 +01:00
|
|
|
}
|
2016-06-28 15:00:55 +02:00
|
|
|
|
2016-03-23 11:09:27 +01:00
|
|
|
got = AccountingPersistenceBackendQueryFactory.getInstance()
|
2016-03-25 16:22:59 +01:00
|
|
|
.getTopValues(clz, temporalConstraint, filters, topKey,
|
2016-06-28 15:00:55 +02:00
|
|
|
orderingProperty);
|
|
|
|
|
2016-03-25 16:22:59 +01:00
|
|
|
int count = got.size() > limit ? limit : got.size();
|
|
|
|
NumberedFilter firstRemovalKey = null;
|
|
|
|
for(NumberedFilter nf : got.keySet()){
|
|
|
|
if(--count>=0 || limit<=0){
|
|
|
|
if(pad){
|
2016-09-19 16:02:52 +02:00
|
|
|
padMap(got.get(nf), temporalConstraint);
|
|
|
|
|
2016-03-25 16:22:59 +01:00
|
|
|
}
|
|
|
|
}else{
|
|
|
|
if(firstRemovalKey==null){
|
|
|
|
firstRemovalKey = nf;
|
|
|
|
}else{
|
|
|
|
break;
|
2016-03-16 17:30:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-25 16:22:59 +01:00
|
|
|
if(firstRemovalKey!=null){
|
|
|
|
return got.subMap(got.firstKey(), firstRemovalKey);
|
|
|
|
}
|
|
|
|
return got;
|
2016-03-16 17:30:26 +01:00
|
|
|
}
|
2016-06-28 15:00:55 +02:00
|
|
|
|
2016-03-17 12:05:17 +01:00
|
|
|
public SortedMap<NumberedFilter, SortedMap<Calendar, Info>> getTopValues(
|
2016-03-17 12:16:30 +01:00
|
|
|
Class<? extends AggregatedRecord<?,?>> clz,
|
2016-06-28 15:00:55 +02:00
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters,
|
|
|
|
String topKey) throws DuplicatedKeyFilterException,
|
|
|
|
KeyException, ValueException, Exception {
|
2016-03-24 18:59:34 +01:00
|
|
|
String orderingProperty = AccountingPersistenceQuery
|
|
|
|
.getDefaultOrderingProperties(clz);
|
2016-06-28 15:00:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-03-24 18:59:34 +01:00
|
|
|
return this.getTopValues(clz, temporalConstraint, filters, topKey,
|
|
|
|
orderingProperty, false, 0);
|
|
|
|
}
|
2016-06-28 15:00:55 +02:00
|
|
|
|
2016-03-24 18:59:34 +01:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public SortedMap<NumberedFilter, SortedMap<Calendar, Info>> getTopValues(
|
|
|
|
Class<? extends AggregatedRecord<?,?>> clz,
|
2016-06-28 15:00:55 +02:00
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters,
|
|
|
|
String topKey, String orderingProperty) throws
|
|
|
|
DuplicatedKeyFilterException, KeyException, ValueException,
|
|
|
|
Exception {
|
2016-03-24 18:59:34 +01:00
|
|
|
return this.getTopValues(clz, temporalConstraint, filters, topKey,
|
2016-06-28 15:00:55 +02:00
|
|
|
orderingProperty, false, 0);
|
2016-03-16 13:29:03 +01:00
|
|
|
}
|
|
|
|
|
2016-03-17 12:05:17 +01:00
|
|
|
public SortedSet<NumberedFilter> getNextPossibleValues(
|
2016-03-17 12:16:30 +01:00
|
|
|
Class<? extends AggregatedRecord<?,?>> clz,
|
2016-06-28 15:00:55 +02:00
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters,
|
|
|
|
String key) throws DuplicatedKeyFilterException, KeyException,
|
|
|
|
ValueException, Exception {
|
|
|
|
|
2016-03-24 18:59:34 +01:00
|
|
|
String orderingProperty = AccountingPersistenceQuery
|
|
|
|
.getDefaultOrderingProperties(clz);
|
2016-06-28 15:00:55 +02:00
|
|
|
|
2016-03-24 18:59:34 +01:00
|
|
|
return this.getNextPossibleValues(clz, temporalConstraint, filters,
|
2016-06-28 15:00:55 +02:00
|
|
|
key, orderingProperty);
|
2016-03-16 13:29:03 +01:00
|
|
|
}
|
2016-06-28 15:00:55 +02:00
|
|
|
|
2016-03-24 18:59:34 +01:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public SortedSet<NumberedFilter> getNextPossibleValues(
|
|
|
|
Class<? extends AggregatedRecord<?, ?>> clz,
|
2016-06-28 15:00:55 +02:00
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters,
|
|
|
|
String key, String orderingProperty) throws
|
|
|
|
DuplicatedKeyFilterException, KeyException, ValueException,
|
|
|
|
Exception {
|
|
|
|
|
2016-03-24 18:59:34 +01:00
|
|
|
return AccountingPersistenceBackendQueryFactory.getInstance()
|
|
|
|
.getNextPossibleValues(clz, temporalConstraint, filters,
|
2016-03-30 09:42:48 +02:00
|
|
|
key, orderingProperty);
|
2016-06-28 15:00:55 +02:00
|
|
|
|
2016-03-24 18:59:34 +01:00
|
|
|
}
|
2016-06-28 15:00:55 +02:00
|
|
|
|
2017-01-19 11:42:05 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public SortedSet<NumberedFilter> getNextPossibleValuesWithMap(
|
|
|
|
Class<? extends AggregatedRecord<?, ?>> clz,
|
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters,
|
|
|
|
String key, String orderingProperty) throws Exception {
|
|
|
|
return AccountingPersistenceBackendQueryFactory.getInstance()
|
|
|
|
.getNextPossibleValuesWithMap(clz, temporalConstraint, filters,
|
|
|
|
key, orderingProperty);
|
|
|
|
}
|
|
|
|
|
2015-09-29 16:25:58 +02:00
|
|
|
/**
|
2016-03-24 18:59:34 +01:00
|
|
|
* {@inheritDoc}
|
2015-09-29 16:25:58 +02:00
|
|
|
*/
|
2016-03-24 18:59:34 +01:00
|
|
|
@Override
|
2015-10-14 15:10:06 +02:00
|
|
|
public void close() throws Exception {
|
|
|
|
AccountingPersistenceBackendQueryFactory.getInstance().close();
|
|
|
|
}
|
2016-03-16 13:29:03 +01:00
|
|
|
|
2016-03-24 18:59:34 +01:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void prepareConnection(
|
|
|
|
AccountingPersistenceBackendQueryConfiguration configuration)
|
2016-06-28 15:00:55 +02:00
|
|
|
throws Exception {
|
2016-03-24 18:59:34 +01:00
|
|
|
throw new InvalidActivityException();
|
|
|
|
}
|
2016-06-28 15:00:55 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public SortedSet<NumberedFilter> getFilterValues(
|
|
|
|
Class<? extends AggregatedRecord<?, ?>> clz,
|
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters,
|
|
|
|
String key) throws Exception {
|
2016-11-08 10:00:15 +01:00
|
|
|
|
2016-06-28 15:00:55 +02:00
|
|
|
return AccountingPersistenceBackendQueryFactory.getInstance()
|
|
|
|
.getFilterValues(clz, temporalConstraint, filters,
|
|
|
|
key);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public JSONObject getUsageValue(Class<? extends AggregatedRecord<?, ?>> clz,
|
|
|
|
TemporalConstraint temporalConstraint, Filter applicant)
|
2016-09-19 16:02:52 +02:00
|
|
|
throws Exception {
|
2016-11-08 10:00:15 +01:00
|
|
|
|
2016-10-11 16:46:33 +02:00
|
|
|
return AccountingPersistenceBackendQueryFactory.getInstance()
|
|
|
|
.getUsageValue(clz, temporalConstraint, applicant);
|
2016-06-28 15:00:55 +02:00
|
|
|
}
|
2016-11-08 10:00:15 +01:00
|
|
|
|
2016-10-13 09:42:47 +02:00
|
|
|
|
2016-10-13 18:18:19 +02:00
|
|
|
@Override
|
2016-11-15 11:21:51 +01:00
|
|
|
public List<UsageValue> getUsageValueQuotaTotal( List<UsageValue> listUsage)
|
2016-10-13 18:18:19 +02:00
|
|
|
throws Exception {
|
2016-11-08 10:00:15 +01:00
|
|
|
|
2016-10-13 18:18:19 +02:00
|
|
|
return AccountingPersistenceBackendQueryFactory.getInstance()
|
2016-11-11 10:03:09 +01:00
|
|
|
.getUsageValueQuotaTotal(listUsage);
|
2016-10-13 18:18:19 +02:00
|
|
|
}
|
2016-11-08 10:00:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public SortedMap<Filter, SortedMap<Calendar, Info>> getContextTimeSeries(
|
|
|
|
Class<? extends AggregatedRecord<?, ?>> clz,
|
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters,List<String> contexts)
|
|
|
|
throws Exception {
|
|
|
|
|
|
|
|
return AccountingPersistenceBackendQueryFactory.getInstance()
|
|
|
|
.getContextTimeSeries(clz, temporalConstraint, filters, contexts);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public SortedMap<Filter, SortedMap<Calendar, Info>> getContextTimeSeries(
|
|
|
|
Class<? extends AggregatedRecord<?, ?>> clz,
|
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters,
|
|
|
|
List<String> contexts, boolean pad)
|
|
|
|
throws DuplicatedKeyFilterException,
|
|
|
|
Exception {
|
|
|
|
SortedMap<Filter, SortedMap<Calendar, Info>> got;
|
|
|
|
got = AccountingPersistenceBackendQueryFactory.getInstance()
|
|
|
|
.getContextTimeSeries(clz, temporalConstraint, filters, contexts);
|
|
|
|
int count = got.size();
|
|
|
|
Filter firstRemovalKey = null;
|
|
|
|
for(Filter nf : got.keySet()){
|
|
|
|
if(--count>=0){
|
|
|
|
if(pad){
|
|
|
|
padMap(got.get(nf), temporalConstraint);
|
|
|
|
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
if(firstRemovalKey==null){
|
|
|
|
firstRemovalKey = nf;
|
|
|
|
}else{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(firstRemovalKey!=null){
|
|
|
|
return got.subMap(got.firstKey(), firstRemovalKey);
|
|
|
|
}
|
|
|
|
return got;
|
|
|
|
}
|
2017-02-03 12:18:14 +01:00
|
|
|
|
|
|
|
|
2017-01-19 11:42:05 +01:00
|
|
|
|
2017-05-05 17:01:23 +02:00
|
|
|
public String getRecord(String recordId, String type ) throws Exception {
|
|
|
|
String record= AccountingPersistenceBackendQueryFactory.getInstance().getRecord(recordId,type);
|
|
|
|
return record;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-19 11:42:05 +01:00
|
|
|
|
2016-11-08 10:00:15 +01:00
|
|
|
|
2017-05-05 17:01:23 +02:00
|
|
|
@Override
|
|
|
|
public SortedSet<String> getSpaceProvidersIds() throws Exception{
|
|
|
|
SortedSet<String> providersId= AccountingPersistenceBackendQueryFactory.getInstance().getSpaceProvidersIds();
|
|
|
|
return providersId;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public SortedMap<Filter, SortedMap<Calendar, Long>> getSpaceTimeSeries(
|
|
|
|
Class<? extends AggregatedRecord<?, ?>> clz,
|
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters,
|
|
|
|
List<String> providersId)
|
|
|
|
throws Exception {
|
|
|
|
|
|
|
|
|
|
|
|
SortedMap<Filter, SortedMap<Calendar, Long>> spaceTimeSeries=
|
|
|
|
AccountingPersistenceBackendQueryFactory.getInstance().getSpaceTimeSeries(clz, temporalConstraint, filters, providersId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int count = spaceTimeSeries.size();
|
|
|
|
Filter firstRemovalKey = null;
|
|
|
|
for(Filter nf : spaceTimeSeries.keySet()){
|
|
|
|
if(--count>=0){
|
|
|
|
padMapStorage(spaceTimeSeries.get(nf), temporalConstraint);
|
|
|
|
}else{
|
|
|
|
if(firstRemovalKey==null){
|
|
|
|
firstRemovalKey = nf;
|
|
|
|
}else{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(firstRemovalKey!=null){
|
|
|
|
return spaceTimeSeries.subMap(spaceTimeSeries.firstKey(), firstRemovalKey);
|
|
|
|
}
|
|
|
|
return spaceTimeSeries;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public SortedMap<Calendar, Long> padMapStorage(
|
|
|
|
SortedMap<Calendar, Long> unpaddedData,
|
|
|
|
TemporalConstraint temporalConstraint) throws Exception {
|
|
|
|
SortedSet<Calendar> sequence = temporalConstraint.getCalendarSequence();
|
|
|
|
Long longValuePre = null;
|
|
|
|
for (Calendar progressTime : sequence) {
|
|
|
|
Long longValue = unpaddedData.get(progressTime);
|
|
|
|
|
|
|
|
if (longValue == null) {
|
|
|
|
unpaddedData.put(progressTime, longValuePre);
|
|
|
|
}else{
|
|
|
|
longValuePre=longValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return unpaddedData;
|
|
|
|
}
|
2016-11-08 10:00:15 +01:00
|
|
|
|
2017-05-05 17:01:23 +02:00
|
|
|
|
|
|
|
|
2016-06-28 15:00:55 +02:00
|
|
|
|
2015-07-08 15:24:32 +02:00
|
|
|
}
|