RED-7687 - Check if startDate is before endDate for license before overwriting the endDate if it's in the future.

This commit is contained in:
Andrei Isvoran 2023-10-02 16:18:52 +03:00
parent b706a71ec1
commit ad20a1f9f5
2 changed files with 8 additions and 1 deletions

View File

@ -1,5 +1,6 @@
package com.iqser.red.service.persistence.management.v1.processor.service;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.YearMonth;
import java.time.ZoneId;
@ -37,7 +38,7 @@ public class LicenseReportService {
public LicenseReport getLicenseReport(LicenseReportRequest licenseReportRequest) {
if (licenseReportRequest.getEndDate().isBefore(licenseReportRequest.getStartDate())) {
if (!licenseReportRequest.isStartDateBeforeEndDate()) {
throw new BadRequestException("Invalid date period: End date is before start date.");
}

View File

@ -26,6 +26,12 @@ public class LicenseReportRequest {
return startDate;
}
public boolean isStartDateBeforeEndDate() {
var endDate = this.endDate == null ? Instant.now() : this.endDate;
return getStartDate().isBefore(endDate);
}
public Instant getEndDate() {