diff --git a/.classpath b/.classpath
index dcb2dc5..ca9d765 100644
--- a/.classpath
+++ b/.classpath
@@ -20,6 +20,7 @@
+
diff --git a/.project b/.project
index 6b2fe80..98dfdfb 100644
--- a/.project
+++ b/.project
@@ -5,6 +5,11 @@
+
+ org.eclipse.wst.common.project.facet.core.builder
+
+
+
org.eclipse.jdt.core.javabuilder
@@ -15,9 +20,17 @@
+
+ org.eclipse.wst.validation.validationbuilder
+
+
+
+ org.eclipse.jem.workbench.JavaEMFNature
+ org.eclipse.wst.common.modulecore.ModuleCoreNature
org.eclipse.jdt.core.javanature
org.eclipse.m2e.core.maven2Nature
+ org.eclipse.wst.common.project.facet.core.nature
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
index ec4300d..443e085 100644
--- a/.settings/org.eclipse.jdt.core.prefs
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -1,5 +1,8 @@
eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.7
diff --git a/src/main/java/org/gcube/accounting/analytics/exception/NoUsableAccountingPersistenceQueryFound.java b/src/main/java/org/gcube/accounting/analytics/exception/NoUsableAccountingPersistenceQueryFound.java
index 5381cab..2bb71bb 100644
--- a/src/main/java/org/gcube/accounting/analytics/exception/NoUsableAccountingPersistenceQueryFound.java
+++ b/src/main/java/org/gcube/accounting/analytics/exception/NoUsableAccountingPersistenceQueryFound.java
@@ -20,7 +20,8 @@ public class NoUsableAccountingPersistenceQueryFound extends Exception {
* call to {@link #initCause}.
*/
public NoUsableAccountingPersistenceQueryFound() {
- super();
+ super("No Usable Accounting Persistence Query Found");
+
}
/**
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 047462b..f9778ea 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.Map;
import java.util.SortedMap;
import java.util.SortedSet;
@@ -16,6 +17,7 @@ import org.gcube.accounting.analytics.exception.DuplicatedKeyFilterException;
import org.gcube.accounting.analytics.exception.KeyException;
import org.gcube.accounting.analytics.exception.ValueException;
import org.gcube.documentstore.records.AggregatedRecord;
+import org.json.JSONObject;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
@@ -26,7 +28,7 @@ public interface AccountingPersistenceBackendQuery {
public void prepareConnection(
AccountingPersistenceBackendQueryConfiguration configuration)
- throws Exception;
+ throws Exception;
/**
* Query the persistence obtaining a Map where the date is the key and the
@@ -53,9 +55,12 @@ public interface AccountingPersistenceBackendQuery {
*/
public SortedMap getTimeSeries(
Class extends AggregatedRecord, ?>> clz,
- TemporalConstraint temporalConstraint, List filters)
- throws DuplicatedKeyFilterException, KeyException, ValueException,
- Exception;
+ TemporalConstraint temporalConstraint, List filters)
+ throws DuplicatedKeyFilterException, KeyException, ValueException,
+ Exception;
+
+
+
/**
* Return a SortedMap containing the TimeSeries for top values for a certain
@@ -85,11 +90,11 @@ public interface AccountingPersistenceBackendQuery {
* @throws Exception
*/
public SortedMap>
- getTopValues(Class extends AggregatedRecord,?>> clz,
- TemporalConstraint temporalConstraint, List filters,
- String topKey, String orderingProperty)
- throws DuplicatedKeyFilterException, KeyException, ValueException,
- Exception;
+ getTopValues(Class extends AggregatedRecord,?>> clz,
+ TemporalConstraint temporalConstraint, List filters,
+ String topKey, String orderingProperty)
+ throws DuplicatedKeyFilterException, KeyException, ValueException,
+ Exception;
/**
*
@@ -106,10 +111,10 @@ public interface AccountingPersistenceBackendQuery {
*/
public SortedSet getNextPossibleValues(
Class extends AggregatedRecord, ?>> clz,
- TemporalConstraint temporalConstraint, List filters,
- String key, String orderingProperty) throws
- DuplicatedKeyFilterException, KeyException, ValueException,
- Exception;
+ TemporalConstraint temporalConstraint, List filters,
+ String key, String orderingProperty) throws
+ DuplicatedKeyFilterException, KeyException, ValueException,
+ Exception;
/**
* Close the connection to persistence
@@ -119,4 +124,48 @@ public interface AccountingPersistenceBackendQuery {
*/
public void close() throws Exception;
+
+
+ /**
+ * Return a sortedSet filter value
+ *
+ *
+ * @param clz
+ * @param temporalConstraint
+ * @param filters
+ * @param key
+ * @param orderingProperty
+ * @return
+ * @throws DuplicatedKeyFilterException
+ * @throws KeyException
+ * @throws ValueException
+ * @throws Exception
+ */
+ public SortedSet getFilterValues(
+ Class extends AggregatedRecord, ?>> clz,
+ TemporalConstraint temporalConstraint, List filters,
+ String key) throws Exception;
+
+
+ /**
+ * Return a JsonObject with value
+ * e.g.for StorageUsageRecord {"dataVolume":1860328,"operationCount":4115}
+ * e.g. for ServiceUsageRcord {"operationCount":1651624}
+ *
+ * @param clz
+ * the Usage Record Class of interest
+ * @param temporalConstraint
+ * the TemporalConstraint (interval and aggregation)
+ * @param applicant
+ * the type field and value
+ * @return
+ * @throws Exception
+ */
+ public JSONObject getUsageValue(Class extends AggregatedRecord, ?>> clz,
+ TemporalConstraint temporalConstraint, Filter applicant)
+ throws Exception;
+
+
+
+
}
diff --git a/src/main/java/org/gcube/accounting/analytics/persistence/AccountingPersistenceBackendQueryFactory.java b/src/main/java/org/gcube/accounting/analytics/persistence/AccountingPersistenceBackendQueryFactory.java
index d0e11a9..6cd285f 100644
--- a/src/main/java/org/gcube/accounting/analytics/persistence/AccountingPersistenceBackendQueryFactory.java
+++ b/src/main/java/org/gcube/accounting/analytics/persistence/AccountingPersistenceBackendQueryFactory.java
@@ -46,8 +46,9 @@ public abstract class AccountingPersistenceBackendQueryFactory {
try {
ServiceLoader serviceLoader = ServiceLoader.load(AccountingPersistenceBackendQuery.class);
for (AccountingPersistenceBackendQuery found : serviceLoader) {
- Class extends AccountingPersistenceBackendQuery> foundClass = found.getClass();
+ Class extends AccountingPersistenceBackendQuery> foundClass=null;
try {
+ foundClass = found.getClass();
String foundClassName = foundClass.getSimpleName();
logger.debug("Testing {}", foundClassName);
AccountingPersistenceBackendQueryConfiguration configuration = new AccountingPersistenceBackendQueryConfiguration(foundClass);
@@ -55,14 +56,17 @@ public abstract class AccountingPersistenceBackendQueryFactory {
accountingPersistenceQuery = found;
break;
} catch (Exception e) {
- logger.debug(String.format("%s not initialized correctly. It will not be used", foundClass.getSimpleName()));
+ logger.error(String.format("%s not initialized correctly. It will not be used", foundClass.getSimpleName()));
+
}
}
} catch(Exception e){
- throw new NoUsableAccountingPersistenceQueryFound();
+ logger.error(String.format("service loader or not initialized correctly."));
+ throw new NoUsableAccountingPersistenceQueryFound(e.getLocalizedMessage());
}
if(accountingPersistenceQuery==null){
+ logger.error(String.format("accountingPersistenceQuery null"));
throw new NoUsableAccountingPersistenceQueryFound();
}
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 59b3384..27f3cb1 100644
--- a/src/main/java/org/gcube/accounting/analytics/persistence/AccountingPersistenceQuery.java
+++ b/src/main/java/org/gcube/accounting/analytics/persistence/AccountingPersistenceQuery.java
@@ -10,6 +10,7 @@ import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.SortedSet;
+import java.util.TreeMap;
import java.util.TreeSet;
import javax.activity.InvalidActivityException;
@@ -37,7 +38,7 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
private static final AccountingPersistenceQuery accountingPersistenceQuery;
public static final int DEFAULT_LIMIT_RESULT_NUMBER = 5;
-
+
private AccountingPersistenceQuery() {
}
@@ -51,7 +52,7 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
public static SortedSet getQuerableKeys(
@SuppressWarnings("rawtypes") AggregatedRecord instance)
- throws Exception {
+ throws Exception {
SortedSet properties = new TreeSet<>(
instance.getRequiredFields());
@@ -67,11 +68,11 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
public static SortedSet getQuerableKeys(
Class extends AggregatedRecord,?>> clz)
- throws Exception {
+ throws Exception {
AggregatedRecord,?> instance = clz.newInstance();
return getQuerableKeys(instance);
}
-
+
public static String getDefaultOrderingProperties(
Class extends AggregatedRecord, ?>> clz){
if(clz.isAssignableFrom(AggregatedStorageUsageRecord.class)){
@@ -79,23 +80,26 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
}
return AggregatedRecord.OPERATION_COUNT;
}
-
+
protected static JSONObject getPaddingJSONObject(
Map unpaddedResults) throws JSONException {
- Info auxInfo = new ArrayList(unpaddedResults.values()).get(0);
- JSONObject auxJsonObject = auxInfo.getValue();
- @SuppressWarnings("unchecked")
- Iterator keys = auxJsonObject.keys();
JSONObject jsonObject = new JSONObject();
- while (keys.hasNext()) {
- String key = keys.next();
- jsonObject.put(key, 0);
+ //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();
+ while (keys.hasNext()) {
+ String key = keys.next();
+ jsonObject.put(key, 0);
+ }
}
-
+
return jsonObject;
}
-
+
/**
* Pad the data
*
@@ -111,7 +115,7 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
public static SortedMap padMap(
SortedMap unpaddedData,
TemporalConstraint temporalConstraint) throws Exception {
-
+
JSONObject jsonObject = getPaddingJSONObject(unpaddedData);
SortedSet sequence = temporalConstraint.getCalendarSequence();
for (Calendar progressTime : sequence) {
@@ -123,58 +127,66 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
}
return unpaddedData;
}
-
+
/**
* {@inheritDoc}
*/
public SortedMap getTimeSeries(
Class extends AggregatedRecord,?>> clz,
- TemporalConstraint temporalConstraint, List filters)
- throws DuplicatedKeyFilterException, KeyException, ValueException,
- Exception {
-
+ TemporalConstraint temporalConstraint, List filters)
+ throws DuplicatedKeyFilterException, KeyException, ValueException,
+ Exception {
+
return this.getTimeSeries(clz, temporalConstraint, filters, false);
}
-
+
public SortedMap getTimeSeries(
Class extends AggregatedRecord,?>> clz,
- TemporalConstraint temporalConstraint, List filters,
- boolean pad) throws DuplicatedKeyFilterException, KeyException,
- ValueException, Exception {
+ TemporalConstraint temporalConstraint, List filters,
+ boolean pad) throws DuplicatedKeyFilterException, KeyException,
+ ValueException, Exception {
SortedMap ret =
AccountingPersistenceBackendQueryFactory.getInstance()
.getTimeSeries(clz, temporalConstraint,
filters);
-
+
+ if(ret==null){
+ ret = new TreeMap<>();
+ }
+
+
if(pad){
ret = padMap(ret, temporalConstraint);
}
-
+
return ret;
}
public SortedMap> getTopValues(
Class extends AggregatedRecord, ?>> clz,
- TemporalConstraint temporalConstraint, List filters,
- String topKey, String orderingProperty, boolean pad, int limit)
- throws DuplicatedKeyFilterException, KeyException, ValueException,
- Exception {
-
+ TemporalConstraint temporalConstraint, List filters,
+ 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);
-
+ orderingProperty);
+
int count = got.size() > limit ? limit : got.size();
-
+
NumberedFilter firstRemovalKey = null;
-
+
for(NumberedFilter nf : got.keySet()){
if(--count>=0 || limit<=0){
if(pad){
@@ -188,70 +200,73 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
}
}
}
-
+
if(firstRemovalKey!=null){
return got.subMap(got.firstKey(), firstRemovalKey);
}
-
+
return got;
}
-
+
public SortedMap> getTopValues(
Class extends AggregatedRecord,?>> clz,
- TemporalConstraint temporalConstraint, List filters,
- String topKey) throws DuplicatedKeyFilterException,
- KeyException, ValueException, Exception {
+ TemporalConstraint temporalConstraint, List filters,
+ String topKey) throws DuplicatedKeyFilterException,
+ KeyException, ValueException, Exception {
String orderingProperty = AccountingPersistenceQuery
.getDefaultOrderingProperties(clz);
-
+
+
+
+
return this.getTopValues(clz, temporalConstraint, filters, topKey,
orderingProperty, false, 0);
}
-
+
/**
* {@inheritDoc}
*/
@Override
public SortedMap> getTopValues(
Class extends AggregatedRecord,?>> clz,
- TemporalConstraint temporalConstraint, List filters,
- String topKey, String orderingProperty) throws
- DuplicatedKeyFilterException, KeyException, ValueException,
- Exception {
+ TemporalConstraint temporalConstraint, List filters,
+ String topKey, String orderingProperty) throws
+ DuplicatedKeyFilterException, KeyException, ValueException,
+ Exception {
return this.getTopValues(clz, temporalConstraint, filters, topKey,
- orderingProperty, false, 0);
+ orderingProperty, false, 0);
}
public SortedSet getNextPossibleValues(
Class extends AggregatedRecord,?>> clz,
- TemporalConstraint temporalConstraint, List filters,
- String key) throws DuplicatedKeyFilterException, KeyException,
- ValueException, Exception {
-
+ TemporalConstraint temporalConstraint, List filters,
+ String key) throws DuplicatedKeyFilterException, KeyException,
+ ValueException, Exception {
+
String orderingProperty = AccountingPersistenceQuery
.getDefaultOrderingProperties(clz);
-
+
return this.getNextPossibleValues(clz, temporalConstraint, filters,
- key, orderingProperty);
+ key, orderingProperty);
}
-
+
/**
* {@inheritDoc}
*/
@Override
public SortedSet getNextPossibleValues(
Class extends AggregatedRecord, ?>> clz,
- TemporalConstraint temporalConstraint, List filters,
- String key, String orderingProperty) throws
- DuplicatedKeyFilterException, KeyException, ValueException,
- Exception {
-
+ TemporalConstraint temporalConstraint, List filters,
+ String key, String orderingProperty) throws
+ DuplicatedKeyFilterException, KeyException, ValueException,
+ Exception {
+
return AccountingPersistenceBackendQueryFactory.getInstance()
.getNextPossibleValues(clz, temporalConstraint, filters,
key, orderingProperty);
-
+
}
-
+
/**
* {@inheritDoc}
*/
@@ -266,8 +281,27 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
@Override
public void prepareConnection(
AccountingPersistenceBackendQueryConfiguration configuration)
- throws Exception {
+ throws Exception {
throw new InvalidActivityException();
}
-
+
+ @Override
+ public SortedSet getFilterValues(
+ Class extends AggregatedRecord, ?>> clz,
+ TemporalConstraint temporalConstraint, List filters,
+ String key) throws Exception {
+ // TODO Auto-generated method stub
+ return AccountingPersistenceBackendQueryFactory.getInstance()
+ .getFilterValues(clz, temporalConstraint, filters,
+ key);
+ }
+
+ @Override
+ public JSONObject getUsageValue(Class extends AggregatedRecord, ?>> clz,
+ TemporalConstraint temporalConstraint, Filter applicant)
+ throws Exception {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
}