diff --git a/models/workflow/plantuml.go b/models/workflow/plantuml.go index 9beaede..b1fe6e2 100644 --- a/models/workflow/plantuml.go +++ b/models/workflow/plantuml.go @@ -15,20 +15,52 @@ import ( // PlantUML export // --------------------------------------------------------------------------- -// ToPlantUML serializes the workflow graph back to a PlantUML file that is -// compatible with ExtractFromPlantUML (round-trip). -// Resource attributes and instance attributes are merged and written as -// human-readable comments: "key: value, nested.key: value". +// plantUMLProcedures defines the !procedure blocks for each resource type. +// These make the output valid, renderable PlantUML while remaining parseable +// by ExtractFromPlantUML (which already skips lines containing "!procedure"). +const plantUMLProcedures = `!procedure Processing($var, $name) + component "$name" as $var <> +!endprocedure + +!procedure Data($var, $name) + file "$name" as $var <> +!endprocedure + +!procedure Storage($var, $name) + database "$name" as $var <> +!endprocedure + +!procedure ComputeUnit($var, $name) + node "$name" as $var <> +!endprocedure + +!procedure WorkflowEvent($var, $name) + usecase "$name" as $var <> +!endprocedure + +!procedure Workflow($var, $name) + frame "$name" as $var <> +!endprocedure +` + +// ToPlantUML serializes the workflow graph to a valid, renderable PlantUML file +// that is also compatible with ExtractFromPlantUML (round-trip). +// Resource and instance attributes are written as human-readable comments: +// +// Processing(p1, "NDVI") ' access.container.image: myrepo/ndvi:1.2, infrastructure: 0 func (w *Workflow) ToPlantUML() string { var sb strings.Builder sb.WriteString("@startuml\n\n") + sb.WriteString(plantUMLProcedures) + sb.WriteByte('\n') varNames := plantUMLVarNames(w.Graph.Items) // --- resource declarations --- for id, item := range w.Graph.Items { - sb.WriteString(plantUMLItemLine(varNames[id], item)) - sb.WriteByte('\n') + if line := plantUMLItemLine(varNames[id], item); line != "" { + sb.WriteString(line + "\n") + } } sb.WriteByte('\n')