From a18ef023c96bc23806d0ea87ede21688e808626c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=B6ren=20Henning?= <stu114708@informatik.uni-kiel.de>
Date: Mon, 23 May 2016 15:38:23 +0200
Subject: [PATCH] worked on dependency graphs

---
 .../analysis/dev/DependencyGraphCreator.java  | 80 +++++++++++++++++++
 1 file changed, 80 insertions(+)
 create mode 100644 src/main/java/kieker/analysis/dev/DependencyGraphCreator.java

diff --git a/src/main/java/kieker/analysis/dev/DependencyGraphCreator.java b/src/main/java/kieker/analysis/dev/DependencyGraphCreator.java
new file mode 100644
index 00000000..2c02c92b
--- /dev/null
+++ b/src/main/java/kieker/analysis/dev/DependencyGraphCreator.java
@@ -0,0 +1,80 @@
+package kieker.analysis.dev;
+
+import java.util.Collection;
+
+import kieker.analysis.domain.systemdependency.Component;
+import kieker.analysis.domain.systemdependency.Container;
+import kieker.analysis.domain.systemdependency.Operation;
+import kieker.analysis.domain.systemdependency.SoftwareSystem;
+import kieker.analysis.domain.systemdependency.SystemEntity;
+import kieker.analysis.util.graph.Graph;
+import kieker.analysis.util.graph.Vertex;
+import kieker.analysis.util.graph.impl.GraphImpl;
+
+public class DependencyGraphCreator {
+
+	private final boolean containers = true;
+	private final boolean components = true;
+	private final boolean operations = true;
+
+	private final boolean containerDependencies = true;
+	private final boolean componentDependencies = true;
+	private final boolean operationDependencies = true;
+
+	public Graph create(final SoftwareSystem softwareSystem) {
+
+		Graph graph = new GraphImpl();
+
+		addContainers(graph, softwareSystem.getContainers());
+
+		return graph;
+	}
+
+	private void addContainers(final Graph graph, final Collection<Container> containers) {
+		for (Container container : containers) {
+			if (this.containers) {
+				Vertex vertex = graph.addVertex(container.getIdentifier());
+				vertex.setProperty("ContainerName", container.getName());
+				addDurationStatistics(vertex, container);
+				addComponents(vertex.addChildGraph(), container.getComponents());
+			} else {
+				addComponents(graph, container.getComponents());
+			}
+		}
+	}
+
+	private void addComponents(final Graph graph, final Collection<Component> components) {
+		for (Component component : components) {
+			if (this.components) {
+				Vertex vertex = graph.addVertex(component.getIdentifier());
+				vertex.setProperty("ComponentName", component.getName());
+				vertex.setProperty("ContainerName", component.getContainer().getName());
+				addDurationStatistics(vertex, component);
+				addOperations(vertex.addChildGraph(), component.getOperations());
+			} else {
+				addOperations(graph, component.getOperations());
+			}
+		}
+	}
+
+	private void addOperations(final Graph graph, final Collection<Operation> operations) {
+		for (Operation operation : operations) {
+			if (this.operations) {
+				Vertex vertex = graph.addVertex(operation.getIdentifier());
+				vertex.setProperty("OperationName", operation.getName());
+				vertex.setProperty("ComponentName", operation.getComponent().getName());
+				vertex.setProperty("ContainerName", operation.getComponent().getContainer().getName());
+				addDurationStatistics(vertex, operation);
+			}
+		}
+	}
+
+	private void addDurationStatistics(final Vertex vertex, final SystemEntity systemEntity) {
+		vertex.setProperty("MaxDuration", systemEntity.getMaxDuration());
+		vertex.setProperty("MinDuration", systemEntity.getMinDuration());
+		vertex.setProperty("MeanDuration", systemEntity.getMeanDuration());
+		vertex.setProperty("MedianDuration", systemEntity.getMedianDuration());
+		vertex.setProperty("TotalDuration", systemEntity.getTotalDuration());
+	}
+
+}
-- 
GitLab