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.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
|
2017-09-21 14:54:33 +02:00
|
|
|
public static SortedSet<String> getQuerableKeys(@SuppressWarnings("rawtypes") AggregatedRecord instance)
|
|
|
|
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
|
|
|
|
2017-09-21 14:54:33 +02:00
|
|
|
public static SortedSet<String> getQuerableKeys(Class<? extends AggregatedRecord<?, ?>> clz) throws Exception {
|
|
|
|
AggregatedRecord<?, ?> instance = clz.newInstance();
|
|
|
|
|
|
|
|
// limit filter key for accounting storage status (used from portlet
|
|
|
|
// accounting for tad space)
|
|
|
|
if (clz.equals(AggregatedStorageStatusRecord.class)) {
|
|
|
|
SortedSet<String> storageStatus = new TreeSet<>();
|
2017-05-05 17:01:23 +02:00
|
|
|
storageStatus.add(AggregatedStorageStatusRecord.CONSUMER_ID);
|
|
|
|
storageStatus.add(AggregatedStorageStatusRecord.DATA_SERVICEID);
|
|
|
|
return storageStatus;
|
2017-09-21 14:54:33 +02:00
|
|
|
} else {
|
|
|
|
return instance.getQuerableKeys();
|
2017-05-05 17:01:23 +02:00
|
|
|
}
|
2017-09-21 14:54:33 +02:00
|
|
|
|
2015-10-14 15:10:06 +02:00
|
|
|
}
|
2016-06-28 15:00:55 +02:00
|
|
|
|
2017-09-21 14:54:33 +02:00
|
|
|
public static String getDefaultOrderingProperties(Class<? extends AggregatedRecord<?, ?>> clz) {
|
|
|
|
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
|
|
|
|
2017-09-21 14:54:33 +02:00
|
|
|
protected static JSONObject getPaddingJSONObject(Map<Calendar, Info> unpaddedResults) throws JSONException {
|
2016-03-16 17:30:26 +01:00
|
|
|
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
2017-09-21 14:54:33 +02:00
|
|
|
// verify data consistency
|
|
|
|
if (unpaddedResults.size() != 0) {
|
2016-06-28 15:00:55 +02:00
|
|
|
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
|
|
|
|
*/
|
2017-09-21 14:54:33 +02:00
|
|
|
public static SortedMap<Calendar, Info> padMap(SortedMap<Calendar, Info> unpaddedData,
|
2016-03-16 17:30:26 +01:00
|
|
|
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}
|
|
|
|
*/
|
2017-09-21 14:54:33 +02:00
|
|
|
public SortedMap<Calendar, Info> getTimeSeries(Class<? extends AggregatedRecord<?, ?>> clz,
|
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters)
|
|
|
|
throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
2016-06-28 15:00:55 +02:00
|
|
|
|
2016-03-24 18:59:34 +01:00
|
|
|
return this.getTimeSeries(clz, temporalConstraint, filters, false);
|
|
|
|
}
|
2016-06-28 15:00:55 +02:00
|
|
|
|
2017-09-21 14:54:33 +02:00
|
|
|
public SortedMap<Calendar, Info> getTimeSeries(Class<? extends AggregatedRecord<?, ?>> clz,
|
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters, boolean pad)
|
|
|
|
throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
|
|
|
SortedMap<Calendar, Info> ret = AccountingPersistenceBackendQueryFactory.getInstance().getTimeSeries(clz,
|
|
|
|
temporalConstraint, filters);
|
|
|
|
|
|
|
|
if (ret == null) {
|
2016-06-28 15:00:55 +02:00
|
|
|
ret = new TreeMap<>();
|
|
|
|
}
|
|
|
|
|
2017-09-21 14:54:33 +02:00
|
|
|
if (pad) {
|
2016-03-17 12:05:17 +01:00
|
|
|
ret = padMap(ret, temporalConstraint);
|
|
|
|
}
|
2016-06-28 15:00:55 +02:00
|
|
|
|
2016-03-17 12:05:17 +01:00
|
|
|
return ret;
|
|
|
|
}
|
2017-09-21 14:54:33 +02:00
|
|
|
|
|
|
|
public SortedMap<Calendar, Info> getNoContextTimeSeries(Class<? extends AggregatedRecord<?, ?>> clz,
|
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters)
|
|
|
|
throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
2017-02-03 12:18:14 +01:00
|
|
|
|
|
|
|
return this.getNoContextTimeSeries(clz, temporalConstraint, filters, false);
|
|
|
|
}
|
|
|
|
|
2017-09-21 14:54:33 +02:00
|
|
|
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) {
|
2017-02-03 12:18:14 +01:00
|
|
|
ret = new TreeMap<>();
|
|
|
|
}
|
|
|
|
|
2017-09-21 14:54:33 +02:00
|
|
|
if (pad) {
|
2017-02-03 12:18:14 +01:00
|
|
|
ret = padMap(ret, temporalConstraint);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2016-03-17 12:05:17 +01:00
|
|
|
|
|
|
|
public SortedMap<NumberedFilter, SortedMap<Calendar, Info>> getTopValues(
|
2017-09-21 14:54:33 +02:00
|
|
|
Class<? extends AggregatedRecord<?, ?>> clz, 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
|
|
|
|
2017-09-21 14:54:33 +02: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
|
|
|
|
2017-09-21 14:54:33 +02:00
|
|
|
got = AccountingPersistenceBackendQueryFactory.getInstance().getTopValues(clz, temporalConstraint, filters,
|
|
|
|
topKey, orderingProperty);
|
2016-06-28 15:00:55 +02:00
|
|
|
|
2016-03-25 16:22:59 +01:00
|
|
|
int count = got.size() > limit ? limit : got.size();
|
|
|
|
NumberedFilter firstRemovalKey = null;
|
2017-09-21 14:54:33 +02:00
|
|
|
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
|
|
|
}
|
2017-09-21 14:54:33 +02:00
|
|
|
} else {
|
|
|
|
if (firstRemovalKey == null) {
|
2016-03-25 16:22:59 +01:00
|
|
|
firstRemovalKey = nf;
|
2017-09-21 14:54:33 +02:00
|
|
|
} else {
|
2016-03-25 16:22:59 +01:00
|
|
|
break;
|
2016-03-16 17:30:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-09-21 14:54:33 +02:00
|
|
|
if (firstRemovalKey != null) {
|
2016-03-25 16:22:59 +01:00
|
|
|
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(
|
2017-09-21 14:54:33 +02:00
|
|
|
Class<? extends AggregatedRecord<?, ?>> clz, TemporalConstraint temporalConstraint, List<Filter> filters,
|
|
|
|
String topKey) throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
|
|
|
String orderingProperty = AccountingPersistenceQuery.getDefaultOrderingProperties(clz);
|
2016-06-28 15:00:55 +02:00
|
|
|
|
2017-09-21 14:54:33 +02:00
|
|
|
return this.getTopValues(clz, temporalConstraint, filters, topKey, orderingProperty, false, 0);
|
2016-03-24 18:59:34 +01:00
|
|
|
}
|
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(
|
2017-09-21 14:54:33 +02:00
|
|
|
Class<? extends AggregatedRecord<?, ?>> clz, TemporalConstraint temporalConstraint, List<Filter> filters,
|
|
|
|
String topKey, String orderingProperty)
|
|
|
|
throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
|
|
|
return this.getTopValues(clz, temporalConstraint, filters, topKey, orderingProperty, false, 0);
|
2016-03-16 13:29:03 +01:00
|
|
|
}
|
|
|
|
|
2017-09-21 14:54:33 +02:00
|
|
|
public SortedSet<NumberedFilter> getNextPossibleValues(Class<? extends AggregatedRecord<?, ?>> clz,
|
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters, String key)
|
|
|
|
throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
2016-06-28 15:00:55 +02:00
|
|
|
|
2017-09-21 14:54:33 +02:00
|
|
|
String orderingProperty = AccountingPersistenceQuery.getDefaultOrderingProperties(clz);
|
2016-06-28 15:00:55 +02:00
|
|
|
|
2017-09-21 14:54:33 +02:00
|
|
|
return this.getNextPossibleValues(clz, temporalConstraint, filters, 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
|
2017-09-21 14:54:33 +02:00
|
|
|
public SortedSet<NumberedFilter> getNextPossibleValues(Class<? extends AggregatedRecord<?, ?>> clz,
|
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters, String key, String orderingProperty)
|
|
|
|
throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
2016-06-28 15:00:55 +02:00
|
|
|
|
2017-09-21 14:54:33 +02:00
|
|
|
return AccountingPersistenceBackendQueryFactory.getInstance().getNextPossibleValues(clz, temporalConstraint,
|
|
|
|
filters, 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
|
2017-09-21 14:54:33 +02:00
|
|
|
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);
|
2017-01-19 11:42:05 +01:00
|
|
|
}
|
2017-09-21 14:54:33 +02:00
|
|
|
|
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
|
2017-09-21 14:54:33 +02:00
|
|
|
public void prepareConnection(AccountingPersistenceBackendQueryConfiguration configuration) throws Exception {
|
2016-03-24 18:59:34 +01:00
|
|
|
throw new InvalidActivityException();
|
|
|
|
}
|
2016-06-28 15:00:55 +02:00
|
|
|
|
|
|
|
@Override
|
2017-09-21 14:54:33 +02:00
|
|
|
public SortedSet<NumberedFilter> getFilterValues(Class<? extends AggregatedRecord<?, ?>> clz,
|
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters, String key) throws Exception {
|
2016-06-28 15:00:55 +02:00
|
|
|
|
2017-09-21 14:54:33 +02:00
|
|
|
return AccountingPersistenceBackendQueryFactory.getInstance().getFilterValues(clz, temporalConstraint, filters,
|
|
|
|
key);
|
2016-06-28 15:00:55 +02:00
|
|
|
}
|
2016-11-08 10:00:15 +01:00
|
|
|
|
2016-10-13 18:18:19 +02:00
|
|
|
@Override
|
2017-09-21 14:54:33 +02:00
|
|
|
public JSONObject getUsageValue(Class<? extends AggregatedRecord<?, ?>> clz, TemporalConstraint temporalConstraint,
|
|
|
|
Filter applicant) throws Exception {
|
|
|
|
|
|
|
|
return AccountingPersistenceBackendQueryFactory.getInstance().getUsageValue(clz, temporalConstraint, applicant);
|
2016-10-13 18:18:19 +02:00
|
|
|
}
|
2016-11-08 10:00:15 +01:00
|
|
|
|
2017-09-21 14:54:33 +02:00
|
|
|
@Override
|
|
|
|
public List<UsageValue> getUsageValueQuotaTotal(List<UsageValue> listUsage) throws Exception {
|
2016-11-08 10:00:15 +01:00
|
|
|
|
2017-09-21 14:54:33 +02:00
|
|
|
return AccountingPersistenceBackendQueryFactory.getInstance().getUsageValueQuotaTotal(listUsage);
|
|
|
|
}
|
2016-11-08 10:00:15 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public SortedMap<Filter, SortedMap<Calendar, Info>> getContextTimeSeries(
|
2017-09-21 14:54:33 +02:00
|
|
|
Class<? extends AggregatedRecord<?, ?>> clz, TemporalConstraint temporalConstraint, List<Filter> filters,
|
|
|
|
List<String> contexts) throws Exception {
|
2016-11-08 10:00:15 +01:00
|
|
|
|
2017-09-21 14:54:33 +02:00
|
|
|
return AccountingPersistenceBackendQueryFactory.getInstance().getContextTimeSeries(clz, temporalConstraint,
|
|
|
|
filters, contexts);
|
|
|
|
}
|
2016-11-08 10:00:15 +01:00
|
|
|
|
|
|
|
public SortedMap<Filter, SortedMap<Calendar, Info>> getContextTimeSeries(
|
2017-09-21 14:54:33 +02:00
|
|
|
Class<? extends AggregatedRecord<?, ?>> clz, TemporalConstraint temporalConstraint, List<Filter> filters,
|
|
|
|
List<String> contexts, boolean pad) throws DuplicatedKeyFilterException, Exception {
|
2016-11-08 10:00:15 +01:00
|
|
|
SortedMap<Filter, SortedMap<Calendar, Info>> got;
|
2017-09-21 14:54:33 +02:00
|
|
|
got = AccountingPersistenceBackendQueryFactory.getInstance().getContextTimeSeries(clz, temporalConstraint,
|
|
|
|
filters, contexts);
|
2016-11-08 10:00:15 +01:00
|
|
|
int count = got.size();
|
|
|
|
Filter firstRemovalKey = null;
|
2017-09-21 14:54:33 +02:00
|
|
|
for (Filter nf : got.keySet()) {
|
|
|
|
if (--count >= 0) {
|
|
|
|
if (pad) {
|
2016-11-08 10:00:15 +01:00
|
|
|
padMap(got.get(nf), temporalConstraint);
|
|
|
|
|
|
|
|
}
|
2017-09-21 14:54:33 +02:00
|
|
|
} else {
|
|
|
|
if (firstRemovalKey == null) {
|
2016-11-08 10:00:15 +01:00
|
|
|
firstRemovalKey = nf;
|
2017-09-21 14:54:33 +02:00
|
|
|
} else {
|
2016-11-08 10:00:15 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-09-21 14:54:33 +02:00
|
|
|
if (firstRemovalKey != null) {
|
2016-11-08 10:00:15 +01:00
|
|
|
return got.subMap(got.firstKey(), firstRemovalKey);
|
|
|
|
}
|
|
|
|
return got;
|
|
|
|
}
|
2017-02-03 12:18:14 +01:00
|
|
|
|
2017-09-21 14:54:33 +02:00
|
|
|
public String getRecord(String recordId, String type) throws Exception {
|
|
|
|
String record = AccountingPersistenceBackendQueryFactory.getInstance().getRecord(recordId, type);
|
2017-05-05 17:01:23 +02:00
|
|
|
return record;
|
|
|
|
|
2017-09-21 14:54:33 +02:00
|
|
|
}
|
2016-11-08 10:00:15 +01:00
|
|
|
|
2017-05-05 17:01:23 +02:00
|
|
|
@Override
|
2017-09-21 14:54:33 +02:00
|
|
|
public SortedSet<String> getSpaceProvidersIds() throws Exception {
|
|
|
|
SortedSet<String> providersId = AccountingPersistenceBackendQueryFactory.getInstance().getSpaceProvidersIds();
|
2017-05-05 17:01:23 +02:00
|
|
|
return providersId;
|
2017-09-21 14:54:33 +02:00
|
|
|
|
2017-05-05 17:01:23 +02:00
|
|
|
}
|
2017-09-21 14:54:33 +02:00
|
|
|
|
2017-05-05 17:01:23 +02:00
|
|
|
@Override
|
2017-09-21 14:54:33 +02:00
|
|
|
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);
|
|
|
|
|
2017-05-05 17:01:23 +02:00
|
|
|
int count = spaceTimeSeries.size();
|
|
|
|
Filter firstRemovalKey = null;
|
2017-09-21 14:54:33 +02:00
|
|
|
for (Filter nf : spaceTimeSeries.keySet()) {
|
|
|
|
if (--count >= 0) {
|
2017-05-05 17:01:23 +02:00
|
|
|
padMapStorage(spaceTimeSeries.get(nf), temporalConstraint);
|
2017-09-21 14:54:33 +02:00
|
|
|
} else {
|
|
|
|
if (firstRemovalKey == null) {
|
2017-05-05 17:01:23 +02:00
|
|
|
firstRemovalKey = nf;
|
2017-09-21 14:54:33 +02:00
|
|
|
} else {
|
2017-05-05 17:01:23 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-09-21 14:54:33 +02:00
|
|
|
if (firstRemovalKey != null) {
|
2017-05-05 17:01:23 +02:00
|
|
|
return spaceTimeSeries.subMap(spaceTimeSeries.firstKey(), firstRemovalKey);
|
|
|
|
}
|
|
|
|
return spaceTimeSeries;
|
2017-09-21 14:54:33 +02:00
|
|
|
|
2017-05-05 17:01:23 +02:00
|
|
|
}
|
2017-09-21 14:54:33 +02:00
|
|
|
|
|
|
|
public SortedMap<Calendar, Long> padMapStorage(SortedMap<Calendar, Long> unpaddedData,
|
2017-05-05 17:01:23 +02:00
|
|
|
TemporalConstraint temporalConstraint) throws Exception {
|
|
|
|
SortedSet<Calendar> sequence = temporalConstraint.getCalendarSequence();
|
|
|
|
Long longValuePre = null;
|
|
|
|
for (Calendar progressTime : sequence) {
|
|
|
|
Long longValue = unpaddedData.get(progressTime);
|
2017-09-21 14:54:33 +02:00
|
|
|
|
2017-05-05 17:01:23 +02:00
|
|
|
if (longValue == null) {
|
|
|
|
unpaddedData.put(progressTime, longValuePre);
|
2017-09-21 14:54:33 +02:00
|
|
|
} else {
|
|
|
|
longValuePre = longValue;
|
2017-05-05 17:01:23 +02:00
|
|
|
}
|
2017-09-21 14:54:33 +02:00
|
|
|
|
2017-05-05 17:01:23 +02:00
|
|
|
}
|
|
|
|
return unpaddedData;
|
|
|
|
}
|
2016-11-08 10:00:15 +01:00
|
|
|
|
2017-09-06 16:12:15 +02:00
|
|
|
@Override
|
|
|
|
public boolean isConnectionActive() throws Exception {
|
|
|
|
return AccountingPersistenceBackendQueryFactory.getInstance().isConnectionActive();
|
|
|
|
}
|
|
|
|
|
2015-07-08 15:24:32 +02:00
|
|
|
}
|