Merge branch 'RED-7694-backport' into 'release/1.363.x'

RED-7694 - Backport license fix for startDate

See merge request redactmanager/persistence-service!157
This commit is contained in:
Andrei Isvoran 2023-10-05 11:37:42 +02:00
commit 9a3921ed55
2 changed files with 6 additions and 16 deletions

View File

@ -27,21 +27,6 @@ public class LicenseReportRequest {
private List<String> dossierIds = new ArrayList<>();
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())) {

View File

@ -1,5 +1,6 @@
package com.iqser.red.service.peristence.v1.server.service;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.YearMonth;
import java.time.ZoneId;
@ -36,7 +37,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.");
}