RED-7694 - Throw BadRequest if startDate is null or in the future for license report #156

Merged
andrei.isvoran.ext merged 1 commits from RED-7694 into master 2023-10-05 11:37:50 +02:00
2 changed files with 5 additions and 16 deletions

View File

@ -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.");
}

View File

@ -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())) {