From 473703ce723a17d8896110c93919ed8b342e28e8 Mon Sep 17 00:00:00 2001 From: Stefan Ludwig Date: Fri, 15 Mar 2024 22:16:13 +0100 Subject: [PATCH] remove groupId and systemId from application data and introduce static metadata for naming and grouping of components --- .build/buildSrc/build.gradle.kts | 1 + .../asciidoc/EndpointsOverviewGenerator.kt | 2 +- .../plantuml/AbstractDiagramGenerator.kt | 2 +- .../ApplicationContextDiagramGenerator.kt | 4 +- .../documentation/generators/translations.kt | 19 ------ .../kotlin/documentation/model/loading.kt | 4 +- .../kotlin/documentation/model/metadata.kt | 53 +++++++++++++++++ .../main/kotlin/documentation/model/model.kt | 20 +++++-- .../main/resources/i18n/components.properties | 7 --- .../src/main/resources/i18n/groups.properties | 1 - .../main/resources/i18n/systems.properties | 2 - .../buildSrc/src/main/resources/metadata.json | 59 +++++++++++++++++++ 12 files changed, 133 insertions(+), 41 deletions(-) delete mode 100644 .build/buildSrc/src/main/kotlin/documentation/generators/translations.kt create mode 100644 .build/buildSrc/src/main/kotlin/documentation/model/metadata.kt delete mode 100644 .build/buildSrc/src/main/resources/i18n/components.properties delete mode 100644 .build/buildSrc/src/main/resources/i18n/groups.properties delete mode 100644 .build/buildSrc/src/main/resources/i18n/systems.properties create mode 100644 .build/buildSrc/src/main/resources/metadata.json diff --git a/.build/buildSrc/build.gradle.kts b/.build/buildSrc/build.gradle.kts index 1850c09..0308d60 100644 --- a/.build/buildSrc/build.gradle.kts +++ b/.build/buildSrc/build.gradle.kts @@ -10,4 +10,5 @@ dependencies { implementation("com.fasterxml.jackson.core:jackson-databind:2.16.1") implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.16.1") implementation("net.sourceforge.plantuml:plantuml:1.2024.3") + implementation("org.springframework:spring-core:6.1.5") } diff --git a/.build/buildSrc/src/main/kotlin/documentation/generators/asciidoc/EndpointsOverviewGenerator.kt b/.build/buildSrc/src/main/kotlin/documentation/generators/asciidoc/EndpointsOverviewGenerator.kt index 7c00ea1..c437ade 100644 --- a/.build/buildSrc/src/main/kotlin/documentation/generators/asciidoc/EndpointsOverviewGenerator.kt +++ b/.build/buildSrc/src/main/kotlin/documentation/generators/asciidoc/EndpointsOverviewGenerator.kt @@ -1,6 +1,5 @@ package documentation.generators.asciidoc -import documentation.generators.componentName import documentation.model.Application import documentation.model.ComponentType.BACKEND import documentation.model.Dependency @@ -8,6 +7,7 @@ import documentation.model.Distance.CLOSE import documentation.model.Distance.DISTANT import documentation.model.Distance.OWNED import documentation.model.HttpEndpoint +import documentation.model.componentName class EndpointsOverviewGenerator(applications: List) { diff --git a/.build/buildSrc/src/main/kotlin/documentation/generators/plantuml/AbstractDiagramGenerator.kt b/.build/buildSrc/src/main/kotlin/documentation/generators/plantuml/AbstractDiagramGenerator.kt index 4d8f898..2c92fff 100644 --- a/.build/buildSrc/src/main/kotlin/documentation/generators/plantuml/AbstractDiagramGenerator.kt +++ b/.build/buildSrc/src/main/kotlin/documentation/generators/plantuml/AbstractDiagramGenerator.kt @@ -1,10 +1,10 @@ package documentation.generators.plantuml -import documentation.generators.componentName import documentation.model.Component import documentation.model.ComponentType import documentation.model.Dependency import documentation.model.Distance +import documentation.model.componentName abstract class AbstractDiagramGenerator( private val options: DiagramGeneratorOptions diff --git a/.build/buildSrc/src/main/kotlin/documentation/generators/plantuml/ApplicationContextDiagramGenerator.kt b/.build/buildSrc/src/main/kotlin/documentation/generators/plantuml/ApplicationContextDiagramGenerator.kt index 8341d6e..b2a7917 100644 --- a/.build/buildSrc/src/main/kotlin/documentation/generators/plantuml/ApplicationContextDiagramGenerator.kt +++ b/.build/buildSrc/src/main/kotlin/documentation/generators/plantuml/ApplicationContextDiagramGenerator.kt @@ -1,8 +1,6 @@ package documentation.generators.plantuml -import documentation.generators.groupName import documentation.generators.plantuml.DiagramDirection.LEFT_TO_RIGHT -import documentation.generators.systemName import documentation.model.Application import documentation.model.Component import documentation.model.ComponentType @@ -10,6 +8,8 @@ import documentation.model.ComponentType.DATABASE import documentation.model.Dependency import documentation.model.Dependent import documentation.model.Distance.OWNED +import documentation.model.groupName +import documentation.model.systemName import kotlin.contracts.ExperimentalContracts import kotlin.contracts.contract diff --git a/.build/buildSrc/src/main/kotlin/documentation/generators/translations.kt b/.build/buildSrc/src/main/kotlin/documentation/generators/translations.kt deleted file mode 100644 index 132a2f3..0000000 --- a/.build/buildSrc/src/main/kotlin/documentation/generators/translations.kt +++ /dev/null @@ -1,19 +0,0 @@ -package documentation.generators - -import java.util.MissingResourceException -import java.util.ResourceBundle - -private val components = ResourceBundle.getBundle("i18n/components") -private val groups = ResourceBundle.getBundle("i18n/groups") -private val systems = ResourceBundle.getBundle("i18n/systems") - -fun componentName(id: String): String = components.getStringOrDefault(id) -fun groupName(id: String): String = groups.getStringOrDefault(id) -fun systemName(id: String): String = systems.getStringOrDefault(id) - -private fun ResourceBundle.getStringOrDefault(key: String, default: String = key): String = - try { - getString(key) - } catch (e: MissingResourceException) { - default - } diff --git a/.build/buildSrc/src/main/kotlin/documentation/model/loading.kt b/.build/buildSrc/src/main/kotlin/documentation/model/loading.kt index 63ed9bc..1487c08 100644 --- a/.build/buildSrc/src/main/kotlin/documentation/model/loading.kt +++ b/.build/buildSrc/src/main/kotlin/documentation/model/loading.kt @@ -6,7 +6,7 @@ import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import com.fasterxml.jackson.module.kotlin.readValue import java.io.File -private val objectMapper = jacksonObjectMapper() +internal val loadingObjectMapper = jacksonObjectMapper() .disable(FAIL_ON_UNKNOWN_PROPERTIES) .enable(READ_UNKNOWN_ENUM_VALUES_AS_NULL) @@ -14,5 +14,5 @@ fun loadApplications(sourceFolder: File): List { check(sourceFolder.isDirectory) return sourceFolder.listFiles()!! .filter { file -> file.extension == "json" } - .map(objectMapper::readValue) + .map(loadingObjectMapper::readValue) } diff --git a/.build/buildSrc/src/main/kotlin/documentation/model/metadata.kt b/.build/buildSrc/src/main/kotlin/documentation/model/metadata.kt new file mode 100644 index 0000000..f927596 --- /dev/null +++ b/.build/buildSrc/src/main/kotlin/documentation/model/metadata.kt @@ -0,0 +1,53 @@ +package documentation.model + +import com.fasterxml.jackson.module.kotlin.readValue +import org.springframework.core.io.ClassPathResource +import kotlin.text.Charsets.UTF_8 + +private val metadata = Metadata.load() + +data class Metadata( + val components: List, + val groups: List, + val systems: List, +) { + companion object { + fun load(): Metadata { + val resource = ClassPathResource("/metadata.json") + val json = resource.getContentAsString(UTF_8) + return loadingObjectMapper.readValue(json) + } + } +} + +data class ComponentMetadata( + val id: String, + val name: String, + val groupId: String?, + val systemId: String?, +) + +data class GroupMetadata( + val id: String, + val name: String, +) + +data class SystemMetadata( + val id: String, + val name: String, +) + +fun componentName(id: String): String = + metadata.components.firstOrNull { it.id == id }?.name ?: id + +fun groupName(id: String): String = + metadata.groups.firstOrNull { it.id == id }?.name ?: id + +fun systemName(id: String): String = + metadata.systems.firstOrNull { it.id == id }?.name ?: id + +fun groupIdOfComponent(componentId: String): String? = + metadata.components.firstOrNull { it.id == componentId }?.groupId + +fun systemIdOfComponent(componentId: String): String? = + metadata.components.firstOrNull { it.id == componentId }?.systemId diff --git a/.build/buildSrc/src/main/kotlin/documentation/model/model.kt b/.build/buildSrc/src/main/kotlin/documentation/model/model.kt index 376096a..d388638 100644 --- a/.build/buildSrc/src/main/kotlin/documentation/model/model.kt +++ b/.build/buildSrc/src/main/kotlin/documentation/model/model.kt @@ -1,19 +1,24 @@ package documentation.model +import com.fasterxml.jackson.annotation.JsonIgnore + // (!) The content of this file is copied from repository to repository. // It is the model used by the various generation Gradle tasks and is the same for all repositories. // In a real project this would likely be packaged as library package and distributed using some kind of registry. sealed interface Component { val id: String - val groupId: String? - val systemId: String? val type: ComponentType? val distanceFromUs: Distance? -} -enum class ComponentType { BACKEND, FRONTEND, DATABASE } -enum class Distance { OWNED, CLOSE, DISTANT } + @get:JsonIgnore + val groupId: String? + get() = groupIdOfComponent(id) + + @get:JsonIgnore + val systemId: String? + get() = systemIdOfComponent(id) +} data class Application( override val id: String, @@ -43,5 +48,8 @@ data class Dependency( val httpEndpoints: List = emptyList(), ) : Component -data class HttpEndpoint(val method: String, val path: String) +enum class ComponentType { BACKEND, FRONTEND, DATABASE } +enum class Distance { OWNED, CLOSE, DISTANT } enum class Credentials(val label: String) { JWT("JWT"), BASIC_AUTH("Basic-Auth") } + +data class HttpEndpoint(val method: String, val path: String) diff --git a/.build/buildSrc/src/main/resources/i18n/components.properties b/.build/buildSrc/src/main/resources/i18n/components.properties deleted file mode 100644 index 0495c6b..0000000 --- a/.build/buildSrc/src/main/resources/i18n/components.properties +++ /dev/null @@ -1,7 +0,0 @@ -frontend=Frontend -backend-service-1=Backend Service #1 -backend-service-1-database=database -backend-service-2=Backend Service #2 -external-service-1=External Service #1 -external-service-2=External Service #2 -external-service-3=External Service #3 diff --git a/.build/buildSrc/src/main/resources/i18n/groups.properties b/.build/buildSrc/src/main/resources/i18n/groups.properties deleted file mode 100644 index 7cf717b..0000000 --- a/.build/buildSrc/src/main/resources/i18n/groups.properties +++ /dev/null @@ -1 +0,0 @@ -application=Application diff --git a/.build/buildSrc/src/main/resources/i18n/systems.properties b/.build/buildSrc/src/main/resources/i18n/systems.properties deleted file mode 100644 index 536f4ef..0000000 --- a/.build/buildSrc/src/main/resources/i18n/systems.properties +++ /dev/null @@ -1,2 +0,0 @@ -platform=Platform -other-project=Other Project diff --git a/.build/buildSrc/src/main/resources/metadata.json b/.build/buildSrc/src/main/resources/metadata.json new file mode 100644 index 0000000..5fc20ec --- /dev/null +++ b/.build/buildSrc/src/main/resources/metadata.json @@ -0,0 +1,59 @@ +{ + "components": [ + { + "id": "frontend", + "name": "Frontend", + "groupId": "application", + "systemId": "platform" + }, + { + "id": "backend-service-1", + "name": "Backend Service #1", + "groupId": "application", + "systemId": "platform" + }, + { + "id": "backend-service-1-database", + "name": "database", + "groupId": "application", + "systemId": "platform" + }, + { + "id": "backend-service-2", + "name": "Backend Service #2", + "groupId": "application", + "systemId": "platform" + }, + { + "id": "external-service-1", + "name": "External Service #1", + "systemId": "platform" + }, + { + "id": "external-service-2", + "name": "External Service #2", + "systemId": "platform" + }, + { + "id": "external-service-3", + "name": "External Service #3", + "systemId": "other-project" + } + ], + "groups": [ + { + "id": "application", + "name": "Application" + } + ], + "systems": [ + { + "id": "platform", + "name": "Platform" + }, + { + "id": "other-project", + "name": "Other Project" + } + ] +}