Implementing queries
This commit is contained in:
parent
2efd3e3d09
commit
c043013d64
|
@ -13,6 +13,7 @@ import org.gcube.accounting.analytics.TemporalConstraint.AggregationMode;
|
|||
import org.gcube.accounting.analytics.TemporalConstraint.CalendarEnum;
|
||||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord;
|
||||
import org.gcube.accounting.datamodel.aggregation.AggregatedStorageStatusRecord;
|
||||
import org.gcube.accounting.utility.postgresql.PostgreSQLQuery;
|
||||
import org.gcube.accounting.utility.postgresql.RecordToDBFields;
|
||||
import org.gcube.accounting.utility.postgresql.RecordToDBMapping;
|
||||
|
@ -37,6 +38,8 @@ public class Query extends PostgreSQLQuery {
|
|||
|
||||
private String recordId;
|
||||
|
||||
protected Set<String> providersId;
|
||||
|
||||
public Query(Class<? extends AggregatedRecord<?, ?>> clz) throws Exception {
|
||||
this.clz = clz;
|
||||
this.recordToDBFields = RecordToDBMapping.getRecordToDBFields(clz);
|
||||
|
@ -71,16 +74,26 @@ public class Query extends PostgreSQLQuery {
|
|||
}
|
||||
|
||||
public void addContext(String context) {
|
||||
if(contexts == null) {
|
||||
contexts = new HashSet<>();
|
||||
if(this.contexts == null) {
|
||||
this.contexts = new HashSet<>();
|
||||
}
|
||||
contexts.add(context);
|
||||
this.contexts.add(context);
|
||||
}
|
||||
|
||||
public void setRecordId(String recordId) {
|
||||
this.recordId = recordId;
|
||||
}
|
||||
|
||||
public void addProvidersId(String providerId) {
|
||||
if(providersId == null) {
|
||||
providersId = new HashSet<>();
|
||||
}
|
||||
providersId.add(providerId);
|
||||
}
|
||||
|
||||
public void setProvidersId(List<String> providersId) {
|
||||
this.providersId = new HashSet<>(providersId);
|
||||
}
|
||||
|
||||
public RecordToDBFields getRecordToDBMapper() {
|
||||
return recordToDBFields;
|
||||
|
@ -137,6 +150,25 @@ public class Query extends PostgreSQLQuery {
|
|||
}
|
||||
}
|
||||
|
||||
protected void addProvidersIdFilter() {
|
||||
if(providersId!=null && providersId.size()>0) {
|
||||
// The first filter if the time_bucket
|
||||
stringBuffer.append(" AND (");
|
||||
boolean first = true;
|
||||
for(String providerId : providersId) {
|
||||
if(first) {
|
||||
first = false;
|
||||
}else {
|
||||
stringBuffer.append(" OR ");
|
||||
}
|
||||
appendTableField(AggregatedStorageStatusRecord.PROVIDER_ID);
|
||||
stringBuffer.append("=");
|
||||
appendValue(providerId);
|
||||
}
|
||||
stringBuffer.append(")");
|
||||
}
|
||||
}
|
||||
|
||||
protected void addEmittedFields() throws Exception {
|
||||
Set<String> aggregatedField = clz.newInstance().getAggregatedFields();
|
||||
for(String fieldName : aggregatedField) {
|
||||
|
@ -284,7 +316,24 @@ public class Query extends PostgreSQLQuery {
|
|||
return stringBuffer.toString();
|
||||
}
|
||||
|
||||
|
||||
public String getSpaceTimeSeries() {
|
||||
newQuery();
|
||||
|
||||
addRequestedDate();
|
||||
|
||||
stringBuffer.append(" FROM ");
|
||||
stringBuffer.append(recordToDBFields.getTableName());
|
||||
|
||||
addTemporalConstraintToQuery();
|
||||
|
||||
addFilters();
|
||||
addProvidersIdFilter();
|
||||
|
||||
addDateGropuBy();
|
||||
addDateOrderBy();
|
||||
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
|
||||
public String getNextPossibleValueQuery() throws Exception {
|
||||
newQuery();
|
||||
|
|
Loading…
Reference in New Issue