From d4b5501e5be938e2f8688a01a5219fe562182379 Mon Sep 17 00:00:00 2001 From: Eddie Groh <groh@fortiss.org> Date: Mon, 7 Aug 2023 15:38:08 +0200 Subject: [PATCH] Refactor for compatibility with DataDictonaryProvider Issue-Ref: 4310 Issue-Url: https://git.fortiss.org/af3/af3/-/issues/4310 Signed-off-by: Eddie Groh <groh@fortiss.org> --- .../ui/view/fx/ModelQualityFXController.java | 34 ++++++++----------- .../ext/quality/data/MetricDataManager.java | 10 +++--- .../tooling/ext/quality/data/MetricKey.java | 5 +++ .../quality/service/ModelQualityService.java | 26 +++++++++----- 4 files changed, 42 insertions(+), 33 deletions(-) diff --git a/org.fortiss.tooling.ext.quality.ui/src/org/fortiss/tooling/ext/quality/ui/view/fx/ModelQualityFXController.java b/org.fortiss.tooling.ext.quality.ui/src/org/fortiss/tooling/ext/quality/ui/view/fx/ModelQualityFXController.java index ea331dd49..47cd2a388 100644 --- a/org.fortiss.tooling.ext.quality.ui/src/org/fortiss/tooling/ext/quality/ui/view/fx/ModelQualityFXController.java +++ b/org.fortiss.tooling.ext.quality.ui/src/org/fortiss/tooling/ext/quality/ui/view/fx/ModelQualityFXController.java @@ -34,7 +34,6 @@ import org.eclipse.emf.ecore.EObject; import org.eclipse.jface.viewers.ISelection; import org.eclipse.ui.ISelectionListener; import org.eclipse.ui.IWorkbenchPart; -import org.fortiss.tooling.base.model.element.IHierarchicElement; import org.fortiss.tooling.common.ui.javafx.layout.CompositeFXControllerBase; import org.fortiss.tooling.common.ui.javafx.style.FillStyle; import org.fortiss.tooling.common.ui.javafx.style.FontStyle; @@ -107,7 +106,7 @@ public class ModelQualityFXController extends CompositeFXControllerBase<SplitPan * The last IHierachicElement which the user has clicked. Might be null when no or invalid * Object is selected */ - private IHierarchicElement lastSelectedElement; + private EObject lastSelectedElement; /** {@inheritDoc} */ @Override @@ -141,23 +140,14 @@ public class ModelQualityFXController extends CompositeFXControllerBase<SplitPan return; } - if(!(currentRootElement instanceof IHierarchicElement)) { - // topLabel.setText("Root is not an IHierarchicElement"); + var root_provider = manager.getRootNodes().get(currentRootElement); + + if(root_provider == null) { + // topLabel.setText("No Metric found for this project, did you export metrics?"); return; } - if(selected instanceof IHierarchicElement) { - var root_provider = manager.getRootNodes().get(currentRootElement); - - if(root_provider == null) { - // topLabel.setText("No Metric found for this project, did you export metrics?"); - return; - } - - lastSelectedElement = (IHierarchicElement)selected; - } else { - // topLabel.setText("Selected is not an IHierarchicElement"); - } + lastSelectedElement = selected; updateCharts(); } @@ -175,7 +165,7 @@ public class ModelQualityFXController extends CompositeFXControllerBase<SplitPan if(lastSelectedElement != null) { MetricDataManager manager = ModelQualityService.metricDataManagerInstance; - MetricTreeNode node = manager.getHierarchicLookupTable().get(lastSelectedElement); + MetricTreeNode node = manager.getTreeNodeLookupTable().get(lastSelectedElement); if(node != null) { @@ -251,14 +241,18 @@ public class ModelQualityFXController extends CompositeFXControllerBase<SplitPan return null; } - double maxval = - children.stream().mapToDouble(p -> p.getValueAsDouble(key)).max().getAsDouble(); + double maxval = children.stream().map(p -> p.getValueAsDouble(key)).filter(p -> p != null) + .mapToDouble(p -> p).max().getAsDouble(); chartStyle.setUseIndividualAxisSegments(false); chartStyle.setTitleStyle(new FontStyle("Verdana", 14, BLUE.brighter())); DataSeries elementData = new DataSeries("Data"); for(var child : node.getChildren()) { + Double value = child.getValueAsDouble(key); + if(value == null) { + value = 0.0; + } DoubleAxis testing = new DoubleAxis(child.getName(), 0.0, maxval); AxisStyle aStyle3Segs = new AxisStyle(SOLID_BLACK_1PT, BLACK_VERDANA_14PT, 3, @@ -266,7 +260,7 @@ public class ModelQualityFXController extends CompositeFXControllerBase<SplitPan chartStyle.setAxisStyle(testing, aStyle3Segs); spiderChart.addAxis(testing); - elementData.setPoint(testing, child.getValueAsDouble(key)); + elementData.setPoint(testing, value); } spiderChart.addData(elementData); diff --git a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/data/MetricDataManager.java b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/data/MetricDataManager.java index c3f109913..093c59f8b 100644 --- a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/data/MetricDataManager.java +++ b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/data/MetricDataManager.java @@ -18,7 +18,7 @@ package org.fortiss.tooling.ext.quality.data; import java.util.HashMap; import java.util.Map; -import org.fortiss.tooling.base.model.element.IHierarchicElement; +import org.eclipse.emf.ecore.EObject; import org.fortiss.tooling.kernel.model.IProjectRootElement; /** @@ -28,7 +28,7 @@ import org.fortiss.tooling.kernel.model.IProjectRootElement; public class MetricDataManager { /** a map to lookup the corresponding tree node */ - private Map<IHierarchicElement, MetricTreeNode> hierarchicLookupTable; + private Map<EObject, MetricTreeNode> treeNodeLookupTable; /** the root tree node */ private Map<IProjectRootElement, MetricTreeNode> root_nodes; @@ -38,14 +38,14 @@ public class MetricDataManager { */ public MetricDataManager() { root_nodes = new HashMap<>(); - hierarchicLookupTable = new HashMap<>(); + treeNodeLookupTable = new HashMap<>(); } /** * @return the lookup map */ - public Map<IHierarchicElement, MetricTreeNode> getHierarchicLookupTable() { - return hierarchicLookupTable; + public Map<EObject, MetricTreeNode> getTreeNodeLookupTable() { + return treeNodeLookupTable; } /** diff --git a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/data/MetricKey.java b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/data/MetricKey.java index 99c514431..ce669af35 100644 --- a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/data/MetricKey.java +++ b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/data/MetricKey.java @@ -52,6 +52,11 @@ public enum MetricKey { */ CLUSTERING_COEFFICIENT(false, 0.0), + /** How many constraints this element violates with severity error */ + CONSTRAINT_VIOLATIONS_ERROR(false), + /** How many constraints this element violates with severity warning */ + CONSTRAINT_VIOLATIONS_WARNING(false), + // // Metrics which are collected over all children nodes // diff --git a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/ModelQualityService.java b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/ModelQualityService.java index 5a8ec1f22..76b0927b0 100644 --- a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/ModelQualityService.java +++ b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/ModelQualityService.java @@ -126,6 +126,16 @@ public class ModelQualityService extends EObjectAwareServiceBase<IMetricProvider MetricTreeNode root_node = new MetricTreeNode(); recursivlyCollectMetrics(root_node, firstElement, 0); root_nodes.put(rootElement, root_node); + } else { + + var root_nodes = metricDataManagerInstance.getRootNodes(); + MetricTreeNode rootNode = new MetricTreeNode(); + + // Search for provider on ProjectRootElement + collectMetrics(rootNode, rootElement); + + root_nodes.put(rootElement, rootNode); + metricDataManagerInstance.getTreeNodeLookupTable().put(rootElement, rootNode); } } // Store all currently saved metrics to the csv @@ -161,14 +171,14 @@ public class ModelQualityService extends EObjectAwareServiceBase<IMetricProvider specificationElement.getContainedElements(); if(containedElements.size() == 1) { // Add reference from the element to this, so the lookups works as expected - manager.getHierarchicLookupTable().put(specificationElement, node); + manager.getTreeNodeLookupTable().put(specificationElement, node); // Skip the specification element to get a more useful tree structure recursivlyCollectMetrics(node, containedElements.get(0), recursionLevel); } else { recursivlyCollectMetrics(node, specificationElement, recursionLevel); } // Add reference from the element to this, so the lookups works as expected - manager.getHierarchicLookupTable().put(currentElement, node); + manager.getTreeNodeLookupTable().put(currentElement, node); } else { // Iterate over all children and merge values @@ -191,7 +201,7 @@ public class ModelQualityService extends EObjectAwareServiceBase<IMetricProvider } } - manager.getHierarchicLookupTable().put(currentElement, node); + manager.getTreeNodeLookupTable().put(currentElement, node); calculateBetweennessCentrality(currentElement, manager, false); calculateBetweennessCentrality(currentElement, manager, true); @@ -472,7 +482,7 @@ public class ModelQualityService extends EObjectAwareServiceBase<IMetricProvider MetricKey key = recursively ? MetricKey.BETWEENESS_CENTRALITY_RECURSIVELY : MetricKey.BETWEENESS_CENTRALITY; for(IHierarchicElement child : scopeElement.getContainedElements()) { - manager.getHierarchicLookupTable().get(child).getStoredDoubles().put(key, + manager.getTreeNodeLookupTable().get(child).getStoredDoubles().put(key, betweenness.get(child)); } } @@ -485,17 +495,17 @@ public class ModelQualityService extends EObjectAwareServiceBase<IMetricProvider * element to collect the data from */ @SuppressWarnings("unchecked") - private void collectMetrics(MetricTreeNode node, IHierarchicElement element) { + private void collectMetrics(MetricTreeNode node, EObject object) { - List<IMetricProvider<?>> providers = getAllMetricProviders(element); + List<IMetricProvider<?>> providers = getAllMetricProviders(object); if(providers.isEmpty()) { // it should not happen that no provider is found - throw new IllegalStateException(); + // throw new IllegalStateException(); } for(IMetricProvider<?> provider : providers) { - ((IMetricProvider<EObject>)provider).collectMetrics(node, element); + ((IMetricProvider<EObject>)provider).collectMetrics(node, object); } } -- GitLab