@@ -54,6 +54,9 @@ public void validate(NoticeContainer noticeContainer) {
5454 CalendarUtil .servicePeriodToServiceDatesMap (
5555 CalendarUtil .buildServicePeriodMap (calendarTable , calendarDateTable ));
5656 boolean isCalendarTableEmpty = calendarTable .getEntities ().isEmpty ();
57+ List <ExpiredCalendarNotice > noticesToReturn = new ArrayList <>();
58+ // Notices to return only if there are no calendars in `calendar.txt` and
59+ // all calendar dates are in the past.
5760 List <ExpiredCalendarNotice > expiredCalendarDatesNotices = new ArrayList <>();
5861 boolean allCalendarAreExpired = true ;
5962 for (var serviceId : servicePeriodMap .keySet ()) {
@@ -63,7 +66,7 @@ public void validate(NoticeContainer noticeContainer) {
6366 }
6467 if (serviceDates .last ().isBefore (dateForValidation .getDate ())) {
6568 if (calendarTable .byServiceId (serviceId ).isPresent ()) {
66- noticeContainer . addValidationNotice (
69+ noticesToReturn . add (
6770 new ExpiredCalendarNotice (
6871 calendarTable .byServiceId (serviceId ).get ().csvRowNumber (), serviceId ));
6972 } else if (isCalendarTableEmpty && allCalendarAreExpired ) {
@@ -82,8 +85,11 @@ public void validate(NoticeContainer noticeContainer) {
8285 }
8386 }
8487 if (isCalendarTableEmpty && allCalendarAreExpired ) {
85- noticeContainer . addValidationNotices (expiredCalendarDatesNotices );
88+ noticesToReturn . addAll (expiredCalendarDatesNotices );
8689 }
90+
91+ noticesToReturn .sort (Comparator .comparing (ExpiredCalendarNotice ::getCsvRowNumber ));
92+ noticeContainer .addValidationNotices (noticesToReturn );
8793 }
8894
8995 /**
@@ -111,5 +117,9 @@ static class ExpiredCalendarNotice extends ValidationNotice {
111117 this .csvRowNumber = csvRowNumber ;
112118 this .serviceId = serviceId ;
113119 }
120+
121+ public int getCsvRowNumber () {
122+ return csvRowNumber ;
123+ }
114124 }
115125}
0 commit comments