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 @@
- +