Skip to content

Commit

Permalink
Remove glue code
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskn committed Jun 21, 2024
1 parent 231b0af commit a93df91
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ import com.structurizr.model.Model
import com.structurizr.model.Person
import com.structurizr.model.SoftwareSystem
import com.structurizr.model.StaticStructureElement
import com.structurizr.model.enterpriseNameProperty

private const val ENTERPRISE_NAME_PROPERTY = "enterprise:name"

/**
* Stores the name of the enterprise this model belongs to if set
*/
var Model.enterpriseName: String?
set(name) { this.enterpriseNameProperty = name }
get() = this.enterpriseNameProperty
set(name) {
this.addProperty(ENTERPRISE_NAME_PROPERTY, name)
}
get() = this.properties[ENTERPRISE_NAME_PROPERTY]

/**
* Adds a person.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,35 @@ import com.structurizr.view.ContainerView
import com.structurizr.view.DynamicView
import com.structurizr.view.SystemContextView
import com.structurizr.view.SystemLandscapeView
import com.structurizr.view.showEnterpriseBoundaryInternal
import com.structurizr.view.showExternalBoundariesInternal
import com.structurizr.view.showExternalContainerBoundariesInternal
import com.structurizr.view.showExternalSoftwareSystemBoundariesInternal

private const val SHOW_BOUNDARY_PROPERTY = "SHOW_BOUNDARY"

var DynamicView.showExternalBoundaries: Boolean
get() = this.showExternalBoundariesInternal
get() = this.properties[SHOW_BOUNDARY_PROPERTY].toBoolean()
set(value) {
this.showExternalBoundariesInternal = value
this.addProperty(SHOW_BOUNDARY_PROPERTY, value.toString())
}

var ContainerView.showExternalSoftwareSystemBoundaries: Boolean
get() = this.showExternalSoftwareSystemBoundariesInternal
get() = this.properties[SHOW_BOUNDARY_PROPERTY].toBoolean()
set(value) {
this.showExternalSoftwareSystemBoundariesInternal = value
this.addProperty(SHOW_BOUNDARY_PROPERTY, value.toString())
}

var ComponentView.showExternalContainerBoundaries: Boolean
get() = this.showExternalContainerBoundariesInternal
get() = this.properties[SHOW_BOUNDARY_PROPERTY].toBoolean()
set(value) {
this.showExternalContainerBoundariesInternal = value
this.addProperty(SHOW_BOUNDARY_PROPERTY, value.toString())
}

var SystemLandscapeView.showEnterpriseBoundary: Boolean
get() = this.showEnterpriseBoundaryInternal
get() = this.properties[SHOW_BOUNDARY_PROPERTY].toBoolean()
set(value) {
this.showEnterpriseBoundaryInternal = value
this.addProperty(SHOW_BOUNDARY_PROPERTY, value.toString())
}

var SystemContextView.showEnterpriseBoundary: Boolean
get() = this.showEnterpriseBoundaryInternal
get() = this.properties[SHOW_BOUNDARY_PROPERTY].toBoolean()
set(value) {
this.showEnterpriseBoundaryInternal = value
this.addProperty(SHOW_BOUNDARY_PROPERTY, value.toString())
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.github.chriskn.structurizrextension.api.view
package com.github.chriskn.structurizrextension.api.view.dynamic

import com.structurizr.model.StaticStructureElement
import com.structurizr.view.DynamicView
import com.structurizr.view.RelationshipView
import com.structurizr.view.nestedParallelSequenceOrder
import com.structurizr.view.orderInternal

private const val NUMBER_OF_ENDED_PARALLEL_FLOWS = "NUMBER_OF_PARALLEL_ROOT_SEQUENCES"
private const val AS_SEQUENCE_DIAGRAM = "plantuml.sequenceDiagram"
Expand All @@ -27,7 +27,7 @@ fun DynamicView.add(
technology: String? = null,
): RelationshipView {
val relationshipView = this.add(source, description, technology, destination)
relationshipView.nestedParallelSequenceOrder = (relationshipView.order.toInt() + this.numberOfEndedParallelFlows).toString()
relationshipView.orderInternal = (relationshipView.order.toInt() + this.numberOfEndedParallelFlows).toString()
return relationshipView
}

Expand All @@ -46,10 +46,10 @@ fun DynamicView.startNestedParallelSequence(): NestedParallelSequenceContext {

var DynamicView.numberOfEndedParallelFlows: Int
get() {
return this.properties.getOrDefault(NUMBER_OF_ENDED_PARALLEL_FLOWS, "0").toInt()
return properties.getOrDefault(NUMBER_OF_ENDED_PARALLEL_FLOWS, "0").toInt()
}
set(value) {
this.addProperty(NUMBER_OF_ENDED_PARALLEL_FLOWS, value.toString())
addProperty(NUMBER_OF_ENDED_PARALLEL_FLOWS, value.toString())
}

var DynamicView.renderAsSequenceDiagram: Boolean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.github.chriskn.structurizrextension.api.view
package com.github.chriskn.structurizrextension.api.view.dynamic

import com.structurizr.model.StaticStructureElement
import com.structurizr.view.DynamicView
import com.structurizr.view.RelationshipView
import com.structurizr.view.nestedParallelSequenceOrder
import com.structurizr.view.orderInternal

/**
* Wrapper around [DynamicView] to manage nested numbering for parallel sequences.
Expand Down Expand Up @@ -45,7 +45,7 @@ data class NestedParallelSequenceContext(
description = description,
technology = technology
)
view.nestedParallelSequenceOrder = getNextOrder()
view.orderInternal = getNextOrder()

return view
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
package com.github.chriskn.structurizrextension.api.view.layout

import com.github.chriskn.structurizrextension.api.view.layout.Direction.Down
import com.github.chriskn.structurizrextension.api.view.layout.Direction.Left
import com.github.chriskn.structurizrextension.api.view.layout.Direction.Right
import com.github.chriskn.structurizrextension.api.view.layout.Direction.Up
import com.github.chriskn.structurizrextension.api.view.layout.Layout.Landscape
import com.github.chriskn.structurizrextension.api.view.layout.Layout.LeftToRight
import com.github.chriskn.structurizrextension.api.view.layout.Layout.TopDown
import com.github.chriskn.structurizrextension.api.view.layout.Legend.None
import com.github.chriskn.structurizrextension.api.view.layout.Legend.ShowFloatingLegend
import com.github.chriskn.structurizrextension.api.view.layout.Legend.ShowLegend
import com.github.chriskn.structurizrextension.api.view.layout.Legend.ShowStaticLegend
import com.github.chriskn.structurizrextension.api.view.layout.LineType.Ortho
import com.github.chriskn.structurizrextension.api.view.layout.LineType.Polyline
import com.github.chriskn.structurizrextension.api.view.layout.Mode.Back
import com.github.chriskn.structurizrextension.api.view.layout.Mode.BackNeighbor
import com.github.chriskn.structurizrextension.api.view.layout.Mode.Neighbor
import com.github.chriskn.structurizrextension.api.view.layout.Mode.Rel
import com.github.chriskn.structurizrextension.api.view.layout.Mode.RelIndex
import com.structurizr.model.Relationship

/**
* Allows the configuration of the layout for generated C4-PlantUML diagram.
*
* @param nodeSep the PlantUML nodesep skinparam in order to control the distance between nodes
* @param rankSep the PlantUML ranksep skinparam in order to control the distance between ranks
* @param lineType the PlantUML [LineType] skinparam
* @param layout the C4PlantUML [Layout]. [TopDown] is default
* @param layout the C4PlantUML [Legend]. [ShowLegend] is default
* @param showPersonOutline activates person outline instead of a rectangle (default is true)
* @param hideStereotypes hides stereotypes when rendering elements (default is true)
* @param dependencyConfigurations list of [DependencyConfiguration]
*/
data class C4PlantUmlLayout(
val nodeSep: Int? = null,
val rankSep: Int? = null,
val lineType: LineType? = null,
val layout: Layout = TopDown,
val legend: Legend = ShowLegend,
val showPersonOutline: Boolean = true,
val hideStereotypes: Boolean = true,
val dependencyConfigurations: List<DependencyConfiguration> = listOf()
) {
internal fun hasPostamble(): Boolean = nodeSep != null || rankSep != null || lineType != null || legend != None
}

/**
* Options for the PlanUML skinparam linetype.
*
Expand Down Expand Up @@ -112,28 +122,3 @@ data class DependencyConfiguration(
val mode: Mode? = null,
val direction: Direction? = null
)

/**
* Allows the configuration of the layout for generated C4-PlantUML diagram.
*
* @param nodeSep the PlantUML nodesep skinparam in order to control the distance between nodes
* @param rankSep the PlantUML ranksep skinparam in order to control the distance between ranks
* @param lineType the PlantUML [LineType] skinparam
* @param layout the C4PlantUML [Layout]. [TopDown] is default
* @param layout the C4PlantUML [Legend]. [ShowLegend] is default
* @param showPersonOutline activates person outline instead of a rectangle (default is true)
* @param hideStereotypes hides stereotypes when rendering elements (default is true)
* @param dependencyConfigurations list of [DependencyConfiguration]
*/
data class C4PlantUmlLayout(
val nodeSep: Int? = null,
val rankSep: Int? = null,
val lineType: LineType? = null,
val layout: Layout = TopDown,
val legend: Legend = ShowLegend,
val showPersonOutline: Boolean = true,
val hideStereotypes: Boolean = true,
val dependencyConfigurations: List<DependencyConfiguration> = listOf()
) {
fun hasPostamble(): Boolean = nodeSep != null || rankSep != null || lineType != null || legend != None
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.github.chriskn.structurizrextension.internal.export.writer

import com.github.chriskn.structurizrextension.api.model.icon
import com.github.chriskn.structurizrextension.api.model.link
import com.github.chriskn.structurizrextension.api.view.renderAsSequenceDiagram
import com.github.chriskn.structurizrextension.api.view.dynamic.renderAsSequenceDiagram
import com.github.chriskn.structurizrextension.internal.export.idOf
import com.github.chriskn.structurizrextension.internal.icons.IconRegistry
import com.structurizr.export.IndentingWriter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.github.chriskn.structurizrextension.internal.export.writer

import com.github.chriskn.structurizrextension.api.model.icon
import com.github.chriskn.structurizrextension.api.view.dynamic.renderAsSequenceDiagram
import com.github.chriskn.structurizrextension.api.view.layout.LayoutRegistry
import com.github.chriskn.structurizrextension.api.view.renderAsSequenceDiagram
import com.github.chriskn.structurizrextension.internal.icons.AWS_ICON_COMMONS
import com.github.chriskn.structurizrextension.internal.icons.AWS_ICON_URL
import com.github.chriskn.structurizrextension.internal.icons.IconRegistry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package com.github.chriskn.structurizrextension.internal.export.writer

import com.github.chriskn.structurizrextension.api.model.icon
import com.github.chriskn.structurizrextension.api.model.link
import com.github.chriskn.structurizrextension.api.view.dynamic.renderAsSequenceDiagram
import com.github.chriskn.structurizrextension.api.view.layout.DependencyConfiguration
import com.github.chriskn.structurizrextension.api.view.layout.Direction
import com.github.chriskn.structurizrextension.api.view.layout.LayoutRegistry
import com.github.chriskn.structurizrextension.api.view.layout.Mode
import com.github.chriskn.structurizrextension.api.view.renderAsSequenceDiagram
import com.github.chriskn.structurizrextension.internal.export.idOf
import com.github.chriskn.structurizrextension.internal.icons.IconRegistry
import com.structurizr.export.IndentingWriter
Expand Down
11 changes: 0 additions & 11 deletions src/main/kotlin/com/structurizr/model/EnterpriseExtension.kt

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.structurizr.view

internal var RelationshipView.nestedParallelSequenceOrder: String
internal var RelationshipView.orderInternal: String
get() = this.order
set(order) { this.order = order }
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import com.github.chriskn.structurizrextension.api.model.component
import com.github.chriskn.structurizrextension.api.model.container
import com.github.chriskn.structurizrextension.api.model.person
import com.github.chriskn.structurizrextension.api.model.softwareSystem
import com.github.chriskn.structurizrextension.api.view.add
import com.github.chriskn.structurizrextension.api.view.dynamic.add
import com.github.chriskn.structurizrextension.api.view.dynamic.renderAsSequenceDiagram
import com.github.chriskn.structurizrextension.api.view.dynamic.startNestedParallelSequence
import com.github.chriskn.structurizrextension.api.view.dynamicView
import com.github.chriskn.structurizrextension.api.view.layout.C4PlantUmlLayout
import com.github.chriskn.structurizrextension.api.view.layout.DependencyConfiguration
import com.github.chriskn.structurizrextension.api.view.layout.Direction.Left
import com.github.chriskn.structurizrextension.api.view.layout.Direction.Right
import com.github.chriskn.structurizrextension.api.view.layout.Mode.Neighbor
import com.github.chriskn.structurizrextension.api.view.renderAsSequenceDiagram
import com.github.chriskn.structurizrextension.api.view.showExternalBoundaries
import com.github.chriskn.structurizrextension.api.view.startNestedParallelSequence
import com.github.chriskn.structurizrextension.api.writeDiagrams
import com.github.chriskn.structurizrextension.assertExpectedDiagramWasWrittenForView
import com.structurizr.Workspace
Expand Down

0 comments on commit a93df91

Please sign in to comment.