|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Jabe\Engine\Impl; |
|
4
|
|
|
|
|
5
|
|
|
use Jabe\Engine\Exception\NotValidException; |
|
6
|
|
|
use Jabe\Engine\History\HistoricProcessInstanceReportInterface; |
|
7
|
|
|
use Jabe\Engine\Impl\Context\Context; |
|
8
|
|
|
use Jabe\Engine\Impl\Db\TenantCheck; |
|
9
|
|
|
use Jabe\Engine\Impl\Interceptor\{ |
|
10
|
|
|
CommandInterface, |
|
11
|
|
|
CommandContext, |
|
12
|
|
|
CommandExecutorInterface |
|
13
|
|
|
}; |
|
14
|
|
|
use Jabe\Engine\Impl\Util\{ |
|
15
|
|
|
CompareUtil, |
|
16
|
|
|
EnsureUtil |
|
17
|
|
|
}; |
|
18
|
|
|
use Jabe\Engine\Repository\ProcessDefinitionInterface; |
|
19
|
|
|
|
|
20
|
|
|
class HistoricProcessInstanceReportImpl implements HistoricProcessInstanceReportInterface |
|
21
|
|
|
{ |
|
22
|
|
|
protected $startedAfter; |
|
23
|
|
|
protected $startedBefore; |
|
24
|
|
|
protected $processDefinitionIdIn = []; |
|
25
|
|
|
protected $processDefinitionKeyIn = []; |
|
26
|
|
|
|
|
27
|
|
|
protected $durationPeriodUnit; |
|
28
|
|
|
|
|
29
|
|
|
protected $commandExecutor; |
|
30
|
|
|
|
|
31
|
|
|
protected $tenantCheck; |
|
32
|
|
|
|
|
33
|
|
|
public function __construct(CommandExecutorInterface $commandExecutor = null) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->tenantCheck = new TenantCheck(); |
|
36
|
|
|
$this->commandExecutor = $commandExecutor; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function startedAfter(string $startedAfter): HistoricProcessInstanceReportInterface |
|
40
|
|
|
{ |
|
41
|
|
|
EnsureUtil::ensureNotNull(NotValidException::class, "startedAfter", $startedAfter); |
|
42
|
|
|
$this->startedAfter = $startedAfter; |
|
43
|
|
|
return $this; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function startedBefore(string $startedBefore): HistoricProcessInstanceReportInterface |
|
47
|
|
|
{ |
|
48
|
|
|
EnsureUtil::ensureNotNull(NotValidException::class, "startedBefore", $startedBefore); |
|
49
|
|
|
$this->startedBefore = $startedBefore; |
|
50
|
|
|
return $this; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function processDefinitionIdIn(array $processDefinitionIds): HistoricProcessInstanceReportInterface |
|
54
|
|
|
{ |
|
55
|
|
|
EnsureUtil::ensureNotNull("processDefinitionIdIn", "processDefinitionIds", $processDefinitionIds); |
|
56
|
|
|
$this->processDefinitionIdIn = $processDefinitionIds; |
|
57
|
|
|
return $this; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function processDefinitionKeyIn(array $processDefinitionKeys): HistoricProcessInstanceReportInterface |
|
61
|
|
|
{ |
|
62
|
|
|
EnsureUtil::ensureNotNull("processDefinitionKeyIn", "processDefinitionKeys", $processDefinitionKeys); |
|
63
|
|
|
$this->processDefinitionKeyIn = $processDefinitionKeys; |
|
64
|
|
|
return $this; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function duration(string $periodUnit): array |
|
68
|
|
|
{ |
|
69
|
|
|
EnsureUtil::ensureNotNull(NotValidException::class, "periodUnit", $periodUnit); |
|
70
|
|
|
$this->durationPeriodUnit = $periodUnit; |
|
71
|
|
|
|
|
72
|
|
|
$commandContext = Context::getCommandContext(); |
|
73
|
|
|
|
|
74
|
|
|
if ($commandContext == null) { |
|
75
|
|
|
return $commandExecutor->execute(new ExecuteDurationReportCmd($this)); |
|
|
|
|
|
|
76
|
|
|
} else { |
|
77
|
|
|
return $this->executeDurationReport($commandContext); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function executeDurationReport(CommandContext $commandContext): array |
|
82
|
|
|
{ |
|
83
|
|
|
$this->doAuthCheck($commandContext); |
|
84
|
|
|
|
|
85
|
|
|
if (CompareUtil::areNotInAscendingOrder($startedAfter, $startedBefore)) { |
|
|
|
|
|
|
86
|
|
|
return []; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
return $commandContext |
|
90
|
|
|
->getHistoricReportManager() |
|
91
|
|
|
->selectHistoricProcessInstanceDurationReport($this); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
protected function doAuthCheck(CommandContext $commandContext): void |
|
95
|
|
|
{ |
|
96
|
|
|
// since a report does only make sense in context of historic |
|
97
|
|
|
// data, the authorization check will be performed here |
|
98
|
|
|
foreach ($commandContext->getProcessEngineConfiguration()->getCommandCheckers() as $checker) { |
|
|
|
|
|
|
99
|
|
|
if (empty($this->processDefinitionIdIn) && empty($this->processDefinitionKeyIn)) { |
|
100
|
|
|
$checker->checkReadHistoryAnyProcessDefinition(); |
|
101
|
|
|
} else { |
|
102
|
|
|
$processDefinitionKeys = []; |
|
103
|
|
|
if (!empty($this->processDefinitionKeyIn)) { |
|
104
|
|
|
$processDefinitionKeys = $this->processDefinitionKeyIn; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
if (!empty($this->processDefinitionIdIn)) { |
|
108
|
|
|
foreach ($this->processDefinitionIdIn as $processDefinitionId) { |
|
109
|
|
|
$processDefinition = $commandContext->getProcessDefinitionManager() |
|
110
|
|
|
->findLatestProcessDefinitionById($processDefinitionId); |
|
111
|
|
|
|
|
112
|
|
|
if ($processDefinition != null && $processDefinition->getKey() != null) { |
|
113
|
|
|
$processDefinitionKeys[] = $processDefinition->getKey(); |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
if (!empty($processDefinitionKeys)) { |
|
119
|
|
|
foreach ($processDefinitionKeys as $processDefinitionKey) { |
|
120
|
|
|
$checker->checkReadHistoryProcessDefinition($processDefinitionKey); |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
public function getStartedAfter(): string |
|
128
|
|
|
{ |
|
129
|
|
|
return $this->startedAfter; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
public function getStartedBefore(): string |
|
133
|
|
|
{ |
|
134
|
|
|
return $this->startedBefore; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
public function getProcessDefinitionIdIn(): array |
|
138
|
|
|
{ |
|
139
|
|
|
return $this->processDefinitionIdIn; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
public function getProcessDefinitionKeyIn(): array |
|
143
|
|
|
{ |
|
144
|
|
|
return $this->processDefinitionKeyIn; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
public function getTenantCheck(): TenantCheck |
|
148
|
|
|
{ |
|
149
|
|
|
return $this->tenantCheck; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
public function getReportPeriodUnitName(): string |
|
153
|
|
|
{ |
|
154
|
|
|
return $this->durationPeriodUnit; |
|
155
|
|
|
} |
|
156
|
|
|
} |
|
157
|
|
|
|