Skip to content

Commit

Permalink
base setup for generating database documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
slu-it committed Sep 3, 2024
1 parent b820599 commit fceffea
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .build/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import documentation.generateComponentDiagramsFromJson
import documentation.generateDatabasesOverviewDocumentFromJson
import documentation.generateDiagramsFromPlantUml
import documentation.generateEndpointOverviewDocumentFromJson
import documentation.generateEventsOverviewDocumentFromJson
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Application>) {

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 ->
}
}
}
24 changes: 24 additions & 0 deletions .build/buildSrc/src/main/kotlin/documentation/model/model.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ data class Application(
val dependents: List<Dependent> = emptyList(),
val dependencies: List<Dependency> = emptyList(),
val events: List<Event> = emptyList(),
val databases: List<Database> = emptyList(),
val messaging: Messaging = Messaging(),
) : Component

Expand Down Expand Up @@ -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<Table> = emptyList(),
) {
data class Table(
val name: String,
val description: String?,
val columns: List<Column> = emptyList(),
)

data class Column(
val name: String,
val dataType: String,
val defaultValue: String?,
val nullable: Boolean,
val description: String?,
val partOfPrimaryKey: Boolean,
)
}
16 changes: 16 additions & 0 deletions .build/buildSrc/src/main/kotlin/documentation/tasks.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand Down Expand Up @@ -103,6 +105,14 @@ fun loadConsumedQueues(sourceFolder: File): List<ConsumedQueue> {
return emptyList()
}

fun loadDatabases(sourceFolder: File): List<Database> =
listJsonFilesInFolder(File(sourceFolder, "databases"))
.map { file -> loadDatabase(file) }

private fun loadDatabase(file: File): Database {
return objectMapper.readValue<Database>(file)
}

private fun listJsonFilesInFolder(folder: File): List<File> =
if (folder.isDirectory) {
folder.listFiles()!!
Expand Down

0 comments on commit fceffea

Please sign in to comment.