major(fullstack): Add dynamic section spawning, removal of app. form create DTOs,

This commit is contained in:
2025-12-15 19:12:00 +01:00
parent 7bacff967e
commit 844ab8661c
47 changed files with 1283 additions and 511 deletions

View File

@@ -2,8 +2,7 @@ package com.betriebsratkanzlei.legalconsenthub.application_form
import com.betriebsratkanzlei.legalconsenthub_api.api.ApplicationFormApi
import com.betriebsratkanzlei.legalconsenthub_api.model.ApplicationFormDto
import com.betriebsratkanzlei.legalconsenthub_api.model.CreateApplicationFormDto
import com.betriebsratkanzlei.legalconsenthub_api.model.CreateFormElementDto
import com.betriebsratkanzlei.legalconsenthub_api.model.FormElementDto
import com.betriebsratkanzlei.legalconsenthub_api.model.PagedApplicationFormDto
import org.springframework.core.io.ByteArrayResource
import org.springframework.core.io.Resource
@@ -24,13 +23,11 @@ class ApplicationFormController(
@PreAuthorize(
"hasAnyRole('CHIEF_EXECUTIVE_OFFICER', 'BUSINESS_DEPARTMENT', 'IT_DEPARTMENT', 'HUMAN_RESOURCES', 'HEAD_OF_WORKS_COUNCIL', 'WORKS_COUNCIL')",
)
override fun createApplicationForm(
createApplicationFormDto: CreateApplicationFormDto,
): ResponseEntity<ApplicationFormDto> {
val updatedCreateApplicationFormDto = createApplicationFormDto.copy(isTemplate = false)
override fun createApplicationForm(applicationFormDto: ApplicationFormDto): ResponseEntity<ApplicationFormDto> {
val updatedApplicationFormDto = applicationFormDto.copy(isTemplate = false)
return ResponseEntity.ok(
applicationFormMapper.toApplicationFormDto(
applicationFormService.createApplicationForm(updatedCreateApplicationFormDto),
applicationFormService.createApplicationForm(updatedApplicationFormDto),
),
)
}
@@ -88,7 +85,7 @@ class ApplicationFormController(
): ResponseEntity<ApplicationFormDto> =
ResponseEntity.ok(
applicationFormMapper.toApplicationFormDto(
applicationFormService.updateApplicationForm(applicationFormDto),
applicationFormService.updateApplicationForm(id, applicationFormDto),
),
)
@@ -117,14 +114,14 @@ class ApplicationFormController(
applicationFormId: UUID,
subsectionId: UUID,
position: Int,
createFormElementDto: CreateFormElementDto,
formElementDto: FormElementDto,
): ResponseEntity<ApplicationFormDto> =
ResponseEntity.status(201).body(
applicationFormMapper.toApplicationFormDto(
applicationFormService.addFormElementToSubSection(
applicationFormId,
subsectionId,
createFormElementDto,
formElementDto,
position,
),
),

View File

@@ -43,38 +43,45 @@ class ApplicationFormFormatService(
val visibilityMap = evaluateVisibility(formElementsByRef)
val filteredSections =
applicationForm.formElementSections.mapNotNull { section ->
val filteredSubSections =
section.formElementSubSections.mapNotNull { subsection ->
val filteredElements =
subsection.formElements.filter { element ->
visibilityMap[element.id] == true
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 (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,
)
}
if (filteredSubSections.isEmpty()) {
null
} else {
FormElementSection(
id = section.id,
title = section.title,
shortTitle = section.shortTitle,
description = section.description,
formElementSubSections = filteredSubSections.toMutableList(),
applicationForm = null,
)
}
}
return ApplicationForm(
id = applicationForm.id,
@@ -122,9 +129,10 @@ class ApplicationFormFormatService(
val sourceElement = formElementsByRef[condition.sourceFormElementReference] ?: return false
val sourceValue = getFormElementValue(sourceElement)
val conditionMet = evaluateCondition(sourceValue, condition.expectedValue, condition.operator)
val conditionMet =
evaluateCondition(sourceValue, condition.formElementExpectedValue, condition.formElementOperator)
return when (condition.conditionType) {
return when (condition.formElementConditionType) {
VisibilityConditionType.SHOW -> conditionMet
VisibilityConditionType.HIDE -> !conditionMet
}

View File

@@ -4,9 +4,9 @@ import com.betriebsratkanzlei.legalconsenthub.form_element.FormElementSectionMap
import com.betriebsratkanzlei.legalconsenthub.user.UserMapper
import com.betriebsratkanzlei.legalconsenthub.user.UserService
import com.betriebsratkanzlei.legalconsenthub_api.model.ApplicationFormDto
import com.betriebsratkanzlei.legalconsenthub_api.model.CreateApplicationFormDto
import org.springframework.stereotype.Component
import java.time.LocalDateTime
import java.util.UUID
@Component
class ApplicationFormMapper(
@@ -16,7 +16,7 @@ class ApplicationFormMapper(
) {
fun toApplicationFormDto(applicationForm: ApplicationForm): ApplicationFormDto =
ApplicationFormDto(
id = applicationForm.id ?: throw IllegalStateException("ApplicationForm ID must not be null!"),
id = applicationForm.id,
name = applicationForm.name,
formElementSections =
applicationForm.formElementSections.map {
@@ -34,45 +34,53 @@ class ApplicationFormMapper(
status = applicationForm.status,
)
fun toApplicationForm(applicationForm: ApplicationFormDto): ApplicationForm {
val form =
ApplicationForm(
id = applicationForm.id,
name = applicationForm.name,
isTemplate = applicationForm.isTemplate,
organizationId = applicationForm.organizationId,
status = applicationForm.status,
createdBy = userMapper.toUser(applicationForm.createdBy),
lastModifiedBy = userMapper.toUser(applicationForm.lastModifiedBy),
createdAt = applicationForm.createdAt,
modifiedAt = applicationForm.modifiedAt,
)
form.formElementSections =
applicationForm.formElementSections
.map {
formElementSectionMapper.toFormElementSection(it, form)
}.toMutableList()
return form
}
fun toApplicationForm(createApplicationFormDto: CreateApplicationFormDto): ApplicationForm {
fun toNewApplicationForm(applicationFormDto: ApplicationFormDto): ApplicationForm {
val currentUser = userService.getCurrentUser()
val applicationForm =
ApplicationForm(
name = createApplicationFormDto.name,
isTemplate = createApplicationFormDto.isTemplate,
organizationId = createApplicationFormDto.organizationId ?: "",
id = null,
name = applicationFormDto.name,
isTemplate = applicationFormDto.isTemplate,
organizationId = applicationFormDto.organizationId ?: "",
status =
createApplicationFormDto.status
applicationFormDto.status
?: com.betriebsratkanzlei.legalconsenthub_api.model.ApplicationFormStatus.DRAFT,
createdBy = currentUser,
lastModifiedBy = currentUser,
)
applicationForm.formElementSections =
createApplicationFormDto.formElementSections
.map { formElementSectionMapper.toFormElementSection(it, applicationForm) }
applicationFormDto.formElementSections
.map { formElementSectionMapper.toNewFormElementSection(it, applicationForm) }
.toMutableList()
return applicationForm
}
fun toUpdatedApplicationForm(
id: UUID,
applicationFormDto: ApplicationFormDto,
existingApplicationForm: ApplicationForm,
): ApplicationForm {
val currentUser = userService.getCurrentUser()
val form =
ApplicationForm(
id = id,
name = applicationFormDto.name,
isTemplate = applicationFormDto.isTemplate,
organizationId = applicationFormDto.organizationId ?: existingApplicationForm.organizationId,
status = applicationFormDto.status ?: existingApplicationForm.status,
createdBy = existingApplicationForm.createdBy,
lastModifiedBy = currentUser,
createdAt = existingApplicationForm.createdAt,
modifiedAt = existingApplicationForm.modifiedAt,
)
form.formElementSections =
applicationFormDto.formElementSections
.map { formElementSectionMapper.toFormElementSection(it, form) }
.toMutableList()
return form
}
}

View File

@@ -13,9 +13,8 @@ import com.betriebsratkanzlei.legalconsenthub.notification.NotificationService
import com.betriebsratkanzlei.legalconsenthub.user.UserService
import com.betriebsratkanzlei.legalconsenthub_api.model.ApplicationFormDto
import com.betriebsratkanzlei.legalconsenthub_api.model.ApplicationFormStatus
import com.betriebsratkanzlei.legalconsenthub_api.model.CreateApplicationFormDto
import com.betriebsratkanzlei.legalconsenthub_api.model.CreateFormElementDto
import com.betriebsratkanzlei.legalconsenthub_api.model.CreateNotificationDto
import com.betriebsratkanzlei.legalconsenthub_api.model.FormElementDto
import com.betriebsratkanzlei.legalconsenthub_api.model.NotificationType
import org.springframework.context.ApplicationEventPublisher
import org.springframework.data.domain.Page
@@ -33,8 +32,8 @@ class ApplicationFormService(
private val userService: UserService,
private val eventPublisher: ApplicationEventPublisher,
) {
fun createApplicationForm(createApplicationFormDto: CreateApplicationFormDto): ApplicationForm {
val applicationForm = applicationFormMapper.toApplicationForm(createApplicationFormDto)
fun createApplicationForm(applicationFormDto: ApplicationFormDto): ApplicationForm {
val applicationForm = applicationFormMapper.toNewApplicationForm(applicationFormDto)
val savedApplicationForm: ApplicationForm
try {
savedApplicationForm = applicationFormRepository.save(applicationForm)
@@ -67,17 +66,26 @@ class ApplicationFormService(
return applicationFormRepository.findAllByIsTemplateFalseAndOrganizationId(organizationId, pageable)
}
fun updateApplicationForm(applicationFormDto: ApplicationFormDto): ApplicationForm {
val existingApplicationForm = getApplicationFormById(applicationFormDto.id)
fun updateApplicationForm(
id: UUID,
applicationFormDto: ApplicationFormDto,
): ApplicationForm {
println("Updating ApplicationForm: $applicationFormDto")
val existingApplicationForm = getApplicationFormById(id)
val existingSnapshot = versionService.createSnapshot(existingApplicationForm)
val applicationForm = applicationFormMapper.toApplicationForm(applicationFormDto)
val applicationForm =
applicationFormMapper.toUpdatedApplicationForm(
id,
applicationFormDto,
existingApplicationForm,
)
val updatedApplicationForm: ApplicationForm
try {
updatedApplicationForm = applicationFormRepository.save(applicationForm)
} catch (e: Exception) {
throw ApplicationFormNotUpdatedException(e, applicationFormDto.id)
throw ApplicationFormNotUpdatedException(e, id)
}
val currentUser = userService.getCurrentUser()
@@ -160,7 +168,7 @@ class ApplicationFormService(
fun addFormElementToSubSection(
applicationFormId: UUID,
subsectionId: UUID,
createFormElementDto: CreateFormElementDto,
formElementDto: FormElementDto,
position: Int,
): ApplicationForm {
val applicationForm = getApplicationFormById(applicationFormId)
@@ -171,7 +179,7 @@ class ApplicationFormService(
.find { it.id == subsectionId }
?: throw IllegalArgumentException("FormElementSubSection with id $subsectionId not found")
val newFormElement = formElementMapper.toFormElement(createFormElementDto, subsection)
val newFormElement = formElementMapper.toNewFormElement(formElementDto, subsection)
if (position >= 0 && position < subsection.formElements.size) {
subsection.formElements.add(position, newFormElement)

View File

@@ -4,7 +4,6 @@ import com.betriebsratkanzlei.legalconsenthub.application_form.ApplicationFormMa
import com.betriebsratkanzlei.legalconsenthub.application_form.PagedApplicationFormMapper
import com.betriebsratkanzlei.legalconsenthub_api.api.ApplicationFormTemplateApi
import com.betriebsratkanzlei.legalconsenthub_api.model.ApplicationFormDto
import com.betriebsratkanzlei.legalconsenthub_api.model.CreateApplicationFormDto
import com.betriebsratkanzlei.legalconsenthub_api.model.PagedApplicationFormDto
import org.springframework.http.ResponseEntity
import org.springframework.security.access.prepost.PreAuthorize
@@ -21,11 +20,13 @@ class ApplicationFormTemplateController(
"hasAnyRole('CHIEF_EXECUTIVE_OFFICER', 'BUSINESS_DEPARTMENT', 'IT_DEPARTMENT', 'HUMAN_RESOURCES', 'HEAD_OF_WORKS_COUNCIL', 'WORKS_COUNCIL')",
)
override fun createApplicationFormTemplate(
createApplicationFormDto: CreateApplicationFormDto,
applicationFormDto: ApplicationFormDto,
): ResponseEntity<ApplicationFormDto> =
ResponseEntity.ok(
applicationFormMapper.toApplicationFormDto(
applicationFormTemplateService.createApplicationFormTemplate(createApplicationFormDto),
applicationFormTemplateService.createApplicationFormTemplate(
applicationFormDto.copy(isTemplate = true),
),
),
)
@@ -58,7 +59,7 @@ class ApplicationFormTemplateController(
): ResponseEntity<ApplicationFormDto> =
ResponseEntity.ok(
applicationFormMapper.toApplicationFormDto(
applicationFormTemplateService.updateApplicationFormTemplate(applicationFormDto),
applicationFormTemplateService.updateApplicationFormTemplate(id, applicationFormDto),
),
)

View File

@@ -8,7 +8,6 @@ import com.betriebsratkanzlei.legalconsenthub.error.ApplicationFormNotDeletedExc
import com.betriebsratkanzlei.legalconsenthub.error.ApplicationFormNotFoundException
import com.betriebsratkanzlei.legalconsenthub.error.ApplicationFormNotUpdatedException
import com.betriebsratkanzlei.legalconsenthub_api.model.ApplicationFormDto
import com.betriebsratkanzlei.legalconsenthub_api.model.CreateApplicationFormDto
import org.springframework.data.domain.Page
import org.springframework.data.domain.PageRequest
import org.springframework.stereotype.Service
@@ -19,8 +18,8 @@ class ApplicationFormTemplateService(
private val applicationFormRepository: ApplicationFormRepository,
private val applicationFormMapper: ApplicationFormMapper,
) {
fun createApplicationFormTemplate(createApplicationFormDto: CreateApplicationFormDto): ApplicationForm {
val applicationForm = applicationFormMapper.toApplicationForm(createApplicationFormDto)
fun createApplicationFormTemplate(applicationFormDto: ApplicationFormDto): ApplicationForm {
val applicationForm = applicationFormMapper.toNewApplicationForm(applicationFormDto)
val savedApplicationForm: ApplicationForm
try {
savedApplicationForm = applicationFormRepository.save(applicationForm)
@@ -41,14 +40,23 @@ class ApplicationFormTemplateService(
return applicationFormRepository.findAllByIsTemplateTrue(pageable)
}
fun updateApplicationFormTemplate(applicationFormDto: ApplicationFormDto): ApplicationForm {
val applicationForm = applicationFormMapper.toApplicationForm(applicationFormDto)
fun updateApplicationFormTemplate(
id: UUID,
applicationFormDto: ApplicationFormDto,
): ApplicationForm {
val existingApplicationForm = getApplicationFormTemplateById(id)
val applicationForm =
applicationFormMapper.toUpdatedApplicationForm(
id,
applicationFormDto,
existingApplicationForm,
)
val updatedApplicationForm: ApplicationForm
try {
updatedApplicationForm = applicationFormRepository.save(applicationForm)
} catch (e: Exception) {
throw ApplicationFormNotUpdatedException(e, applicationFormDto.id)
throw ApplicationFormNotUpdatedException(e, id)
}
return updatedApplicationForm

View File

@@ -8,6 +8,7 @@ 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.FormOption
import com.betriebsratkanzlei.legalconsenthub.form_element.SectionSpawnTriggerMapper
import com.betriebsratkanzlei.legalconsenthub.user.User
import com.betriebsratkanzlei.legalconsenthub_api.model.ApplicationFormSnapshotDto
import com.betriebsratkanzlei.legalconsenthub_api.model.FormElementSectionSnapshotDto
@@ -24,6 +25,7 @@ class ApplicationFormVersionService(
private val versionRepository: ApplicationFormVersionRepository,
private val applicationFormRepository: ApplicationFormRepository,
private val objectMapper: ObjectMapper,
private val spawnTriggerMapper: SectionSpawnTriggerMapper,
) {
@Transactional
fun createVersion(
@@ -103,6 +105,10 @@ class ApplicationFormVersionService(
title = section.title,
shortTitle = section.shortTitle,
description = section.description,
isTemplate = section.isTemplate,
templateReference = section.templateReference,
titleTemplate = section.titleTemplate,
spawnedFromElementReference = section.spawnedFromElementReference,
subsections =
section.formElementSubSections.map { subsection ->
FormElementSubSectionSnapshotDto(
@@ -111,6 +117,7 @@ class ApplicationFormVersionService(
elements =
subsection.formElements.map { element ->
FormElementSnapshotDto(
reference = element.reference,
title = element.title,
description = element.description,
type = element.type,
@@ -123,6 +130,11 @@ class ApplicationFormVersionService(
employeeDataCategory = option.employeeDataCategory,
)
},
sectionSpawnTrigger =
element.sectionSpawnTrigger?.let {
spawnTriggerMapper.toSectionSpawnTriggerDto(it)
},
isClonable = element.isClonable,
)
},
)
@@ -140,6 +152,10 @@ class ApplicationFormVersionService(
title = sectionSnapshot.title,
shortTitle = sectionSnapshot.shortTitle,
description = sectionSnapshot.description,
isTemplate = sectionSnapshot.isTemplate ?: false,
templateReference = sectionSnapshot.templateReference,
titleTemplate = sectionSnapshot.titleTemplate,
spawnedFromElementReference = sectionSnapshot.spawnedFromElementReference,
applicationForm = applicationForm,
)
@@ -154,6 +170,7 @@ class ApplicationFormVersionService(
subsectionSnapshot.elements.forEach { elementSnapshot ->
val element =
FormElement(
reference = elementSnapshot.reference,
title = elementSnapshot.title,
description = elementSnapshot.description,
type = elementSnapshot.type,
@@ -168,6 +185,11 @@ class ApplicationFormVersionService(
employeeDataCategory = optionDto.employeeDataCategory,
)
}.toMutableList(),
sectionSpawnTrigger =
elementSnapshot.sectionSpawnTrigger?.let {
spawnTriggerMapper.toSectionSpawnTrigger(it)
},
isClonable = elementSnapshot.isClonable ?: false,
)
subsection.formElements.add(element)
}

View File

@@ -4,6 +4,7 @@ import com.betriebsratkanzlei.legalconsenthub_api.model.FormElementType
import jakarta.persistence.CollectionTable
import jakarta.persistence.Column
import jakarta.persistence.ElementCollection
import jakarta.persistence.Embedded
import jakarta.persistence.Entity
import jakarta.persistence.GeneratedValue
import jakarta.persistence.Id
@@ -27,5 +28,9 @@ class FormElement(
@ManyToOne
@JoinColumn(name = "form_element_sub_section_id", nullable = false)
var formElementSubSection: FormElementSubSection? = null,
@Embedded
var visibilityCondition: FormElementVisibilityCondition? = null,
@Embedded
var sectionSpawnTrigger: SectionSpawnTrigger? = null,
var isClonable: Boolean = false,
)

View File

@@ -1,6 +1,5 @@
package com.betriebsratkanzlei.legalconsenthub.form_element
import com.betriebsratkanzlei.legalconsenthub_api.model.CreateFormElementDto
import com.betriebsratkanzlei.legalconsenthub_api.model.FormElementDto
import org.springframework.stereotype.Component
@@ -8,10 +7,11 @@ import org.springframework.stereotype.Component
class FormElementMapper(
private val formOptionMapper: FormOptionMapper,
private val visibilityConditionMapper: FormElementVisibilityConditionMapper,
private val spawnTriggerMapper: SectionSpawnTriggerMapper,
) {
fun toFormElementDto(formElement: FormElement): FormElementDto =
FormElementDto(
id = formElement.id ?: throw IllegalStateException("FormElement ID must not be null!"),
id = formElement.id,
reference = formElement.reference,
title = formElement.title,
description = formElement.description,
@@ -24,6 +24,11 @@ class FormElementMapper(
formElement.visibilityCondition?.let {
visibilityConditionMapper.toFormElementVisibilityConditionDto(it)
},
sectionSpawnTrigger =
formElement.sectionSpawnTrigger?.let {
spawnTriggerMapper.toSectionSpawnTriggerDto(it)
},
isClonable = formElement.isClonable,
)
fun toFormElement(
@@ -42,10 +47,15 @@ class FormElementMapper(
formElement.visibilityCondition?.let {
visibilityConditionMapper.toFormElementVisibilityCondition(it)
},
sectionSpawnTrigger =
formElement.sectionSpawnTrigger?.let {
spawnTriggerMapper.toSectionSpawnTrigger(it)
},
isClonable = formElement.isClonable ?: false,
)
fun toFormElement(
formElement: CreateFormElementDto,
fun toNewFormElement(
formElement: FormElementDto,
formElementSubSection: FormElementSubSection,
): FormElement =
FormElement(
@@ -60,5 +70,10 @@ class FormElementMapper(
formElement.visibilityCondition?.let {
visibilityConditionMapper.toFormElementVisibilityCondition(it)
},
sectionSpawnTrigger =
formElement.sectionSpawnTrigger?.let {
spawnTriggerMapper.toSectionSpawnTrigger(it)
},
isClonable = formElement.isClonable ?: false,
)
}

View File

@@ -21,6 +21,10 @@ class FormElementSection(
var title: String,
var shortTitle: String? = null,
var description: String? = null,
var isTemplate: Boolean = false,
var templateReference: String? = null,
var titleTemplate: String? = null,
var spawnedFromElementReference: String? = null,
@OneToMany(mappedBy = "formElementSection", cascade = [CascadeType.ALL], orphanRemoval = true)
@OrderColumn(name = "form_element_sub_section_order")
var formElementSubSections: MutableList<FormElementSubSection> = mutableListOf(),

View File

@@ -1,7 +1,6 @@
package com.betriebsratkanzlei.legalconsenthub.form_element
import com.betriebsratkanzlei.legalconsenthub.application_form.ApplicationForm
import com.betriebsratkanzlei.legalconsenthub_api.model.CreateFormElementSectionDto
import com.betriebsratkanzlei.legalconsenthub_api.model.FormElementSectionDto
import org.springframework.stereotype.Component
@@ -11,7 +10,7 @@ class FormElementSectionMapper(
) {
fun toFormElementSectionDto(formElementSection: FormElementSection): FormElementSectionDto =
FormElementSectionDto(
id = formElementSection.id ?: throw IllegalStateException("FormElementSection ID must not be null!"),
id = formElementSection.id,
title = formElementSection.title,
description = formElementSection.description,
shortTitle = formElementSection.shortTitle,
@@ -22,6 +21,10 @@ class FormElementSectionMapper(
applicationFormId =
formElementSection.applicationForm?.id
?: throw IllegalStateException("ApplicationForm ID must not be null!"),
isTemplate = formElementSection.isTemplate,
templateReference = formElementSection.templateReference,
titleTemplate = formElementSection.titleTemplate,
spawnedFromElementReference = formElementSection.spawnedFromElementReference,
)
fun toFormElementSection(
@@ -34,6 +37,10 @@ class FormElementSectionMapper(
title = formElementSection.title,
description = formElementSection.description,
shortTitle = formElementSection.shortTitle,
isTemplate = formElementSection.isTemplate ?: false,
templateReference = formElementSection.templateReference,
titleTemplate = formElementSection.titleTemplate,
spawnedFromElementReference = formElementSection.spawnedFromElementReference,
applicationForm = applicationForm,
)
section.formElementSubSections =
@@ -43,21 +50,26 @@ class FormElementSectionMapper(
return section
}
fun toFormElementSection(
createFormElementSection: CreateFormElementSectionDto,
fun toNewFormElementSection(
formElementSection: FormElementSectionDto,
applicationForm: ApplicationForm,
): FormElementSection {
val formElementSection =
val section =
FormElementSection(
title = createFormElementSection.title,
description = createFormElementSection.description,
shortTitle = createFormElementSection.shortTitle,
id = null,
title = formElementSection.title,
description = formElementSection.description,
shortTitle = formElementSection.shortTitle,
isTemplate = formElementSection.isTemplate ?: false,
templateReference = formElementSection.templateReference,
titleTemplate = formElementSection.titleTemplate,
spawnedFromElementReference = formElementSection.spawnedFromElementReference,
applicationForm = applicationForm,
)
formElementSection.formElementSubSections =
createFormElementSection.formElementSubSections
.map { formElementSubSectionMapper.toFormElementSubSection(it, formElementSection) }
section.formElementSubSections =
formElementSection.formElementSubSections
.map { formElementSubSectionMapper.toNewFormElementSubSection(it, section) }
.toMutableList()
return formElementSection
return section
}
}

View File

@@ -1,6 +1,5 @@
package com.betriebsratkanzlei.legalconsenthub.form_element
import com.betriebsratkanzlei.legalconsenthub_api.model.CreateFormElementSubSectionDto
import com.betriebsratkanzlei.legalconsenthub_api.model.FormElementSubSectionDto
import org.springframework.stereotype.Component
@@ -10,7 +9,7 @@ class FormElementSubSectionMapper(
) {
fun toFormElementSubSectionDto(formElementSubSection: FormElementSubSection): FormElementSubSectionDto =
FormElementSubSectionDto(
id = formElementSubSection.id ?: throw IllegalStateException("FormElementSubSection ID must not be null!"),
id = formElementSubSection.id,
title = formElementSubSection.title,
subtitle = formElementSubSection.subtitle,
formElements = formElementSubSection.formElements.map { formElementMapper.toFormElementDto(it) },
@@ -37,20 +36,21 @@ class FormElementSubSectionMapper(
return subsection
}
fun toFormElementSubSection(
createFormElementSubSection: CreateFormElementSubSectionDto,
fun toNewFormElementSubSection(
formElementSubSection: FormElementSubSectionDto,
formElementSection: FormElementSection,
): FormElementSubSection {
val formElementSubSection =
val subsection =
FormElementSubSection(
title = createFormElementSubSection.title,
subtitle = createFormElementSubSection.subtitle,
id = null,
title = formElementSubSection.title,
subtitle = formElementSubSection.subtitle,
formElementSection = formElementSection,
)
formElementSubSection.formElements =
createFormElementSubSection.formElements
.map { formElementMapper.toFormElement(it, formElementSubSection) }
subsection.formElements =
formElementSubSection.formElements
.map { formElementMapper.toNewFormElement(it, subsection) }
.toMutableList()
return formElementSubSection
return subsection
}
}

View File

@@ -7,9 +7,9 @@ import jakarta.persistence.Enumerated
@Embeddable
data class FormElementVisibilityCondition(
@Enumerated(EnumType.STRING)
val conditionType: VisibilityConditionType,
val formElementConditionType: VisibilityConditionType,
val sourceFormElementReference: String,
val expectedValue: String,
val formElementExpectedValue: String,
@Enumerated(EnumType.STRING)
val operator: VisibilityConditionOperator = VisibilityConditionOperator.EQUALS,
val formElementOperator: VisibilityConditionOperator = VisibilityConditionOperator.EQUALS,
)

View File

@@ -11,21 +11,21 @@ class FormElementVisibilityConditionMapper {
condition: FormElementVisibilityCondition,
): FormElementVisibilityConditionDto =
FormElementVisibilityConditionDto(
conditionType = toVisibilityConditionTypeDto(condition.conditionType),
formElementConditionType = toVisibilityConditionTypeDto(condition.formElementConditionType),
sourceFormElementReference = condition.sourceFormElementReference,
expectedValue = condition.expectedValue,
operator = toVisibilityConditionOperatorDto(condition.operator),
formElementExpectedValue = condition.formElementExpectedValue,
formElementOperator = toVisibilityConditionOperatorDto(condition.formElementOperator),
)
fun toFormElementVisibilityCondition(
conditionDto: FormElementVisibilityConditionDto,
): FormElementVisibilityCondition =
FormElementVisibilityCondition(
conditionType = toVisibilityConditionType(conditionDto.conditionType),
formElementConditionType = toVisibilityConditionType(conditionDto.formElementConditionType),
sourceFormElementReference = conditionDto.sourceFormElementReference,
expectedValue = conditionDto.expectedValue,
operator =
conditionDto.operator?.let { toVisibilityConditionOperator(it) }
formElementExpectedValue = conditionDto.formElementExpectedValue,
formElementOperator =
conditionDto.formElementOperator?.let { toVisibilityConditionOperator(it) }
?: VisibilityConditionOperator.EQUALS,
)

View File

@@ -0,0 +1,15 @@
package com.betriebsratkanzlei.legalconsenthub.form_element
import jakarta.persistence.Embeddable
import jakarta.persistence.EnumType
import jakarta.persistence.Enumerated
@Embeddable
data class SectionSpawnTrigger(
val templateReference: String,
@Enumerated(EnumType.STRING)
val sectionSpawnConditionType: VisibilityConditionType,
val sectionSpawnExpectedValue: String? = null,
@Enumerated(EnumType.STRING)
val sectionSpawnOperator: VisibilityConditionOperator = VisibilityConditionOperator.EQUALS,
)

View File

@@ -0,0 +1,57 @@
package com.betriebsratkanzlei.legalconsenthub.form_element
import com.betriebsratkanzlei.legalconsenthub_api.model.SectionSpawnTriggerDto
import org.springframework.stereotype.Component
import com.betriebsratkanzlei.legalconsenthub_api.model.VisibilityConditionOperator as VisibilityConditionOperatorDto
import com.betriebsratkanzlei.legalconsenthub_api.model.VisibilityConditionType as VisibilityConditionTypeDto
@Component
class SectionSpawnTriggerMapper {
fun toSectionSpawnTriggerDto(trigger: SectionSpawnTrigger): SectionSpawnTriggerDto =
SectionSpawnTriggerDto(
templateReference = trigger.templateReference,
sectionSpawnConditionType = toVisibilityConditionTypeDto(trigger.sectionSpawnConditionType),
sectionSpawnExpectedValue = trigger.sectionSpawnExpectedValue,
sectionSpawnOperator = toVisibilityConditionOperatorDto(trigger.sectionSpawnOperator),
)
fun toSectionSpawnTrigger(triggerDto: SectionSpawnTriggerDto): SectionSpawnTrigger =
SectionSpawnTrigger(
templateReference = triggerDto.templateReference,
sectionSpawnConditionType = toVisibilityConditionType(triggerDto.sectionSpawnConditionType),
sectionSpawnExpectedValue = triggerDto.sectionSpawnExpectedValue,
sectionSpawnOperator = toVisibilityConditionOperator(triggerDto.sectionSpawnOperator),
)
private fun toVisibilityConditionTypeDto(type: VisibilityConditionType): VisibilityConditionTypeDto =
when (type) {
VisibilityConditionType.SHOW -> VisibilityConditionTypeDto.SHOW
VisibilityConditionType.HIDE -> VisibilityConditionTypeDto.HIDE
}
private fun toVisibilityConditionType(typeDto: VisibilityConditionTypeDto): VisibilityConditionType =
when (typeDto) {
VisibilityConditionTypeDto.SHOW -> VisibilityConditionType.SHOW
VisibilityConditionTypeDto.HIDE -> VisibilityConditionType.HIDE
}
private fun toVisibilityConditionOperatorDto(
operator: VisibilityConditionOperator,
): VisibilityConditionOperatorDto =
when (operator) {
VisibilityConditionOperator.EQUALS -> VisibilityConditionOperatorDto.EQUALS
VisibilityConditionOperator.NOT_EQUALS -> VisibilityConditionOperatorDto.NOT_EQUALS
VisibilityConditionOperator.IS_EMPTY -> VisibilityConditionOperatorDto.IS_EMPTY
VisibilityConditionOperator.IS_NOT_EMPTY -> VisibilityConditionOperatorDto.IS_NOT_EMPTY
}
private fun toVisibilityConditionOperator(
operatorDto: VisibilityConditionOperatorDto,
): VisibilityConditionOperator =
when (operatorDto) {
VisibilityConditionOperatorDto.EQUALS -> VisibilityConditionOperator.EQUALS
VisibilityConditionOperatorDto.NOT_EQUALS -> VisibilityConditionOperator.NOT_EQUALS
VisibilityConditionOperatorDto.IS_EMPTY -> VisibilityConditionOperator.IS_EMPTY
VisibilityConditionOperatorDto.IS_NOT_EMPTY -> VisibilityConditionOperator.IS_NOT_EMPTY
}
}

View File

@@ -45,7 +45,7 @@ logging:
springframework:
security: TRACE
oauth2: TRACE
web: DEBUG
web: TRACE
org.testcontainers: INFO
com.github.dockerjava: WARN

View File

@@ -63,26 +63,37 @@ create table form_element_options
create table form_element
(
form_element_order integer,
type smallint not null check (type between 0 and 6),
is_clonable boolean not null,
type smallint not null check (type between 0 and 7),
form_element_sub_section_id uuid not null,
id uuid not null,
condition_type varchar(255) check (condition_type in ('SHOW', 'HIDE')),
description varchar(255),
expected_value varchar(255),
operator varchar(255) check (operator in ('EQUALS', 'NOT_EQUALS', 'IS_EMPTY', 'IS_NOT_EMPTY')),
form_element_condition_type varchar(255) check (form_element_condition_type in ('SHOW', 'HIDE')),
form_element_expected_value varchar(255),
form_element_operator varchar(255) check (form_element_operator in
('EQUALS', 'NOT_EQUALS', 'IS_EMPTY', 'IS_NOT_EMPTY')),
reference varchar(255),
section_spawn_condition_type varchar(255) check (section_spawn_condition_type in ('SHOW', 'HIDE')),
section_spawn_expected_value varchar(255),
section_spawn_operator varchar(255) check (section_spawn_operator in
('EQUALS', 'NOT_EQUALS', 'IS_EMPTY', 'IS_NOT_EMPTY')),
source_form_element_reference varchar(255),
template_reference varchar(255),
title varchar(255),
primary key (id)
);
create table form_element_section
(
application_form_id uuid not null,
id uuid not null,
description varchar(255),
short_title varchar(255),
title varchar(255) not null,
is_template boolean not null,
application_form_id uuid not null,
id uuid not null,
description varchar(255),
short_title varchar(255),
spawned_from_element_reference varchar(255),
template_reference varchar(255),
title varchar(255) not null,
title_template varchar(255),
primary key (id)
);