RED-7694 - Throw BadRequest if startDate is null or in the future for license report #156
@ -38,7 +38,11 @@ public class LicenseReportService {
|
||||
|
||||
public LicenseReport getLicenseReport(LicenseReportRequest licenseReportRequest) {
|
||||
|
||||
if (!licenseReportRequest.isStartDateBeforeEndDate()) {
|
||||
if (licenseReportRequest.getStartDate() == null || licenseReportRequest.getStartDate().isAfter(Instant.now())) {
|
||||
throw new BadRequestException("Invalid start date.");
|
||||
}
|
||||
|
||||
if (licenseReportRequest.getStartDate().isAfter(licenseReportRequest.getEndDate())) {
|
||||
throw new BadRequestException("Invalid date period: End date is before start date.");
|
||||
}
|
||||
|
||||
|
||||
@ -18,21 +18,6 @@ public class LicenseReportRequest {
|
||||
private Instant startDate;
|
||||
private Instant endDate;
|
||||
|
||||
public Instant getStartDate() {
|
||||
|
||||
if (startDate == null) {
|
||||
startDate = Year.of(getEndDate().atOffset(ZoneOffset.UTC).getYear()).atMonth(1).atDay(1).atStartOfDay().toInstant(ZoneOffset.UTC);
|
||||
}
|
||||
return startDate;
|
||||
}
|
||||
|
||||
public boolean isStartDateBeforeEndDate() {
|
||||
|
||||
var endDate = this.endDate == null ? Instant.now() : this.endDate;
|
||||
return getStartDate().isBefore(endDate);
|
||||
}
|
||||
|
||||
|
||||
public Instant getEndDate() {
|
||||
|
||||
if (endDate == null || endDate.isAfter(Instant.now())) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user