Skip to content

Commit a300182

Browse files
Simplify rendering endpoint
RISDEV-0000
1 parent 406101e commit a300182

File tree

6 files changed

+19
-130
lines changed

6 files changed

+19
-130
lines changed

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

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
import static org.springframework.http.MediaType.*;
44

5-
import de.bund.digitalservice.ris.norms.adapter.input.restapi.schema.PreviewRequestSchema;
65
import de.bund.digitalservice.ris.norms.application.port.input.TransformLegalDocMlToHtmlUseCase;
7-
import java.time.Instant;
8-
import java.util.Optional;
96
import org.springframework.http.ResponseEntity;
107
import org.springframework.web.bind.annotation.*;
118

@@ -26,29 +23,20 @@ public RenderingController(TransformLegalDocMlToHtmlUseCase transformLegalDocMlT
2623
/**
2724
* Retrieves the HTML rendering of a norm.
2825
*
29-
* @param previewRequestSchema The Request schema for rendering a norm. It includes the norm xml
30-
* and any additional norms that should be used instead of the saved once for rendering the
31-
* norm.
26+
* @param xml The xml that should be rendered.
3227
* @param showMetadata A boolean indicating whether metadata should be included in the rendering.
3328
* @param snippet A boolean indicating whether the XML passed is just a snippet.
34-
* @param atIsoDate ISO date string indicating which modifications should be applied before the
35-
* HTML gets rendered and returned. If no date is provided the current date is used.
3629
* @return A {@link ResponseEntity} containing the HTML rendering of the law document.
3730
*/
38-
@PostMapping(consumes = { APPLICATION_JSON_VALUE }, produces = { TEXT_HTML_VALUE })
31+
@PostMapping(consumes = { APPLICATION_XML_VALUE }, produces = { TEXT_HTML_VALUE })
3932
public ResponseEntity<String> getHtmlPreview(
40-
@RequestBody final PreviewRequestSchema previewRequestSchema,
33+
@RequestBody final String xml,
4134
@RequestParam(defaultValue = "false") boolean showMetadata,
42-
@RequestParam(defaultValue = "false") boolean snippet,
43-
@RequestParam Optional<Instant> atIsoDate
35+
@RequestParam(defaultValue = "false") boolean snippet
4436
) {
4537
return ResponseEntity.ok(
4638
this.transformLegalDocMlToHtmlUseCase.transformLegalDocMlToHtml(
47-
new TransformLegalDocMlToHtmlUseCase.Query(
48-
previewRequestSchema.getRegelungstext(),
49-
showMetadata,
50-
snippet
51-
)
39+
new TransformLegalDocMlToHtmlUseCase.Query(xml, showMetadata, snippet)
5240
)
5341
);
5442
}

backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/input/restapi/schema/PreviewRequestSchema.java

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

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

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,8 @@ void itThrowsXmlProcessingException() throws Exception {
4848
post("/api/v1/renderings")
4949
.accept(MediaType.TEXT_HTML)
5050
.with(csrf())
51-
.contentType(MediaType.APPLICATION_JSON)
52-
.content(
53-
"""
54-
55-
{
56-
"regelungstext": "<law>original-law</law>"
57-
}
58-
"""
59-
)
51+
.contentType(MediaType.APPLICATION_XML)
52+
.content("<law>original-law</law>")
6053
)
6154
.andExpect(status().isInternalServerError())
6255
.andExpect(jsonPath("type").value("/errors/xml-processing-error"))
@@ -77,15 +70,8 @@ void getHtmlPreviewWithShowMetadataTrue() throws Exception {
7770
.queryParam("showMetadata", "true")
7871
.accept(MediaType.TEXT_HTML)
7972
.with(csrf())
80-
.contentType(MediaType.APPLICATION_JSON)
81-
.content(
82-
"""
83-
84-
{
85-
"regelungstext": "<law>original-law</law>"
86-
}
87-
"""
88-
)
73+
.contentType(MediaType.APPLICATION_XML)
74+
.content("<law>original-law</law>")
8975
)
9076
.andExpect(status().isOk())
9177
.andExpect(content().string("<html></html>"));
@@ -107,14 +93,8 @@ void getHtmlPreviewWithShowMetadataFalse() throws Exception {
10793
.queryParam("showMetadata", "false")
10894
.accept(MediaType.TEXT_HTML)
10995
.with(csrf())
110-
.contentType(MediaType.APPLICATION_JSON)
111-
.content(
112-
"""
113-
{
114-
"regelungstext": "<law>original-law</law>"
115-
}
116-
"""
117-
)
96+
.contentType(MediaType.APPLICATION_XML)
97+
.content("<law>original-law</law>")
11898
)
11999
.andExpect(status().isOk())
120100
.andExpect(content().string("<html></html>"));
@@ -135,14 +115,8 @@ void getHtmlPreviewWithSnippetTrue() throws Exception {
135115
.queryParam("snippet", "true")
136116
.accept(MediaType.TEXT_HTML)
137117
.with(csrf())
138-
.contentType(MediaType.APPLICATION_JSON)
139-
.content(
140-
"""
141-
{
142-
"regelungstext": "<law>original-law</law>"
143-
}
144-
"""
145-
)
118+
.contentType(MediaType.APPLICATION_XML)
119+
.content("<law>original-law</law>")
146120
)
147121
.andExpect(status().isOk())
148122
.andExpect(content().string("<html></html>"));

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
55
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
66

7-
import com.google.gson.JsonObject;
87
import de.bund.digitalservice.ris.norms.adapter.output.database.repository.DokumentRepository;
98
import de.bund.digitalservice.ris.norms.domain.entity.Fixtures;
109
import de.bund.digitalservice.ris.norms.integration.BaseIntegrationTest;
@@ -35,20 +34,12 @@ class getHtmlPreview {
3534

3635
@Test
3736
void itReturnsRender() throws Exception {
38-
// Given
39-
var jsonPayload = new JsonObject();
40-
jsonPayload.addProperty(
41-
"regelungstext",
42-
Fixtures.loadTextFromDisk("NormWithPassiveModifications.xml")
43-
);
44-
45-
// When // Then
4637
mockMvc
4738
.perform(
4839
post("/api/v1/renderings?atIsoDate=2024-01-01T00:00:00.0Z")
4940
.accept(MediaType.TEXT_HTML)
50-
.contentType(MediaType.APPLICATION_JSON)
51-
.content(jsonPayload.toString())
41+
.contentType(MediaType.APPLICATION_XML)
42+
.content(Fixtures.loadTextFromDisk("NormWithPassiveModifications.xml"))
5243
)
5344
.andExpect(status().isOk())
5445
.andExpect(

frontend/src/composables/useNormRender.spec.ts

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -33,48 +33,13 @@ describe("useNormRenderHtml", () => {
3333
method: "POST",
3434
headers: expect.objectContaining({
3535
Accept: "text/html",
36-
"Content-Type": "application/json",
36+
"Content-Type": "application/xml",
3737
}),
3838
body: expect.stringContaining(xml),
3939
}),
4040
)
4141
})
4242

43-
it("support setting a date", async () => {
44-
const fetchSpy = vi.spyOn(global, "fetch").mockResolvedValue(new Response())
45-
46-
const { useNormRenderHtml } = await import("./useNormRender")
47-
const { isFinished } = useNormRenderHtml("<law></law>", {
48-
showMetadata: true,
49-
at: new Date(Date.UTC(2023, 0, 1)),
50-
})
51-
await vi.waitUntil(() => isFinished.value)
52-
53-
expect(fetchSpy).toHaveBeenCalledWith(
54-
"/api/v1/renderings?showMetadata=true&atIsoDate=2023-01-01T00%3A00%3A00.000Z",
55-
expect.anything(),
56-
)
57-
})
58-
59-
it("support setting custom norms", async () => {
60-
const fetchSpy = vi.spyOn(global, "fetch").mockResolvedValue(new Response())
61-
62-
const { useNormRenderHtml } = await import("./useNormRender")
63-
64-
const { isFinished } = useNormRenderHtml("<law></law>", {
65-
showMetadata: true,
66-
customNorms: ["<xml>other-norm</xml>"],
67-
})
68-
await vi.waitUntil(() => isFinished.value)
69-
70-
expect(fetchSpy).toHaveBeenCalledWith(
71-
"/api/v1/renderings?showMetadata=true",
72-
expect.objectContaining({
73-
body: expect.stringMatching("<xml>other-norm</xml>"),
74-
}),
75-
)
76-
})
77-
7843
it("calls the API with snippet set to true", async () => {
7944
const fetchSpy = vi
8045
.spyOn(global, "fetch")
@@ -93,7 +58,7 @@ describe("useNormRenderHtml", () => {
9358
method: "POST",
9459
headers: expect.objectContaining({
9560
Accept: "text/html",
96-
"Content-Type": "application/json",
61+
"Content-Type": "application/xml",
9762
}),
9863
body: expect.stringContaining(xml),
9964
}),

frontend/src/composables/useNormRender.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ export function useNormRenderHtml(
1515
showMetadata?: MaybeRefOrGetter<boolean>
1616
/** If the XML sent is only a snippet of a norm */
1717
snippet?: MaybeRefOrGetter<boolean>
18-
/** Passive modifications coming into effect before this date should be applied before rendering the HTML */
19-
at?: MaybeRefOrGetter<Date | undefined>
20-
/** The XMLs of norms which are referenced by the norm (e.g. in passiveModifications) and should be used instead of the data stored. */
21-
customNorms?: MaybeRefOrGetter<string[] | undefined>
2218
},
2319
): UseFetchReturn<string> {
2420
return useApiFetch<string>(
@@ -31,25 +27,18 @@ export function useNormRenderHtml(
3127
searchParams.set("showMetadata", showMetadataVal ? "true" : "false")
3228
const snippetVal = toValue(options?.snippet)
3329
if (snippetVal) searchParams.set("snippet", snippetVal ? "true" : "false")
34-
const atVal = toValue(options?.at)
35-
if (atVal) searchParams.set("atIsoDate", atVal.toISOString())
3630

3731
const queryString = searchParams.toString()
3832
return queryString ? `renderings?${queryString}` : "renderings"
3933
}),
4034
{
4135
headers: {
4236
Accept: "text/html",
43-
"Content-Type": "application/json",
37+
"Content-Type": "application/xml",
4438
},
4539
},
4640
{
4741
refetch: true,
4842
},
49-
).post(
50-
computed(() => ({
51-
regelungstext: toValue(normXml),
52-
customRegelungstexte: toValue(options?.customNorms),
53-
})),
54-
)
43+
).post(normXml)
5544
}

0 commit comments

Comments
 (0)