|
|
|
@ -98,12 +98,13 @@ AccountingPersistenceBackendQuery {
|
|
|
|
|
public static final String DESIGN_DOC_ID_LIST_USAGE="ListUsage";
|
|
|
|
|
|
|
|
|
|
public static final long ENV_TIME_OUT=240000;
|
|
|
|
|
//public static final long ENV_TIME_OUT_VIEW=30000;
|
|
|
|
|
/* The environment configuration */
|
|
|
|
|
protected static final CouchbaseEnvironment ENV = DefaultCouchbaseEnvironment
|
|
|
|
|
.builder()
|
|
|
|
|
.connectTimeout(ENV_TIME_OUT)
|
|
|
|
|
.maxRequestLifetime(ENV_TIME_OUT)
|
|
|
|
|
.viewTimeout(ENV_TIME_OUT)
|
|
|
|
|
//.viewTimeout(ENV_TIME_OUT_VIEW)
|
|
|
|
|
.queryTimeout(ENV_TIME_OUT).build();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -550,9 +551,7 @@ AccountingPersistenceBackendQuery {
|
|
|
|
|
//infos.put(info);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//TODO DA Completare per la richiesta utente e servizi/altro utilizzati nel periodo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//TODO complete the request from user/service usage into period
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -561,7 +560,7 @@ AccountingPersistenceBackendQuery {
|
|
|
|
|
|
|
|
|
|
protected SortedMap<Calendar, Info> mapReduceQuery(
|
|
|
|
|
Class<? extends AggregatedRecord<?, ?>> clz,
|
|
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters,String context)
|
|
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters,String context,Boolean valueEmpty)
|
|
|
|
|
throws Exception {
|
|
|
|
|
String currentScope=null;
|
|
|
|
|
if (context==null)
|
|
|
|
@ -680,41 +679,49 @@ AccountingPersistenceBackendQuery {
|
|
|
|
|
infos.put(calendar, info);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (infos.isEmpty()){
|
|
|
|
|
query = ViewQuery.from(designDocId, viewName);
|
|
|
|
|
query.groupLevel(groupLevel);
|
|
|
|
|
query.descending(false);
|
|
|
|
|
try {
|
|
|
|
|
//execute query in a specify bucket
|
|
|
|
|
viewResult = connectionMap.get(clz.getSimpleName()).query(query);
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error(e.getLocalizedMessage());
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ViewRow row=viewResult.allRows().get(0);
|
|
|
|
|
|
|
|
|
|
JsonArray array = getRangeKey(
|
|
|
|
|
temporalConstraint.getStartTime(),
|
|
|
|
|
aggregationMode, false, false);
|
|
|
|
|
Calendar calendar = getCalendarFromArray(array);
|
|
|
|
|
|
|
|
|
|
JsonObject value = (JsonObject) row.value();
|
|
|
|
|
|
|
|
|
|
JSONObject objJson = new JSONObject(value.toString());
|
|
|
|
|
JSONObject objJsontemplate = new JSONObject();
|
|
|
|
|
Iterator<?> iterateJson = objJson.keys();
|
|
|
|
|
while( iterateJson.hasNext() ) {
|
|
|
|
|
String key = (String)iterateJson.next();
|
|
|
|
|
objJsontemplate.put(key, 0);
|
|
|
|
|
logger.trace("valueEmpty not permitted:{}",valueEmpty);
|
|
|
|
|
//infos not empity is permitted only for getTimeSeries and Top
|
|
|
|
|
if (valueEmpty){
|
|
|
|
|
if (infos.isEmpty()){
|
|
|
|
|
logger.trace("infos is empity");
|
|
|
|
|
query = ViewQuery.from(designDocId, viewName);
|
|
|
|
|
query.groupLevel(groupLevel);
|
|
|
|
|
query.descending(false);
|
|
|
|
|
try {
|
|
|
|
|
//execute query in a specify bucket
|
|
|
|
|
viewResult = connectionMap.get(clz.getSimpleName()).query(query);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.warn("not execute query",e.getLocalizedMessage());
|
|
|
|
|
//throw e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if(viewResult.totalRows()!=0){
|
|
|
|
|
ViewRow row=viewResult.allRows().get(0);
|
|
|
|
|
JsonArray array = getRangeKey(
|
|
|
|
|
temporalConstraint.getStartTime(),
|
|
|
|
|
aggregationMode, false, false);
|
|
|
|
|
Calendar calendar = getCalendarFromArray(array);
|
|
|
|
|
|
|
|
|
|
JsonObject value = (JsonObject) row.value();
|
|
|
|
|
JSONObject objJson= new JSONObject(value.toString());
|
|
|
|
|
JSONObject objJsontemplate=new JSONObject();
|
|
|
|
|
Iterator<?> iterateJson = objJson.keys();
|
|
|
|
|
while( iterateJson.hasNext() ) {
|
|
|
|
|
String key = (String)iterateJson.next();
|
|
|
|
|
objJsontemplate.put(key, 0);
|
|
|
|
|
}
|
|
|
|
|
//generate an example object for json
|
|
|
|
|
Info info = new Info(calendar, objJsontemplate);
|
|
|
|
|
infos.put(calendar, info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.warn("error :{}",e.getLocalizedMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//generate an example object for json
|
|
|
|
|
Info info = new Info(calendar, objJsontemplate);
|
|
|
|
|
infos.put(calendar, info);
|
|
|
|
|
//break;
|
|
|
|
|
}
|
|
|
|
|
logger.trace("infos:{}",infos.toString());
|
|
|
|
|
return infos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -728,7 +735,7 @@ AccountingPersistenceBackendQuery {
|
|
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters)
|
|
|
|
|
throws Exception {
|
|
|
|
|
|
|
|
|
|
SortedMap<Calendar, Info> map = mapReduceQuery(clz, temporalConstraint, filters,null);
|
|
|
|
|
SortedMap<Calendar, Info> map = mapReduceQuery(clz, temporalConstraint, filters,null,true);
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -780,7 +787,7 @@ AccountingPersistenceBackendQuery {
|
|
|
|
|
for(NumberedFilter nf : top){
|
|
|
|
|
filters.add(nf);
|
|
|
|
|
SortedMap<Calendar, Info> map =
|
|
|
|
|
mapReduceQuery(clz, temporalConstraint, filters,null);
|
|
|
|
|
mapReduceQuery(clz, temporalConstraint, filters,null,true);
|
|
|
|
|
ret.put(nf, map);
|
|
|
|
|
filters.remove(nf);
|
|
|
|
|
}
|
|
|
|
@ -1207,8 +1214,11 @@ AccountingPersistenceBackendQuery {
|
|
|
|
|
for(Filter nf : listContexts){
|
|
|
|
|
logger.debug("detail time series :{}",nf.toString());
|
|
|
|
|
SortedMap<Calendar, Info> map =
|
|
|
|
|
mapReduceQuery(clz, temporalConstraint, filters,nf.getValue());
|
|
|
|
|
ret.put(nf, map);
|
|
|
|
|
mapReduceQuery(clz, temporalConstraint, filters,nf.getValue(),false);
|
|
|
|
|
if (!map.isEmpty()){
|
|
|
|
|
ret.put(nf, map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
filters.remove(nf);
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|