Skip to content

Commit

Permalink
extend model with messaging data
Browse files Browse the repository at this point in the history
  • Loading branch information
slu-it committed Aug 30, 2024
1 parent b78ba2b commit c6113d9
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 7 deletions.
21 changes: 21 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 messaging: Messaging = Messaging(),
) : Component

data class Dependent(
Expand Down Expand Up @@ -63,3 +64,23 @@ data class Event(
val description: String?,
)
}

data class Messaging(
val publishedMessages: List<PublishedMessage> = emptyList(),
val consumedQueues: List<ConsumedQueue> = emptyList(),
) {
data class PublishedMessage(
val exchange: String,
val routingKey: String,
)

data class ConsumedQueue(
val name: String,
val bindings: List<Binding>,
)

data class Binding(
val exchange: String,
val routingKeyPattern: String,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import documentation.model.Dependency
import documentation.model.Dependent
import documentation.model.Event
import documentation.model.HttpEndpoint
import documentation.model.Messaging
import documentation.model.Messaging.ConsumedQueue
import documentation.model.Messaging.PublishedMessage
import java.io.File
import kotlin.reflect.KClass

Expand All @@ -20,13 +23,16 @@ private val objectMapper = jacksonObjectMapper()
.enable(SerializationFeature.INDENT_OUTPUT)

fun generateComponentDescription(sourceFolder: File, targetFolder: File, applicationId: String) {
val baseApplicationDescription = loadBaseApplicationDescription(sourceFolder, applicationId)
val dependents = loadDependents(sourceFolder)
val dependencies = loadDependencies(sourceFolder)
val events = loadEvents(sourceFolder)

val applicationDescription = baseApplicationDescription
.copy(dependents = dependents, dependencies = dependencies, events = events)
val applicationDescription = loadBaseApplicationDescription(sourceFolder, applicationId)
.copy(
dependents = loadDependents(sourceFolder),
dependencies = loadDependencies(sourceFolder),
events = loadEvents(sourceFolder),
messaging = Messaging(
publishedMessages = loadPublishedMessages(sourceFolder),
consumedQueues = loadConsumedQueues(sourceFolder),
)
)

val file = File(targetFolder, applicationDescription.id + ".json")
objectMapper.writeValue(file, applicationDescription)
Expand Down Expand Up @@ -73,6 +79,28 @@ private fun loadEvent(file: File): Event {
return objectMapper.readValue<Event>(file)
}

fun loadPublishedMessages(sourceFolder: File): List<PublishedMessage> {
val messagingFolder = File(sourceFolder, "messaging")
val file = File(messagingFolder, "published-messages.jsonl")
if (file.isFile) {
return loadFromJsonListFile(file, PublishedMessage::class)
.distinct()
}
return emptyList()
}

fun loadConsumedQueues(sourceFolder: File): List<ConsumedQueue> {
val messagingFolder = File(sourceFolder, "messaging")
val file = File(messagingFolder, "consumed-queues.jsonl")
if (file.isFile) {
return loadFromJsonListFile(file, ConsumedQueue::class)
.groupBy(ConsumedQueue::name, ConsumedQueue::bindings)
.mapValues { (_, bindings) -> bindings.flatten().distinct() }
.map { (name, bindings) -> ConsumedQueue(name, bindings) }
}
return emptyList()
}

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

0 comments on commit c6113d9

Please sign in to comment.