Skip to content

Commit

Permalink
Remove /elements endpoint
Browse files Browse the repository at this point in the history
RISDEV-6266
  • Loading branch information
VictorDelCampo committed Feb 15, 2025
1 parent 5885a89 commit 8ed12e6
Show file tree
Hide file tree
Showing 8 changed files with 2 additions and 569 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,13 @@ public class ElementController {

private final LoadElementUseCase loadElementUseCase;
private final LoadElementHtmlUseCase loadElementHtmlUseCase;
private final LoadElementsByTypeUseCase loadElementsByTypeUseCase;

public ElementController(
LoadElementUseCase loadElementUseCase,
LoadElementHtmlUseCase loadElementHtmlUseCase,
LoadElementsByTypeUseCase loadElementsByTypeUseCase
LoadElementHtmlUseCase loadElementHtmlUseCase
) {
this.loadElementUseCase = loadElementUseCase;
this.loadElementHtmlUseCase = loadElementHtmlUseCase;
this.loadElementsByTypeUseCase = loadElementsByTypeUseCase;
}

/**
Expand Down Expand Up @@ -73,32 +70,4 @@ public ResponseEntity<ElementResponseSchema> getElementInfo(

return ResponseEntity.ok(ElementResponseMapper.fromElementNode(element));
}

/**
* Retrieves a list of elements inside a norm based on the ELI of the norm and the types of the
* elements.
*
* @param eli Eli of the request
* @param type The type(s) of the elements that should be returned. Elements are returned in the
* order of the types, and then in the order of elements in the norm.
* @param amendedBy Only the elements modified by the norm of the given ELI will be returned.
* @return A {@link ResponseEntity} containing the list of elements.
* <p>Returns HTTP 200 (OK) if the norm is found. The list might be empty.
* <p>Returns HTTP 404 (Not Found) if the norm is not found.
* <p>Returns HTTP 500 (Server error) if an unsupported type is provided.
*/
@GetMapping(produces = { APPLICATION_JSON_VALUE })
public ResponseEntity<List<ElementResponseSchema>> getElementList(
final DokumentExpressionEli eli,
@RequestParam final String[] type,
@RequestParam final Optional<DokumentExpressionEli> amendedBy
) {
List<ElementResponseSchema> elements = loadElementsByTypeUseCase
.loadElementsByType(new LoadElementsByTypeUseCase.Query(eli, Arrays.asList(type)))
.stream()
.map(ElementResponseMapper::fromElementNode)
.toList();

return ResponseEntity.ok(elements);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package de.bund.digitalservice.ris.norms.adapter.input.restapi.exception;

import de.bund.digitalservice.ris.norms.application.exception.*;
import de.bund.digitalservice.ris.norms.application.port.input.LoadElementsByTypeUseCase;
import de.bund.digitalservice.ris.norms.application.port.input.LoadSpecificArticlesXmlFromDokumentUseCase;
import de.bund.digitalservice.ris.norms.utils.exceptions.MandatoryNodeNotFoundException;
import de.bund.digitalservice.ris.norms.utils.exceptions.XmlProcessingException;
Expand Down Expand Up @@ -225,22 +224,6 @@ public ProblemDetail handleException(final MandatoryNodeNotFoundException e) {
return problemDetail;
}

/**
* Exception handler method for handling {@link
* LoadElementsByTypeUseCase.UnsupportedElementTypeException}.
*
* @param e The exception that occurred.
* @return A {@link ResponseEntity} with an HTTP 400 status code and the exception message.
*/
@ExceptionHandler(LoadElementsByTypeUseCase.UnsupportedElementTypeException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ProblemDetail handleException(
final LoadElementsByTypeUseCase.UnsupportedElementTypeException e
) {
log.error("UnsupportedElementTypeException: {}", e.getMessage(), e);
return ProblemDetailFactory.createProblemDetail(e, HttpStatus.BAD_REQUEST);
}

/**
* Exception handler method for handling {@link NormExistsAlreadyException}.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package de.bund.digitalservice.ris.norms.adapter.input.restapi.exception;

import de.bund.digitalservice.ris.norms.application.exception.*;
import de.bund.digitalservice.ris.norms.application.port.input.LoadElementsByTypeUseCase;
import de.bund.digitalservice.ris.norms.application.port.input.LoadSpecificArticlesXmlFromDokumentUseCase;
import de.bund.digitalservice.ris.norms.utils.exceptions.MandatoryNodeNotFoundException;
import de.bund.digitalservice.ris.norms.utils.exceptions.NormsAppException;
Expand Down Expand Up @@ -97,11 +96,6 @@ private enum ProblemMapping {
URI.create("/errors/xml-processing-error"),
"XML processing error"
),
UNSUPPORTED_ELEMENT_TYPE(
LoadElementsByTypeUseCase.UnsupportedElementTypeException.class,
URI.create("/errors/unsupported-element-type"),
"Unsupported element type"
),
NORM_WITH_ELI_EXISTS_ALREADY(
NormExistsAlreadyException.class,
URI.create("/errors/norm-with-eli-exists-already"),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import de.bund.digitalservice.ris.norms.domain.entity.Norm;
import de.bund.digitalservice.ris.norms.utils.NodeParser;
import de.bund.digitalservice.ris.norms.utils.XmlMapper;
import java.util.List;
import org.springframework.stereotype.Service;
import org.w3c.dom.Node;

Expand All @@ -18,8 +17,7 @@
* related to articles), you should use a more specific service.
*/
@Service
public class ElementService
implements LoadElementUseCase, LoadElementHtmlUseCase, LoadElementsByTypeUseCase {
public class ElementService implements LoadElementUseCase, LoadElementHtmlUseCase {

private final LoadRegelungstextPort loadRegelungstextPort;
private final XsltTransformationService xsltTransformationService;
Expand Down Expand Up @@ -48,22 +46,6 @@ public enum ElementType {
this.label = label;
this.xPath = xPath;
}

/**
* Infers the enum value based on the provided label.
*
* @param label Label to infer the enum value from.
* @return Enum value for that label
*/
public static ElementType fromLabel(String label) {
for (ElementType type : values()) {
if (type.label.equals(label)) {
return type;
}
}

throw new UnsupportedElementTypeException(label + " is not supported");
}
}

public ElementService(
Expand Down Expand Up @@ -98,26 +80,6 @@ public String loadElementHtml(final LoadElementHtmlUseCase.Query query) {
);
}

@Override
public List<Node> loadElementsByType(LoadElementsByTypeUseCase.Query query) {
// No need to do anything if no types are requested
if (query.elementType().isEmpty()) return List.of();

final var combinedXPaths = String.join(
"|",
query.elementType().stream().map(label -> ElementType.fromLabel(label).xPath).toList()
);

final var regelungstext = loadRegelungstextPort
.loadRegelungstext(new LoadRegelungstextPort.Command(query.eli()))
.orElseThrow(() -> new RegelungstextNotFoundException(query.eli().toString()));

return NodeParser
.getNodesFromExpression(combinedXPaths, regelungstext.getDocument())
.stream()
.toList();
}

private String getXPathForEid(String eid) {
return String.format("//*[@eId='%s']", eid);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import de.bund.digitalservice.ris.norms.domain.entity.eli.DokumentExpressionEli;
import de.bund.digitalservice.ris.norms.utils.XmlMapper;
import de.bund.digitalservice.ris.norms.utils.exceptions.XmlProcessingException;
import java.util.List;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -41,9 +40,6 @@ class ElementControllerTest {
@MockitoBean
private LoadElementHtmlUseCase loadElementHtmlUseCase;

@MockitoBean
private LoadElementsByTypeUseCase loadElementsByTypeUseCase;

@Nested
class getElementHtmlPreview {

Expand Down Expand Up @@ -149,66 +145,4 @@ void returnsJsonWithElementEidTitleAndType() throws Exception {
.andExpect(jsonPath("title").value("Artikel 1 Änderung des Vereinsgesetzes"));
}
}

@Nested
class getELementList {

@Test
void itReturnsListOfElements() throws Exception {
// given
when(
loadElementsByTypeUseCase.loadElementsByType(
new LoadElementsByTypeUseCase.Query(
DokumentExpressionEli.fromString(
"eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/regelungstext-1"
),
eq(List.of("preface", "preamble", "article", "conclusions"))
)
)
)
.thenReturn(List.of());

var url =
"/api/v1/norms/eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/regelungstext-1/elements" +
"?type=preface" +
"&type=preamble" +
"&type=article" +
"&type=conclusions";

// when
mockMvc
.perform(get(url))
// then
.andExpect(status().isOk());
}

@Test
void itReturnsOnlyTheElementsMatchingTheGivenAmendingLaw() throws Exception {
when(
loadElementsByTypeUseCase.loadElementsByType(
new LoadElementsByTypeUseCase.Query(
DokumentExpressionEli.fromString(
"eli/bund/bgbl-1/1990/s2954/2022-12-19/1/deu/regelungstext-1"
),
eq(List.of("preface", "preamble", "article", "conclusions"))
)
)
)
.thenReturn(List.of());

var url =
"/api/v1/norms/eli/bund/bgbl-1/1990/s2954/2022-12-19/1/deu/regelungstext-1/elements" +
"?type=preface" +
"&type=preamble" +
"&type=article" +
"&type=conclusions" +
"&amendedBy=eli/bund/bgbl-1/2017/s815/1995-03-15/1/deu/regelungstext-1"; // second

// when
mockMvc
.perform(get(url))
// then
.andExpect(status().isOk());
}
}
}
Loading

0 comments on commit 8ed12e6

Please sign in to comment.