Skip to content

Commit

Permalink
Rename LoadNormXmlUseCase to LoadRegelungstextXmlUseCase
Browse files Browse the repository at this point in the history
RISDEV-6261
  • Loading branch information
malte-laukoetter committed Jan 22, 2025
1 parent c9d17ed commit 344a5ae
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class NormExpressionController {

private final LoadNormUseCase loadNormUseCase;
private final LoadRegelungstextUseCase loadRegelungstextUseCase;
private final LoadNormXmlUseCase loadNormXmlUseCase;
private final LoadRegelungstextXmlUseCase loadRegelungstextXmlUseCase;
private final UpdateRegelungstextXmlUseCase updateRegelungstextXmlUseCase;
private final TransformLegalDocMlToHtmlUseCase transformLegalDocMlToHtmlUseCase;
private final ApplyPassiveModificationsUseCase applyPassiveModificationsUseCase;
Expand All @@ -47,7 +47,7 @@ public class NormExpressionController {
public NormExpressionController(
LoadNormUseCase loadNormUseCase,
LoadRegelungstextUseCase loadRegelungstextUseCase,
LoadNormXmlUseCase loadNormXmlUseCase,
LoadRegelungstextXmlUseCase loadRegelungstextXmlUseCase,
UpdateRegelungstextXmlUseCase updateRegelungstextXmlUseCase,
TransformLegalDocMlToHtmlUseCase transformLegalDocMlToHtmlUseCase,
ApplyPassiveModificationsUseCase applyPassiveModificationsUseCase,
Expand All @@ -56,7 +56,7 @@ public NormExpressionController(
) {
this.loadNormUseCase = loadNormUseCase;
this.loadRegelungstextUseCase = loadRegelungstextUseCase;
this.loadNormXmlUseCase = loadNormXmlUseCase;
this.loadRegelungstextXmlUseCase = loadRegelungstextXmlUseCase;
this.updateRegelungstextXmlUseCase = updateRegelungstextXmlUseCase;
this.transformLegalDocMlToHtmlUseCase = transformLegalDocMlToHtmlUseCase;
this.applyPassiveModificationsUseCase = applyPassiveModificationsUseCase;
Expand Down Expand Up @@ -88,7 +88,9 @@ public ResponseEntity<NormResponseSchema> getNorm(final DokumentExpressionEli el
*/
@GetMapping(produces = { APPLICATION_XML_VALUE })
public ResponseEntity<String> getNormXml(final DokumentExpressionEli eli) {
return ResponseEntity.ok(loadNormXmlUseCase.loadNormXml(new LoadNormXmlUseCase.Query(eli)));
return ResponseEntity.ok(
loadRegelungstextXmlUseCase.loadRegelungstextXml(new LoadRegelungstextXmlUseCase.Query(eli))
);
}

/**
Expand Down Expand Up @@ -128,7 +130,9 @@ public ResponseEntity<String> getNormRender(
);
}

var normXml = loadNormXmlUseCase.loadNormXml(new LoadNormXmlUseCase.Query(eli));
var normXml = loadRegelungstextXmlUseCase.loadRegelungstextXml(
new LoadRegelungstextXmlUseCase.Query(eli)
);
var legalDocHtml =
this.transformLegalDocMlToHtmlUseCase.transformLegalDocMlToHtml(
new TransformLegalDocMlToHtmlUseCase.Query(normXml, showMetadata, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static org.springframework.http.MediaType.APPLICATION_XML_VALUE;

import de.bund.digitalservice.ris.norms.application.port.input.LoadNormXmlUseCase;
import de.bund.digitalservice.ris.norms.application.port.input.LoadRegelungstextXmlUseCase;
import de.bund.digitalservice.ris.norms.domain.entity.eli.DokumentExpressionEli;
import de.bund.digitalservice.ris.norms.domain.entity.eli.DokumentManifestationEli;
import org.springframework.http.ResponseEntity;
Expand All @@ -24,10 +24,10 @@
)
public class NormManifestationController {

private final LoadNormXmlUseCase loadNormXmlUseCase;
private final LoadRegelungstextXmlUseCase loadRegelungstextXmlUseCase;

public NormManifestationController(LoadNormXmlUseCase loadNormXmlUseCase) {
this.loadNormXmlUseCase = loadNormXmlUseCase;
public NormManifestationController(LoadRegelungstextXmlUseCase loadRegelungstextXmlUseCase) {
this.loadRegelungstextXmlUseCase = loadRegelungstextXmlUseCase;
}

/**
Expand All @@ -40,7 +40,9 @@ public NormManifestationController(LoadNormXmlUseCase loadNormXmlUseCase) {
*/
@GetMapping(produces = { APPLICATION_XML_VALUE })
public ResponseEntity<String> getNormManifestationXml(final DokumentManifestationEli eli) {
var norm = loadNormXmlUseCase.loadNormXml(new LoadNormXmlUseCase.Query(eli));
var norm = loadRegelungstextXmlUseCase.loadRegelungstextXml(
new LoadRegelungstextXmlUseCase.Query(eli)
);
return ResponseEntity.ok(norm);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package de.bund.digitalservice.ris.norms.application.port.input;

import de.bund.digitalservice.ris.norms.domain.entity.Regelungstext;
import de.bund.digitalservice.ris.norms.domain.entity.eli.DokumentEli;
import java.util.Optional;

/**
* Interface representing the use case for loading the xml representation of a {@link Regelungstext}.
*/
public interface LoadRegelungstextXmlUseCase {
/**
* Retrieves the xml representation of a dokument based on the provided query.
*
* @param query The query containing the ELI (European Legislation Identifier) of the dokument.
* @return An {@link Optional} containing the loaded {@link Regelungstext} if found, or empty if not found.
*/
String loadRegelungstextXml(Query query);

/**
* A record representing the query for loading the xml representation of a dokument.
*
* @param eli The ELI (European Legislation Identifier) used to identify the dokument in the query.
*/
record Query(DokumentEli eli) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
public class NormService
implements
LoadNormUseCase,
LoadNormXmlUseCase,
LoadRegelungstextXmlUseCase,
UpdateRegelungstextXmlUseCase,
UpdateModUseCase,
UpdateModsUseCase,
Expand Down Expand Up @@ -74,12 +74,12 @@ public Regelungstext loadRegelungstext(final LoadRegelungstextUseCase.Query quer
}

@Override
public String loadNormXml(final LoadNormXmlUseCase.Query query) {
final Norm norm = loadNormPort
.loadNorm(new LoadNormPort.Command(query.eli()))
.orElseThrow(() -> new NormNotFoundException(query.eli().toString()));
public String loadRegelungstextXml(final LoadRegelungstextXmlUseCase.Query query) {
final Regelungstext regelungstext = loadRegelungstextPort
.loadRegelungstext(new LoadRegelungstextPort.Command(query.eli()))
.orElseThrow(() -> new RegelungstextNotFoundException(query.eli().toString()));

return XmlMapper.toString(norm.getDocument());
return XmlMapper.toString(regelungstext.getDocument());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class NormExpressionControllerTest {
private LoadRegelungstextUseCase loadRegelungstextUseCase;

@MockitoBean
private LoadNormXmlUseCase loadNormXmlUseCase;
private LoadRegelungstextXmlUseCase loadRegelungstextXmlUseCase;

@MockitoBean
private UpdateRegelungstextXmlUseCase updateRegelungstextXmlUseCase;
Expand Down Expand Up @@ -189,7 +189,7 @@ void itCallsLoadNormXmlAndReturnsNormXml() throws Exception {
final String xml = "<target></target>";

// When
when(loadNormXmlUseCase.loadNormXml(any())).thenReturn(xml);
when(loadRegelungstextXmlUseCase.loadRegelungstextXml(any())).thenReturn(xml);

// When // Then
mockMvc
Expand All @@ -209,7 +209,7 @@ void itCallsNormServiceAndReturnsNormRender() throws Exception {
final String xml = "<akn:doc></akn:doc>";
final String html = "<div></div>";

when(loadNormXmlUseCase.loadNormXml(any())).thenReturn(xml);
when(loadRegelungstextXmlUseCase.loadRegelungstextXml(any())).thenReturn(xml);
when(transformLegalDocMlToHtmlUseCase.transformLegalDocMlToHtml(any())).thenReturn(html);

// When // Then
Expand All @@ -232,7 +232,7 @@ void itCallsNormServiceAndReturnsNormRenderWithMetadata() throws Exception {
final String xml = "<akn:doc></akn:doc>";
final String html = "<div></div>";

when(loadNormXmlUseCase.loadNormXml(any())).thenReturn(xml);
when(loadRegelungstextXmlUseCase.loadRegelungstextXml(any())).thenReturn(xml);
when(transformLegalDocMlToHtmlUseCase.transformLegalDocMlToHtml(any())).thenReturn(html);

// When // Then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

import de.bund.digitalservice.ris.norms.application.port.input.LoadNormXmlUseCase;
import de.bund.digitalservice.ris.norms.application.port.input.LoadRegelungstextXmlUseCase;
import de.bund.digitalservice.ris.norms.config.SecurityConfig;
import de.bund.digitalservice.ris.norms.domain.entity.eli.DokumentManifestationEli;
import org.junit.jupiter.api.Nested;
Expand Down Expand Up @@ -32,7 +32,7 @@ public class NormManifestationControllerTest {
private MockMvc mockMvc;

@MockitoBean
private LoadNormXmlUseCase loadNormXmlUseCase;
private LoadRegelungstextXmlUseCase loadRegelungstextXmlUseCase;

@Nested
class getNormManifestationXml {
Expand Down Expand Up @@ -72,16 +72,18 @@ void itReturnsNorm() throws Exception {
""";

// When
when(loadNormXmlUseCase.loadNormXml(any())).thenReturn(xml);
when(loadRegelungstextXmlUseCase.loadRegelungstextXml(any())).thenReturn(xml);

// When // Then
mockMvc
.perform(get("/api/v1/norms/{manifestationEli}", eli).accept(MediaType.APPLICATION_XML))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_XML));

verify(loadNormXmlUseCase, times(1))
.loadNormXml(new LoadNormXmlUseCase.Query(DokumentManifestationEli.fromString(eli)));
verify(loadRegelungstextXmlUseCase, times(1))
.loadRegelungstextXml(
new LoadRegelungstextXmlUseCase.Query(DokumentManifestationEli.fromString(eli))
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,67 +173,60 @@ void itThrowsWhenNotFound() {
}

@Nested
class loadNormXml {
class loadRegelungstextXml {

@Test
void itCallsLoadNormAndReturnsXml() {
void itCallsLoadRegelungstextAndReturnsXml() {
// Given
var eli = DokumentExpressionEli.fromString(
"eli/bund/bgbl-1/1964/s593/1964-08-05/1/deu/regelungstext-1"
);

var norm = Norm
.builder()
.regelungstexte(
Set.of(
new Regelungstext(
XmlMapper.toDocument(
"""
<?xml-model href="../../../Grammatiken/legalDocML.de.sch" schematypens="http://purl.oclc.org/dsdl/schematron"?>
<akn:akomaNtoso xmlns:akn="http://Inhaltsdaten.LegalDocML.de/1.7.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://Metadaten.LegalDocML.de/1.7.1/ ../../../Grammatiken/legalDocML.de-metadaten.xsd
http://Inhaltsdaten.LegalDocML.de/1.7.1/ ../../../Grammatiken/legalDocML.de-regelungstextverkuendungsfassung.xsd">
<akn:act name="regelungstext">
<!-- Metadaten -->
<akn:meta eId="meta-1" GUID="82a65581-0ea7-4525-9190-35ff86c977af">
<akn:identification eId="meta-1_ident-1" GUID="100a364a-4680-4c7a-91ad-1b0ad9b68e7f" source="attributsemantik-noch-undefiniert">
<akn:FRBRExpression eId="meta-1_ident-1_frbrexpression-1" GUID="4cce38bb-236b-4947-bee1-e90f3b6c2b8d">
<akn:FRBRthis eId="meta-1_ident-1_frbrexpression-1_frbrthis-1" GUID="c01334e2-f12b-4055-ac82-15ac03c74c78" value="eli/bund/bgbl-1/1964/s593/1964-08-05/1/deu/regelungstext-1" />
</akn:FRBRExpression>
</akn:identification>
</akn:meta>
</akn:act>
</akn:akomaNtoso>
"""
)
)
)
var regelungstext = new Regelungstext(
XmlMapper.toDocument(
"""
<?xml-model href="../../../Grammatiken/legalDocML.de.sch" schematypens="http://purl.oclc.org/dsdl/schematron"?>
<akn:akomaNtoso xmlns:akn="http://Inhaltsdaten.LegalDocML.de/1.7.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://Metadaten.LegalDocML.de/1.7.1/ ../../../Grammatiken/legalDocML.de-metadaten.xsd
http://Inhaltsdaten.LegalDocML.de/1.7.1/ ../../../Grammatiken/legalDocML.de-regelungstextverkuendungsfassung.xsd">
<akn:act name="regelungstext">
<!-- Metadaten -->
<akn:meta eId="meta-1" GUID="82a65581-0ea7-4525-9190-35ff86c977af">
<akn:identification eId="meta-1_ident-1" GUID="100a364a-4680-4c7a-91ad-1b0ad9b68e7f" source="attributsemantik-noch-undefiniert">
<akn:FRBRExpression eId="meta-1_ident-1_frbrexpression-1" GUID="4cce38bb-236b-4947-bee1-e90f3b6c2b8d">
<akn:FRBRthis eId="meta-1_ident-1_frbrexpression-1_frbrthis-1" GUID="c01334e2-f12b-4055-ac82-15ac03c74c78" value="eli/bund/bgbl-1/1964/s593/1964-08-05/1/deu/regelungstext-1" />
</akn:FRBRExpression>
</akn:identification>
</akn:meta>
</akn:act>
</akn:akomaNtoso>
"""
)
.build();
when(loadNormPort.loadNorm(any())).thenReturn(Optional.of(norm));
);
when(loadRegelungstextPort.loadRegelungstext(any())).thenReturn(Optional.of(regelungstext));

// When
var xml = service.loadNormXml(new LoadNormXmlUseCase.Query(eli));
var xml = service.loadRegelungstextXml(new LoadRegelungstextXmlUseCase.Query(eli));

// Then
verify(loadNormPort, times(1))
.loadNorm(argThat(argument -> Objects.equals(argument.eli(), eli.asNormEli())));
verify(loadRegelungstextPort, times(1))
.loadRegelungstext(argThat(argument -> Objects.equals(argument.eli(), eli)));
assertThat(xml).contains("eId=\"meta-1_ident-1_frbrexpression-1_frbrthis-1\"");
}

@Test
void itCallsLoadNormAndThrowsNotFound() {
void itCallsLoadRegelungstextAndThrowsNotFound() {
// Given
var eli = DokumentExpressionEli.fromString(
"eli/bund/bgbl-1/1964/s593/1964-08-05/1/deu/regelungstext-1"
);
when(loadNormPort.loadNorm(any())).thenReturn(Optional.empty());
var query = new LoadNormXmlUseCase.Query(eli);
when(loadRegelungstextPort.loadRegelungstext(any())).thenReturn(Optional.empty());
var query = new LoadRegelungstextXmlUseCase.Query(eli);

// When
assertThatThrownBy(() -> service.loadNormXml(query))
assertThatThrownBy(() -> service.loadRegelungstextXml(query))
// then
.isInstanceOf(NormNotFoundException.class);
.isInstanceOf(RegelungstextNotFoundException.class);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ void itReturnsNotFoundIfManifestationDoesntExist() throws Exception {
mockMvc
.perform(get("/api/v1/norms/{eli}", eli).accept(MediaType.APPLICATION_XML))
.andExpect(status().isNotFound())
.andExpect(jsonPath("type").value("/errors/norm-not-found"))
.andExpect(jsonPath("title").value("Norm not found"))
.andExpect(jsonPath("type").value("/errors/regelungstext-not-found"))
.andExpect(jsonPath("title").value("Regelungstext not found"))
.andExpect(jsonPath("status").value(404))
.andExpect(
jsonPath("detail")
.value(
"Norm with eli eli/bund/bgbl-1/1964/s593/1964-08-05/1/deu/1964-08-05/regelungstext-1.xml does not exist"
"Regelungstext with eli eli/bund/bgbl-1/1964/s593/1964-08-05/1/deu/1964-08-05/regelungstext-1.xml does not exist"
)
)
.andExpect(
Expand Down

0 comments on commit 344a5ae

Please sign in to comment.