Skip to content

Commit

Permalink
Activate throwErrorNoDestinationSet
Browse files Browse the repository at this point in the history
RISDEV-3966
  • Loading branch information
reckseba committed May 23, 2024
1 parent 900c1a8 commit 6d897c8
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -82,14 +83,27 @@ public void destNodeHasTextOnlyContent(Norm amendingLaw) {
// TODO no "<>" exists
}

private void throwErrorNoDestinationSet(Norm amendingLaw) {
// List<String> 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<String> 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);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
"""
<?xml-model href="../../../Grammatiken/legalDocML.de.sch" schematypens="http://purl.oclc.org/dsdl/schematron"?>
<akn:akomaNtoso xmlns:akn="http://Inhaltsdaten.LegalDocML.de/1.6/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://Metadaten.LegalDocML.de/1.6/ ../../../Grammatiken/legalDocML.de-metadaten.xsd http://Inhaltsdaten.LegalDocML.de/1.6/ ../../../Grammatiken/legalDocML.de-regelungstextverkuendungsfassung.xsd">
<akn:act name="regelungstext">
<akn:body eId="hauptteil-1" GUID="0B4A8E1F-65EF-4B7C-9E22-E83BA6B73CD8">
<akn:article eId="hauptteil-1_art-1"
GUID="cdbfc728-a070-42d9-ba2f-357945afef06"
period="#geltungszeitgr-1"
refersTo="hauptaenderung">
<akn:paragraph eId="hauptteil-1_art-1_abs-1"
GUID="48ead358-f901-41d3-a135-e372d5ef97b1">
<akn:list eId="hauptteil-1_art-1_abs-1_untergl-1"
GUID="41675622-ed62-46e3-869f-94d99908b010">
<akn:intro eId="hauptteil-1_art-1_abs-1_untergl-1_intro-1"
GUID="5d6fc824-7926-43b4-b243-b0096da183f9">
<akn:p eId="hauptteil-1_art-1_abs-1_untergl-1_intro-1_text-1"
GUID="04879ca1-994b-4eb2-b59b-032e528d9ce5">Das <akn:affectedDocument
eId="hauptteil-1_art-1_abs-1_untergl-1_intro-1_text-1_bezugsdoc-1"
GUID="88b3b9f3-e4a8-49c6-9320-b5b42150bcc5"
href="">Vereinsgesetz vom
5. August 1964 (BGBl. I S. 593), das zuletzt
durch … geändert worden ist</akn:affectedDocument>, wird wie folgt geändert:
</akn:p>
</akn:intro>
</akn:list>
</akn:paragraph>
</akn:article>
</akn:body>
</akn:act>
</akn:akomaNtoso>
""";

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");
}
}

0 comments on commit 6d897c8

Please sign in to comment.