From 1414e76d941b45c3c3fc760b7f979b9f7f30b02c Mon Sep 17 00:00:00 2001 From: Dominik Seidel Date: Wed, 20 Nov 2019 15:50:22 +0100 Subject: [PATCH] CLI: Add options --blame and --root-cause --- application/clicommands/ProcessCommand.php | 12 ++++++++ library/Businessprocess/BpNode.php | 32 ++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/application/clicommands/ProcessCommand.php b/application/clicommands/ProcessCommand.php index a11a202..33c8936 100644 --- a/application/clicommands/ProcessCommand.php +++ b/application/clicommands/ProcessCommand.php @@ -75,6 +75,12 @@ class ProcessCommand extends Command * --state-type Define which state type to look at. Could be * either soft or hard, overrides an eventually * configured default + * --blame Show problem details as a tree reduced to the + * nodes which have the same state as the business + * process + * --root-cause Used in combination with --blame. Only shows + * the path of the nodes which are responsible for + * the state of the business process */ public function checkAction() { @@ -110,6 +116,12 @@ class ProcessCommand extends Command if ($this->params->shift('details')) { echo $this->renderProblemTree($node->getProblemTree(), $this->params->shift('colors')); } + if ($this->params->shift('blame')) { + echo $this->renderProblemTree( + $node->getProblemTreeBlame($this->params->shift('root-cause')), + $this->params->shift('colors') + ); + } exit($node->getState()); } diff --git a/library/Businessprocess/BpNode.php b/library/Businessprocess/BpNode.php index 1575b34..bc8487e 100644 --- a/library/Businessprocess/BpNode.php +++ b/library/Businessprocess/BpNode.php @@ -175,6 +175,38 @@ class BpNode extends Node return $tree; } + /** + * Get the problem nodes as tree reduced to the nodes which have the same state as the business process + * + * @param bool $rootCause Reduce nodes to the nodes which are responsible for the state of the business process + * + * @return array + */ + public function getProblemTreeBlame($rootCause = false) + { + $tree = []; + $nodeState = $this->getState(); + + if ($nodeState !== 0) { + foreach ($this->getChildren() as $child) { + $childState = $rootCause ? $child->getSortingState() : $child->getState(); + if (($rootCause ? $this->getSortingState() : $nodeState) === $childState) { + $name = $child->getName(); + $tree[$name] = [ + 'children' => [], + 'node' => $child + ]; + if ($child instanceof BpNode) { + $tree[$name]['children'] = $child->getProblemTreeBlame($rootCause); + } + } + } + } + + return $tree; + } + + public function isMissing() { if ($this->missing === null) {