From 8d486684609b27920947a80a3ff4bdc780acfb96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Ga=C5=82uszka?= Date: Fri, 27 Sep 2024 13:49:28 +0200 Subject: [PATCH 1/4] fix: Fix broken Indexing with correct URLs --- .../generatr/site/model/SearchViewModel.kt | 25 +++++++++++-------- .../SoftwareSystemContainerDecisions.kt | 22 ++++++++++++++++ .../SoftwareSystemContainerSections.kt | 20 +++++++++++++++ .../model/indexing/SoftwareSystemDecisions.kt | 14 +++++------ .../model/indexing/SoftwareSystemSections.kt | 18 ++++++------- .../site/model/indexing/WorkspaceDecisions.kt | 4 ++- .../site/model/indexing/WorkspaceSections.kt | 4 ++- .../site/generatr/site/model/IndexingTest.kt | 12 ++++----- .../site/model/SearchViewModelTest.kt | 8 ++++-- 9 files changed, 87 insertions(+), 40 deletions(-) create mode 100644 src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/indexing/SoftwareSystemContainerDecisions.kt create mode 100644 src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/indexing/SoftwareSystemContainerSections.kt diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SearchViewModel.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SearchViewModel.kt index 0c8f5d41..cb835190 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SearchViewModel.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SearchViewModel.kt @@ -1,16 +1,7 @@ package nl.avisi.structurizr.site.generatr.site.model import nl.avisi.structurizr.site.generatr.site.GeneratorContext -import nl.avisi.structurizr.site.generatr.site.model.indexing.home -import nl.avisi.structurizr.site.generatr.site.model.indexing.softwareSystemComponents -import nl.avisi.structurizr.site.generatr.site.model.indexing.softwareSystemContainers -import nl.avisi.structurizr.site.generatr.site.model.indexing.softwareSystemContext -import nl.avisi.structurizr.site.generatr.site.model.indexing.softwareSystemDecisions -import nl.avisi.structurizr.site.generatr.site.model.indexing.softwareSystemHome -import nl.avisi.structurizr.site.generatr.site.model.indexing.softwareSystemRelationships -import nl.avisi.structurizr.site.generatr.site.model.indexing.softwareSystemSections -import nl.avisi.structurizr.site.generatr.site.model.indexing.workspaceDecisions -import nl.avisi.structurizr.site.generatr.site.model.indexing.workspaceSections +import nl.avisi.structurizr.site.generatr.site.model.indexing.* class SearchViewModel(generatorContext: GeneratorContext) : PageViewModel(generatorContext) { override val pageSubTitle = "Search results" @@ -36,7 +27,19 @@ class SearchViewModel(generatorContext: GeneratorContext) : PageViewModel(genera addAll(softwareSystemSections(it, this@SearchViewModel)) } } - .mapNotNull { it }, + .mapNotNull { it } + ) + addAll( + includedSoftwareSystems + .flatMap { + buildList { + it.containers.forEach { + addAll(softwareSystemContainerSections(it, this@SearchViewModel)) + addAll(softwareSystemContainerDecisions(it, this@SearchViewModel)) + } + } + } + .mapNotNull { it } ) }.mapNotNull { it } diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/indexing/SoftwareSystemContainerDecisions.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/indexing/SoftwareSystemContainerDecisions.kt new file mode 100644 index 00000000..1e4c615c --- /dev/null +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/indexing/SoftwareSystemContainerDecisions.kt @@ -0,0 +1,22 @@ +package nl.avisi.structurizr.site.generatr.site.model.indexing + +import com.structurizr.model.Container +import nl.avisi.structurizr.site.generatr.site.asUrlToDirectory +import nl.avisi.structurizr.site.generatr.site.model.PageViewModel +import nl.avisi.structurizr.site.generatr.site.model.SoftwareSystemContainerDecisionPageViewModel +import nl.avisi.structurizr.site.generatr.site.model.contentText + +fun softwareSystemContainerDecisions(container: Container, viewModel: PageViewModel) = container + .documentation + .decisions + .map { decision -> + Document( + SoftwareSystemContainerDecisionPageViewModel.url( + container, + decision + ).asUrlToDirectory(viewModel.url), + "Container Decision", + "${container.name} | ${decision.title}", + "${decision.title} ${decision.contentText()}".trim() + ) + } diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/indexing/SoftwareSystemContainerSections.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/indexing/SoftwareSystemContainerSections.kt new file mode 100644 index 00000000..ca42f3c1 --- /dev/null +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/indexing/SoftwareSystemContainerSections.kt @@ -0,0 +1,20 @@ +package nl.avisi.structurizr.site.generatr.site.model.indexing + +import com.structurizr.model.Container +import nl.avisi.structurizr.site.generatr.site.asUrlToDirectory +import nl.avisi.structurizr.site.generatr.site.model.* + +fun softwareSystemContainerSections(container: Container, viewModel: PageViewModel) = container + .documentation + .sections + .map { section -> + Document( + SoftwareSystemContainerSectionPageViewModel.url( + container, + section + ).asUrlToDirectory(viewModel.url), + "Container Documentation", + "${container.name} | ${section.contentTitle()}", + "${section.contentTitle()} ${section.contentText()}".trim() + ) + } diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/indexing/SoftwareSystemDecisions.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/indexing/SoftwareSystemDecisions.kt index 9fd2dd24..c2774e0e 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/indexing/SoftwareSystemDecisions.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/indexing/SoftwareSystemDecisions.kt @@ -3,20 +3,18 @@ package nl.avisi.structurizr.site.generatr.site.model.indexing import com.structurizr.model.SoftwareSystem import nl.avisi.structurizr.site.generatr.site.asUrlToDirectory import nl.avisi.structurizr.site.generatr.site.model.PageViewModel -import nl.avisi.structurizr.site.generatr.site.model.SoftwareSystemPageViewModel +import nl.avisi.structurizr.site.generatr.site.model.SoftwareSystemDecisionPageViewModel import nl.avisi.structurizr.site.generatr.site.model.contentText fun softwareSystemDecisions(softwareSystem: SoftwareSystem, viewModel: PageViewModel) = softwareSystem.documentation .decisions .map { decision -> Document( - "${ - SoftwareSystemPageViewModel.url( - softwareSystem, - SoftwareSystemPageViewModel.Tab.HOME - ) - }/decisions/${decision.id}".asUrlToDirectory(viewModel.url), - "Decision", + SoftwareSystemDecisionPageViewModel.url( + softwareSystem, + decision + ).asUrlToDirectory(viewModel.url), + "Software System Decision", "${softwareSystem.name} | ${decision.title}", "${decision.title} ${decision.contentText()}".trim() ) diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/indexing/SoftwareSystemSections.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/indexing/SoftwareSystemSections.kt index 93fb1213..71385520 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/indexing/SoftwareSystemSections.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/indexing/SoftwareSystemSections.kt @@ -2,23 +2,19 @@ package nl.avisi.structurizr.site.generatr.site.model.indexing import com.structurizr.model.SoftwareSystem import nl.avisi.structurizr.site.generatr.site.asUrlToDirectory -import nl.avisi.structurizr.site.generatr.site.model.PageViewModel -import nl.avisi.structurizr.site.generatr.site.model.SoftwareSystemPageViewModel -import nl.avisi.structurizr.site.generatr.site.model.contentText -import nl.avisi.structurizr.site.generatr.site.model.contentTitle +import nl.avisi.structurizr.site.generatr.site.model.* fun softwareSystemSections(softwareSystem: SoftwareSystem, viewModel: PageViewModel) = softwareSystem.documentation .sections .drop(1) // Drop software system home .map { section -> Document( - "${ - SoftwareSystemPageViewModel.url( - softwareSystem, - SoftwareSystemPageViewModel.Tab.HOME - ) - }/sections/${section.order}".asUrlToDirectory(viewModel.url), - "Documentation", + + SoftwareSystemSectionPageViewModel.url( + softwareSystem, + section + ).asUrlToDirectory(viewModel.url), + "Software System Documentation", "${softwareSystem.name} | ${section.contentTitle()}", "${section.contentTitle()} ${section.contentText()}".trim() ) diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/indexing/WorkspaceDecisions.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/indexing/WorkspaceDecisions.kt index 63624475..d6a8479c 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/indexing/WorkspaceDecisions.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/indexing/WorkspaceDecisions.kt @@ -3,12 +3,14 @@ package nl.avisi.structurizr.site.generatr.site.model.indexing import com.structurizr.documentation.Documentation import nl.avisi.structurizr.site.generatr.site.asUrlToDirectory import nl.avisi.structurizr.site.generatr.site.model.PageViewModel +import nl.avisi.structurizr.site.generatr.site.model.WorkspaceDecisionPageViewModel import nl.avisi.structurizr.site.generatr.site.model.contentText fun workspaceDecisions(documentation: Documentation, viewModel: PageViewModel) = documentation.decisions .map { decision -> Document( - "/decisions/${decision.id}".asUrlToDirectory(viewModel.url), + WorkspaceDecisionPageViewModel.url(decision) + .asUrlToDirectory(viewModel.url), "Workspace Decision", decision.title, "${decision.title} ${decision.contentText()}".trim() diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/indexing/WorkspaceSections.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/indexing/WorkspaceSections.kt index 5d35709e..8c348459 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/indexing/WorkspaceSections.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/indexing/WorkspaceSections.kt @@ -4,6 +4,7 @@ import com.structurizr.documentation.Documentation import nl.avisi.structurizr.site.generatr.normalize import nl.avisi.structurizr.site.generatr.site.asUrlToDirectory import nl.avisi.structurizr.site.generatr.site.model.PageViewModel +import nl.avisi.structurizr.site.generatr.site.model.WorkspaceDocumentationSectionPageViewModel import nl.avisi.structurizr.site.generatr.site.model.contentText import nl.avisi.structurizr.site.generatr.site.model.contentTitle @@ -11,7 +12,8 @@ fun workspaceSections(documentation: Documentation, viewModel: PageViewModel) = .drop(1) // Drop home .map { section -> Document( - "/${section.contentTitle().normalize()}".asUrlToDirectory(viewModel.url), + WorkspaceDocumentationSectionPageViewModel.url(section) + .asUrlToDirectory(viewModel.url), "Workspace Documentation", section.contentTitle(), "${section.contentTitle()} ${section.contentText()}".trim() diff --git a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/IndexingTest.kt b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/IndexingTest.kt index 107a7478..bcc2a2da 100644 --- a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/IndexingTest.kt +++ b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/IndexingTest.kt @@ -265,13 +265,13 @@ class IndexingTest : ViewModelTest() { assertThat(documents).containsAtLeast( Document( "../software-system-1/decisions/1/", - "Decision", + "Software System Decision", "Software System 1 | Decision 1", "Decision 1 Decision 1 content" ), Document( "../software-system-1/decisions/2/", - "Decision", + "Software System Decision", "Software System 1 | Decision 2", "Decision 2 Decision 2 content" ) @@ -307,14 +307,14 @@ class IndexingTest : ViewModelTest() { assertThat(documents).containsAtLeast( Document( - "../software-system-1/sections/2/", - "Documentation", + "../software-system-1/sections/usage/", + "Software System Documentation", "Software System 1 | Usage", "Usage That's how it works" ), Document( - "../software-system-1/sections/3/", - "Documentation", + "../software-system-1/sections/history/", + "Software System Documentation", "Software System 1 | History", "History That's how we got here" ) diff --git a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SearchViewModelTest.kt b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SearchViewModelTest.kt index 6ebd8b55..43a2021a 100644 --- a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SearchViewModelTest.kt +++ b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SearchViewModelTest.kt @@ -81,6 +81,8 @@ class SearchViewModelTest : ViewModelTest() { documentation.addSection(Section(Format.Markdown, "# Introduction\nSome info")) addContainer("Container 1", "a container").apply { addComponent("Component 1", "a component") + documentation.addDecision(createDecision("1")) + documentation.addSection(Section(Format.Markdown, "# Component Usage\nThat's how it works")) } documentation.addDecision(createDecision("1")) documentation.addSection(Section(Format.Markdown, "# Usage\nThat's how it works")) @@ -94,8 +96,10 @@ class SearchViewModelTest : ViewModelTest() { "Context views", "Container views", "Component views", - "Decision", - "Documentation" + "Software System Decision", + "Software System Documentation", + "Container Documentation", + "Container Decision" ) } From 4a3a441ad42c94b802533e3c34078050b5b1a57b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Ga=C5=82uszka?= Date: Mon, 30 Sep 2024 12:08:11 +0200 Subject: [PATCH 2/4] test: requested tests by @jenspav --- .../site/generatr/site/model/IndexingTest.kt | 81 ++++++++++++++++--- 1 file changed, 70 insertions(+), 11 deletions(-) diff --git a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/IndexingTest.kt b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/IndexingTest.kt index bcc2a2da..28f783e1 100644 --- a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/IndexingTest.kt +++ b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/IndexingTest.kt @@ -8,17 +8,7 @@ import assertk.assertions.isEqualTo import assertk.assertions.isNull import com.structurizr.documentation.Format import com.structurizr.documentation.Section -import nl.avisi.structurizr.site.generatr.site.model.indexing.Document -import nl.avisi.structurizr.site.generatr.site.model.indexing.home -import nl.avisi.structurizr.site.generatr.site.model.indexing.softwareSystemComponents -import nl.avisi.structurizr.site.generatr.site.model.indexing.softwareSystemContainers -import nl.avisi.structurizr.site.generatr.site.model.indexing.softwareSystemContext -import nl.avisi.structurizr.site.generatr.site.model.indexing.softwareSystemDecisions -import nl.avisi.structurizr.site.generatr.site.model.indexing.softwareSystemHome -import nl.avisi.structurizr.site.generatr.site.model.indexing.softwareSystemRelationships -import nl.avisi.structurizr.site.generatr.site.model.indexing.softwareSystemSections -import nl.avisi.structurizr.site.generatr.site.model.indexing.workspaceDecisions -import nl.avisi.structurizr.site.generatr.site.model.indexing.workspaceSections +import nl.avisi.structurizr.site.generatr.site.model.indexing.* import kotlin.test.Test class IndexingTest : ViewModelTest() { @@ -320,4 +310,73 @@ class IndexingTest : ViewModelTest() { ) ) } + + @Test + fun `no container sections`() { + val softwareSystem = workspace.model.addSoftwareSystem("Software System 1", "One system to rule them all") + softwareSystem.addContainer("Container 1", "a container") + val documents = softwareSystemContainerSections(softwareSystem.containers.single(), this.pageViewModel()) + + assertThat(documents).isEmpty() + } + + @Test + fun `no container decisions`() { + val softwareSystem = workspace.model.addSoftwareSystem("Software System 1", "One system to rule them all") + softwareSystem.addContainer("Container 1", "a container") + val documents = softwareSystemContainerDecisions(softwareSystem.containers.single(), this.pageViewModel()) + + assertThat(documents).isEmpty() + } + + @Test + fun `indexes container decisions`() { + val softwareSystem = workspace.model.addSoftwareSystem("Software System 1", "One system to rule them all") + val container = softwareSystem.addContainer("Container 1", "a container").apply { + documentation.addDecision(createDecision("1")) + documentation.addDecision(createDecision("2")) + } + val documents = softwareSystemContainerDecisions(container, this.pageViewModel()) + + assertThat(documents).containsAtLeast( + Document( + "../software-system-1/decisions/container-1/1/", + "Container Decision", + "Container 1 | Decision 1", + "Decision 1 Decision 1 content" + ), + Document( + "../software-system-1/decisions/container-1/2/", + "Container Decision", + "Container 1 | Decision 2", + "Decision 2 Decision 2 content" + ) + ) + } + + @Test + fun `indexes container sections`() { + val softwareSystem = workspace.model.addSoftwareSystem("Software System 1", "One system to rule them all") + val container = softwareSystem.addContainer("Container 1", "a container").apply { + documentation.addSection(Section(Format.Markdown, "# Introduction\nSome info")) + documentation.addSection(Section(Format.Markdown, "# Usage\nThat's how it works")) + documentation.addSection(Section(Format.Markdown, "# History\nThat's how we got here")) + } + val documents = softwareSystemContainerSections(container, this.pageViewModel()) + + assertThat(documents).containsAtLeast( + Document( + "../software-system-1/sections/container-1/usage/", + "Container Documentation", + "Container 1 | Usage", + "Usage That's how it works" + ), + Document( + "../software-system-1/sections/container-1/history/", + "Container Documentation", + "Container 1 | History", + "History That's how we got here" + ) + ) + } } From 3d9a142808c25347157df756860473f7c9d5e6dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Ga=C5=82uszka?= Date: Mon, 30 Sep 2024 15:45:32 +0200 Subject: [PATCH 3/4] fix: align naming in tests --- .../structurizr/site/generatr/site/model/IndexingTest.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/IndexingTest.kt b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/IndexingTest.kt index 28f783e1..4f44b52f 100644 --- a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/IndexingTest.kt +++ b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/IndexingTest.kt @@ -269,7 +269,7 @@ class IndexingTest : ViewModelTest() { } @Test - fun `no software system documentation`() { + fun `no software system sections`() { workspace.model.addSoftwareSystem("Software System 1", "One system to rule them all") val documents = softwareSystemSections(workspace.model.softwareSystems.single(), this.pageViewModel()) @@ -277,7 +277,7 @@ class IndexingTest : ViewModelTest() { } @Test - fun `only software system documentation for software system home`() { + fun `only software system section for software system home`() { workspace.model.addSoftwareSystem("Software System 1", "One system to rule them all").apply { documentation.addSection(Section(Format.Markdown, "# Introduction\nSome info")) } From 871f9be29caaf1b5e191e45044ca885b0792ce03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Ga=C5=82uszka?= Date: Mon, 30 Sep 2024 17:18:52 +0200 Subject: [PATCH 4/4] fix(formating): removing unnecessary empty line --- .../site/generatr/site/model/indexing/SoftwareSystemSections.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/indexing/SoftwareSystemSections.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/indexing/SoftwareSystemSections.kt index 71385520..d7a03bcb 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/indexing/SoftwareSystemSections.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/indexing/SoftwareSystemSections.kt @@ -9,7 +9,6 @@ fun softwareSystemSections(softwareSystem: SoftwareSystem, viewModel: PageViewMo .drop(1) // Drop software system home .map { section -> Document( - SoftwareSystemSectionPageViewModel.url( softwareSystem, section