Merge branch 'RED-7694' into 'master'
RED-7694 - Throw BadRequest if startDate is null or in the future for license report Closes RED-7694 See merge request redactmanager/persistence-service!156
This commit is contained in:
commit
3a1908b8ff
@ -38,7 +38,11 @@ public class LicenseReportService {
|
|||||||
|
|
||||||
public LicenseReport getLicenseReport(LicenseReportRequest licenseReportRequest) {
|
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.");
|
throw new BadRequestException("Invalid date period: End date is before start date.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,21 +18,6 @@ public class LicenseReportRequest {
|
|||||||
private Instant startDate;
|
private Instant startDate;
|
||||||
private Instant endDate;
|
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() {
|
public Instant getEndDate() {
|
||||||
|
|
||||||
if (endDate == null || endDate.isAfter(Instant.now())) {
|
if (endDate == null || endDate.isAfter(Instant.now())) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user