Skip to content

Commit 8ed12e6

Browse files
Remove /elements endpoint
RISDEV-6266
1 parent 5885a89 commit 8ed12e6

File tree

8 files changed

+2
-569
lines changed

8 files changed

+2
-569
lines changed

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

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,13 @@ public class ElementController {
2121

2222
private final LoadElementUseCase loadElementUseCase;
2323
private final LoadElementHtmlUseCase loadElementHtmlUseCase;
24-
private final LoadElementsByTypeUseCase loadElementsByTypeUseCase;
2524

2625
public ElementController(
2726
LoadElementUseCase loadElementUseCase,
28-
LoadElementHtmlUseCase loadElementHtmlUseCase,
29-
LoadElementsByTypeUseCase loadElementsByTypeUseCase
27+
LoadElementHtmlUseCase loadElementHtmlUseCase
3028
) {
3129
this.loadElementUseCase = loadElementUseCase;
3230
this.loadElementHtmlUseCase = loadElementHtmlUseCase;
33-
this.loadElementsByTypeUseCase = loadElementsByTypeUseCase;
3431
}
3532

3633
/**
@@ -73,32 +70,4 @@ public ResponseEntity<ElementResponseSchema> getElementInfo(
7370

7471
return ResponseEntity.ok(ElementResponseMapper.fromElementNode(element));
7572
}
76-
77-
/**
78-
* Retrieves a list of elements inside a norm based on the ELI of the norm and the types of the
79-
* elements.
80-
*
81-
* @param eli Eli of the request
82-
* @param type The type(s) of the elements that should be returned. Elements are returned in the
83-
* order of the types, and then in the order of elements in the norm.
84-
* @param amendedBy Only the elements modified by the norm of the given ELI will be returned.
85-
* @return A {@link ResponseEntity} containing the list of elements.
86-
* <p>Returns HTTP 200 (OK) if the norm is found. The list might be empty.
87-
* <p>Returns HTTP 404 (Not Found) if the norm is not found.
88-
* <p>Returns HTTP 500 (Server error) if an unsupported type is provided.
89-
*/
90-
@GetMapping(produces = { APPLICATION_JSON_VALUE })
91-
public ResponseEntity<List<ElementResponseSchema>> getElementList(
92-
final DokumentExpressionEli eli,
93-
@RequestParam final String[] type,
94-
@RequestParam final Optional<DokumentExpressionEli> amendedBy
95-
) {
96-
List<ElementResponseSchema> elements = loadElementsByTypeUseCase
97-
.loadElementsByType(new LoadElementsByTypeUseCase.Query(eli, Arrays.asList(type)))
98-
.stream()
99-
.map(ElementResponseMapper::fromElementNode)
100-
.toList();
101-
102-
return ResponseEntity.ok(elements);
103-
}
10473
}

backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/input/restapi/exception/NormsAppExceptionHandler.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package de.bund.digitalservice.ris.norms.adapter.input.restapi.exception;
22

33
import de.bund.digitalservice.ris.norms.application.exception.*;
4-
import de.bund.digitalservice.ris.norms.application.port.input.LoadElementsByTypeUseCase;
54
import de.bund.digitalservice.ris.norms.application.port.input.LoadSpecificArticlesXmlFromDokumentUseCase;
65
import de.bund.digitalservice.ris.norms.utils.exceptions.MandatoryNodeNotFoundException;
76
import de.bund.digitalservice.ris.norms.utils.exceptions.XmlProcessingException;
@@ -225,22 +224,6 @@ public ProblemDetail handleException(final MandatoryNodeNotFoundException e) {
225224
return problemDetail;
226225
}
227226

228-
/**
229-
* Exception handler method for handling {@link
230-
* LoadElementsByTypeUseCase.UnsupportedElementTypeException}.
231-
*
232-
* @param e The exception that occurred.
233-
* @return A {@link ResponseEntity} with an HTTP 400 status code and the exception message.
234-
*/
235-
@ExceptionHandler(LoadElementsByTypeUseCase.UnsupportedElementTypeException.class)
236-
@ResponseStatus(HttpStatus.BAD_REQUEST)
237-
public ProblemDetail handleException(
238-
final LoadElementsByTypeUseCase.UnsupportedElementTypeException e
239-
) {
240-
log.error("UnsupportedElementTypeException: {}", e.getMessage(), e);
241-
return ProblemDetailFactory.createProblemDetail(e, HttpStatus.BAD_REQUEST);
242-
}
243-
244227
/**
245228
* Exception handler method for handling {@link NormExistsAlreadyException}.
246229
*

backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/input/restapi/exception/ProblemDetailFactory.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package de.bund.digitalservice.ris.norms.adapter.input.restapi.exception;
22

33
import de.bund.digitalservice.ris.norms.application.exception.*;
4-
import de.bund.digitalservice.ris.norms.application.port.input.LoadElementsByTypeUseCase;
54
import de.bund.digitalservice.ris.norms.application.port.input.LoadSpecificArticlesXmlFromDokumentUseCase;
65
import de.bund.digitalservice.ris.norms.utils.exceptions.MandatoryNodeNotFoundException;
76
import de.bund.digitalservice.ris.norms.utils.exceptions.NormsAppException;
@@ -97,11 +96,6 @@ private enum ProblemMapping {
9796
URI.create("/errors/xml-processing-error"),
9897
"XML processing error"
9998
),
100-
UNSUPPORTED_ELEMENT_TYPE(
101-
LoadElementsByTypeUseCase.UnsupportedElementTypeException.class,
102-
URI.create("/errors/unsupported-element-type"),
103-
"Unsupported element type"
104-
),
10599
NORM_WITH_ELI_EXISTS_ALREADY(
106100
NormExistsAlreadyException.class,
107101
URI.create("/errors/norm-with-eli-exists-already"),

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

Lines changed: 0 additions & 37 deletions
This file was deleted.

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

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import de.bund.digitalservice.ris.norms.domain.entity.Norm;
88
import de.bund.digitalservice.ris.norms.utils.NodeParser;
99
import de.bund.digitalservice.ris.norms.utils.XmlMapper;
10-
import java.util.List;
1110
import org.springframework.stereotype.Service;
1211
import org.w3c.dom.Node;
1312

@@ -18,8 +17,7 @@
1817
* related to articles), you should use a more specific service.
1918
*/
2019
@Service
21-
public class ElementService
22-
implements LoadElementUseCase, LoadElementHtmlUseCase, LoadElementsByTypeUseCase {
20+
public class ElementService implements LoadElementUseCase, LoadElementHtmlUseCase {
2321

2422
private final LoadRegelungstextPort loadRegelungstextPort;
2523
private final XsltTransformationService xsltTransformationService;
@@ -48,22 +46,6 @@ public enum ElementType {
4846
this.label = label;
4947
this.xPath = xPath;
5048
}
51-
52-
/**
53-
* Infers the enum value based on the provided label.
54-
*
55-
* @param label Label to infer the enum value from.
56-
* @return Enum value for that label
57-
*/
58-
public static ElementType fromLabel(String label) {
59-
for (ElementType type : values()) {
60-
if (type.label.equals(label)) {
61-
return type;
62-
}
63-
}
64-
65-
throw new UnsupportedElementTypeException(label + " is not supported");
66-
}
6749
}
6850

6951
public ElementService(
@@ -98,26 +80,6 @@ public String loadElementHtml(final LoadElementHtmlUseCase.Query query) {
9880
);
9981
}
10082

101-
@Override
102-
public List<Node> loadElementsByType(LoadElementsByTypeUseCase.Query query) {
103-
// No need to do anything if no types are requested
104-
if (query.elementType().isEmpty()) return List.of();
105-
106-
final var combinedXPaths = String.join(
107-
"|",
108-
query.elementType().stream().map(label -> ElementType.fromLabel(label).xPath).toList()
109-
);
110-
111-
final var regelungstext = loadRegelungstextPort
112-
.loadRegelungstext(new LoadRegelungstextPort.Command(query.eli()))
113-
.orElseThrow(() -> new RegelungstextNotFoundException(query.eli().toString()));
114-
115-
return NodeParser
116-
.getNodesFromExpression(combinedXPaths, regelungstext.getDocument())
117-
.stream()
118-
.toList();
119-
}
120-
12183
private String getXPathForEid(String eid) {
12284
return String.format("//*[@eId='%s']", eid);
12385
}

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

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import de.bund.digitalservice.ris.norms.domain.entity.eli.DokumentExpressionEli;
1111
import de.bund.digitalservice.ris.norms.utils.XmlMapper;
1212
import de.bund.digitalservice.ris.norms.utils.exceptions.XmlProcessingException;
13-
import java.util.List;
1413
import org.junit.jupiter.api.Nested;
1514
import org.junit.jupiter.api.Test;
1615
import org.springframework.beans.factory.annotation.Autowired;
@@ -41,9 +40,6 @@ class ElementControllerTest {
4140
@MockitoBean
4241
private LoadElementHtmlUseCase loadElementHtmlUseCase;
4342

44-
@MockitoBean
45-
private LoadElementsByTypeUseCase loadElementsByTypeUseCase;
46-
4743
@Nested
4844
class getElementHtmlPreview {
4945

@@ -149,66 +145,4 @@ void returnsJsonWithElementEidTitleAndType() throws Exception {
149145
.andExpect(jsonPath("title").value("Artikel 1 Änderung des Vereinsgesetzes"));
150146
}
151147
}
152-
153-
@Nested
154-
class getELementList {
155-
156-
@Test
157-
void itReturnsListOfElements() throws Exception {
158-
// given
159-
when(
160-
loadElementsByTypeUseCase.loadElementsByType(
161-
new LoadElementsByTypeUseCase.Query(
162-
DokumentExpressionEli.fromString(
163-
"eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/regelungstext-1"
164-
),
165-
eq(List.of("preface", "preamble", "article", "conclusions"))
166-
)
167-
)
168-
)
169-
.thenReturn(List.of());
170-
171-
var url =
172-
"/api/v1/norms/eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/regelungstext-1/elements" +
173-
"?type=preface" +
174-
"&type=preamble" +
175-
"&type=article" +
176-
"&type=conclusions";
177-
178-
// when
179-
mockMvc
180-
.perform(get(url))
181-
// then
182-
.andExpect(status().isOk());
183-
}
184-
185-
@Test
186-
void itReturnsOnlyTheElementsMatchingTheGivenAmendingLaw() throws Exception {
187-
when(
188-
loadElementsByTypeUseCase.loadElementsByType(
189-
new LoadElementsByTypeUseCase.Query(
190-
DokumentExpressionEli.fromString(
191-
"eli/bund/bgbl-1/1990/s2954/2022-12-19/1/deu/regelungstext-1"
192-
),
193-
eq(List.of("preface", "preamble", "article", "conclusions"))
194-
)
195-
)
196-
)
197-
.thenReturn(List.of());
198-
199-
var url =
200-
"/api/v1/norms/eli/bund/bgbl-1/1990/s2954/2022-12-19/1/deu/regelungstext-1/elements" +
201-
"?type=preface" +
202-
"&type=preamble" +
203-
"&type=article" +
204-
"&type=conclusions" +
205-
"&amendedBy=eli/bund/bgbl-1/2017/s815/1995-03-15/1/deu/regelungstext-1"; // second
206-
207-
// when
208-
mockMvc
209-
.perform(get(url))
210-
// then
211-
.andExpect(status().isOk());
212-
}
213-
}
214148
}

0 commit comments

Comments
 (0)