Skip to content

Commit

Permalink
#19 Draw images onto the report
Browse files Browse the repository at this point in the history
  • Loading branch information
ThetaSinner committed Nov 10, 2018
1 parent f01f3f8 commit 5ab3d48
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ class Graph {
* Model to represent a node in a graph
*/
class Node(
val label: String
val label: String,

val representedByResourceName: String
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ internal class ReportRunner : IReportRunner {
}

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

positions.forEach { node, position ->
val imageResource = imageSource.get(node.representedByResourceName)
renderer.addImage(position.x.toInt(), position.y.toInt(), imageResource)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import java.awt.Polygon
import java.awt.image.BufferedImage
import java.awt.image.BufferedImage.TYPE_INT_RGB
import java.io.File
import java.io.InputStream
import java.lang.IllegalStateException
import javax.imageio.ImageIO

Expand Down Expand Up @@ -36,9 +37,9 @@ class DiagramRenderer(
*
* @param positionX The offset of the left side of the image from the left side of the diagram
* @param positionY The offset of the top side of the image from the top side of the diagram
* @param source The source to fetch the image from
* @param source The input stream to read the image from
*/
fun addImage(positionX: Int, positionY: Int, source: File) {
fun addImage(positionX: Int, positionY: Int, source: InputStream) {
val img = ImageIO.read(source)
target.drawImage(img, positionX, positionY, img.width, img.height, null)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package org.ephyra.acropolis.service.impl

import org.ephyra.acropolis.external.SystemSoftwareSpecialization
import org.ephyra.acropolis.external.packSystemSpecialization
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.DatastoreEntity
import org.ephyra.acropolis.persistence.api.entity.LoadBalancerEntity
import org.ephyra.acropolis.persistence.api.entity.QueueEntity
import org.ephyra.acropolis.persistence.api.entity.ReverseProxyEntity
import org.ephyra.acropolis.persistence.api.entity.SystemSoftwareEntity
import org.ephyra.acropolis.report.api.IReportRunner
import org.ephyra.acropolis.report.api.model.Graph
Expand Down Expand Up @@ -50,14 +56,14 @@ class ReportService : IReportService {
val graph = Graph()

applications.forEach { app ->
val node = Node(app.name)
val node = Node(app.name, "application")
graph.addNode(node)

nodeMap[app] = node
}

systems.forEach { system ->
val node = Node(system.name)
val node = Node(system.name, getRepresentedByResourceNameFromSystem(system))
graph.addNode(node)

nodeMap[system] = node
Expand All @@ -79,4 +85,24 @@ class ReportService : IReportService {
val graphContainer = GraphContainer(graph)
reportRunner.run(graphContainer, graphicalAssetImageSource)
}

/**
* Gets the default image resource name for a given system. Falls back to the
* default resource names.
*/
private fun getRepresentedByResourceNameFromSystem(system: SystemSoftwareEntity): String {
// TODO this is bootstrap data and should be extracted.
return if (system.specialization == null) {
"system"
}
else {
when (system.specialization) {
is LoadBalancerEntity -> "load-balancer"
is DatastoreEntity -> "datastore"
is QueueEntity -> "queue"
is ReverseProxyEntity -> "reverse-proxy"
else -> "system"
}
}
}
}

0 comments on commit 5ab3d48

Please sign in to comment.