icingaweb2-module-businessp.../library/Businessprocess/ImportedNode.php

123 lines
2.6 KiB
PHP
Raw Normal View History

<?php
namespace Icinga\Module\Businessprocess;
use Exception;
class ImportedNode extends BpNode
{
/** @var BpConfig */
protected $parentBp;
/** @var string */
protected $configName;
2017-01-03 05:17:17 -05:00
/** @var string */
protected $nodeName;
/** @var BpNode */
protected $importedNode;
/** @var string */
protected $className = 'process subtree';
/** @var string */
2019-01-22 05:21:40 -05:00
protected $icon = 'download';
2017-01-11 08:04:45 -05:00
public function __construct(BpConfig $bp, $object)
{
$this->parentBp = $bp;
$this->configName = $object->configName;
$this->nodeName = $object->node;
$importedConfig = $bp->getImportedConfig($this->configName);
parent::__construct($importedConfig, (object) [
'name' => '@' . $this->configName . ':' . $this->nodeName,
'operator' => null,
'child_names' => null
]
);
2017-01-03 05:17:17 -05:00
}
/**
* @return string
*/
public function getConfigName()
{
return $this->configName;
}
/**
* @return string
*/
public function getNodeName()
{
return $this->nodeName;
}
public function getAlias()
{
if ($this->alias === null) {
$this->alias = $this->importedNode()->getAlias();
}
2017-01-03 05:17:17 -05:00
return $this->alias;
}
public function getOperator()
{
if ($this->operator === null) {
$this->operator = $this->importedNode()->getOperator();
}
2017-01-03 05:17:17 -05:00
return $this->operator;
}
public function getChildNames()
{
if ($this->childNames === null) {
$this->childNames = $this->importedNode()->getChildNames();
}
return $this->childNames;
}
/**
* @return BpNode
*/
protected function importedNode()
2017-01-03 05:17:17 -05:00
{
if ($this->importedNode === null) {
try {
$this->importedNode = $this->bp->getBpNode($this->nodeName);
} catch (Exception $e) {
return $this->createFailedNode($e);
}
}
2017-01-03 05:17:17 -05:00
return $this->importedNode;
2015-03-16 04:08:00 -04:00
}
/**
* @param Exception $e
*
* @return BpNode
*/
protected function createFailedNode(Exception $e)
2015-03-16 04:08:00 -04:00
{
$this->parentBp->addError($e->getMessage());
$node = new BpNode($this->bp, (object) array(
2017-01-03 05:17:17 -05:00
'name' => $this->getName(),
'operator' => '&',
'child_names' => []
2015-03-16 04:08:00 -04:00
));
$node->setState(2);
$node->setMissing(false)
->setDowntime(false)
->setAck(false)
->setAlias($e->getMessage());
return $node;
}
}