-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run schema validation in separate stage (#589)
- Loading branch information
Showing
19 changed files
with
906 additions
and
351 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...n/java/no/entur/antu/routes/validation/AggregateValidationReportsAggregationStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package no.entur.antu.routes.validation; | ||
|
||
import static no.entur.antu.Constants.*; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
import org.apache.camel.Exchange; | ||
import org.apache.camel.processor.aggregate.GroupedMessageAggregationStrategy; | ||
import org.entur.netex.validation.validator.ValidationReport; | ||
import org.entur.netex.validation.validator.ValidationReportEntry; | ||
|
||
/** | ||
* Strategy that aggregates the validation reports produced for individual files into a single validation report. | ||
*/ | ||
class AggregateValidationReportsAggregationStrategy | ||
extends GroupedMessageAggregationStrategy { | ||
|
||
@Override | ||
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) { | ||
if ( | ||
oldExchange == null || | ||
oldExchange.getIn().getBody(ValidationReport.class) == null | ||
) { | ||
return newExchange; | ||
} | ||
|
||
ValidationReport oldValidationReport = oldExchange | ||
.getIn() | ||
.getBody(ValidationReport.class); | ||
ValidationReport newValidationReport = newExchange | ||
.getIn() | ||
.getBody(ValidationReport.class); | ||
|
||
List<ValidationReportEntry> validationReportEntries = Stream | ||
.concat( | ||
oldValidationReport.getValidationReportEntries().stream(), | ||
newValidationReport.getValidationReportEntries().stream() | ||
) | ||
.toList(); | ||
|
||
Map<String, Long> numberOfValidationEntriesPerRule = Stream | ||
.concat( | ||
oldValidationReport | ||
.getNumberOfValidationEntriesPerRule() | ||
.entrySet() | ||
.stream(), | ||
newValidationReport | ||
.getNumberOfValidationEntriesPerRule() | ||
.entrySet() | ||
.stream() | ||
) | ||
.collect( | ||
Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, Long::sum) | ||
); | ||
|
||
oldExchange | ||
.getIn() | ||
.setBody( | ||
new ValidationReport( | ||
oldExchange.getIn().getHeader(DATASET_CODESPACE, String.class), | ||
oldExchange | ||
.getIn() | ||
.getHeader(VALIDATION_REPORT_ID_HEADER, String.class), | ||
validationReportEntries, | ||
numberOfValidationEntriesPerRule | ||
) | ||
); | ||
|
||
LocalDateTime reportCreationDate = oldExchange | ||
.getIn() | ||
.getHeader(REPORT_CREATION_DATE, LocalDateTime.class); | ||
if ( | ||
reportCreationDate == null || | ||
reportCreationDate.isAfter(oldValidationReport.getCreationDate()) | ||
) { | ||
oldExchange | ||
.getIn() | ||
.setHeader(REPORT_CREATION_DATE, oldValidationReport.getCreationDate()); | ||
} | ||
return oldExchange; | ||
} | ||
} |
Oops, something went wrong.