diff --git a/acropolis-report/src/main/kotlin/org/ephyra/acropolis/report/api/model/Graph.kt b/acropolis-report/src/main/kotlin/org/ephyra/acropolis/report/api/model/Graph.kt index e73a6c5..704567d 100644 --- a/acropolis-report/src/main/kotlin/org/ephyra/acropolis/report/api/model/Graph.kt +++ b/acropolis-report/src/main/kotlin/org/ephyra/acropolis/report/api/model/Graph.kt @@ -26,12 +26,15 @@ class Graph { fun addDirectedEdge(from: Node, to: Node) { edges.add(Edge(from, to, true)) } + + fun findNode(label: String): Node? { + return nodes.find { node -> node.label == label } + } } class Node( val label: String -) { -} +) class Edge( val source: Node, @@ -39,12 +42,10 @@ class Edge( val sink: Node, val directed: Boolean = false -) { -} +) class SubGraphSelector ( val name: String, val includeNodes: List -) { -} +) 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 a829a93..4685e35 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 @@ -1,13 +1,22 @@ package org.ephyra.acropolis.service.impl +import org.ephyra.acropolis.persistence.api.ConnectionType +import org.ephyra.acropolis.persistence.api.IConnectable +import org.ephyra.acropolis.persistence.api.entity.ApplicationSoftwareEntity +import org.ephyra.acropolis.persistence.api.entity.SystemSoftwareEntity import org.ephyra.acropolis.report.api.IReportRunner +import org.ephyra.acropolis.report.api.model.Graph +import org.ephyra.acropolis.report.api.model.GraphContainer +import org.ephyra.acropolis.report.api.model.Node import org.ephyra.acropolis.service.api.IApplicationSoftwareService +import org.ephyra.acropolis.service.api.IConnectionService import org.ephyra.acropolis.service.api.IReportService import org.ephyra.acropolis.service.api.ISystemSoftwareService import org.slf4j.Logger import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Service +import java.lang.IllegalStateException /** * Report service implementation @@ -22,13 +31,49 @@ class ReportService : IReportService { @Autowired private lateinit var systemService: ISystemSoftwareService + @Autowired + private lateinit var connectionService: IConnectionService + @Autowired private lateinit var reportRunner: IReportRunner override fun runSoftwareReport(projectName: String) { logger.trace("Starting to run software report for project [$projectName]") - applicationService.findAll(projectName) - systemService.findAll(projectName) + val applications = applicationService.findAll(projectName) + val systems = systemService.findAll(projectName) + + val nodeMap: MutableMap = HashMap() + val graph = Graph() + + applications.forEach { app -> + val node = Node(app.name) + graph.addNode(node) + + nodeMap[app] = node + } + + systems.forEach { system -> + val node = Node(system.name) + graph.addNode(node) + + nodeMap[system] = node + } + + nodeMap.forEach { fromConnectable, fromNode -> + val connections = connectionService.getConnectionsFrom(fromConnectable, ConnectionType.TALKS_TO) + connections.forEach { toConnection -> + val toNode = when (toConnection) { + is SystemSoftwareEntity -> graph.findNode(toConnection.name) + is ApplicationSoftwareEntity -> graph.findNode(toConnection.name) + else -> throw IllegalStateException("Unknown connection type type") + } ?: throw IllegalStateException("Unable to find node to connect to") + + graph.addDirectedEdge(fromNode, toNode) + } + } + + val graphContainer = GraphContainer(graph) + reportRunner.run(graphContainer) } }