Skip to content

Commit

Permalink
#19 Build the report model graph in the report service
Browse files Browse the repository at this point in the history
  • Loading branch information
ThetaSinner committed Oct 27, 2018
1 parent 2d5a2d2 commit cc4e857
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,26 @@ 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,

val sink: Node,

val directed: Boolean = false
) {
}
)

class SubGraphSelector (
val name: String,

val includeNodes: List<Node>
) {
}
)
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<IConnectable, Node> = 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)
}
}

0 comments on commit cc4e857

Please sign in to comment.