From 548989cdbacf40938bac9727b914c2254493f2d4 Mon Sep 17 00:00:00 2001 From: ThetaSinner Date: Tue, 30 Oct 2018 00:39:21 +0000 Subject: [PATCH] #19 Give the report service access to the graphical asset service --- .../persistence/GraphicalAssetPersistence.kt | 5 +++++ .../impl/GraphicalAssetRepository.kt | 5 ++++- .../acropolis/report/api/IImageSource.kt | 7 +++++++ .../acropolis/report/api/IReportRunner.kt | 2 +- .../acropolis/report/impl/ReportRunner.kt | 5 +++-- .../service/api/IGraphicalAssetService.kt | 3 +++ .../service/impl/GraphicalAssetImageSource.kt | 21 +++++++++++++++++++ .../service/impl/GraphicalAssetService.kt | 4 ++++ .../acropolis/service/impl/ReportService.kt | 5 ++++- 9 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 acropolis-report/src/main/kotlin/org/ephyra/acropolis/report/api/IImageSource.kt create mode 100644 acropolis-service/src/main/kotlin/org/ephyra/acropolis/service/impl/GraphicalAssetImageSource.kt diff --git a/acropolis-persistence/src/main/kotlin/org/ephyra/acropolis/persistence/api/persistence/GraphicalAssetPersistence.kt b/acropolis-persistence/src/main/kotlin/org/ephyra/acropolis/persistence/api/persistence/GraphicalAssetPersistence.kt index 03ace06..38c8a0b 100644 --- a/acropolis-persistence/src/main/kotlin/org/ephyra/acropolis/persistence/api/persistence/GraphicalAssetPersistence.kt +++ b/acropolis-persistence/src/main/kotlin/org/ephyra/acropolis/persistence/api/persistence/GraphicalAssetPersistence.kt @@ -30,4 +30,9 @@ class GraphicalAssetPersistence { fun findAll(): MutableIterable { return repo.findAll() } + + fun find(name: String): GraphicalAssetEntity? { + val asset = repo.findByName(name) + return if (asset.isPresent) asset.get() else null + } } diff --git a/acropolis-persistence/src/main/kotlin/org/ephyra/acropolis/persistence/impl/GraphicalAssetRepository.kt b/acropolis-persistence/src/main/kotlin/org/ephyra/acropolis/persistence/impl/GraphicalAssetRepository.kt index 3f31ea9..7f50572 100644 --- a/acropolis-persistence/src/main/kotlin/org/ephyra/acropolis/persistence/impl/GraphicalAssetRepository.kt +++ b/acropolis-persistence/src/main/kotlin/org/ephyra/acropolis/persistence/impl/GraphicalAssetRepository.kt @@ -2,8 +2,11 @@ package org.ephyra.acropolis.persistence.impl import org.ephyra.acropolis.persistence.api.entity.GraphicalAssetEntity import org.springframework.data.repository.CrudRepository +import java.util.Optional /** * Repository for storing graphical assets */ -interface GraphicalAssetRepository : CrudRepository +interface GraphicalAssetRepository : CrudRepository { + fun findByName(name: String): Optional +} diff --git a/acropolis-report/src/main/kotlin/org/ephyra/acropolis/report/api/IImageSource.kt b/acropolis-report/src/main/kotlin/org/ephyra/acropolis/report/api/IImageSource.kt new file mode 100644 index 0000000..26fc716 --- /dev/null +++ b/acropolis-report/src/main/kotlin/org/ephyra/acropolis/report/api/IImageSource.kt @@ -0,0 +1,7 @@ +package org.ephyra.acropolis.report.api + +import java.io.InputStream + +interface IImageSource { + fun get(resourceName: String): InputStream +} diff --git a/acropolis-report/src/main/kotlin/org/ephyra/acropolis/report/api/IReportRunner.kt b/acropolis-report/src/main/kotlin/org/ephyra/acropolis/report/api/IReportRunner.kt index 6aa8589..e2bf131 100644 --- a/acropolis-report/src/main/kotlin/org/ephyra/acropolis/report/api/IReportRunner.kt +++ b/acropolis-report/src/main/kotlin/org/ephyra/acropolis/report/api/IReportRunner.kt @@ -3,5 +3,5 @@ package org.ephyra.acropolis.report.api import org.ephyra.acropolis.report.api.model.GraphContainer interface IReportRunner { - fun run(graphContainer: GraphContainer) + fun run(graphContainer: GraphContainer, imageSource: IImageSource) } diff --git a/acropolis-report/src/main/kotlin/org/ephyra/acropolis/report/impl/ReportRunner.kt b/acropolis-report/src/main/kotlin/org/ephyra/acropolis/report/impl/ReportRunner.kt index 3d7a340..3c5b194 100644 --- a/acropolis-report/src/main/kotlin/org/ephyra/acropolis/report/impl/ReportRunner.kt +++ b/acropolis-report/src/main/kotlin/org/ephyra/acropolis/report/impl/ReportRunner.kt @@ -1,5 +1,6 @@ package org.ephyra.acropolis.report.impl +import org.ephyra.acropolis.report.api.IImageSource import org.ephyra.acropolis.report.api.IReportRunner import org.ephyra.acropolis.report.api.model.Graph import org.ephyra.acropolis.report.api.model.GraphContainer @@ -10,7 +11,7 @@ import java.lang.IllegalStateException @Component private class ReportRunner : IReportRunner { - override fun run(graphContainer: GraphContainer) { + override fun run(graphContainer: GraphContainer, imageSource: IImageSource) { println("Running report") val depthMap = buildNodeDepth(graphContainer.graph) val depthCounts = countDepths(depthMap) @@ -53,7 +54,7 @@ private class ReportRunner : IReportRunner { } DiagramRenderer(diagramWidth, diagramHeight).use { renderer -> - + } } diff --git a/acropolis-service/src/main/kotlin/org/ephyra/acropolis/service/api/IGraphicalAssetService.kt b/acropolis-service/src/main/kotlin/org/ephyra/acropolis/service/api/IGraphicalAssetService.kt index c5f0b77..7315560 100644 --- a/acropolis-service/src/main/kotlin/org/ephyra/acropolis/service/api/IGraphicalAssetService.kt +++ b/acropolis-service/src/main/kotlin/org/ephyra/acropolis/service/api/IGraphicalAssetService.kt @@ -1,6 +1,7 @@ package org.ephyra.acropolis.service.api import org.ephyra.acropolis.persistence.api.GraphicalAssetType +import org.ephyra.acropolis.persistence.api.entity.GraphicalAssetEntity import org.ephyra.acropolis.service.api.model.GraphicalAsset /** @@ -22,4 +23,6 @@ interface IGraphicalAssetService { * @return list of graphical assets */ fun findAll(): List + + fun find(name: String): GraphicalAssetEntity? } diff --git a/acropolis-service/src/main/kotlin/org/ephyra/acropolis/service/impl/GraphicalAssetImageSource.kt b/acropolis-service/src/main/kotlin/org/ephyra/acropolis/service/impl/GraphicalAssetImageSource.kt new file mode 100644 index 0000000..602f8ba --- /dev/null +++ b/acropolis-service/src/main/kotlin/org/ephyra/acropolis/service/impl/GraphicalAssetImageSource.kt @@ -0,0 +1,21 @@ +package org.ephyra.acropolis.service.impl + +import org.ephyra.acropolis.report.api.IImageSource +import org.ephyra.acropolis.service.api.IGraphicalAssetService +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.stereotype.Component +import java.io.ByteArrayInputStream +import java.io.InputStream +import java.lang.IllegalStateException + +@Component +class GraphicalAssetImageSource : IImageSource { + @Autowired + private lateinit var graphicalAssetService: IGraphicalAssetService + + override fun get(resourceName: String): InputStream { + val asset = graphicalAssetService.find(resourceName) + ?: throw IllegalStateException("Missing resource [$resourceName]") + return ByteArrayInputStream(asset.source) + } +} diff --git a/acropolis-service/src/main/kotlin/org/ephyra/acropolis/service/impl/GraphicalAssetService.kt b/acropolis-service/src/main/kotlin/org/ephyra/acropolis/service/impl/GraphicalAssetService.kt index 8042d99..ef208a1 100644 --- a/acropolis-service/src/main/kotlin/org/ephyra/acropolis/service/impl/GraphicalAssetService.kt +++ b/acropolis-service/src/main/kotlin/org/ephyra/acropolis/service/impl/GraphicalAssetService.kt @@ -32,4 +32,8 @@ class GraphicalAssetService : IGraphicalAssetService { GraphicalAsset(type, assetEntity.source) } } + + override fun find(name: String): GraphicalAssetEntity? { + return persistence.find(name) + } } diff --git a/acropolis-service/src/main/kotlin/org/ephyra/acropolis/service/impl/ReportService.kt b/acropolis-service/src/main/kotlin/org/ephyra/acropolis/service/impl/ReportService.kt index 4685e35..c8cb226 100644 --- a/acropolis-service/src/main/kotlin/org/ephyra/acropolis/service/impl/ReportService.kt +++ b/acropolis-service/src/main/kotlin/org/ephyra/acropolis/service/impl/ReportService.kt @@ -37,6 +37,9 @@ class ReportService : IReportService { @Autowired private lateinit var reportRunner: IReportRunner + @Autowired + private lateinit var graphicalAssetImageSource: GraphicalAssetImageSource + override fun runSoftwareReport(projectName: String) { logger.trace("Starting to run software report for project [$projectName]") @@ -74,6 +77,6 @@ class ReportService : IReportService { } val graphContainer = GraphContainer(graph) - reportRunner.run(graphContainer) + reportRunner.run(graphContainer, graphicalAssetImageSource) } }