diff --git a/src/main/java/org/gcube/accounting/accounting/summary/access/impl/AccountingDaoImpl.java b/src/main/java/org/gcube/accounting/accounting/summary/access/impl/AccountingDaoImpl.java index ae15c8d..5359238 100644 --- a/src/main/java/org/gcube/accounting/accounting/summary/access/impl/AccountingDaoImpl.java +++ b/src/main/java/org/gcube/accounting/accounting/summary/access/impl/AccountingDaoImpl.java @@ -30,6 +30,7 @@ import org.gcube.accounting.accounting.summary.access.model.update.UpdateReport; import lombok.extern.slf4j.Slf4j; +import static java.time.temporal.TemporalAdjusters.*; @Slf4j public class AccountingDaoImpl implements AccountingDao{ @@ -64,6 +65,10 @@ public class AccountingDaoImpl implements AccountingDao{ log.info("Loading report {} for {} between {} and {} ",resolution,desc.getId(),formatter.format(fromDate),formatter.format(toDate)); long startReportTime=System.currentTimeMillis(); + fromDate=fixLowerBound(fromDate, resolution); + toDate=fixUpperBound(toDate, resolution); + + if(fromDate.isAfter(toDate)) throw new ParameterException("Irregular time interval: \"From\" parameter cannot be after \"To\" parameter."); int timeSlices=getRangeSize(fromDate, toDate, resolution); @@ -132,8 +137,20 @@ public class AccountingDaoImpl implements AccountingDao{ } + private LocalDateTime fixLowerBound(LocalDateTime toFix,MeasureResolution resolution) throws ParameterException { + switch(resolution) { + case MONTHLY : return toFix.with(firstDayOfMonth()).withHour(0).withMinute(0).withSecond(0).withNano(0); + default : throw new ParameterException("Invalid resolution "+resolution); + } + } - + private LocalDateTime fixUpperBound(LocalDateTime toFix,MeasureResolution resolution) throws ParameterException { + switch(resolution) { + case MONTHLY : return toFix.with(lastDayOfMonth()).withHour(23).withMinute(59).withSecond(59).withNano(999999999); + default : throw new ParameterException("Invalid resolution "+resolution); + } + } + @Override public ScopeDescriptor getTree(Object request) throws Exception { diff --git a/src/test/java/org/gcube/data/access/accounting/summary/access/test/SimpleTest.java b/src/test/java/org/gcube/data/access/accounting/summary/access/test/SimpleTest.java index 9bb881a..fe1842a 100644 --- a/src/test/java/org/gcube/data/access/accounting/summary/access/test/SimpleTest.java +++ b/src/test/java/org/gcube/data/access/accounting/summary/access/test/SimpleTest.java @@ -24,10 +24,12 @@ public class SimpleTest { System.out.println(desc); - Date from=new GregorianCalendar(2018,0,1).getTime(); - Date to=new GregorianCalendar(2018,7,1).getTime(); + Date from=new Date(1514764800000l); -// Date to=from; +// Date from=new GregorianCalendar(2018,0,1).getTime(); +// Date to=new GregorianCalendar(2018,7,1).getTime(); + + Date to=from; scan(desc,from,to,dao); diff --git a/target/accounting-summary-access-1.0.0-SNAPSHOT-javadoc.jar b/target/accounting-summary-access-1.0.0-SNAPSHOT-javadoc.jar index 6d1b103..06bfc7a 100644 Binary files a/target/accounting-summary-access-1.0.0-SNAPSHOT-javadoc.jar and b/target/accounting-summary-access-1.0.0-SNAPSHOT-javadoc.jar differ diff --git a/target/accounting-summary-access-1.0.0-SNAPSHOT-sources.jar b/target/accounting-summary-access-1.0.0-SNAPSHOT-sources.jar index fea40c0..bf9b1cf 100644 Binary files a/target/accounting-summary-access-1.0.0-SNAPSHOT-sources.jar and b/target/accounting-summary-access-1.0.0-SNAPSHOT-sources.jar differ diff --git a/target/accounting-summary-access-1.0.0-SNAPSHOT.jar b/target/accounting-summary-access-1.0.0-SNAPSHOT.jar index a12e984..aac3980 100644 Binary files a/target/accounting-summary-access-1.0.0-SNAPSHOT.jar and b/target/accounting-summary-access-1.0.0-SNAPSHOT.jar differ diff --git a/target/apidocs/allclasses-frame.html b/target/apidocs/allclasses-frame.html index 8441d30..53e594a 100644 --- a/target/apidocs/allclasses-frame.html +++ b/target/apidocs/allclasses-frame.html @@ -2,7 +2,7 @@ - + All Classes (Accounting Summary Access 1.0.0-SNAPSHOT API) diff --git a/target/apidocs/allclasses-noframe.html b/target/apidocs/allclasses-noframe.html index eb18dad..c93c6a9 100644 --- a/target/apidocs/allclasses-noframe.html +++ b/target/apidocs/allclasses-noframe.html @@ -2,7 +2,7 @@ - + All Classes (Accounting Summary Access 1.0.0-SNAPSHOT API) diff --git a/target/apidocs/constant-values.html b/target/apidocs/constant-values.html index 74bad1a..83a788b 100644 --- a/target/apidocs/constant-values.html +++ b/target/apidocs/constant-values.html @@ -2,7 +2,7 @@ - + Constant Field Values (Accounting Summary Access 1.0.0-SNAPSHOT API) diff --git a/target/apidocs/deprecated-list.html b/target/apidocs/deprecated-list.html index 1993fc3..8856c2d 100644 --- a/target/apidocs/deprecated-list.html +++ b/target/apidocs/deprecated-list.html @@ -2,7 +2,7 @@ - + Deprecated List (Accounting Summary Access 1.0.0-SNAPSHOT API) diff --git a/target/apidocs/help-doc.html b/target/apidocs/help-doc.html index 5e4430e..c8d2c44 100644 --- a/target/apidocs/help-doc.html +++ b/target/apidocs/help-doc.html @@ -2,7 +2,7 @@ - + API Help (Accounting Summary Access 1.0.0-SNAPSHOT API) diff --git a/target/apidocs/index-all.html b/target/apidocs/index-all.html index 147b9d3..9e8487f 100644 --- a/target/apidocs/index-all.html +++ b/target/apidocs/index-all.html @@ -2,7 +2,7 @@ - + Index (Accounting Summary Access 1.0.0-SNAPSHOT API) diff --git a/target/apidocs/index.html b/target/apidocs/index.html index 6a1e7c4..b56ff39 100644 --- a/target/apidocs/index.html +++ b/target/apidocs/index.html @@ -2,7 +2,7 @@ - + Accounting Summary Access 1.0.0-SNAPSHOT API