diff --git a/.build/build.gradle.kts b/.build/build.gradle.kts index f2a709a..0ea57d1 100644 --- a/.build/build.gradle.kts +++ b/.build/build.gradle.kts @@ -1,4 +1,5 @@ import documentation.generateComponentDiagramsFromJson +import documentation.generateDatabasesOverviewDocumentFromJson import documentation.generateDiagramsFromPlantUml import documentation.generateEndpointOverviewDocumentFromJson import documentation.generateEventsOverviewDocumentFromJson @@ -11,6 +12,7 @@ tasks.register("generateFiles") { val rootFolder = project.rootDir.parentFile doLast { generateComponentDiagramsFromJson(srcFolder, rootFolder) + generateDatabasesOverviewDocumentFromJson(srcFolder, rootFolder) generateDiagramsFromPlantUml(srcFolder, rootFolder) generateEndpointOverviewDocumentFromJson(srcFolder, rootFolder) generateEventsOverviewDocumentFromJson(srcFolder, rootFolder) diff --git a/.build/buildSrc/src/main/kotlin/documentation/generators/asciidoc/DatabasesOverviewGenerator.kt b/.build/buildSrc/src/main/kotlin/documentation/generators/asciidoc/DatabasesOverviewGenerator.kt new file mode 100644 index 0000000..3dd8ac0 --- /dev/null +++ b/.build/buildSrc/src/main/kotlin/documentation/generators/asciidoc/DatabasesOverviewGenerator.kt @@ -0,0 +1,25 @@ +package documentation.generators.asciidoc + +import documentation.model.Application +import documentation.model.Distance.OWNED +import documentation.model.componentName + +class DatabasesOverviewGenerator(applications: List) { + + private val ourApplicationsWithDatabases = applications + .filter { it.distanceFromUs == OWNED } + .filter { it.databases.isNotEmpty() } + .sortedBy { componentName(it.id) } + + fun asciiDocSource(): String = + buildString { + appendLine(":toc: left") + appendLine(":toclevels: 2") + appendLine() + appendLine("= Databases") + appendLine() + ourApplicationsWithDatabases + .forEach { application -> + } + } +} diff --git a/.build/buildSrc/src/main/kotlin/documentation/model/model.kt b/.build/buildSrc/src/main/kotlin/documentation/model/model.kt index a3cbcc2..350dd19 100644 --- a/.build/buildSrc/src/main/kotlin/documentation/model/model.kt +++ b/.build/buildSrc/src/main/kotlin/documentation/model/model.kt @@ -27,6 +27,7 @@ data class Application( val dependents: List = emptyList(), val dependencies: List = emptyList(), val events: List = emptyList(), + val databases: List = emptyList(), val messaging: Messaging = Messaging(), ) : Component @@ -84,3 +85,26 @@ data class Messaging( val routingKeyPattern: String, ) } + +data class Database( + val id: String, + val name: String, + val type: String, + val description: String?, + val tables: List = emptyList(), +) { + data class Table( + val name: String, + val description: String?, + val columns: List = emptyList(), + ) + + data class Column( + val name: String, + val dataType: String, + val defaultValue: String?, + val nullable: Boolean, + val description: String?, + val partOfPrimaryKey: Boolean, + ) +} diff --git a/.build/buildSrc/src/main/kotlin/documentation/tasks.kt b/.build/buildSrc/src/main/kotlin/documentation/tasks.kt index ee5331f..93a9554 100644 --- a/.build/buildSrc/src/main/kotlin/documentation/tasks.kt +++ b/.build/buildSrc/src/main/kotlin/documentation/tasks.kt @@ -1,5 +1,6 @@ package documentation +import documentation.generators.asciidoc.DatabasesOverviewGenerator import documentation.generators.asciidoc.EndpointsOverviewGenerator import documentation.generators.asciidoc.EventsOverviewGenerator import documentation.generators.plantuml.ApplicationContextDiagramGenerator @@ -227,6 +228,21 @@ fun generateEventsOverviewDocumentFromJson(srcFolder: File, rootFolder: File) { createOrReplaceFile(targetFile, source) } +// DATABASES + +fun generateDatabasesOverviewDocumentFromJson(srcFolder: File, rootFolder: File) { + val sourcesFolder = File(srcFolder, "json/components") + val targetFolder = File(rootFolder, "documents") + val targetFile = File(targetFolder, "databases.adoc") + + val applications = loadApplications(sourcesFolder) + + val generator = DatabasesOverviewGenerator(applications) + val source = generator.asciiDocSource() + + createOrReplaceFile(targetFile, source) +} + // COMMON fun lineTypes(block: (LineType, String) -> Unit) { diff --git a/.build/buildSrc/src/main/kotlin/documentation/tasks/combine-parts.kt b/.build/buildSrc/src/main/kotlin/documentation/tasks/combine-parts.kt index 6dd5fa2..d69300b 100644 --- a/.build/buildSrc/src/main/kotlin/documentation/tasks/combine-parts.kt +++ b/.build/buildSrc/src/main/kotlin/documentation/tasks/combine-parts.kt @@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.SerializationFeature import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import com.fasterxml.jackson.module.kotlin.readValue import documentation.model.Application +import documentation.model.Database import documentation.model.Dependency import documentation.model.Dependent import documentation.model.Event @@ -28,6 +29,7 @@ fun generateComponentDescription(sourceFolder: File, targetFolder: File, applica dependents = loadDependents(sourceFolder), dependencies = loadDependencies(sourceFolder), events = loadEvents(sourceFolder), + databases = loadDatabases(sourceFolder), messaging = Messaging( publishedMessages = loadPublishedMessages(sourceFolder), consumedQueues = loadConsumedQueues(sourceFolder), @@ -103,6 +105,14 @@ fun loadConsumedQueues(sourceFolder: File): List { return emptyList() } +fun loadDatabases(sourceFolder: File): List = + listJsonFilesInFolder(File(sourceFolder, "databases")) + .map { file -> loadDatabase(file) } + +private fun loadDatabase(file: File): Database { + return objectMapper.readValue(file) +} + private fun listJsonFilesInFolder(folder: File): List = if (folder.isDirectory) { folder.listFiles()!!