1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Data Analytics |
4
|
|
|
* |
5
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
6
|
|
|
* later. See the LICENSE.md file. |
7
|
|
|
* |
8
|
|
|
* @author Marcel Scherello <[email protected]> |
9
|
|
|
* @copyright 2019 Marcel Scherello |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace OCA\Analytics\Controller; |
13
|
|
|
|
14
|
|
|
use OCA\Analytics\Notification\NotificationManager; |
15
|
|
|
use OCP\AppFramework\Controller; |
16
|
|
|
use OCP\ILogger; |
17
|
|
|
use OCP\IRequest; |
18
|
|
|
|
19
|
|
|
class ThresholdController extends Controller |
20
|
|
|
{ |
21
|
|
|
private $logger; |
22
|
|
|
private $DBController; |
23
|
|
|
private $NotificationManager; |
24
|
|
|
|
25
|
|
|
public function __construct( |
26
|
|
|
$appName, |
27
|
|
|
IRequest $request, |
28
|
|
|
ILogger $logger, |
29
|
|
|
DbController $DBController, |
30
|
|
|
NotificationManager $NotificationManager |
31
|
|
|
) |
32
|
|
|
{ |
33
|
|
|
parent::__construct($appName, $request); |
34
|
|
|
$this->logger = $logger; |
35
|
|
|
$this->DBController = $DBController; |
36
|
|
|
$this->NotificationManager = $NotificationManager; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* read all thresholds for a dataset |
41
|
|
|
* |
42
|
|
|
* @NoAdminRequired |
43
|
|
|
* @param int $datasetId |
44
|
|
|
* @return array |
45
|
|
|
*/ |
46
|
|
|
public function read(int $datasetId) |
47
|
|
|
{ |
48
|
|
|
return $this->DBController->getThresholdsByDataset($datasetId); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* create new threshold for dataset |
53
|
|
|
* |
54
|
|
|
* @NoAdminRequired |
55
|
|
|
* @param int $datasetId |
56
|
|
|
* @param $dimension1 |
57
|
|
|
* @param $option |
58
|
|
|
* @param $dimension3 |
59
|
|
|
* @param int $severity |
60
|
|
|
* @return int |
61
|
|
|
*/ |
62
|
|
|
public function create(int $datasetId, $dimension1, $option, $dimension3, int $severity) |
63
|
|
|
{ |
64
|
|
|
return $this->DBController->createThreshold($datasetId, $dimension1, $dimension3, $option, $severity); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Delete threshold for dataset |
69
|
|
|
* |
70
|
|
|
* @NoAdminRequired |
71
|
|
|
* @param int $thresholdId |
72
|
|
|
* @return bool |
73
|
|
|
*/ |
74
|
|
|
public function delete(int $thresholdId) |
75
|
|
|
{ |
76
|
|
|
$this->DBController->deleteThreshold($thresholdId); |
77
|
|
|
return true; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* update threshold |
82
|
|
|
* |
83
|
|
|
* @NoAdminRequired |
84
|
|
|
* @param int $datasetId |
85
|
|
|
* @param int $thresholdId |
86
|
|
|
* @return bool |
87
|
|
|
*/ |
88
|
|
|
public function update(int $datasetId, int $thresholdId) |
|
|
|
|
89
|
|
|
{ |
90
|
|
|
return $this->DBController->updateDataset($datasetId); |
|
|
|
|
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* validate threshold |
95
|
|
|
* |
96
|
|
|
* @NoAdminRequired |
97
|
|
|
* @param int $datasetId |
98
|
|
|
* @param $dimension1 |
99
|
|
|
* @param $dimension2 |
100
|
|
|
* @param $dimension3 |
101
|
|
|
* @return string |
102
|
|
|
* @throws \Exception |
103
|
|
|
*/ |
104
|
|
|
public function validate(int $datasetId, $dimension1, $dimension2, $dimension3) |
|
|
|
|
105
|
|
|
{ |
106
|
|
|
$thresholds = array(); |
107
|
|
|
array_push($thresholds, ['dimension1' => 'a', 'option' => '<', 'value' => '10']); |
108
|
|
|
array_push($thresholds, ['dimension1' => 'b', 'option' => '<', 'value' => '10']); |
109
|
|
|
$thresholds = $this->DBController->getSevOneThresholdsByDataset($datasetId); |
110
|
|
|
|
111
|
|
|
$result = ''; |
112
|
|
|
$datasetMetadata = $this->DBController->getOwnDataset($datasetId); |
113
|
|
|
|
114
|
|
|
foreach ($thresholds as $threshold) { |
115
|
|
|
//$this->logger->error('ThresholdController 108: ' . json_encode($threshold)); |
116
|
|
|
if ($threshold['dimension1'] === $dimension1) { |
117
|
|
|
if (version_compare($dimension3, $threshold['dimension3'], $threshold['option'])) { |
118
|
|
|
$this->NotificationManager->triggerNotification(NotificationManager::OBJECT_DATASET, $datasetId, NotificationManager::SUBJECT_THRESHOLD, ['report' => $datasetMetadata['name'], 'subject' => $dimension1, 'rule' => $threshold['option'], 'value' => $threshold['dimension3']]); |
119
|
|
|
$result = 'Threshold value met'; |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
return $result; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
} |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.