diff --git a/backend/src/main/java/de/bund/digitalservice/ris/norms/application/service/ModificationValidator.java b/backend/src/main/java/de/bund/digitalservice/ris/norms/application/service/ModificationValidator.java index 08bcb05e5..aa7863ecb 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/norms/application/service/ModificationValidator.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/norms/application/service/ModificationValidator.java @@ -12,12 +12,13 @@ /** */ @Service public class ModificationValidator { + + private final DBService dbService; + public ModificationValidator(DBService dbService) { this.dbService = dbService; } - private final DBService dbService; - /** * @param amendingLaw the amending law to be checked */ @@ -82,14 +83,27 @@ public void destNodeHasTextOnlyContent(Norm amendingLaw) { // TODO no "<>" exists } - private void throwErrorNoDestinationSet(Norm amendingLaw) { - // List emptyElis = - // amendingLaw.getActiveModifications().stream() - // .filter(am -> am.getDestinationEli().isEmpty()) - // .map(ActiveModification::getEid) - // .map(Optional::get) - // .toList(); - // TODO + /** + * Throws an error if any of the articles of the passed amendingLaw has an empty affected document + * Eli. The error message contains a comma separated list of all article eIds, that are affected. + * + * @param amendingLaw the amending law to be checked + */ + public void throwErrorNoDestinationSet(Norm amendingLaw) { + List emptyEliEids = + amendingLaw.getArticles().stream() + .filter(a -> a.getAffectedDocumentEli().isEmpty()) + .map(Article::getEid) + .filter(Optional::isPresent) + .map(Optional::get) + .toList(); + + if (!emptyEliEids.isEmpty()) { + throw new XmlProcessingException( + "Some articles have empty affected document Elis. Here are the according eIds: %s" + .formatted(String.join(", ", emptyEliEids)), + null); + } } /** diff --git a/backend/src/test/java/de/bund/digitalservice/ris/norms/application/service/ModificationValidatorTest.java b/backend/src/test/java/de/bund/digitalservice/ris/norms/application/service/ModificationValidatorTest.java index 654d5f5a5..bd693d6e6 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/norms/application/service/ModificationValidatorTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/norms/application/service/ModificationValidatorTest.java @@ -54,4 +54,56 @@ void normDoesNotExist() { // then assertThat(thrown).isInstanceOf(XmlProcessingException.class); } + + @Test + void noDestinationEli() { + + // given + // TODO is this okay or shall this be in a separate file? + var amendingLawXml = + """ + + + + + + + + + Das Vereinsgesetz vom + 5. August 1964 (BGBl. I S. 593), das zuletzt + durch … geändert worden ist, wird wie folgt geändert: + + + + + + + + + """; + + Norm amendingLaw = new Norm(XmlMapper.toDocument(amendingLawXml)); + + // when + Throwable thrown = catchThrowable(() -> underTest.throwErrorNoDestinationSet(amendingLaw)); + + // then + assertThat(thrown) + .isInstanceOf(XmlProcessingException.class) + .hasMessageContaining( + "Some articles have empty affected document Elis. Here are the according eIds: hauptteil-1_art-1"); + } }