Skip to content

Commit 2642811

Browse files
Remove amended by and amended at filter from loadArticles
RISDEV-0000
1 parent 8d4eda1 commit 2642811

File tree

6 files changed

+6
-418
lines changed

6 files changed

+6
-418
lines changed

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,8 @@ public ResponseEntity<List<ArticleResponseSchema>> getArticles(
6363
@RequestParam final Optional<DokumentExpressionEli> amendedBy,
6464
@RequestParam final Optional<String> amendedAt
6565
) {
66-
final var query = new LoadArticlesFromDokumentUseCase.Query(
67-
eli,
68-
amendedBy.orElse(null),
69-
amendedAt.orElse(null)
70-
);
71-
7266
final var articlesWithZf0 = loadArticlesFromDokumentUseCase
73-
.loadArticlesFromDokument(query)
67+
.loadArticlesFromDokument(new LoadArticlesFromDokumentUseCase.Query(eli))
7468
.stream()
7569
.map(ArticleResponseMapper::fromNormArticle)
7670
.toList();
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
package de.bund.digitalservice.ris.norms.application.port.input;
22

33
import de.bund.digitalservice.ris.norms.domain.entity.Article;
4+
import de.bund.digitalservice.ris.norms.domain.entity.Dokument;
45
import de.bund.digitalservice.ris.norms.domain.entity.eli.DokumentExpressionEli;
56
import java.util.List;
6-
import javax.annotation.Nullable;
77

8-
/** Use case for getting a list of {@link Article}s from a Dokument (eg. {@link de.bund.digitalservice.ris.norms.domain.entity.Regelungstext}). */
8+
/** Use case for getting a list of {@link Article}s from a {@link Dokument}. */
99
public interface LoadArticlesFromDokumentUseCase {
1010
/**
11-
* Load the list of articles from a dokument. Articles can be filtered based on whether they have
12-
* pending (passive) modifications that originate from a specific law, or that will be applied at
13-
* a specific date.
11+
* Load the list of articles from a dokument.
1412
*
1513
* @param query Query used for identifying the articles
1614
* @return List of articles (can be empty)
@@ -21,19 +19,6 @@ public interface LoadArticlesFromDokumentUseCase {
2119
* Contains the parameters needed for loading articles from a dokument.
2220
*
2321
* @param eli The ELI used to identify the dokument
24-
* @param amendedBy ELI of an amending law. When specified, only articles with passive
25-
* modifications from that amending law are included in the result.
26-
* @param amendedAt eId of a lifecycle event. When specified, only articles with passive
27-
* modifications that will be applied at the date of this lifecycle event will be included in
28-
* the result.
2922
*/
30-
record Query(
31-
DokumentExpressionEli eli,
32-
@Nullable DokumentExpressionEli amendedBy,
33-
@Nullable String amendedAt
34-
) {
35-
public Query(DokumentExpressionEli eli) {
36-
this(eli, null, null);
37-
}
38-
}
23+
record Query(DokumentExpressionEli eli) {}
3924
}

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

Lines changed: 1 addition & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,9 @@
66
import de.bund.digitalservice.ris.norms.application.port.input.*;
77
import de.bund.digitalservice.ris.norms.application.port.output.LoadRegelungstextPort;
88
import de.bund.digitalservice.ris.norms.domain.entity.*;
9-
import de.bund.digitalservice.ris.norms.domain.entity.eli.DokumentExpressionEli;
109
import de.bund.digitalservice.ris.norms.utils.XmlMapper;
11-
import java.util.Collections;
1210
import java.util.List;
1311
import java.util.Objects;
14-
import java.util.Optional;
15-
import java.util.function.Predicate;
1612
import org.springframework.stereotype.Service;
1713

1814
/** Service for loading a norm's articles */
@@ -56,57 +52,11 @@ public String loadArticleHtml(final LoadArticleHtmlUseCase.Query query) {
5652

5753
@Override
5854
public List<Article> loadArticlesFromDokument(final LoadArticlesFromDokumentUseCase.Query query) {
59-
final var amendedAt = query.amendedAt();
60-
final var amendedBy = query.amendedBy();
61-
6255
final var regelungstext = loadRegelungstextPort
6356
.loadRegelungstext(new LoadRegelungstextPort.Command(query.eli()))
6457
.orElseThrow(() -> new RegelungstextNotFoundException(query.eli().toString()));
6558

66-
List<Article> articles = regelungstext.getArticles();
67-
68-
// Filter list of articles by passive mods if at least one filter is specified
69-
if (amendedBy != null || amendedAt != null) {
70-
var filterPassiveMods = getPassiveModsAmendingByOrAt(regelungstext, amendedBy, amendedAt);
71-
var passiveModFilter = createPassiveModFilter(filterPassiveMods);
72-
articles = articles.stream().filter(passiveModFilter).toList();
73-
}
74-
75-
return articles;
76-
}
77-
78-
private List<TextualMod> getPassiveModsAmendingByOrAt(
79-
final Regelungstext fromRegelungstext,
80-
final DokumentExpressionEli amendingBy,
81-
final String amendingAt
82-
) {
83-
if (amendingBy == null && amendingAt == null) return List.of();
84-
85-
return fromRegelungstext
86-
.getMeta()
87-
.getAnalysis()
88-
.map(Analysis::getPassiveModifications)
89-
.orElse(Collections.emptyList())
90-
.stream()
91-
.filter(passiveModification -> {
92-
if (amendingBy == null) return true;
93-
94-
return passiveModification
95-
.getSourceHref()
96-
.flatMap(Href::getExpressionEli)
97-
.map(sourceEli -> sourceEli.equals(amendingBy))
98-
.orElse(false);
99-
})
100-
.filter(passiveModification -> {
101-
if (amendingAt == null) return true;
102-
103-
return passiveModification
104-
.getForcePeriodEid()
105-
.flatMap(fromRegelungstext::getStartEventRefForTemporalGroup)
106-
.map(startEventRef -> startEventRef.equals(amendingAt))
107-
.orElse(false);
108-
})
109-
.toList();
59+
return regelungstext.getArticles();
11060
}
11161

11262
@Override
@@ -132,24 +82,4 @@ public List<String> loadSpecificArticlesXmlFromDokument(
13282

13383
return articles.stream().map(a -> XmlMapper.toString(a.getElement())).toList();
13484
}
135-
136-
private Predicate<Article> createPassiveModFilter(final List<TextualMod> mods) {
137-
return article ->
138-
// If we filter by amendedAt or amendedBy: Those properties are found
139-
// in the passive modifications we already collected above. What's left
140-
// now is to only return the articles that are going to be modified by
141-
// those passive modifications.
142-
mods
143-
.stream()
144-
.map(TextualMod::getDestinationHref)
145-
.flatMap(Optional::stream)
146-
.map(Href::getEId)
147-
.flatMap(Optional::stream)
148-
.anyMatch(destinationEid ->
149-
// Modifications can be either on the article itself or anywhere
150-
// inside the article, hence the "contains" rather than exact
151-
// matching.
152-
destinationEid.contains(article.getEid())
153-
);
154-
}
15585
}

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

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -99,96 +99,6 @@ void itReturnsArticles() throws Exception {
9999
);
100100
}
101101

102-
@Test
103-
void itReturnsArticlesFilteredByAmendedAt() throws Exception {
104-
// Given
105-
var regelungstext = Fixtures.loadRegelungstextFromDisk(
106-
"NormWithMultiplePassiveModifications.xml"
107-
);
108-
109-
when(loadRegelungstextUseCase.loadRegelungstext(any())).thenReturn(regelungstext);
110-
111-
when(loadArticlesFromDokumentUseCase.loadArticlesFromDokument(any()))
112-
.thenReturn(
113-
regelungstext
114-
.getArticles()
115-
.stream()
116-
.filter(article -> article.getEid().equals("hauptteil-1_art-1"))
117-
.toList()
118-
);
119-
120-
// When
121-
mockMvc
122-
.perform(
123-
get(
124-
"/api/v1/norms/eli/bund/bgbl-1/2023/413/2023-12-29/1/deu/regelungstext-1/articles?amendedAt=meta-1_lebzykl-1_ereignis-4"
125-
)
126-
.accept(MediaType.APPLICATION_JSON)
127-
)
128-
// Then
129-
.andExpect(status().isOk())
130-
.andExpect(jsonPath("$[0]").exists())
131-
.andExpect(jsonPath("$[0].eid").value("hauptteil-1_art-1"))
132-
.andExpect(jsonPath("$[1]").doesNotExist());
133-
134-
verify(loadArticlesFromDokumentUseCase, times(1))
135-
.loadArticlesFromDokument(
136-
new LoadArticlesFromDokumentUseCase.Query(
137-
DokumentExpressionEli.fromString(
138-
"eli/bund/bgbl-1/2023/413/2023-12-29/1/deu/regelungstext-1"
139-
),
140-
null,
141-
"meta-1_lebzykl-1_ereignis-4"
142-
)
143-
);
144-
}
145-
146-
@Test
147-
void itReturnsArticlesFilteredByAmendedBy() throws Exception {
148-
// Given
149-
var regelungstext = Fixtures.loadRegelungstextFromDisk(
150-
"NormWithPassiveModificationsInDifferentArticles.xml"
151-
);
152-
153-
when(loadRegelungstextUseCase.loadRegelungstext(any())).thenReturn(regelungstext);
154-
155-
when(loadArticlesFromDokumentUseCase.loadArticlesFromDokument(any()))
156-
.thenReturn(
157-
regelungstext
158-
.getArticles()
159-
.stream()
160-
.filter(article -> article.getEid().equals("hauptteil-1_art-1"))
161-
.toList()
162-
);
163-
164-
// When
165-
mockMvc
166-
.perform(
167-
get(
168-
"/api/v1/norms/eli/bund/bgbl-1/2023/413/2023-12-29/1/deu/regelungstext-1/articles?amendedBy=eli/bund/bgbl-1/2017/s815/1995-03-15/1/deu/regelungstext-1"
169-
)
170-
.accept(MediaType.APPLICATION_JSON)
171-
)
172-
// Then
173-
.andExpect(status().isOk())
174-
.andExpect(jsonPath("$[0]").exists())
175-
.andExpect(jsonPath("$[0].eid").value("hauptteil-1_art-1"))
176-
.andExpect(jsonPath("$[1]").doesNotExist());
177-
178-
verify(loadArticlesFromDokumentUseCase, times(1))
179-
.loadArticlesFromDokument(
180-
new LoadArticlesFromDokumentUseCase.Query(
181-
DokumentExpressionEli.fromString(
182-
"eli/bund/bgbl-1/2023/413/2023-12-29/1/deu/regelungstext-1"
183-
),
184-
DokumentExpressionEli.fromString(
185-
"eli/bund/bgbl-1/2017/s815/1995-03-15/1/deu/regelungstext-1"
186-
),
187-
null
188-
)
189-
);
190-
}
191-
192102
@Test
193103
void itReturnsUnprocessableEntityWhenMandatoryNodeIsMissing() throws Exception {
194104
// Given

0 commit comments

Comments
 (0)