From 59e89662cf8115e4e01591fb0fc5de15e19dac28 Mon Sep 17 00:00:00 2001 From: Denis Lugowski Date: Fri, 26 Dec 2025 10:46:18 +0100 Subject: [PATCH] feat: Cleanup old HTML and non-versioned PDF export --- api/legalconsenthub.yml | 29 --- .../ApplicationFormController.kt | 10 - .../ApplicationFormFormatService.kt | 233 ------------------ .../templates/application_form_template.html | 223 ----------------- 4 files changed, 495 deletions(-) delete mode 100644 legalconsenthub-backend/src/main/resources/templates/application_form_template.html diff --git a/api/legalconsenthub.yml b/api/legalconsenthub.yml index 34129c8..8219c93 100644 --- a/api/legalconsenthub.yml +++ b/api/legalconsenthub.yml @@ -170,35 +170,6 @@ paths: "503": $ref: "https://api.swaggerhub.com/domains/smartbear-public/ProblemDetails/1.0.0#/components/responses/ServiceUnavailable" - /application-forms/{id}/html: - get: - summary: Returns the application form rendered as HTML - operationId: getApplicationFormHtml - tags: - - application-form - parameters: - - name: id - in: path - required: true - schema: - type: string - format: uuid - responses: - '200': - description: Application form as HTML - content: - text/html: - schema: - type: string - "400": - $ref: "https://api.swaggerhub.com/domains/smartbear-public/ProblemDetails/1.0.0#/components/responses/BadRequest" - "401": - $ref: "https://api.swaggerhub.com/domains/smartbear-public/ProblemDetails/1.0.0#/components/responses/Unauthorized" - "500": - $ref: "https://api.swaggerhub.com/domains/smartbear-public/ProblemDetails/1.0.0#/components/responses/ServerError" - "503": - $ref: "https://api.swaggerhub.com/domains/smartbear-public/ProblemDetails/1.0.0#/components/responses/ServiceUnavailable" - /application-forms/{id}/submit: post: summary: Submit an application form diff --git a/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form/ApplicationFormController.kt b/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form/ApplicationFormController.kt index 4f52387..e45df3f 100644 --- a/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form/ApplicationFormController.kt +++ b/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form/ApplicationFormController.kt @@ -51,16 +51,6 @@ class ApplicationFormController( ), ) - @PreAuthorize( - "hasAnyRole('CHIEF_EXECUTIVE_OFFICER', 'BUSINESS_DEPARTMENT', 'IT_DEPARTMENT', 'HUMAN_RESOURCES', 'HEAD_OF_WORKS_COUNCIL', 'WORKS_COUNCIL', 'EMPLOYEE')", - ) - override fun getApplicationFormHtml(id: UUID): ResponseEntity { - val applicationForm = applicationFormService.getApplicationFormById(id) - return ResponseEntity.ok( - applicationFormFormatService.generateHtml(applicationForm), - ) - } - @PreAuthorize( "hasAnyRole('CHIEF_EXECUTIVE_OFFICER', 'BUSINESS_DEPARTMENT', 'IT_DEPARTMENT', 'HUMAN_RESOURCES', 'HEAD_OF_WORKS_COUNCIL', 'WORKS_COUNCIL')", ) diff --git a/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form/ApplicationFormFormatService.kt b/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form/ApplicationFormFormatService.kt index fcd5224..d7e07b6 100644 --- a/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form/ApplicationFormFormatService.kt +++ b/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form/ApplicationFormFormatService.kt @@ -7,11 +7,6 @@ import com.betriebsratkanzlei.legalconsenthub.application_form.export.latex.Late import com.betriebsratkanzlei.legalconsenthub.application_form.export.latex.LatexSection import com.betriebsratkanzlei.legalconsenthub.application_form.export.latex.LatexSubSection import com.betriebsratkanzlei.legalconsenthub.application_form.export.latex.RichTextToLatexConverter -import com.betriebsratkanzlei.legalconsenthub.form_element.FormElement -import com.betriebsratkanzlei.legalconsenthub.form_element.FormElementSection -import com.betriebsratkanzlei.legalconsenthub.form_element.FormElementSubSection -import com.betriebsratkanzlei.legalconsenthub.form_element.VisibilityConditionOperator -import com.betriebsratkanzlei.legalconsenthub.form_element.VisibilityConditionType import com.betriebsratkanzlei.legalconsenthub_api.model.ApplicationFormSnapshotDto import com.betriebsratkanzlei.legalconsenthub_api.model.FormElementSectionSnapshotDto import com.betriebsratkanzlei.legalconsenthub_api.model.FormElementSnapshotDto @@ -23,7 +18,6 @@ import java.time.Instant import java.time.LocalDate import java.time.ZoneId import java.time.format.DateTimeFormatter -import java.util.UUID import com.betriebsratkanzlei.legalconsenthub_api.model.VisibilityConditionOperator as VisibilityConditionOperatorDto import com.betriebsratkanzlei.legalconsenthub_api.model.VisibilityConditionType as VisibilityConditionTypeDto @@ -33,11 +27,6 @@ class ApplicationFormFormatService( private val richTextToLatexConverter: RichTextToLatexConverter, private val pdfRenderer: LatexPdfRenderer, ) { - fun generatePdf(applicationForm: ApplicationForm): ByteArray { - val latexContent = generateLatex(applicationForm) - return pdfRenderer.render(latexContent) - } - fun generatePdf( snapshot: ApplicationFormSnapshotDto, createdAt: Instant?, @@ -46,17 +35,6 @@ class ApplicationFormFormatService( return pdfRenderer.render(latexContent) } - fun generateLatex(applicationForm: ApplicationForm): String { - val filteredForm = filterVisibleElements(applicationForm) - val exportModel = buildLatexExportModel(filteredForm) - - val context = - Context().apply { - setVariable("applicationForm", exportModel) - } - return templateEngine.process("application_form_latex_template", context) - } - fun generateLatex( snapshot: ApplicationFormSnapshotDto, createdAt: Instant?, @@ -71,50 +49,6 @@ class ApplicationFormFormatService( return templateEngine.process("application_form_latex_template", context) } - fun generateHtml(applicationForm: ApplicationForm): String { - val filteredForm = filterVisibleElements(applicationForm) - val context = - Context().apply { - setVariable("applicationForm", filteredForm) - } - return templateEngine.process("application_form_template", context) - } - - private fun buildLatexExportModel(applicationForm: ApplicationForm): LatexExportModel { - val dateFormatter = DateTimeFormatter.ofPattern("dd.MM.yyyy") - - return LatexExportModel( - id = applicationForm.id, - name = LatexEscaper.escape(applicationForm.name), - organizationId = LatexEscaper.escape(applicationForm.organizationId), - employer = LatexEscaper.escape("Arbeitgeber der Organisation ${applicationForm.organizationId}"), - worksCouncil = LatexEscaper.escape("Betriebsrat der Organisation ${applicationForm.organizationId}"), - createdAt = applicationForm.createdAt?.atZone(ZoneId.of("Europe/Berlin"))?.format(dateFormatter) ?: "", - sections = - applicationForm.formElementSections.map { section -> - LatexSection( - title = LatexEscaper.escape(section.title), - description = LatexEscaper.escape(section.description), - subsections = - section.formElementSubSections.map { subsection -> - LatexSubSection( - title = LatexEscaper.escape(subsection.title), - subtitle = LatexEscaper.escape(subsection.subtitle), - elements = - subsection.formElements.map { element -> - LatexFormElement( - title = LatexEscaper.escape(element.title), - description = LatexEscaper.escape(element.description), - value = renderElementValue(element), - ) - }, - ) - }, - ) - }, - ) - } - private fun buildLatexExportModel( snapshot: ApplicationFormSnapshotDto, createdAt: Instant?, @@ -153,48 +87,6 @@ class ApplicationFormFormatService( ) } - private fun renderElementValue(element: FormElement): String = - when (element.type.name) { - "TEXTFIELD", "TEXTAREA" -> { - val value = element.options.firstOrNull()?.value - if (value.isNullOrBlank()) "Keine Eingabe" else LatexEscaper.escape(value) - } - "DATE" -> { - val value = element.options.firstOrNull()?.value - if (value.isNullOrBlank()) { - "Kein Datum ausgewählt" - } else { - try { - LocalDate.parse(value).format(DateTimeFormatter.ofPattern("dd.MM.yyyy")) - } catch (e: Exception) { - LatexEscaper.escape(value) - } - } - } - "RICH_TEXT" -> { - val value = element.options.firstOrNull()?.value - if (value.isNullOrBlank()) "Keine Eingabe" else richTextToLatexConverter.convertToLatex(value) - } - "SELECT", "CHECKBOX" -> { - val selected = element.options.filter { it.value == "true" }.map { it.label } - if (selected.isEmpty()) { - "Keine Auswahl getroffen" - } else { - selected.joinToString( - ", ", - ) { LatexEscaper.escape(it) } - } - } - "RADIOBUTTON" -> { - val selected = element.options.firstOrNull { it.value == "true" }?.label - if (selected == null) "Keine Auswahl getroffen" else LatexEscaper.escape(selected) - } - "SWITCH" -> { - if (element.options.any { it.value == "true" }) "Ja" else "Nein" - } - else -> "Keine Auswahl getroffen" - } - private fun renderElementValue(element: FormElementSnapshotDto): String = when (element.type.name) { "TEXTFIELD", "TEXTAREA" -> { @@ -237,66 +129,6 @@ class ApplicationFormFormatService( else -> "Keine Auswahl getroffen" } - private fun filterVisibleElements(applicationForm: ApplicationForm): ApplicationForm { - val allElements = collectAllFormElements(applicationForm) - val formElementsByRef = buildFormElementsByRefMap(allElements) - val visibilityMap = evaluateVisibility(allElements, formElementsByRef) - - val filteredSections = - applicationForm.formElementSections - .filter { !it.isTemplate } - .mapNotNull { section -> - val filteredSubSections = - section.formElementSubSections - .mapNotNull { subsection -> - val filteredElements = - subsection.formElements.filter { element -> - visibilityMap[element.id] ?: true - } - if (filteredElements.isEmpty()) { - null - } else { - FormElementSubSection( - id = subsection.id, - title = subsection.title, - subtitle = subsection.subtitle, - formElements = filteredElements.toMutableList(), - formElementSection = null, - ) - } - } - if (filteredSubSections.isEmpty()) { - null - } else { - FormElementSection( - id = section.id, - title = section.title, - shortTitle = section.shortTitle, - description = section.description, - isTemplate = section.isTemplate, - templateReference = section.templateReference, - titleTemplate = section.titleTemplate, - spawnedFromElementReference = section.spawnedFromElementReference, - formElementSubSections = filteredSubSections.toMutableList(), - applicationForm = null, - ) - } - } - - return ApplicationForm( - id = applicationForm.id, - name = applicationForm.name, - status = applicationForm.status, - createdBy = applicationForm.createdBy, - lastModifiedBy = applicationForm.lastModifiedBy, - createdAt = applicationForm.createdAt, - modifiedAt = applicationForm.modifiedAt, - isTemplate = applicationForm.isTemplate, - organizationId = applicationForm.organizationId, - formElementSections = filteredSections.toMutableList(), - ) - } - private fun filterVisibleElements(snapshot: ApplicationFormSnapshotDto): ApplicationFormSnapshotDto { val allElements = collectAllFormElements(snapshot) val formElementsByRef = buildSnapshotFormElementsByRefMap(allElements) @@ -319,21 +151,11 @@ class ApplicationFormFormatService( return snapshot.copy(sections = filteredSections) } - private fun collectAllFormElements(applicationForm: ApplicationForm): List = - applicationForm.formElementSections - .flatMap { it.formElementSubSections } - .flatMap { it.formElements } - private fun collectAllFormElements(snapshot: ApplicationFormSnapshotDto): List = snapshot.sections .flatMap(FormElementSectionSnapshotDto::subsections) .flatMap(FormElementSubSectionSnapshotDto::elements) - private fun buildFormElementsByRefMap(allElements: List): Map = - allElements - .mapNotNull { elem -> elem.reference?.let { it to elem } } - .toMap() - private fun buildSnapshotFormElementsByRefMap( allElements: List, ): Map = @@ -341,38 +163,6 @@ class ApplicationFormFormatService( .mapNotNull { elem -> elem.reference?.let { it to elem } } .toMap() - private fun evaluateVisibility( - allElements: List, - formElementsByRef: Map, - ): Map { - val visibilityMap = mutableMapOf() - - allElements.forEach { element -> - visibilityMap[element.id] = isElementVisible(element, formElementsByRef) - } - - return visibilityMap - } - - private fun isElementVisible( - element: FormElement, - formElementsByRef: Map, - ): Boolean { - val condition = element.visibilityCondition ?: return true - - // Don't show if source element is missing - val sourceElement = formElementsByRef[condition.sourceFormElementReference] ?: return false - - val sourceValue = getFormElementValue(sourceElement) - val conditionMet = - evaluateCondition(sourceValue, condition.formElementExpectedValue, condition.formElementOperator) - - return when (condition.formElementConditionType) { - VisibilityConditionType.SHOW -> conditionMet - VisibilityConditionType.HIDE -> !conditionMet - } - } - private fun isElementVisible( element: FormElementSnapshotDto, formElementsByRef: Map, @@ -391,17 +181,6 @@ class ApplicationFormFormatService( } } - private fun getFormElementValue(element: FormElement): String = - when (element.type.name) { - "SELECT", - "RADIOBUTTON", - -> element.options.firstOrNull { it.value == "true" }?.label ?: "" - "CHECKBOX", - "SWITCH", - -> if (element.options.any { it.value == "true" }) "true" else "false" - else -> element.options.firstOrNull()?.value ?: "" - } - private fun getFormElementValue(element: FormElementSnapshotDto): String = when (element.type.name) { "SELECT", @@ -413,18 +192,6 @@ class ApplicationFormFormatService( else -> element.options.firstOrNull()?.value ?: "" } - private fun evaluateCondition( - actualValue: String, - expectedValue: String, - operator: VisibilityConditionOperator, - ): Boolean = - when (operator) { - VisibilityConditionOperator.EQUALS -> actualValue.equals(expectedValue, ignoreCase = true) - VisibilityConditionOperator.NOT_EQUALS -> !actualValue.equals(expectedValue, ignoreCase = true) - VisibilityConditionOperator.IS_EMPTY -> actualValue.isEmpty() - VisibilityConditionOperator.IS_NOT_EMPTY -> actualValue.isNotEmpty() - } - private fun evaluateCondition( actualValue: String, expectedValue: String, diff --git a/legalconsenthub-backend/src/main/resources/templates/application_form_template.html b/legalconsenthub-backend/src/main/resources/templates/application_form_template.html deleted file mode 100644 index b503c2a..0000000 --- a/legalconsenthub-backend/src/main/resources/templates/application_form_template.html +++ /dev/null @@ -1,223 +0,0 @@ - - - - - - - - -
-

-
- -
-
- - -
-
- - -
-
- - -
-
- - -
-
- -
-

Formularelemente

-
-

-

- -
-

-

- -
-
-

- -
-
-
-

-
-

Keine Eingabe

-
- -
-
-

-
-

Keine Eingabe

-
- -
-
-

-
-

Kein Datum ausgewählt

-
- -
-
-
-
-

Keine Eingabe

-
- -
-
    -
  • -
-

Keine Auswahl getroffen

-
- -
-

-

Keine Auswahl getroffen

-
- -
-
    -
  • -
-

Keine Auswahl getroffen

-
- -
-

Nein

-

Ja

-
- -
-
    -
  • -
-

Keine Auswahl getroffen

-
-
-
-
-
-
- - - -