diff --git a/src/main/java/org/gcube/accounting/analytics/Filter.java b/src/main/java/org/gcube/accounting/analytics/Filter.java index ca5b245..17d8aa0 100644 --- a/src/main/java/org/gcube/accounting/analytics/Filter.java +++ b/src/main/java/org/gcube/accounting/analytics/Filter.java @@ -13,8 +13,8 @@ public class Filter { protected String value; /** - * @param key - * @param value + * @param key the key to filter + * @param value the value fo the key to filter */ public Filter(String key, String value) { this.key = key; diff --git a/src/main/java/org/gcube/accounting/analytics/Info.java b/src/main/java/org/gcube/accounting/analytics/Info.java index 45c89c8..d6aeef3 100644 --- a/src/main/java/org/gcube/accounting/analytics/Info.java +++ b/src/main/java/org/gcube/accounting/analytics/Info.java @@ -19,8 +19,8 @@ public class Info { protected JSONObject value; /** - * @param calendar - * @param value + * @param date the date + * @param value the JSON value */ public Info(Date date, JSONObject value) { super(); diff --git a/src/main/java/org/gcube/accounting/analytics/ResourceRecordQuery.java b/src/main/java/org/gcube/accounting/analytics/ResourceRecordQuery.java index b51b7a3..8752143 100644 --- a/src/main/java/org/gcube/accounting/analytics/ResourceRecordQuery.java +++ b/src/main/java/org/gcube/accounting/analytics/ResourceRecordQuery.java @@ -35,6 +35,11 @@ public class ResourceRecordQuery { protected static Map, Set> resourceRecords = null; + /** + * Return a Map containing a set of required fields for each Resource + * Records Types + * @return the Map + */ public static Map, Set> getResourceRecordsTypes() { if(resourceRecords==null){ resourceRecords = new HashMap, Set>(); @@ -57,10 +62,25 @@ public class ResourceRecordQuery { protected AccountingPersistenceQuery accountingPersistenceQuery; + /** + * Instantiate the ResourceRecord for the current scope + * @throws NoAvailableScopeException if there is not possible to query in + * the current scope + * @throws NoUsableAccountingPersistenceQueryFound if there is no available + * instance which can query in that scope + */ public ResourceRecordQuery() throws NoAvailableScopeException, NoUsableAccountingPersistenceQueryFound { this.accountingPersistenceQuery = AccountingPersistenceQueryFactory.getInstance(); } + /** + * Instantiate the ResourceRecord for the provided scope + * @param scope the scope + * @throws NoAvailableScopeException if there is not possible to query in + * that scope + * @throws NoUsableAccountingPersistenceQueryFound if there is no available + * instance which can query in that scope + */ public ResourceRecordQuery(String scope) throws NoAvailableScopeException, NoUsableAccountingPersistenceQueryFound { ScopeProvider.instance.set(scope); this.accountingPersistenceQuery = AccountingPersistenceQueryFactory.getInstance(); @@ -81,17 +101,24 @@ public class ResourceRecordQuery { return jsonObject; } - - - public static List getPaddedResults(Map unpaddedResults, TemporalConstraint temporalConstraint) throws JSONException{ - JSONObject jsonObject = getPaddingJSONObject(unpaddedResults); + /** + * Pad the data + * @param unpaddedData the data to be pad + * @param temporalConstraint temporalConstraint the temporal interval and + * the granularity of the data to pad + * @return the data padded taking in account the TemporalConstraint + * @throws Exception if fails + */ + public static List getPaddedResults(Map unpaddedData, + TemporalConstraint temporalConstraint) throws Exception { + JSONObject jsonObject = getPaddingJSONObject(unpaddedData); List paddedResults = new ArrayList(); List sequence = temporalConstraint.getCalendarSequence(); for(Calendar progressTime : sequence){ - if(unpaddedResults.get(progressTime)!=null){ - paddedResults.add(unpaddedResults.get(progressTime)); + if(unpaddedData.get(progressTime)!=null){ + paddedResults.add(unpaddedData.get(progressTime)); }else{ Date date = new Date(progressTime.getTimeInMillis()); Info info = new Info(date, jsonObject); @@ -104,12 +131,13 @@ public class ResourceRecordQuery { /** * Return results with padding if pad is set to true. - * @param usageRecordType - * @param temporalConstraint - * @param filters - * @param pad - * @return - * @throws Exception + * @param usageRecordType the UsageRecord type to query + * @param temporalConstraint the temporal interval and the granularity + * @param filters the list keys to filter (in AND) + * @param pad indicate is the results have to be padded with zeros when + * there is no data available at certain data points of sequence + * @return the requested list of Info + * @throws Exception if fails */ public List getInfo(@SuppressWarnings("rawtypes") Class usageRecordType, TemporalConstraint temporalConstraint, List filters, boolean pad) throws Exception { @@ -117,17 +145,16 @@ public class ResourceRecordQuery { if(!pad){ return new ArrayList(unpaddedResults.values()); } - return getPaddedResults(unpaddedResults, temporalConstraint); } /** - * Return unpadded result - * @param usageRecordType - * @param temporalConstraint - * @param filters - * @return - * @throws Exception + * Return unpadded results + * @param usageRecordType the UsageRecord type to query + * @param temporalConstraint the temporal interval and the granularity + * @param filters the list keys to filter (in AND) + * @return the requested list of Info + * @throws Exception if fails */ public List getInfo(@SuppressWarnings("rawtypes") Class usageRecordType, TemporalConstraint temporalConstraint, List filters) throws Exception{ diff --git a/src/main/java/org/gcube/accounting/analytics/TemporalConstraint.java b/src/main/java/org/gcube/accounting/analytics/TemporalConstraint.java index 43f3165..8eb2564 100644 --- a/src/main/java/org/gcube/accounting/analytics/TemporalConstraint.java +++ b/src/main/java/org/gcube/accounting/analytics/TemporalConstraint.java @@ -22,12 +22,22 @@ public class TemporalConstraint { private static final Logger logger = LoggerFactory.getLogger(TemporalConstraint.class); private static final String UTC_TIME_ZONE = "UTC"; + public static final TimeZone DEFAULT_TIME_ZONE = TimeZone.getTimeZone(UTC_TIME_ZONE); + /** + * Valid Aggregation Mode + * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ + */ public enum AggregationMode { YEARLY, MONTHLY, DAILY, HOURLY, MINUTELY, SECONDLY, MILLISECONDLY } + /** + * Used to map the Calendar constant to an enum value which has the same + * ordinal of {@link AggregationMode} + * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ + */ public enum CalendarEnum { YEAR(Calendar.YEAR), MONTH(Calendar.MONTH), @@ -53,6 +63,11 @@ public class TemporalConstraint { protected long endTime; protected AggregationMode aggregationMode; + /** + * @param startTime StartTime + * @param endTime End Time + * @param aggregationMode Aggregation Mode + */ public TemporalConstraint(long startTime, long endTime, AggregationMode aggregationMode){ this.startTime = startTime; this.endTime = endTime; diff --git a/src/main/java/org/gcube/accounting/analytics/exception/NoAvailableScopeException.java b/src/main/java/org/gcube/accounting/analytics/exception/NoAvailableScopeException.java index 129344a..11780c4 100644 --- a/src/main/java/org/gcube/accounting/analytics/exception/NoAvailableScopeException.java +++ b/src/main/java/org/gcube/accounting/analytics/exception/NoAvailableScopeException.java @@ -14,14 +14,22 @@ public class NoAvailableScopeException extends Exception { */ private static final long serialVersionUID = -327144230654860518L; + public NoAvailableScopeException() { super(); } + /** + * Constructs a new exception with the specified detail message. The cause + * is not initialized, and may subsequently be initialized by a call to + * initCause. + * @param message the detail message. The detail message is saved for later + * retrieval by the getMessage() method. + */ public NoAvailableScopeException(String message) { super(message); } - + public NoAvailableScopeException(Throwable cause) { super(cause); }