diff --git a/CHANGELOG.md b/CHANGELOG.md index 79bc798..3740149 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,16 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm # Changelog for Accounting Analytics +<<<<<<< HEAD ## [v3.0.1] +======= +## [v4.0.0-SNAPSHOT] + +- Supporting zero or multiple contexts in all queries [#21353] +- Query parameters are now provided via setter and not as functions parameters [#21353] +- Removed getSpaceProvidersIds() and added getDataType() [#21353] + +>>>>>>> refs/heads/feature/21353 - Aligned model diff --git a/pom.xml b/pom.xml index 30d7be5..326d1ae 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,11 @@ org.gcube.accounting accounting-analytics +<<<<<<< HEAD 3.0.1 +======= + 4.0.0-SNAPSHOT +>>>>>>> refs/heads/feature/21353 Accounting Analytics Accounting Analytics allows querying accounting data. It @@ -44,27 +48,18 @@ org.slf4j slf4j-api - provided org.gcube.accounting accounting-lib - provided org.gcube.data.publishing document-store-lib - provided org.gcube.core common-scope - provided - - - org.json - json - 20090211 diff --git a/src/main/java/org/gcube/accounting/analytics/FiltersValue.java b/src/main/java/org/gcube/accounting/analytics/FiltersValue.java deleted file mode 100644 index cf67feb..0000000 --- a/src/main/java/org/gcube/accounting/analytics/FiltersValue.java +++ /dev/null @@ -1,95 +0,0 @@ -package org.gcube.accounting.analytics; - -import java.util.List; -/** - * @author Alessandro Pieve (ISTI - CNR) alessandro.pieve@isti.cnr.it - * - */ -public class FiltersValue { - - - protected List filters; - protected Double d; - protected String orderingProperty; - - public FiltersValue(){} - - public FiltersValue(List filters, Number n, String orderingProperty) { - super(); - this.filters=filters; - this.d = n.doubleValue(); - this.orderingProperty = orderingProperty; - } - - public List getFiltersValue() { - return filters; - } - - public void setFiltersValue(List filters) { - this.filters = filters; - } - - public Double getD() { - return d; - } - - public void setD(Double d) { - this.d = d; - } - - public String getOrderingProperty() { - return orderingProperty; - } - - public void setOrderingProperty(String orderingProperty) { - this.orderingProperty = orderingProperty; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((d == null) ? 0 : d.hashCode()); - result = prime * result + ((filters == null) ? 0 : filters.hashCode()); - result = prime - * result - + ((orderingProperty == null) ? 0 : orderingProperty.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - FiltersValue other = (FiltersValue) obj; - if (d == null) { - if (other.d != null) - return false; - } else if (!d.equals(other.d)) - return false; - if (filters == null) { - if (other.filters != null) - return false; - } else if (!filters.equals(other.filters)) - return false; - if (orderingProperty == null) { - if (other.orderingProperty != null) - return false; - } else if (!orderingProperty.equals(other.orderingProperty)) - return false; - return true; - } - - @Override - public String toString() { - return "FiltersValue [filters=" + filters + ", d=" + d - + ", orderingProperty=" + orderingProperty + "]"; - } - - - -} diff --git a/src/main/java/org/gcube/accounting/analytics/Info.java b/src/main/java/org/gcube/accounting/analytics/Info.java index aa04e3b..1372ca1 100644 --- a/src/main/java/org/gcube/accounting/analytics/Info.java +++ b/src/main/java/org/gcube/accounting/analytics/Info.java @@ -6,7 +6,7 @@ package org.gcube.accounting.analytics; import java.text.SimpleDateFormat; import java.util.Calendar; -import org.json.JSONObject; +import org.gcube.com.fasterxml.jackson.databind.JsonNode; /** @@ -16,13 +16,13 @@ import org.json.JSONObject; public class Info { protected Calendar calendar; - protected JSONObject value; + protected JsonNode value; /** * @param calendar the date * @param value the JSON value */ - public Info(Calendar calendar, JSONObject value) { + public Info(Calendar calendar, JsonNode value) { super(); this.calendar = calendar; this.value = value; @@ -45,14 +45,14 @@ public class Info { /** * @return the value */ - public JSONObject getValue() { + public JsonNode getValue() { return value; } /** * @param value the value to set */ - public void setValue(JSONObject value) { + public void setValue(JsonNode value) { this.value = value; } diff --git a/src/main/java/org/gcube/accounting/analytics/NumberedFilter.java b/src/main/java/org/gcube/accounting/analytics/NumberedFilter.java index ebb4eb7..943bf4d 100644 --- a/src/main/java/org/gcube/accounting/analytics/NumberedFilter.java +++ b/src/main/java/org/gcube/accounting/analytics/NumberedFilter.java @@ -6,7 +6,7 @@ package org.gcube.accounting.analytics; import java.util.Calendar; import java.util.Map; -import org.json.JSONObject; +import org.gcube.com.fasterxml.jackson.databind.JsonNode; /** * @author Luca Frosini (ISTI - CNR) @@ -34,11 +34,11 @@ public class NumberedFilter extends Filter { this.orderingProperty = orderingProperty; for(Info info : timeSeries.values()){ - JSONObject value = info.getValue(); + JsonNode value = info.getValue(); if(this.d == null){ - this.d = value.getDouble(orderingProperty); + this.d = value.get(orderingProperty).asDouble(); }else{ - this.d = this.d + value.getDouble(orderingProperty); + this.d = this.d + value.get(orderingProperty).asDouble(); } } diff --git a/src/main/java/org/gcube/accounting/analytics/UsageServiceValue.java b/src/main/java/org/gcube/accounting/analytics/UsageServiceValue.java deleted file mode 100644 index 16166ee..0000000 --- a/src/main/java/org/gcube/accounting/analytics/UsageServiceValue.java +++ /dev/null @@ -1,101 +0,0 @@ -package org.gcube.accounting.analytics; - -import java.util.List; - -import org.gcube.accounting.datamodel.AggregatedUsageRecord; - -public class UsageServiceValue extends UsageValue { - - - protected Class> clz; - protected TemporalConstraint temporalConstraint; - - //USED for a list service for each identifier (package service ) - //protected List filtersValue; - - protected List filters; - protected String identifier; - protected Double d; - protected String orderingProperty; - - public String getIdentifier() { - return identifier; - } - public void setIdentifier(String identifier) { - this.identifier = identifier; - } - - public Double getD() { - return d; - } - - public void setD(Double d) { - this.d = d; - } - public TemporalConstraint getTemporalConstraint() { - if (temporalConstraint!=null) - return temporalConstraint; - else - return null; - - } - - public String getOrderingProperty() { - return orderingProperty; - } - - public void setOrderingProperty(String orderingProperty) { - this.orderingProperty = orderingProperty; - } - public void setTemporalConstraint(TemporalConstraint temporalConstraint) { - this.temporalConstraint = temporalConstraint; - } - - public Class> getClz() { - return clz; - } - - public void setClz(String context,Class> clz) { - this.clz = clz; - } - - public UsageServiceValue(){} - - public UsageServiceValue(String context,String identifier,Class> clz,TemporalConstraint temporalConstraint,List filters){ - super(); - this.context=context; - this.filters=filters; - this.clz=clz; - this.temporalConstraint=temporalConstraint; - this.identifier=identifier; - - } - - public List getFilters() { - return filters; - } - - public void setFilters(List filters) { - this.filters = filters; - } - - @Override - public String getContext() { - return this.context; - } - @Override - public void setContext(String context) { - this.context=context; - - } - @Override - public String toString() { - return "UsageServiceValue [clz=" + clz + ", temporalConstraint=" - + temporalConstraint + ", filters=" + filters + ", identifier=" - + identifier + ", d=" + d + ", orderingProperty=" - + orderingProperty + "]"; - } - - - -} diff --git a/src/main/java/org/gcube/accounting/analytics/UsageStorageValue.java b/src/main/java/org/gcube/accounting/analytics/UsageStorageValue.java deleted file mode 100644 index 2b515b4..0000000 --- a/src/main/java/org/gcube/accounting/analytics/UsageStorageValue.java +++ /dev/null @@ -1,90 +0,0 @@ -package org.gcube.accounting.analytics; - -import org.gcube.accounting.datamodel.AggregatedUsageRecord; - -public class UsageStorageValue extends UsageValue { - protected Class> clz; - protected TemporalConstraint temporalConstraint; - protected String identifier; - protected Double d; - protected String orderingProperty; - - public String getIdentifier() { - return identifier; - } - public void setIdentifier(String identifier) { - this.identifier = identifier; - } - - public Double getD() { - return d; - } - - public void setD(Double d) { - this.d = d; - } - public String getOrderingProperty() { - return orderingProperty; - } - - public void setOrderingProperty(String orderingProperty) { - this.orderingProperty = orderingProperty; - } - public TemporalConstraint getTemporalConstraint() { - if (temporalConstraint!=null) - return temporalConstraint; - else - return null; - } - - public void setTemporalConstraint(TemporalConstraint temporalConstraint) { - this.temporalConstraint = temporalConstraint; - } - - public Class> getClz() { - return clz; - } - - public void setClz(Class> clz) { - this.clz = clz; - } - - public UsageStorageValue(){} - - - public UsageStorageValue(String context,String identifier,Class> clz){ - super(); - this.context=context; - this.clz=clz; - this.identifier=identifier; - - } - - public UsageStorageValue(String context,String identifier,Class> clz,TemporalConstraint temporalConstraint){ - super(); - this.context=context; - this.identifier=identifier; - this.clz=clz; - this.temporalConstraint=temporalConstraint; - - } - @Override - public String getContext() { - return this.context; - } - @Override - public void setContext(String context) { - this.context=context; - - } - @Override - public String toString() { - return "UsageStorageValue [clz=" + clz + ", temporalConstraint=" - + temporalConstraint + ", identifier=" + identifier + ", d=" - + d + ", orderingProperty=" + orderingProperty - + ", context=" + context - + "]"; - } - - -} diff --git a/src/main/java/org/gcube/accounting/analytics/persistence/AccountingPersistenceBackendQuery.java b/src/main/java/org/gcube/accounting/analytics/persistence/AccountingPersistenceBackendQuery.java index 750cf20..268a7f1 100644 --- a/src/main/java/org/gcube/accounting/analytics/persistence/AccountingPersistenceBackendQuery.java +++ b/src/main/java/org/gcube/accounting/analytics/persistence/AccountingPersistenceBackendQuery.java @@ -5,6 +5,7 @@ package org.gcube.accounting.analytics.persistence; import java.util.Calendar; import java.util.List; +import java.util.Set; import java.util.SortedMap; import java.util.SortedSet; @@ -13,9 +14,6 @@ import org.gcube.accounting.analytics.Info; import org.gcube.accounting.analytics.NumberedFilter; import org.gcube.accounting.analytics.TemporalConstraint; import org.gcube.accounting.analytics.UsageValue; -import org.gcube.accounting.analytics.exception.DuplicatedKeyFilterException; -import org.gcube.accounting.analytics.exception.KeyException; -import org.gcube.accounting.analytics.exception.ValueException; import org.gcube.accounting.datamodel.BasicUsageRecord; import org.gcube.documentstore.records.AggregatedRecord; import org.gcube.documentstore.records.Record; @@ -39,98 +37,72 @@ public interface AccountingPersistenceBackendQuery { AccountingPersistenceBackendQueryConfiguration configuration) throws Exception; + /** + * @param clz the Usage Record Class of interest + * + * Required + * + */ + public void setRequestedRecords(Class> clz); + + /** + * @param temporalConstraint the TemporalConstraint (interval and aggregation) + * + * Required + */ + public void setTemporalConstraint(TemporalConstraint temporalConstraint); + + + /** + * @param contexts the list of context to use as filter + * + * If null or empty list get all data for the interested Record Class + * with the applying temporal constraint with no contexts constraint. + * The contexts are evaluated in OR. + * + */ + public void setContexts(Set contexts); + + /** + * @param filters list of filter to obtain the results. + * If null or empty list get all data for the interested Record Class + * with the applying temporal constraint. + * All Filter must have not null and not empty key and value. + * The filters must be related to different keys and are in AND. + * If the list contains more than one filter with the same key an Exception is thrown + * when trying to query. + */ + public void setFilters(Set filters); + /** * 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. * - * @param clz - * the Record Class of interest - * @param temporalConstraint - * the TemporalConstraint (interval and aggregation) - * @param filters - * list of filter to obtain the time series. If null or empty - * list get all data for the interested Record Class with the - * applying temporal constraint. All Filter must have not null - * and not empty key and value. The filters are must be related - * to different keys and are in AND. If the list contains more - * than one filter with the same key an Exception is thrown. - * @return the Map containing for each date in the required interval the - * requested data - * @throws DuplicatedKeyFilterException - * @throws KeyException - * @throws ValueException + * @return the Map containing for each date in the required interval the requested data * @throws Exception */ - public SortedMap getTimeSeries( - Class> clz, - TemporalConstraint temporalConstraint, List filters) - throws DuplicatedKeyFilterException, KeyException, ValueException, - Exception; - + public SortedMap getTimeSeries() throws Exception; + /** - * 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. - * Used for no context call - * - * @param clz - * the Record Class of interest - * @param temporalConstraint - * the TemporalConstraint (interval and aggregation) - * @param filters - * list of filter to obtain the time series. If null or empty - * list get all data for the interested Record Class with the - * applying temporal constraint. All Filter must have not null - * and not empty key and value. The filters are must be related - * to different keys and are in AND. If the list contains more - * than one filter with the same key an Exception is thrown. - * @return the Map containing for each date in the required interval the - * requested data - * @throws DuplicatedKeyFilterException - * @throws KeyException - * @throws ValueException - * @throws Exception + * Return a SortedMap containing the TimeSeries for each context. + * @return a SortedMap containing the TimeSeries for each context. */ - public SortedMap getNoContextTimeSeries( - Class> clz, - TemporalConstraint temporalConstraint, List filters) - throws DuplicatedKeyFilterException, KeyException, ValueException, - Exception; - + public SortedMap> getContextTimeSeries() throws Exception; + /** * Return a SortedMap containing the TimeSeries for top values for a certain - * key taking in account all Filters. The key is identified adding a Filter - * with a null value. Only one Filter with null value is allowed otherwise - * an Exception is thrown. The values are ordered from the most occurred - * value. + * key taking in account all Filters. * - * @param clz - * the Usage Record Class of interest - * @param temporalConstraint - * the TemporalConstraint (interval and aggregation) - * @param filters - * list of filter to obtain the time series of top values. If - * null or empty list get all data for the interested Record - * Class with the applying temporal constraint. All Filter must - * have not null and not empty key and value. The filters are - * must be related to different keys and are in AND. If the list - * contains more than one filter with the same key an Exception - * is thrown. - * @param topKey + * The values are ordered from the most occurred value. + * + * @param topKey the key to obtain top values * @param orderingProperty * @return a SortedMap - * @throws DuplicatedKeyFilterException - * @throws KeyException - * @throws ValueException + * @throws Exception */ - public SortedMap> - getTopValues(Class> clz, - TemporalConstraint temporalConstraint, List filters, - String topKey, String orderingProperty) - throws DuplicatedKeyFilterException, KeyException, ValueException, - Exception; + public SortedMap> getTopValues(String topKey, String orderingProperty) throws Exception; /** * Close the connection to persistence @@ -140,20 +112,20 @@ public interface AccountingPersistenceBackendQuery { */ public void close() throws Exception; - public SortedSet getFilterValues( - Class> clz, - TemporalConstraint temporalConstraint, List filters, - String key) throws Exception; + public SortedSet getFilterValues(String key) throws Exception; + + public SortedSet getFilterValues(String key, Integer limit) throws Exception; + + public Record getRecord(String recordId, String type) throws Exception; + + + public SortedMap> getSpaceTimeSeries(Set dataTypes) throws Exception; - public SortedSet getFilterValues( - Class> clz, - TemporalConstraint temporalConstraint, List filters, - String key, Integer limit) throws Exception; /** * getUsageValueQuotaTotal * - * Example for crequire 2 different quota (lucio.lelii for service and alessandro.pieve for storage) + * Example to require 2 different quota (lucio.lelii for service and alessandro.pieve for storage) * Input: * [ * TotalFilters [ @@ -194,32 +166,10 @@ public interface AccountingPersistenceBackendQuery { * @return List * @throws Exception */ - public List getUsageValueQuotaTotal( - List listUsage) + public List getUsageValueQuotaTotal(List listUsage) throws Exception; + - /** - * Return a SortedMap containing the TimeSeries for each context. - * @param clz - * @param temporalConstraint - * @param filters - * @param contexts - * @return a SortedMap containing the TimeSeries for each context. - */ - public SortedMap> getContextTimeSeries( - Class> clz, - TemporalConstraint temporalConstraint, List filters,List contexts) - throws Exception; - - public Record getRecord(String recordId, String type) throws Exception; - - public SortedSet getSpaceProvidersIds() throws Exception; - - public SortedMap> getSpaceTimeSeries( - Class> clz, - TemporalConstraint temporalConstraint, List filters, - List providersId) throws Exception; - boolean isConnectionActive() throws Exception; -} +} \ No newline at end of file diff --git a/src/main/java/org/gcube/accounting/analytics/persistence/AccountingPersistenceQuery.java b/src/main/java/org/gcube/accounting/analytics/persistence/AccountingPersistenceQuery.java index 88c4303..813c73c 100644 --- a/src/main/java/org/gcube/accounting/analytics/persistence/AccountingPersistenceQuery.java +++ b/src/main/java/org/gcube/accounting/analytics/persistence/AccountingPersistenceQuery.java @@ -8,6 +8,7 @@ import java.util.Calendar; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.SortedMap; import java.util.SortedSet; import java.util.TreeMap; @@ -25,10 +26,12 @@ import org.gcube.accounting.analytics.exception.KeyException; import org.gcube.accounting.analytics.exception.ValueException; import org.gcube.accounting.datamodel.aggregation.AggregatedStorageStatusRecord; import org.gcube.accounting.datamodel.aggregation.AggregatedStorageUsageRecord; +import org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord.DataType; +import org.gcube.com.fasterxml.jackson.databind.JsonNode; +import org.gcube.com.fasterxml.jackson.databind.ObjectMapper; +import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode; import org.gcube.documentstore.records.AggregatedRecord; import org.gcube.documentstore.records.Record; -import org.json.JSONException; -import org.json.JSONObject; /** * @author Luca Frosini (ISTI - CNR) @@ -40,17 +43,58 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ public static final int DEFAULT_LIMIT_RESULT_NUMBER = 5; - private AccountingPersistenceQuery() { - } - static { - accountingPersistenceQuery = new AccountingPersistenceQuery(); + try { + accountingPersistenceQuery = new AccountingPersistenceQuery(); + }catch (Exception e) { + throw new RuntimeException(e); + } + } protected static synchronized AccountingPersistenceQuery getInstance() { return accountingPersistenceQuery; } - + + protected Class> clz; + protected TemporalConstraint temporalConstraint; + + protected Set contexts; + protected Set filters; + + protected ObjectMapper objectMapper; + + protected AccountingPersistenceBackendQuery accountingPersistenceBackendQuery; + + private AccountingPersistenceQuery() throws Exception { + accountingPersistenceBackendQuery = AccountingPersistenceBackendQueryFactory.getInstance(); + objectMapper = new ObjectMapper(); + } + + @Override + public void setRequestedRecords(Class> clz) { + this.clz = clz; + accountingPersistenceBackendQuery.setRequestedRecords(clz); + } + + @Override + public void setTemporalConstraint(TemporalConstraint temporalConstraint) { + this.temporalConstraint = temporalConstraint; + accountingPersistenceBackendQuery.setTemporalConstraint(temporalConstraint); + } + + @Override + public void setContexts(Set contexts) { + this.contexts = contexts; + accountingPersistenceBackendQuery.setContexts(this.contexts); + } + + @Override + public void setFilters(Set filters) { + this.filters = filters; + accountingPersistenceBackendQuery.setFilters(filters); + } + public static SortedSet getQuerableKeys(Class> clz) throws Exception { AggregatedRecord instance = clz.newInstance(); @@ -59,7 +103,11 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ if (clz.equals(AggregatedStorageStatusRecord.class)) { SortedSet storageStatus = new TreeSet<>(); storageStatus.add(AggregatedStorageStatusRecord.CONSUMER_ID); +<<<<<<< HEAD storageStatus.add(AggregatedStorageStatusRecord.PROVIDER_URI); +======= + // storageStatus.add(AggregatedStorageStatusRecord.DATA_SERVICEID); +>>>>>>> refs/heads/feature/21353 return storageStatus; } else { return instance.getQuerableKeys(); @@ -74,21 +122,19 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ return AggregatedRecord.OPERATION_COUNT; } - protected static JSONObject getPaddingJSONObject(Map unpaddedResults) throws JSONException { - - JSONObject jsonObject = new JSONObject(); + protected JsonNode getPaddingJsonNode(Map unpaddedResults) throws Exception { + ObjectNode objectNode = objectMapper.createObjectNode(); // verify data consistency if (unpaddedResults.size() != 0) { Info auxInfo = new ArrayList(unpaddedResults.values()).get(0); - JSONObject auxJsonObject = auxInfo.getValue(); - @SuppressWarnings("unchecked") - Iterator keys = auxJsonObject.keys(); + JsonNode auxJsonNode = auxInfo.getValue(); + Iterator keys = auxJsonNode.fieldNames(); while (keys.hasNext()) { String key = keys.next(); - jsonObject.put(key, 0); + objectNode.put(key, 0); } } - return jsonObject; + return objectNode; } /** @@ -103,15 +149,13 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ * @throws Exception * if fails */ - protected static SortedMap padMap(SortedMap unpaddedData, - TemporalConstraint temporalConstraint) throws Exception { - - JSONObject jsonObject = getPaddingJSONObject(unpaddedData); + protected SortedMap padMap(SortedMap unpaddedData) throws Exception { + JsonNode jsonNode = getPaddingJsonNode(unpaddedData); SortedSet sequence = temporalConstraint.getCalendarSequence(); for (Calendar progressTime : sequence) { Info info = unpaddedData.get(progressTime); if (info == null) { - info = new Info(progressTime, jsonObject); + info = new Info(progressTime, jsonNode); unpaddedData.put(progressTime, info); } } @@ -119,74 +163,43 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ } @Override - public SortedMap getTimeSeries(Class> clz, - TemporalConstraint temporalConstraint, List filters) + public SortedMap getTimeSeries() throws DuplicatedKeyFilterException, KeyException, ValueException, Exception { - - return this.getTimeSeries(clz, temporalConstraint, filters, false); + return this.getTimeSeries(true); } - public SortedMap getTimeSeries(Class> clz, - TemporalConstraint temporalConstraint, List filters, boolean pad) + public SortedMap getTimeSeries(boolean pad) throws DuplicatedKeyFilterException, KeyException, ValueException, Exception { - SortedMap ret = AccountingPersistenceBackendQueryFactory.getInstance().getTimeSeries(clz, - temporalConstraint, filters); + + SortedMap ret = accountingPersistenceBackendQuery.getTimeSeries(); if (ret == null) { ret = new TreeMap<>(); } if (pad) { - ret = padMap(ret, temporalConstraint); + ret = padMap(ret); } return ret; } - @Override - public SortedMap getNoContextTimeSeries(Class> clz, - TemporalConstraint temporalConstraint, List filters) - throws DuplicatedKeyFilterException, KeyException, ValueException, Exception { - - return this.getNoContextTimeSeries(clz, temporalConstraint, filters, false); - } - - public SortedMap getNoContextTimeSeries(Class> clz, - TemporalConstraint temporalConstraint, List filters, boolean pad) - throws DuplicatedKeyFilterException, KeyException, ValueException, Exception { - SortedMap ret = AccountingPersistenceBackendQueryFactory.getInstance() - .getNoContextTimeSeries(clz, temporalConstraint, filters); - - if (ret == null) { - ret = new TreeMap<>(); - } - - if (pad) { - ret = padMap(ret, temporalConstraint); - } - - return ret; - } - - public SortedMap> getTopValues( - Class> clz, TemporalConstraint temporalConstraint, List filters, - String topKey, String orderingProperty, boolean pad, int limit) + public SortedMap> getTopValues(String topKey, String orderingProperty, boolean pad, int limit) throws DuplicatedKeyFilterException, KeyException, ValueException, Exception { SortedMap> got; if (orderingProperty == null) { orderingProperty = getDefaultOrderingProperties(clz); } - - got = AccountingPersistenceBackendQueryFactory.getInstance().getTopValues(clz, temporalConstraint, filters, - topKey, orderingProperty); + + got = accountingPersistenceBackendQuery.getTopValues(topKey, orderingProperty); int count = got.size() > limit ? limit : got.size(); NumberedFilter firstRemovalKey = null; for (NumberedFilter nf : got.keySet()) { if (--count >= 0 || limit <= 0) { if (pad) { - padMap(got.get(nf), temporalConstraint); + padMap(got.get(nf)); } } else { @@ -203,20 +216,15 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ return got; } - public SortedMap> getTopValues( - Class> clz, TemporalConstraint temporalConstraint, List filters, - String topKey) throws DuplicatedKeyFilterException, KeyException, ValueException, Exception { + public SortedMap> getTopValues(String topKey) throws DuplicatedKeyFilterException, KeyException, ValueException, Exception { String orderingProperty = AccountingPersistenceQuery.getDefaultOrderingProperties(clz); - - return this.getTopValues(clz, temporalConstraint, filters, topKey, orderingProperty, false, 0); + return this.getTopValues(topKey, orderingProperty, false, 0); } @Override - public SortedMap> getTopValues( - Class> clz, TemporalConstraint temporalConstraint, List filters, - String topKey, String orderingProperty) - throws DuplicatedKeyFilterException, KeyException, ValueException, Exception { - return this.getTopValues(clz, temporalConstraint, filters, topKey, orderingProperty, false, 0); + public SortedMap> getTopValues(String topKey, String orderingProperty) + throws Exception { + return this.getTopValues(topKey, orderingProperty, false, 0); } @Override @@ -230,46 +238,35 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ } @Override - public SortedSet getFilterValues(Class> clz, - TemporalConstraint temporalConstraint, List filters, String key) throws Exception { - return getFilterValues(clz, temporalConstraint, filters, key, null); + public SortedSet getFilterValues(String key) throws Exception { + return getFilterValues(key, null); } @Override - public SortedSet getFilterValues(Class> clz, - TemporalConstraint temporalConstraint, List filters, String key, Integer limit) throws Exception { - - return AccountingPersistenceBackendQueryFactory.getInstance().getFilterValues(clz, temporalConstraint, filters, - key, limit); + public SortedSet getFilterValues(String key, Integer limit) throws Exception { + return accountingPersistenceBackendQuery.getFilterValues(key, limit); } @Override public List getUsageValueQuotaTotal(List listUsage) throws Exception { - - return AccountingPersistenceBackendQueryFactory.getInstance().getUsageValueQuotaTotal(listUsage); + return accountingPersistenceBackendQuery.getUsageValueQuotaTotal(listUsage); } @Override - public SortedMap> getContextTimeSeries( - Class> clz, TemporalConstraint temporalConstraint, List filters, - List contexts) throws Exception { - - return AccountingPersistenceBackendQueryFactory.getInstance().getContextTimeSeries(clz, temporalConstraint, - filters, contexts); + public SortedMap> getContextTimeSeries() throws Exception { + return getContextTimeSeries(true); } - - public SortedMap> getContextTimeSeries( - Class> clz, TemporalConstraint temporalConstraint, List filters, - List contexts, boolean pad) throws DuplicatedKeyFilterException, Exception { + + public SortedMap> getContextTimeSeries(boolean pad) throws DuplicatedKeyFilterException, Exception { SortedMap> got; - got = AccountingPersistenceBackendQueryFactory.getInstance().getContextTimeSeries(clz, temporalConstraint, - filters, contexts); + + got = accountingPersistenceBackendQuery.getContextTimeSeries(); int count = got.size(); Filter firstRemovalKey = null; for (Filter nf : got.keySet()) { if (--count >= 0) { if (pad) { - padMap(got.get(nf), temporalConstraint); + padMap(got.get(nf)); } } else { @@ -285,31 +282,31 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ } return got; } - + @Override public Record getRecord(String recordId, String type) throws Exception { Record record = AccountingPersistenceBackendQueryFactory.getInstance().getRecord(recordId, type); return record; } - @Override - public SortedSet getSpaceProvidersIds() throws Exception { - SortedSet providersId = AccountingPersistenceBackendQueryFactory.getInstance().getSpaceProvidersIds(); - return providersId; + public SortedSet getDataType() throws Exception { + SortedSet dataTypes = new TreeSet(); + for(DataType dataType : DataType.values()) { + dataTypes.add(dataType.name()); + } + return dataTypes; } @Override - public SortedMap> getSpaceTimeSeries(Class> clz, - TemporalConstraint temporalConstraint, List filters, List providersId) throws Exception { + public SortedMap> getSpaceTimeSeries(Set dataTypes) throws Exception { - SortedMap> spaceTimeSeries = AccountingPersistenceBackendQueryFactory - .getInstance().getSpaceTimeSeries(clz, temporalConstraint, filters, providersId); + SortedMap> spaceTimeSeries = accountingPersistenceBackendQuery.getSpaceTimeSeries(dataTypes); int count = spaceTimeSeries.size(); Filter firstRemovalKey = null; for (Filter nf : spaceTimeSeries.keySet()) { if (--count >= 0) { - padMapStorage(spaceTimeSeries.get(nf), temporalConstraint); + padMapStorage(spaceTimeSeries.get(nf)); } else { if (firstRemovalKey == null) { firstRemovalKey = nf; @@ -325,20 +322,20 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ } - protected SortedMap padMapStorage(SortedMap unpaddedData, - TemporalConstraint temporalConstraint) throws Exception { + protected SortedMap padMapStorage(SortedMap unpaddedData) throws Exception { SortedSet sequence = temporalConstraint.getCalendarSequence(); - Long longValuePre = null; + + Info previuosInfo = null; for (Calendar progressTime : sequence) { - Long longValue = unpaddedData.get(progressTime); + Info info = unpaddedData.get(progressTime); - if (longValue == null) { - unpaddedData.put(progressTime, longValuePre); + if (info == null) { + unpaddedData.put(progressTime, previuosInfo); } else { - longValuePre = longValue; + previuosInfo = info; } - } + return unpaddedData; }