Merge branch 'feature/21353'
Conflicts: CHANGELOG.md pom.xml src/main/java/org/gcube/accounting/analytics/persistence/AccountingPersistenceQuery.java
This commit is contained in:
commit
7cc25cd68e
|
@ -2,7 +2,16 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
||||||
|
|
||||||
# Changelog for Accounting Analytics
|
# Changelog for Accounting Analytics
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
## [v3.0.1]
|
## [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
|
- Aligned model
|
||||||
|
|
||||||
|
|
13
pom.xml
13
pom.xml
|
@ -9,7 +9,11 @@
|
||||||
|
|
||||||
<groupId>org.gcube.accounting</groupId>
|
<groupId>org.gcube.accounting</groupId>
|
||||||
<artifactId>accounting-analytics</artifactId>
|
<artifactId>accounting-analytics</artifactId>
|
||||||
|
<<<<<<< HEAD
|
||||||
<version>3.0.1</version>
|
<version>3.0.1</version>
|
||||||
|
=======
|
||||||
|
<version>4.0.0-SNAPSHOT</version>
|
||||||
|
>>>>>>> refs/heads/feature/21353
|
||||||
<name>Accounting Analytics</name>
|
<name>Accounting Analytics</name>
|
||||||
<description>
|
<description>
|
||||||
Accounting Analytics allows querying accounting data. It
|
Accounting Analytics allows querying accounting data. It
|
||||||
|
@ -44,27 +48,18 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.accounting</groupId>
|
<groupId>org.gcube.accounting</groupId>
|
||||||
<artifactId>accounting-lib</artifactId>
|
<artifactId>accounting-lib</artifactId>
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.data.publishing</groupId>
|
<groupId>org.gcube.data.publishing</groupId>
|
||||||
<artifactId>document-store-lib</artifactId>
|
<artifactId>document-store-lib</artifactId>
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.core</groupId>
|
<groupId>org.gcube.core</groupId>
|
||||||
<artifactId>common-scope</artifactId>
|
<artifactId>common-scope</artifactId>
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.json</groupId>
|
|
||||||
<artifactId>json</artifactId>
|
|
||||||
<version>20090211</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- Test Dependencies -->
|
<!-- Test Dependencies -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -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<Filter> filters;
|
|
||||||
protected Double d;
|
|
||||||
protected String orderingProperty;
|
|
||||||
|
|
||||||
public FiltersValue(){}
|
|
||||||
|
|
||||||
public FiltersValue(List<Filter> filters, Number n, String orderingProperty) {
|
|
||||||
super();
|
|
||||||
this.filters=filters;
|
|
||||||
this.d = n.doubleValue();
|
|
||||||
this.orderingProperty = orderingProperty;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Filter> getFiltersValue() {
|
|
||||||
return filters;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFiltersValue(List<Filter> 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 + "]";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -6,7 +6,7 @@ package org.gcube.accounting.analytics;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Calendar;
|
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 {
|
public class Info {
|
||||||
|
|
||||||
protected Calendar calendar;
|
protected Calendar calendar;
|
||||||
protected JSONObject value;
|
protected JsonNode value;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param calendar the date
|
* @param calendar the date
|
||||||
* @param value the JSON value
|
* @param value the JSON value
|
||||||
*/
|
*/
|
||||||
public Info(Calendar calendar, JSONObject value) {
|
public Info(Calendar calendar, JsonNode value) {
|
||||||
super();
|
super();
|
||||||
this.calendar = calendar;
|
this.calendar = calendar;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
|
@ -45,14 +45,14 @@ public class Info {
|
||||||
/**
|
/**
|
||||||
* @return the value
|
* @return the value
|
||||||
*/
|
*/
|
||||||
public JSONObject getValue() {
|
public JsonNode getValue() {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param value the value to set
|
* @param value the value to set
|
||||||
*/
|
*/
|
||||||
public void setValue(JSONObject value) {
|
public void setValue(JsonNode value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ package org.gcube.accounting.analytics;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
|
@ -34,11 +34,11 @@ public class NumberedFilter extends Filter {
|
||||||
this.orderingProperty = orderingProperty;
|
this.orderingProperty = orderingProperty;
|
||||||
|
|
||||||
for(Info info : timeSeries.values()){
|
for(Info info : timeSeries.values()){
|
||||||
JSONObject value = info.getValue();
|
JsonNode value = info.getValue();
|
||||||
if(this.d == null){
|
if(this.d == null){
|
||||||
this.d = value.getDouble(orderingProperty);
|
this.d = value.get(orderingProperty).asDouble();
|
||||||
}else{
|
}else{
|
||||||
this.d = this.d + value.getDouble(orderingProperty);
|
this.d = this.d + value.get(orderingProperty).asDouble();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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<? extends AggregatedUsageRecord<?, ?>> clz;
|
|
||||||
protected TemporalConstraint temporalConstraint;
|
|
||||||
|
|
||||||
//USED for a list service for each identifier (package service )
|
|
||||||
//protected List<FiltersValue> filtersValue;
|
|
||||||
|
|
||||||
protected List<Filter> 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<? extends AggregatedUsageRecord<?, ?>> getClz() {
|
|
||||||
return clz;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setClz(String context,Class<? extends AggregatedUsageRecord<?, ?>> clz) {
|
|
||||||
this.clz = clz;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UsageServiceValue(){}
|
|
||||||
|
|
||||||
public UsageServiceValue(String context,String identifier,Class<? extends AggregatedUsageRecord<?, ?>> clz,TemporalConstraint temporalConstraint,List<Filter> filters){
|
|
||||||
super();
|
|
||||||
this.context=context;
|
|
||||||
this.filters=filters;
|
|
||||||
this.clz=clz;
|
|
||||||
this.temporalConstraint=temporalConstraint;
|
|
||||||
this.identifier=identifier;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Filter> getFilters() {
|
|
||||||
return filters;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFilters(List<Filter> 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 + "]";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,90 +0,0 @@
|
||||||
package org.gcube.accounting.analytics;
|
|
||||||
|
|
||||||
import org.gcube.accounting.datamodel.AggregatedUsageRecord;
|
|
||||||
|
|
||||||
public class UsageStorageValue extends UsageValue {
|
|
||||||
protected Class<? extends AggregatedUsageRecord<?, ?>> 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<? extends AggregatedUsageRecord<?, ?>> getClz() {
|
|
||||||
return clz;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setClz(Class<? extends AggregatedUsageRecord<?, ?>> clz) {
|
|
||||||
this.clz = clz;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UsageStorageValue(){}
|
|
||||||
|
|
||||||
|
|
||||||
public UsageStorageValue(String context,String identifier,Class<? extends AggregatedUsageRecord<?, ?>> clz){
|
|
||||||
super();
|
|
||||||
this.context=context;
|
|
||||||
this.clz=clz;
|
|
||||||
this.identifier=identifier;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public UsageStorageValue(String context,String identifier,Class<? extends AggregatedUsageRecord<?, ?>> 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
|
|
||||||
+ "]";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -5,6 +5,7 @@ package org.gcube.accounting.analytics.persistence;
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.SortedMap;
|
import java.util.SortedMap;
|
||||||
import java.util.SortedSet;
|
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.NumberedFilter;
|
||||||
import org.gcube.accounting.analytics.TemporalConstraint;
|
import org.gcube.accounting.analytics.TemporalConstraint;
|
||||||
import org.gcube.accounting.analytics.UsageValue;
|
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.accounting.datamodel.BasicUsageRecord;
|
||||||
import org.gcube.documentstore.records.AggregatedRecord;
|
import org.gcube.documentstore.records.AggregatedRecord;
|
||||||
import org.gcube.documentstore.records.Record;
|
import org.gcube.documentstore.records.Record;
|
||||||
|
@ -39,98 +37,72 @@ public interface AccountingPersistenceBackendQuery {
|
||||||
AccountingPersistenceBackendQueryConfiguration configuration)
|
AccountingPersistenceBackendQueryConfiguration configuration)
|
||||||
throws Exception;
|
throws Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param clz the Usage Record Class of interest
|
||||||
|
*
|
||||||
|
* Required
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void setRequestedRecords(Class<? extends AggregatedRecord<?, ?>> 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<String> 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<Filter> filters);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query the persistence obtaining a Map where the date is the key and the
|
* 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,
|
* #Info is the value. The result is relative to an Usage Record Type,
|
||||||
* respect a TemporalConstraint and can be applied one or more filters.
|
* respect a TemporalConstraint and can be applied one or more filters.
|
||||||
*
|
*
|
||||||
* @param clz
|
* @return the Map containing for each date in the required interval the requested data
|
||||||
* 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
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public SortedMap<Calendar, Info> getTimeSeries(
|
public SortedMap<Calendar, Info> getTimeSeries() throws Exception;
|
||||||
Class<? extends AggregatedRecord<?, ?>> clz,
|
|
||||||
TemporalConstraint temporalConstraint, List<Filter> filters)
|
|
||||||
throws DuplicatedKeyFilterException, KeyException, ValueException,
|
|
||||||
Exception;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query the persistence obtaining a Map where the date is the key and the
|
* Return a SortedMap containing the TimeSeries for each context.
|
||||||
* #Info is the value. The result is relative to an Usage Record Type,
|
* @return a SortedMap containing the TimeSeries for each context.
|
||||||
* 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
|
|
||||||
*/
|
*/
|
||||||
public SortedMap<Calendar, Info> getNoContextTimeSeries(
|
public SortedMap<Filter, SortedMap<Calendar, Info>> getContextTimeSeries() throws Exception;
|
||||||
Class<? extends AggregatedRecord<?, ?>> clz,
|
|
||||||
TemporalConstraint temporalConstraint, List<Filter> filters)
|
|
||||||
throws DuplicatedKeyFilterException, KeyException, ValueException,
|
|
||||||
Exception;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a SortedMap containing the TimeSeries for top values for a certain
|
* 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
|
* key taking in account all Filters.
|
||||||
* 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.
|
|
||||||
*
|
*
|
||||||
* @param clz
|
* The values are ordered from the most occurred value.
|
||||||
* the Usage Record Class of interest
|
*
|
||||||
* @param temporalConstraint
|
* @param topKey the key to obtain top values
|
||||||
* 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
|
|
||||||
* @param orderingProperty
|
* @param orderingProperty
|
||||||
* @return a SortedMap
|
* @return a SortedMap
|
||||||
* @throws DuplicatedKeyFilterException
|
|
||||||
* @throws KeyException
|
|
||||||
* @throws ValueException
|
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public SortedMap<NumberedFilter, SortedMap<Calendar, Info>>
|
public SortedMap<NumberedFilter, SortedMap<Calendar, Info>> getTopValues(String topKey, String orderingProperty) throws Exception;
|
||||||
getTopValues(Class<? extends AggregatedRecord<?,?>> clz,
|
|
||||||
TemporalConstraint temporalConstraint, List<Filter> filters,
|
|
||||||
String topKey, String orderingProperty)
|
|
||||||
throws DuplicatedKeyFilterException, KeyException, ValueException,
|
|
||||||
Exception;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close the connection to persistence
|
* Close the connection to persistence
|
||||||
|
@ -140,20 +112,20 @@ public interface AccountingPersistenceBackendQuery {
|
||||||
*/
|
*/
|
||||||
public void close() throws Exception;
|
public void close() throws Exception;
|
||||||
|
|
||||||
public SortedSet<NumberedFilter> getFilterValues(
|
public SortedSet<NumberedFilter> getFilterValues(String key) throws Exception;
|
||||||
Class<? extends AggregatedRecord<?, ?>> clz,
|
|
||||||
TemporalConstraint temporalConstraint, List<Filter> filters,
|
public SortedSet<NumberedFilter> getFilterValues(String key, Integer limit) throws Exception;
|
||||||
String key) throws Exception;
|
|
||||||
|
public Record getRecord(String recordId, String type) throws Exception;
|
||||||
|
|
||||||
|
|
||||||
|
public SortedMap<Filter, SortedMap<Calendar, Info>> getSpaceTimeSeries(Set<String> dataTypes) throws Exception;
|
||||||
|
|
||||||
public SortedSet<NumberedFilter> getFilterValues(
|
|
||||||
Class<? extends AggregatedRecord<?, ?>> clz,
|
|
||||||
TemporalConstraint temporalConstraint, List<Filter> filters,
|
|
||||||
String key, Integer limit) throws Exception;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getUsageValueQuotaTotal
|
* 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:
|
* Input:
|
||||||
* [
|
* [
|
||||||
* TotalFilters [
|
* TotalFilters [
|
||||||
|
@ -194,32 +166,10 @@ public interface AccountingPersistenceBackendQuery {
|
||||||
* @return List<UsageValue>
|
* @return List<UsageValue>
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public List<UsageValue> getUsageValueQuotaTotal(
|
public List<UsageValue> getUsageValueQuotaTotal(List<UsageValue> listUsage)
|
||||||
List<UsageValue> listUsage)
|
|
||||||
throws Exception;
|
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<Filter, SortedMap<Calendar, Info>> getContextTimeSeries(
|
|
||||||
Class<? extends AggregatedRecord<?, ?>> clz,
|
|
||||||
TemporalConstraint temporalConstraint, List<Filter> filters,List<String> contexts)
|
|
||||||
throws Exception;
|
|
||||||
|
|
||||||
public Record getRecord(String recordId, String type) throws Exception;
|
|
||||||
|
|
||||||
public SortedSet<String> getSpaceProvidersIds() throws Exception;
|
|
||||||
|
|
||||||
public SortedMap<Filter, SortedMap<Calendar, Long>> getSpaceTimeSeries(
|
|
||||||
Class<? extends AggregatedRecord<?, ?>> clz,
|
|
||||||
TemporalConstraint temporalConstraint, List<Filter> filters,
|
|
||||||
List<String> providersId) throws Exception;
|
|
||||||
|
|
||||||
boolean isConnectionActive() throws Exception;
|
boolean isConnectionActive() throws Exception;
|
||||||
|
|
||||||
}
|
}
|
|
@ -8,6 +8,7 @@ import java.util.Calendar;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.SortedMap;
|
import java.util.SortedMap;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.TreeMap;
|
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.analytics.exception.ValueException;
|
||||||
import org.gcube.accounting.datamodel.aggregation.AggregatedStorageStatusRecord;
|
import org.gcube.accounting.datamodel.aggregation.AggregatedStorageStatusRecord;
|
||||||
import org.gcube.accounting.datamodel.aggregation.AggregatedStorageUsageRecord;
|
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.AggregatedRecord;
|
||||||
import org.gcube.documentstore.records.Record;
|
import org.gcube.documentstore.records.Record;
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
|
@ -40,17 +43,58 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
|
||||||
|
|
||||||
public static final int DEFAULT_LIMIT_RESULT_NUMBER = 5;
|
public static final int DEFAULT_LIMIT_RESULT_NUMBER = 5;
|
||||||
|
|
||||||
private AccountingPersistenceQuery() {
|
|
||||||
}
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
accountingPersistenceQuery = new AccountingPersistenceQuery();
|
try {
|
||||||
|
accountingPersistenceQuery = new AccountingPersistenceQuery();
|
||||||
|
}catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static synchronized AccountingPersistenceQuery getInstance() {
|
protected static synchronized AccountingPersistenceQuery getInstance() {
|
||||||
return accountingPersistenceQuery;
|
return accountingPersistenceQuery;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Class<? extends AggregatedRecord<?, ?>> clz;
|
||||||
|
protected TemporalConstraint temporalConstraint;
|
||||||
|
|
||||||
|
protected Set<String> contexts;
|
||||||
|
protected Set<Filter> filters;
|
||||||
|
|
||||||
|
protected ObjectMapper objectMapper;
|
||||||
|
|
||||||
|
protected AccountingPersistenceBackendQuery accountingPersistenceBackendQuery;
|
||||||
|
|
||||||
|
private AccountingPersistenceQuery() throws Exception {
|
||||||
|
accountingPersistenceBackendQuery = AccountingPersistenceBackendQueryFactory.getInstance();
|
||||||
|
objectMapper = new ObjectMapper();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setRequestedRecords(Class<? extends AggregatedRecord<?, ?>> clz) {
|
||||||
|
this.clz = clz;
|
||||||
|
accountingPersistenceBackendQuery.setRequestedRecords(clz);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setTemporalConstraint(TemporalConstraint temporalConstraint) {
|
||||||
|
this.temporalConstraint = temporalConstraint;
|
||||||
|
accountingPersistenceBackendQuery.setTemporalConstraint(temporalConstraint);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setContexts(Set<String> contexts) {
|
||||||
|
this.contexts = contexts;
|
||||||
|
accountingPersistenceBackendQuery.setContexts(this.contexts);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setFilters(Set<Filter> filters) {
|
||||||
|
this.filters = filters;
|
||||||
|
accountingPersistenceBackendQuery.setFilters(filters);
|
||||||
|
}
|
||||||
|
|
||||||
public static SortedSet<String> getQuerableKeys(Class<? extends AggregatedRecord<?, ?>> clz) throws Exception {
|
public static SortedSet<String> getQuerableKeys(Class<? extends AggregatedRecord<?, ?>> clz) throws Exception {
|
||||||
AggregatedRecord<?, ?> instance = clz.newInstance();
|
AggregatedRecord<?, ?> instance = clz.newInstance();
|
||||||
|
|
||||||
|
@ -59,7 +103,11 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
|
||||||
if (clz.equals(AggregatedStorageStatusRecord.class)) {
|
if (clz.equals(AggregatedStorageStatusRecord.class)) {
|
||||||
SortedSet<String> storageStatus = new TreeSet<>();
|
SortedSet<String> storageStatus = new TreeSet<>();
|
||||||
storageStatus.add(AggregatedStorageStatusRecord.CONSUMER_ID);
|
storageStatus.add(AggregatedStorageStatusRecord.CONSUMER_ID);
|
||||||
|
<<<<<<< HEAD
|
||||||
storageStatus.add(AggregatedStorageStatusRecord.PROVIDER_URI);
|
storageStatus.add(AggregatedStorageStatusRecord.PROVIDER_URI);
|
||||||
|
=======
|
||||||
|
// storageStatus.add(AggregatedStorageStatusRecord.DATA_SERVICEID);
|
||||||
|
>>>>>>> refs/heads/feature/21353
|
||||||
return storageStatus;
|
return storageStatus;
|
||||||
} else {
|
} else {
|
||||||
return instance.getQuerableKeys();
|
return instance.getQuerableKeys();
|
||||||
|
@ -74,21 +122,19 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
|
||||||
return AggregatedRecord.OPERATION_COUNT;
|
return AggregatedRecord.OPERATION_COUNT;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static JSONObject getPaddingJSONObject(Map<Calendar, Info> unpaddedResults) throws JSONException {
|
protected JsonNode getPaddingJsonNode(Map<Calendar, Info> unpaddedResults) throws Exception {
|
||||||
|
ObjectNode objectNode = objectMapper.createObjectNode();
|
||||||
JSONObject jsonObject = new JSONObject();
|
|
||||||
// verify data consistency
|
// verify data consistency
|
||||||
if (unpaddedResults.size() != 0) {
|
if (unpaddedResults.size() != 0) {
|
||||||
Info auxInfo = new ArrayList<Info>(unpaddedResults.values()).get(0);
|
Info auxInfo = new ArrayList<Info>(unpaddedResults.values()).get(0);
|
||||||
JSONObject auxJsonObject = auxInfo.getValue();
|
JsonNode auxJsonNode = auxInfo.getValue();
|
||||||
@SuppressWarnings("unchecked")
|
Iterator<String> keys = auxJsonNode.fieldNames();
|
||||||
Iterator<String> keys = auxJsonObject.keys();
|
|
||||||
while (keys.hasNext()) {
|
while (keys.hasNext()) {
|
||||||
String key = keys.next();
|
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
|
* @throws Exception
|
||||||
* if fails
|
* if fails
|
||||||
*/
|
*/
|
||||||
protected static SortedMap<Calendar, Info> padMap(SortedMap<Calendar, Info> unpaddedData,
|
protected SortedMap<Calendar, Info> padMap(SortedMap<Calendar, Info> unpaddedData) throws Exception {
|
||||||
TemporalConstraint temporalConstraint) throws Exception {
|
JsonNode jsonNode = getPaddingJsonNode(unpaddedData);
|
||||||
|
|
||||||
JSONObject jsonObject = getPaddingJSONObject(unpaddedData);
|
|
||||||
SortedSet<Calendar> sequence = temporalConstraint.getCalendarSequence();
|
SortedSet<Calendar> sequence = temporalConstraint.getCalendarSequence();
|
||||||
for (Calendar progressTime : sequence) {
|
for (Calendar progressTime : sequence) {
|
||||||
Info info = unpaddedData.get(progressTime);
|
Info info = unpaddedData.get(progressTime);
|
||||||
if (info == null) {
|
if (info == null) {
|
||||||
info = new Info(progressTime, jsonObject);
|
info = new Info(progressTime, jsonNode);
|
||||||
unpaddedData.put(progressTime, info);
|
unpaddedData.put(progressTime, info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,74 +163,43 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SortedMap<Calendar, Info> getTimeSeries(Class<? extends AggregatedRecord<?, ?>> clz,
|
public SortedMap<Calendar, Info> getTimeSeries()
|
||||||
TemporalConstraint temporalConstraint, List<Filter> filters)
|
|
||||||
throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
||||||
|
return this.getTimeSeries(true);
|
||||||
return this.getTimeSeries(clz, temporalConstraint, filters, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SortedMap<Calendar, Info> getTimeSeries(Class<? extends AggregatedRecord<?, ?>> clz,
|
public SortedMap<Calendar, Info> getTimeSeries(boolean pad)
|
||||||
TemporalConstraint temporalConstraint, List<Filter> filters, boolean pad)
|
|
||||||
throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
||||||
SortedMap<Calendar, Info> ret = AccountingPersistenceBackendQueryFactory.getInstance().getTimeSeries(clz,
|
|
||||||
temporalConstraint, filters);
|
SortedMap<Calendar, Info> ret = accountingPersistenceBackendQuery.getTimeSeries();
|
||||||
|
|
||||||
if (ret == null) {
|
if (ret == null) {
|
||||||
ret = new TreeMap<>();
|
ret = new TreeMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pad) {
|
if (pad) {
|
||||||
ret = padMap(ret, temporalConstraint);
|
ret = padMap(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public SortedMap<NumberedFilter, SortedMap<Calendar, Info>> getTopValues(String topKey, String orderingProperty, boolean pad, int limit)
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SortedMap<NumberedFilter, SortedMap<Calendar, Info>> getTopValues(
|
|
||||||
Class<? extends AggregatedRecord<?, ?>> clz, TemporalConstraint temporalConstraint, List<Filter> filters,
|
|
||||||
String topKey, String orderingProperty, boolean pad, int limit)
|
|
||||||
throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
||||||
SortedMap<NumberedFilter, SortedMap<Calendar, Info>> got;
|
SortedMap<NumberedFilter, SortedMap<Calendar, Info>> got;
|
||||||
|
|
||||||
if (orderingProperty == null) {
|
if (orderingProperty == null) {
|
||||||
orderingProperty = getDefaultOrderingProperties(clz);
|
orderingProperty = getDefaultOrderingProperties(clz);
|
||||||
}
|
}
|
||||||
|
|
||||||
got = AccountingPersistenceBackendQueryFactory.getInstance().getTopValues(clz, temporalConstraint, filters,
|
got = accountingPersistenceBackendQuery.getTopValues(topKey, orderingProperty);
|
||||||
topKey, orderingProperty);
|
|
||||||
|
|
||||||
int count = got.size() > limit ? limit : got.size();
|
int count = got.size() > limit ? limit : got.size();
|
||||||
NumberedFilter firstRemovalKey = null;
|
NumberedFilter firstRemovalKey = null;
|
||||||
for (NumberedFilter nf : got.keySet()) {
|
for (NumberedFilter nf : got.keySet()) {
|
||||||
if (--count >= 0 || limit <= 0) {
|
if (--count >= 0 || limit <= 0) {
|
||||||
if (pad) {
|
if (pad) {
|
||||||
padMap(got.get(nf), temporalConstraint);
|
padMap(got.get(nf));
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -203,20 +216,15 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
|
||||||
return got;
|
return got;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SortedMap<NumberedFilter, SortedMap<Calendar, Info>> getTopValues(
|
public SortedMap<NumberedFilter, SortedMap<Calendar, Info>> getTopValues(String topKey) throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
||||||
Class<? extends AggregatedRecord<?, ?>> clz, TemporalConstraint temporalConstraint, List<Filter> filters,
|
|
||||||
String topKey) throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
|
||||||
String orderingProperty = AccountingPersistenceQuery.getDefaultOrderingProperties(clz);
|
String orderingProperty = AccountingPersistenceQuery.getDefaultOrderingProperties(clz);
|
||||||
|
return this.getTopValues(topKey, orderingProperty, false, 0);
|
||||||
return this.getTopValues(clz, temporalConstraint, filters, topKey, orderingProperty, false, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SortedMap<NumberedFilter, SortedMap<Calendar, Info>> getTopValues(
|
public SortedMap<NumberedFilter, SortedMap<Calendar, Info>> getTopValues(String topKey, String orderingProperty)
|
||||||
Class<? extends AggregatedRecord<?, ?>> clz, TemporalConstraint temporalConstraint, List<Filter> filters,
|
throws Exception {
|
||||||
String topKey, String orderingProperty)
|
return this.getTopValues(topKey, orderingProperty, false, 0);
|
||||||
throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
|
||||||
return this.getTopValues(clz, temporalConstraint, filters, topKey, orderingProperty, false, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -230,46 +238,35 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SortedSet<NumberedFilter> getFilterValues(Class<? extends AggregatedRecord<?, ?>> clz,
|
public SortedSet<NumberedFilter> getFilterValues(String key) throws Exception {
|
||||||
TemporalConstraint temporalConstraint, List<Filter> filters, String key) throws Exception {
|
return getFilterValues(key, null);
|
||||||
return getFilterValues(clz, temporalConstraint, filters, key, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SortedSet<NumberedFilter> getFilterValues(Class<? extends AggregatedRecord<?, ?>> clz,
|
public SortedSet<NumberedFilter> getFilterValues(String key, Integer limit) throws Exception {
|
||||||
TemporalConstraint temporalConstraint, List<Filter> filters, String key, Integer limit) throws Exception {
|
return accountingPersistenceBackendQuery.getFilterValues(key, limit);
|
||||||
|
|
||||||
return AccountingPersistenceBackendQueryFactory.getInstance().getFilterValues(clz, temporalConstraint, filters,
|
|
||||||
key, limit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<UsageValue> getUsageValueQuotaTotal(List<UsageValue> listUsage) throws Exception {
|
public List<UsageValue> getUsageValueQuotaTotal(List<UsageValue> listUsage) throws Exception {
|
||||||
|
return accountingPersistenceBackendQuery.getUsageValueQuotaTotal(listUsage);
|
||||||
return AccountingPersistenceBackendQueryFactory.getInstance().getUsageValueQuotaTotal(listUsage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SortedMap<Filter, SortedMap<Calendar, Info>> getContextTimeSeries(
|
public SortedMap<Filter, SortedMap<Calendar, Info>> getContextTimeSeries() throws Exception {
|
||||||
Class<? extends AggregatedRecord<?, ?>> clz, TemporalConstraint temporalConstraint, List<Filter> filters,
|
return getContextTimeSeries(true);
|
||||||
List<String> contexts) throws Exception {
|
|
||||||
|
|
||||||
return AccountingPersistenceBackendQueryFactory.getInstance().getContextTimeSeries(clz, temporalConstraint,
|
|
||||||
filters, contexts);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SortedMap<Filter, SortedMap<Calendar, Info>> getContextTimeSeries(
|
public SortedMap<Filter, SortedMap<Calendar, Info>> getContextTimeSeries(boolean pad) throws DuplicatedKeyFilterException, Exception {
|
||||||
Class<? extends AggregatedRecord<?, ?>> clz, TemporalConstraint temporalConstraint, List<Filter> filters,
|
|
||||||
List<String> contexts, boolean pad) throws DuplicatedKeyFilterException, Exception {
|
|
||||||
SortedMap<Filter, SortedMap<Calendar, Info>> got;
|
SortedMap<Filter, SortedMap<Calendar, Info>> got;
|
||||||
got = AccountingPersistenceBackendQueryFactory.getInstance().getContextTimeSeries(clz, temporalConstraint,
|
|
||||||
filters, contexts);
|
got = accountingPersistenceBackendQuery.getContextTimeSeries();
|
||||||
int count = got.size();
|
int count = got.size();
|
||||||
Filter firstRemovalKey = null;
|
Filter firstRemovalKey = null;
|
||||||
for (Filter nf : got.keySet()) {
|
for (Filter nf : got.keySet()) {
|
||||||
if (--count >= 0) {
|
if (--count >= 0) {
|
||||||
if (pad) {
|
if (pad) {
|
||||||
padMap(got.get(nf), temporalConstraint);
|
padMap(got.get(nf));
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -285,31 +282,31 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
|
||||||
}
|
}
|
||||||
return got;
|
return got;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Record getRecord(String recordId, String type) throws Exception {
|
public Record getRecord(String recordId, String type) throws Exception {
|
||||||
Record record = AccountingPersistenceBackendQueryFactory.getInstance().getRecord(recordId, type);
|
Record record = AccountingPersistenceBackendQueryFactory.getInstance().getRecord(recordId, type);
|
||||||
return record;
|
return record;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public SortedSet<String> getDataType() throws Exception {
|
||||||
public SortedSet<String> getSpaceProvidersIds() throws Exception {
|
SortedSet<String> dataTypes = new TreeSet<String>();
|
||||||
SortedSet<String> providersId = AccountingPersistenceBackendQueryFactory.getInstance().getSpaceProvidersIds();
|
for(DataType dataType : DataType.values()) {
|
||||||
return providersId;
|
dataTypes.add(dataType.name());
|
||||||
|
}
|
||||||
|
return dataTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SortedMap<Filter, SortedMap<Calendar, Long>> getSpaceTimeSeries(Class<? extends AggregatedRecord<?, ?>> clz,
|
public SortedMap<Filter, SortedMap<Calendar, Info>> getSpaceTimeSeries(Set<String> dataTypes) throws Exception {
|
||||||
TemporalConstraint temporalConstraint, List<Filter> filters, List<String> providersId) throws Exception {
|
|
||||||
|
|
||||||
SortedMap<Filter, SortedMap<Calendar, Long>> spaceTimeSeries = AccountingPersistenceBackendQueryFactory
|
SortedMap<Filter, SortedMap<Calendar, Info>> spaceTimeSeries = accountingPersistenceBackendQuery.getSpaceTimeSeries(dataTypes);
|
||||||
.getInstance().getSpaceTimeSeries(clz, temporalConstraint, filters, providersId);
|
|
||||||
|
|
||||||
int count = spaceTimeSeries.size();
|
int count = spaceTimeSeries.size();
|
||||||
Filter firstRemovalKey = null;
|
Filter firstRemovalKey = null;
|
||||||
for (Filter nf : spaceTimeSeries.keySet()) {
|
for (Filter nf : spaceTimeSeries.keySet()) {
|
||||||
if (--count >= 0) {
|
if (--count >= 0) {
|
||||||
padMapStorage(spaceTimeSeries.get(nf), temporalConstraint);
|
padMapStorage(spaceTimeSeries.get(nf));
|
||||||
} else {
|
} else {
|
||||||
if (firstRemovalKey == null) {
|
if (firstRemovalKey == null) {
|
||||||
firstRemovalKey = nf;
|
firstRemovalKey = nf;
|
||||||
|
@ -325,20 +322,20 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected SortedMap<Calendar, Long> padMapStorage(SortedMap<Calendar, Long> unpaddedData,
|
protected SortedMap<Calendar, Info> padMapStorage(SortedMap<Calendar, Info> unpaddedData) throws Exception {
|
||||||
TemporalConstraint temporalConstraint) throws Exception {
|
|
||||||
SortedSet<Calendar> sequence = temporalConstraint.getCalendarSequence();
|
SortedSet<Calendar> sequence = temporalConstraint.getCalendarSequence();
|
||||||
Long longValuePre = null;
|
|
||||||
|
Info previuosInfo = null;
|
||||||
for (Calendar progressTime : sequence) {
|
for (Calendar progressTime : sequence) {
|
||||||
Long longValue = unpaddedData.get(progressTime);
|
Info info = unpaddedData.get(progressTime);
|
||||||
|
|
||||||
if (longValue == null) {
|
if (info == null) {
|
||||||
unpaddedData.put(progressTime, longValuePre);
|
unpaddedData.put(progressTime, previuosInfo);
|
||||||
} else {
|
} else {
|
||||||
longValuePre = longValue;
|
previuosInfo = info;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return unpaddedData;
|
return unpaddedData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue