Skip to content

Commit

Permalink
#19 Give the report service access to the graphical asset service
Browse files Browse the repository at this point in the history
  • Loading branch information
ThetaSinner committed Oct 30, 2018
1 parent 7797d6f commit 548989c
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ class GraphicalAssetPersistence {
fun findAll(): MutableIterable<GraphicalAssetEntity> {
return repo.findAll()
}

fun find(name: String): GraphicalAssetEntity? {
val asset = repo.findByName(name)
return if (asset.isPresent) asset.get() else null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<GraphicalAssetEntity, Long>
interface GraphicalAssetRepository : CrudRepository<GraphicalAssetEntity, Long> {
fun findByName(name: String): Optional<GraphicalAssetEntity>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.ephyra.acropolis.report.api

import java.io.InputStream

interface IImageSource {
fun get(resourceName: String): InputStream
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -53,7 +54,7 @@ private class ReportRunner : IReportRunner {
}

DiagramRenderer(diagramWidth, diagramHeight).use { renderer ->

}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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

/**
Expand All @@ -22,4 +23,6 @@ interface IGraphicalAssetService {
* @return list of graphical assets
*/
fun findAll(): List<GraphicalAsset>

fun find(name: String): GraphicalAssetEntity?
}
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ class GraphicalAssetService : IGraphicalAssetService {
GraphicalAsset(type, assetEntity.source)
}
}

override fun find(name: String): GraphicalAssetEntity? {
return persistence.find(name)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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]")

Expand Down Expand Up @@ -74,6 +77,6 @@ class ReportService : IReportService {
}

val graphContainer = GraphContainer(graph)
reportRunner.run(graphContainer)
reportRunner.run(graphContainer, graphicalAssetImageSource)
}
}

0 comments on commit 548989c

Please sign in to comment.