Reihenfolge von UNH und UNT pro Nachricht validieren
This commit is contained in:
@@ -26,6 +26,7 @@ import de.gecheckt.asv.validation.model.ValidationSeverity;
|
||||
* 8. Die im UNT angegebene Segmentanzahl muss der tatsächlichen Anzahl der Segmente entsprechen
|
||||
* 9. Eine Nachricht muss mindestens ein UNH-Segment enthalten
|
||||
* 10. Eine Nachricht muss mindestens ein UNT-Segment enthalten
|
||||
* 11. UNH muss vor UNT stehen
|
||||
*/
|
||||
public class DefaultStructureValidator implements StructureValidator {
|
||||
|
||||
@@ -111,6 +112,12 @@ public class DefaultStructureValidator implements StructureValidator {
|
||||
if (message.getFirstSegment("UNT").isPresent()) {
|
||||
validateUntSegmentCount(message, errors);
|
||||
}
|
||||
|
||||
// Regel 11: UNH muss vor UNT stehen
|
||||
// Nur prüfen, wenn beide Segmente vorhanden sind
|
||||
if (message.getFirstSegment("UNH").isPresent() && message.getFirstSegment("UNT").isPresent()) {
|
||||
validateUnhBeforeUnt(message, errors);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,6 +214,38 @@ public class DefaultStructureValidator implements StructureValidator {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validiert, dass UNH vor UNT steht.
|
||||
*
|
||||
* @param message die zu validierende Nachricht
|
||||
* @param errors die Liste zum Hinzufügen von Validierungsfehlern
|
||||
*/
|
||||
private void validateUnhBeforeUnt(Message message, List<ValidationError> errors) {
|
||||
var unhSegment = message.getFirstSegment("UNH");
|
||||
var untSegment = message.getFirstSegment("UNT");
|
||||
|
||||
// Prüft, ob beide Segmente vorhanden sind, bevor eine Validierung erfolgt
|
||||
if (unhSegment.isPresent() && untSegment.isPresent()) {
|
||||
int unhPosition = unhSegment.get().segmentPosition();
|
||||
int untPosition = untSegment.get().segmentPosition();
|
||||
|
||||
// UNH muss vor UNT stehen
|
||||
if (unhPosition > untPosition) {
|
||||
errors.add(createError(
|
||||
"STRUCTURE_011",
|
||||
"UNH muss vor UNT stehen",
|
||||
ValidationSeverity.ERROR,
|
||||
"UNH/UNT",
|
||||
message.messagePosition(),
|
||||
"",
|
||||
0,
|
||||
"UNH at position " + unhPosition + ", UNT at position " + untPosition,
|
||||
"UNH muss vor UNT stehen"
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validiert, dass die Referenznummern in UNH und UNT übereinstimmen.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user