Skip to content

Commit 7c1847f

Browse files
Remove amended by filter from LoadElementsByTypeUseCase
RISDEV-0000
1 parent 2642811 commit 7c1847f

File tree

6 files changed

+4
-184
lines changed

6 files changed

+4
-184
lines changed

backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/input/restapi/controller/ElementController.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,7 @@ public ResponseEntity<List<ElementResponseSchema>> getElementList(
9494
@RequestParam final Optional<DokumentExpressionEli> amendedBy
9595
) {
9696
List<ElementResponseSchema> elements = loadElementsByTypeUseCase
97-
.loadElementsByType(
98-
new LoadElementsByTypeUseCase.Query(eli, Arrays.asList(type), amendedBy.orElse(null))
99-
)
97+
.loadElementsByType(new LoadElementsByTypeUseCase.Query(eli, Arrays.asList(type)))
10098
.stream()
10199
.map(ElementResponseMapper::fromElementNode)
102100
.toList();

backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/input/LoadElementsByTypeUseCase.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44
import de.bund.digitalservice.ris.norms.domain.entity.eli.DokumentExpressionEli;
55
import de.bund.digitalservice.ris.norms.utils.exceptions.NormsAppException;
66
import java.util.List;
7-
import javax.annotation.Nullable;
87
import org.w3c.dom.Node;
98

109
/** Use case for getting a list of elements of certain types as {@link Node} from a dokument. */
1110
public interface LoadElementsByTypeUseCase {
1211
/**
13-
* Load the list of elements of certain types from the dokument. Elements can additionally be filtered
14-
* to include only those touched by a specific amending command.
12+
* Load the list of elements of certain types from the dokument.
1513
*
1614
* @return List of elements from the dokument
1715
* @param query Query used for identifying the elements
@@ -24,18 +22,8 @@ public interface LoadElementsByTypeUseCase {
2422
* @param eli The ELI used to identify the dokument
2523
* @param elementType The types of the elements. While this is a list of strings, only certain
2624
* values are allowed. Check {@link ElementService.ElementType} for the supported types.
27-
* @param amendedBy EId of an amending command. If provided, filters the list to include only
28-
* elements touched by that amending command.
2925
*/
30-
record Query(
31-
DokumentExpressionEli eli,
32-
List<String> elementType,
33-
@Nullable DokumentExpressionEli amendedBy
34-
) {
35-
public Query(DokumentExpressionEli eli, List<String> elementType) {
36-
this(eli, elementType, null);
37-
}
38-
}
26+
record Query(DokumentExpressionEli eli, List<String> elementType) {}
3927

4028
/** Indicates that at least one of the requested types is not supported. */
4129
class UnsupportedElementTypeException

backend/src/main/java/de/bund/digitalservice/ris/norms/application/service/ElementService.java

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,10 @@
44
import de.bund.digitalservice.ris.norms.application.exception.RegelungstextNotFoundException;
55
import de.bund.digitalservice.ris.norms.application.port.input.*;
66
import de.bund.digitalservice.ris.norms.application.port.output.LoadRegelungstextPort;
7-
import de.bund.digitalservice.ris.norms.domain.entity.Analysis;
8-
import de.bund.digitalservice.ris.norms.domain.entity.EId;
9-
import de.bund.digitalservice.ris.norms.domain.entity.Href;
107
import de.bund.digitalservice.ris.norms.domain.entity.Norm;
11-
import de.bund.digitalservice.ris.norms.domain.entity.TextualMod;
12-
import de.bund.digitalservice.ris.norms.domain.entity.eli.DokumentExpressionEli;
138
import de.bund.digitalservice.ris.norms.utils.NodeParser;
149
import de.bund.digitalservice.ris.norms.utils.XmlMapper;
15-
import java.util.Collections;
1610
import java.util.List;
17-
import java.util.Optional;
18-
import javax.annotation.Nullable;
1911
import org.springframework.stereotype.Service;
2012
import org.w3c.dom.Node;
2113

@@ -120,52 +112,13 @@ public List<Node> loadElementsByType(LoadElementsByTypeUseCase.Query query) {
120112
.loadRegelungstext(new LoadRegelungstextPort.Command(query.eli()))
121113
.orElseThrow(() -> new RegelungstextNotFoundException(query.eli().toString()));
122114

123-
// Source EIDs from passive mods
124-
final var passiveModsDestinationEids = getDestinationEidsFromPassiveMods(
125-
regelungstext
126-
.getMeta()
127-
.getAnalysis()
128-
.map(Analysis::getPassiveModifications)
129-
.orElse(Collections.emptyList()),
130-
query.amendedBy()
131-
);
132-
133115
return NodeParser
134116
.getNodesFromExpression(combinedXPaths, regelungstext.getDocument())
135117
.stream()
136-
.filter(element -> { // filter by "amendedBy")
137-
// no amending law -> all elements are fine
138-
if (query.amendedBy() == null) return true;
139-
140-
var eId = EId.fromMandatoryNode(element).value();
141-
return passiveModsDestinationEids.stream().anyMatch(modEid -> modEid.contains(eId));
142-
})
143118
.toList();
144119
}
145120

146121
private String getXPathForEid(String eid) {
147122
return String.format("//*[@eId='%s']", eid);
148123
}
149-
150-
private List<String> getDestinationEidsFromPassiveMods(
151-
List<TextualMod> mods,
152-
@Nullable DokumentExpressionEli amendedBy
153-
) {
154-
return mods
155-
.stream()
156-
.filter(passiveMod -> {
157-
if (amendedBy == null) return true;
158-
159-
return passiveMod
160-
.getSourceHref()
161-
.flatMap(Href::getExpressionEli)
162-
.orElseThrow()
163-
.equals(amendedBy);
164-
})
165-
.map(TextualMod::getDestinationHref)
166-
.flatMap(Optional::stream)
167-
.map(Href::getEId)
168-
.flatMap(Optional::stream)
169-
.toList();
170-
}
171124
}

backend/src/test/java/de/bund/digitalservice/ris/norms/adapter/input/restapi/controller/ElementControllerTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,7 @@ void itReturnsOnlyTheElementsMatchingTheGivenAmendingLaw() throws Exception {
190190
DokumentExpressionEli.fromString(
191191
"eli/bund/bgbl-1/1990/s2954/2022-12-19/1/deu/regelungstext-1"
192192
),
193-
eq(List.of("preface", "preamble", "article", "conclusions")),
194-
DokumentExpressionEli.fromString(
195-
"eli/bund/bgbl-1/2017/s815/1995-03-15/1/deu/regelungstext-1"
196-
)
193+
eq(List.of("preface", "preamble", "article", "conclusions"))
197194
)
198195
)
199196
)

backend/src/test/java/de/bund/digitalservice/ris/norms/application/service/ElementServiceTest.java

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -384,65 +384,6 @@ void throwsWhenNormDoesNotExist() {
384384
assertThatThrownBy(() -> service.loadElementsByType(query))
385385
.isInstanceOf(RegelungstextNotFoundException.class);
386386
}
387-
388-
@Test
389-
void filtersReturnedElementsByAmendingNorm() {
390-
// Given
391-
var regelungstext = Fixtures.loadRegelungstextFromDisk(
392-
"NormWithPassiveModificationsInDifferentArticles.xml"
393-
);
394-
var eli = regelungstext.getExpressionEli();
395-
when(loadRegelungstextPort.loadRegelungstext(new LoadRegelungstextPort.Command(eli)))
396-
.thenReturn(Optional.of(regelungstext));
397-
398-
// When
399-
var elements = service.loadElementsByType(
400-
new LoadElementsByTypeUseCase.Query(
401-
eli,
402-
List.of("preface", "preamble", "article", "conclusions"),
403-
DokumentExpressionEli.fromString(
404-
"eli/bund/bgbl-1/2017/s815/1995-03-15/1/deu/regelungstext-1"
405-
)
406-
)
407-
);
408-
409-
// Then
410-
assertThat(elements).hasSize(1);
411-
assertThat(elements.getFirst().getNodeName()).isEqualTo("akn:article");
412-
}
413-
414-
@Test
415-
void returnsEmptyListIfNoElementIsAffectedByTheAmendingNorm() {
416-
// Given
417-
var regelungstext = Fixtures.loadRegelungstextFromDisk(
418-
"NormWithMultiplePassiveModifications.xml"
419-
);
420-
var eli = regelungstext.getExpressionEli();
421-
when(
422-
loadRegelungstextPort.loadRegelungstext(
423-
new LoadRegelungstextPort.Command(
424-
DokumentExpressionEli.fromString(
425-
"eli/bund/bgbl-1/1990/s2954/2022-12-19/1/deu/regelungstext-1"
426-
)
427-
)
428-
)
429-
)
430-
.thenReturn(Optional.of(regelungstext));
431-
432-
// When
433-
var elements = service.loadElementsByType(
434-
new LoadElementsByTypeUseCase.Query(
435-
eli,
436-
List.of("preface", "preamble", "article", "conclusions"),
437-
DokumentExpressionEli.fromString(
438-
"eli/bund/bgbl-1/1000/1/1000-01-01/1/deu/regelungstext-1"
439-
)
440-
)
441-
);
442-
443-
// Then
444-
assertThat(elements).isEmpty();
445-
}
446387
}
447388

448389
@Nested

backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/input/restapi/ElementControllerIntegrationTest.java

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -472,62 +472,5 @@ void itReturnsEntriesWithBookPartChapterTitleSubtitleSectionAndSubsectionInforma
472472
)
473473
.andExpect(jsonPath("$[6].type").value("subtitle"));
474474
}
475-
476-
@Test
477-
void itReturnsAnEmptyListIfNoElementIsAffectedByTheGivenAmendingLaw() throws Exception {
478-
// Given
479-
dokumentRepository.save(
480-
DokumentMapper.mapToDto(
481-
Fixtures.loadRegelungstextFromDisk("NormWithMultiplePassiveModifications.xml")
482-
)
483-
);
484-
dokumentRepository.save(
485-
DokumentMapper.mapToDto(
486-
Fixtures.loadRegelungstextFromDisk("NormWithPrefacePreambleAndConclusions.xml")
487-
)
488-
);
489-
490-
var url =
491-
"/api/v1/norms/eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/regelungstext-1/elements" +
492-
"?type=preface" +
493-
"&type=preamble" +
494-
"&type=article" +
495-
"&type=conclusions" +
496-
"&amendedBy=eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/regelungstext-1"; // amending norm eli
497-
498-
// When
499-
mockMvc
500-
.perform(get(url))
501-
// Then
502-
.andExpect(status().isOk())
503-
.andExpect(jsonPath("$[0]").doesNotExist());
504-
}
505-
506-
@Test
507-
void itReturnsOnlyTheElementsMatchingTheGivenAmendingLaw() throws Exception {
508-
dokumentRepository.save(
509-
DokumentMapper.mapToDto(
510-
Fixtures.loadRegelungstextFromDisk("NormWithPassiveModificationsInDifferentArticles.xml")
511-
)
512-
);
513-
514-
var url =
515-
"/api/v1/norms/eli/bund/bgbl-1/1990/s2954/2022-12-19/1/deu/regelungstext-1/elements" +
516-
"?type=preface" +
517-
"&type=preamble" +
518-
"&type=article" +
519-
"&type=conclusions" +
520-
"&amendedBy=eli/bund/bgbl-1/2017/s815/1995-03-15/1/deu/regelungstext-1"; // second
521-
522-
// When
523-
mockMvc
524-
.perform(get(url))
525-
// Then
526-
.andExpect(status().isOk())
527-
.andExpect(jsonPath("$[0].eid").exists())
528-
.andExpect(jsonPath("$[0].title").exists())
529-
.andExpect(jsonPath("$[0].type").exists())
530-
.andExpect(jsonPath("$[1]").doesNotExist());
531-
}
532475
}
533476
}

0 commit comments

Comments
 (0)