|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Jabe\Engine\Impl; |
|
4
|
|
|
|
|
5
|
|
|
use Jabe\Engine\Exception\NotValidException; |
|
6
|
|
|
use Jabe\Engine\History\{ |
|
7
|
|
|
HistoricVariableInstanceInterface, |
|
8
|
|
|
HistoricVariableInstanceQueryInterface |
|
9
|
|
|
}; |
|
10
|
|
|
use Jabe\Engine\Impl\Cfg\ProcessEngineConfigurationImpl; |
|
11
|
|
|
use Jabe\Engine\Impl\Context\Context; |
|
12
|
|
|
use Jabe\Engine\Impl\Interceptor\{ |
|
13
|
|
|
CommandContext, |
|
14
|
|
|
CommandExecutorInterface |
|
15
|
|
|
}; |
|
16
|
|
|
use Jabe\Engine\Impl\Persistence\Entity\HistoricVariableInstanceEntity; |
|
17
|
|
|
use Jabe\Engine\Impl\Util\EnsureUtil; |
|
18
|
|
|
use Jabe\Engine\Impl\Variable\Serializer\{ |
|
19
|
|
|
AbstractTypedValueSerializer, |
|
20
|
|
|
VariableSerializersInterface |
|
21
|
|
|
}; |
|
22
|
|
|
|
|
23
|
|
|
class HistoricVariableInstanceQueryImpl extends AbstractQuery implements HistoricVariableInstanceQuery |
|
24
|
|
|
{ |
|
25
|
|
|
//private final static CommandLogger LOG = ProcessEngineLogger.CMD_LOGGER; |
|
26
|
|
|
|
|
27
|
|
|
protected $variableNameIn = []; |
|
28
|
|
|
protected $variableId; |
|
29
|
|
|
protected $processInstanceId; |
|
30
|
|
|
protected $processDefinitionId; |
|
31
|
|
|
protected $processDefinitionKey; |
|
32
|
|
|
protected $caseInstanceId; |
|
33
|
|
|
protected $variableName; |
|
34
|
|
|
protected $variableNameLike; |
|
35
|
|
|
protected $queryVariableValue; |
|
36
|
|
|
protected $variableNamesIgnoreCase; |
|
37
|
|
|
protected $variableValuesIgnoreCase; |
|
38
|
|
|
protected $variableTypes = []; |
|
39
|
|
|
protected $taskIds = []; |
|
40
|
|
|
protected $executionIds = []; |
|
41
|
|
|
//protected String[] caseExecutionIds; |
|
42
|
|
|
//protected String[] caseActivityIds; |
|
43
|
|
|
protected $activityInstanceIds = []; |
|
44
|
|
|
|
|
45
|
|
|
protected $tenantIds = []; |
|
46
|
|
|
protected $isTenantIdSet; |
|
47
|
|
|
|
|
48
|
|
|
protected $processInstanceIds = []; |
|
49
|
|
|
protected $includeDeleted = false; |
|
50
|
|
|
|
|
51
|
|
|
protected $isByteArrayFetchingEnabled = true; |
|
52
|
|
|
protected $isCustomObjectDeserializationEnabled = true; |
|
53
|
|
|
|
|
54
|
|
|
public function __construct(CommandExecutorInterface $commandExecutor = null) |
|
55
|
|
|
{ |
|
56
|
|
|
parent::__construct($commandExecutor); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function variableNameIn(array $names): HistoricVariableInstanceQueryInterface |
|
60
|
|
|
{ |
|
61
|
|
|
EnsureUtil::ensureNotNull("Variable names", "names", $names); |
|
62
|
|
|
$this->variableNameIn = $names; |
|
63
|
|
|
return $this; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function variableId(string $id): HistoricVariableInstanceQueryInterface |
|
67
|
|
|
{ |
|
68
|
|
|
EnsureUtil::ensureNotNull("variableId", "variableId", $id); |
|
69
|
|
|
$this->variableId = $id; |
|
70
|
|
|
return $this; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function processInstanceId(string $processInstanceId): HistoricVariableInstanceQueryImpl |
|
74
|
|
|
{ |
|
75
|
|
|
EnsureUtil::ensureNotNull("processInstanceId", "processInstanceId", $processInstanceId); |
|
76
|
|
|
$this->processInstanceId = $processInstanceId; |
|
77
|
|
|
return $this; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function processDefinitionId(string $processDefinitionId): HistoricVariableInstanceQueryInterface |
|
81
|
|
|
{ |
|
82
|
|
|
EnsureUtil::ensureNotNull("processDefinitionId", "processDefinitionId", $processDefinitionId); |
|
83
|
|
|
$this->processDefinitionId = $processDefinitionId; |
|
84
|
|
|
return $this; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function processDefinitionKey(string $processDefinitionKey): HistoricVariableInstanceQueryInterface |
|
88
|
|
|
{ |
|
89
|
|
|
$this->processDefinitionKey = $processDefinitionKey; |
|
90
|
|
|
return $this; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/*public HistoricVariableInstanceQueryInterface caseInstanceId(string $caseInstanceId) { |
|
94
|
|
|
EnsureUtil::ensureNotNull("caseInstanceId", caseInstanceId); |
|
95
|
|
|
$this->caseInstanceId = caseInstanceId; |
|
96
|
|
|
return $this; |
|
97
|
|
|
}*/ |
|
98
|
|
|
|
|
99
|
|
|
public function variableTypeIn(array $variableTypes): HistoricVariableInstanceQueryInterface |
|
100
|
|
|
{ |
|
101
|
|
|
EnsureUtil::ensureNotNull("Variable types", "variableTypes", $variableTypes); |
|
102
|
|
|
$this->variableTypes = $this->lowerCase($variableTypes); |
|
103
|
|
|
return $this; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function matchVariableNamesIgnoreCase(): HistoricVariableInstanceQueryInterface |
|
107
|
|
|
{ |
|
108
|
|
|
$this->variableNamesIgnoreCase = true; |
|
109
|
|
|
if ($this->queryVariableValue != null) { |
|
110
|
|
|
$this->queryVariableValue->variableNameIgnoreCase = true; |
|
111
|
|
|
} |
|
112
|
|
|
return $this; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
public function matchVariableValuesIgnoreCase(): HistoricVariableInstanceQueryInterface |
|
116
|
|
|
{ |
|
117
|
|
|
$this->variableValuesIgnoreCase = true; |
|
118
|
|
|
if ($this->queryVariableValue != null) { |
|
119
|
|
|
$this->queryVariableValue->variableValueIgnoreCase = true; |
|
120
|
|
|
} |
|
121
|
|
|
return $this; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
private function lowerCase(array $variableTypes): array |
|
125
|
|
|
{ |
|
126
|
|
|
for ($i = 0; $i < count($variableTypes); $i += 1) { |
|
|
|
|
|
|
127
|
|
|
$variableTypes[$i] = strtolower($variableTypes[$i]); |
|
128
|
|
|
} |
|
129
|
|
|
return $variableTypes; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** Only select historic process variables with the given process instance ids. */ |
|
133
|
|
|
public function processInstanceIdIn(array $processInstanceIds): HistoricVariableInstanceQueryInterface |
|
134
|
|
|
{ |
|
135
|
|
|
EnsureUtil::ensureNotNull("Process Instance Ids", "processInstanceIds", $processInstanceIds); |
|
136
|
|
|
$this->processInstanceIds = $processInstanceIds; |
|
137
|
|
|
return $this; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
public function taskIdIn(array $taskIds): HistoricVariableInstanceQueryInterface |
|
141
|
|
|
{ |
|
142
|
|
|
EnsureUtil::ensureNotNull("Task Ids", "taskIds", $taskIds); |
|
143
|
|
|
$this->taskIds = $taskIds; |
|
144
|
|
|
return $this; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
public function executionIdIn(array $executionIds): HistoricVariableInstanceQueryInterface |
|
148
|
|
|
{ |
|
149
|
|
|
EnsureUtil::ensureNotNull("Execution Ids", "executionIds", $executionIds); |
|
150
|
|
|
$this->executionIds = $executionIds; |
|
151
|
|
|
return $this; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/*public function caseExecutionIdIn(array $caseExecutionIds) { |
|
155
|
|
|
EnsureUtil::ensureNotNull("Case execution ids", (Object[]) caseExecutionIds); |
|
156
|
|
|
$this->caseExecutionIds = caseExecutionIds; |
|
157
|
|
|
return $this; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
public HistoricVariableInstanceQueryInterface caseActivityIdIn(array $caseActivityIds) { |
|
161
|
|
|
EnsureUtil::ensureNotNull("Case activity ids", (Object[]) caseActivityIds); |
|
162
|
|
|
$this->caseActivityIds = caseActivityIds; |
|
163
|
|
|
return $this; |
|
164
|
|
|
}*/ |
|
165
|
|
|
|
|
166
|
|
|
public function activityInstanceIdIn(array $activityInstanceIds): HistoricVariableInstanceQueryInterface |
|
167
|
|
|
{ |
|
168
|
|
|
EnsureUtil::ensureNotNull("Activity Instance Ids", "activityInstanceIds", $activityInstanceIds); |
|
169
|
|
|
$this->activityInstanceIds = $activityInstanceIds; |
|
170
|
|
|
return $this; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
public function variableName(string $variableName): HistoricVariableInstanceQueryInterface |
|
174
|
|
|
{ |
|
175
|
|
|
EnsureUtil::ensureNotNull("variableName", "variableName", $variableName); |
|
176
|
|
|
$this->variableName = $variableName; |
|
177
|
|
|
return $this; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
public function variableValueEquals(string $variableName, $variableValue): HistoricVariableInstanceQueryInterface |
|
181
|
|
|
{ |
|
182
|
|
|
EnsureUtil::ensureNotNull("variableName", "variableName", $variableName); |
|
183
|
|
|
EnsureUtil::ensureNotNull("variableValue", "variableValue", $variableValue); |
|
184
|
|
|
$this->variableName = $variableName; |
|
185
|
|
|
$this->queryVariableValue = new QueryVariableValue($variableName, $variableValue, QueryOperator::EQUALS, true, $this->variableNamesIgnoreCase, $this->variableValuesIgnoreCase); |
|
186
|
|
|
return $this; |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
public function variableNameLike(string $variableNameLike): HistoricVariableInstanceQueryInterface |
|
190
|
|
|
{ |
|
191
|
|
|
EnsureUtil::ensureNotNull("variableNameLike", "variableNameLike", $variableNameLike); |
|
192
|
|
|
$this->variableNameLike = $variableNameLike; |
|
193
|
|
|
return $this; |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
protected function ensureVariablesInitialized(): void |
|
197
|
|
|
{ |
|
198
|
|
|
if ($this->queryVariableValue != null) { |
|
199
|
|
|
$processEngineConfiguration = Context::getProcessEngineConfiguration(); |
|
200
|
|
|
$variableSerializers = $processEngineConfiguration->getVariableSerializers(); |
|
|
|
|
|
|
201
|
|
|
$dbType = $processEngineConfiguration->getDatabaseType(); |
|
202
|
|
|
$this->queryVariableValue->initialize($variableSerializers, $dbType); |
|
203
|
|
|
} |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
public function disableBinaryFetching(): HistoricVariableInstanceQueryInterface |
|
207
|
|
|
{ |
|
208
|
|
|
$this->isByteArrayFetchingEnabled = false; |
|
209
|
|
|
return $this; |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
public function disableCustomObjectDeserialization(): HistoricVariableInstanceQueryInterface |
|
213
|
|
|
{ |
|
214
|
|
|
$this->isCustomObjectDeserializationEnabled = false; |
|
215
|
|
|
return $this; |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
public function tenantIdIn(array $tenantIds): HistoricVariableInstanceQueryInterface |
|
219
|
|
|
{ |
|
220
|
|
|
EnsureUtil::ensureNotNull("tenantIds", "tenantIds", $tenantIds); |
|
221
|
|
|
$this->tenantIds = $tenantIds; |
|
222
|
|
|
$this->isTenantIdSet = true; |
|
223
|
|
|
return $this; |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
public function withoutTenantId(): HistoricVariableInstanceQueryInterface |
|
227
|
|
|
{ |
|
228
|
|
|
$this->tenantIds = null; |
|
229
|
|
|
$this->isTenantIdSet = true; |
|
230
|
|
|
return $this; |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
public function executeCount(CommandContext $commandContext): int |
|
234
|
|
|
{ |
|
235
|
|
|
$this->checkQueryOk(); |
|
236
|
|
|
$this->ensureVariablesInitialized(); |
|
237
|
|
|
return $commandContext->getHistoricVariableInstanceManager()->findHistoricVariableInstanceCountByQueryCriteria($this); |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
public function executeList(CommandContext $commandContext, Page $page): array |
|
241
|
|
|
{ |
|
242
|
|
|
$this->checkQueryOk(); |
|
243
|
|
|
$this->ensureVariablesInitialized(); |
|
244
|
|
|
$historicVariableInstances = $commandContext |
|
245
|
|
|
->getHistoricVariableInstanceManager() |
|
246
|
|
|
->findHistoricVariableInstancesByQueryCriteria($this, $page); |
|
247
|
|
|
|
|
248
|
|
|
if (!empty($historicVariableInstances)) { |
|
249
|
|
|
foreach ($historicVariableInstances as $historicVariableInstance) { |
|
250
|
|
|
$variableInstanceEntity = $historicVariableInstance; |
|
251
|
|
|
if ($this->shouldFetchValue($variableInstanceEntity)) { |
|
252
|
|
|
try { |
|
253
|
|
|
$variableInstanceEntity->getTypedValue($this->isCustomObjectDeserializationEnabled); |
|
254
|
|
|
} catch (\Exception $t) { |
|
255
|
|
|
// do not fail if one of the variables fails to load |
|
256
|
|
|
//LOG.exceptionWhileGettingValueForVariable(t); |
|
257
|
|
|
} |
|
258
|
|
|
} |
|
259
|
|
|
} |
|
260
|
|
|
} |
|
261
|
|
|
return $historicVariableInstances; |
|
262
|
|
|
} |
|
263
|
|
|
|
|
264
|
|
|
protected function shouldFetchValue(HistoricVariableInstanceEntity $entity): bool |
|
265
|
|
|
{ |
|
266
|
|
|
// do not fetch values for byte arrays eagerly (unless requested by the user) |
|
267
|
|
|
return $this->isByteArrayFetchingEnabled |
|
268
|
|
|
|| !in_array($entity->getSerializer()->getType()->getName(), AbstractTypedValueSerializer::BINARY_VALUE_TYPES); |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
// order by ///////////////////////////////////////////////////////////////// |
|
272
|
|
|
|
|
273
|
|
|
public function orderByProcessInstanceId(): HistoricVariableInstanceQueryInterface |
|
274
|
|
|
{ |
|
275
|
|
|
$this->orderBy(HistoricVariableInstanceQueryProperty::processInstanceId()); |
|
276
|
|
|
return $this; |
|
277
|
|
|
} |
|
278
|
|
|
|
|
279
|
|
|
public function orderByVariableName(): HistoricVariableInstanceQueryInterface |
|
280
|
|
|
{ |
|
281
|
|
|
$this->orderBy(HistoricVariableInstanceQueryProperty::variableName()); |
|
282
|
|
|
return $this; |
|
283
|
|
|
} |
|
284
|
|
|
|
|
285
|
|
|
public function orderByTenantId(): HistoricVariableInstanceQueryInterface |
|
286
|
|
|
{ |
|
287
|
|
|
$this->orderBy(HistoricVariableInstanceQueryProperty::tenantId()); |
|
288
|
|
|
return $this; |
|
289
|
|
|
} |
|
290
|
|
|
|
|
291
|
|
|
// getters and setters ////////////////////////////////////////////////////// |
|
292
|
|
|
|
|
293
|
|
|
public function getProcessInstanceId(): string |
|
294
|
|
|
{ |
|
295
|
|
|
return $this->processInstanceId; |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
/*public String getCaseInstanceId() { |
|
299
|
|
|
return caseInstanceId; |
|
300
|
|
|
}*/ |
|
301
|
|
|
|
|
302
|
|
|
public function getActivityInstanceIds(): array |
|
303
|
|
|
{ |
|
304
|
|
|
return $this->activityInstanceIds; |
|
305
|
|
|
} |
|
306
|
|
|
|
|
307
|
|
|
public function getProcessInstanceIds(): array |
|
308
|
|
|
{ |
|
309
|
|
|
return $this->processInstanceIds; |
|
310
|
|
|
} |
|
311
|
|
|
|
|
312
|
|
|
public function getTaskIds(): array |
|
313
|
|
|
{ |
|
314
|
|
|
return $this->taskIds; |
|
315
|
|
|
} |
|
316
|
|
|
|
|
317
|
|
|
public function getExecutionIds(): array |
|
318
|
|
|
{ |
|
319
|
|
|
return $this->executionIds; |
|
320
|
|
|
} |
|
321
|
|
|
|
|
322
|
|
|
/*public String[] getCaseExecutionIds() { |
|
323
|
|
|
return caseExecutionIds; |
|
324
|
|
|
} |
|
325
|
|
|
|
|
326
|
|
|
public function getCaseActivityIds(): array |
|
327
|
|
|
{ |
|
328
|
|
|
return caseActivityIds; |
|
329
|
|
|
}*/ |
|
330
|
|
|
|
|
331
|
|
|
public function isTenantIdSet(): bool |
|
332
|
|
|
{ |
|
333
|
|
|
return $this->isTenantIdSet; |
|
334
|
|
|
} |
|
335
|
|
|
|
|
336
|
|
|
public function getVariableName(): string |
|
337
|
|
|
{ |
|
338
|
|
|
return $this->variableName; |
|
339
|
|
|
} |
|
340
|
|
|
|
|
341
|
|
|
public function getVariableNameLike(): string |
|
342
|
|
|
{ |
|
343
|
|
|
return $this->variableNameLike; |
|
344
|
|
|
} |
|
345
|
|
|
|
|
346
|
|
|
public function getQueryVariableValue(): QueryVariableValue |
|
347
|
|
|
{ |
|
348
|
|
|
return $this->queryVariableValue; |
|
349
|
|
|
} |
|
350
|
|
|
|
|
351
|
|
|
public function getVariableNamesIgnoreCase(): bool |
|
352
|
|
|
{ |
|
353
|
|
|
return $this->variableNamesIgnoreCase; |
|
354
|
|
|
} |
|
355
|
|
|
|
|
356
|
|
|
public function getVariableValuesIgnoreCase(): bool |
|
357
|
|
|
{ |
|
358
|
|
|
return $this->variableValuesIgnoreCase; |
|
359
|
|
|
} |
|
360
|
|
|
|
|
361
|
|
|
public function includeDeleted(): HistoricVariableInstanceQueryInterface |
|
362
|
|
|
{ |
|
363
|
|
|
$this->includeDeleted = true; |
|
364
|
|
|
return $this; |
|
365
|
|
|
} |
|
366
|
|
|
|
|
367
|
|
|
public function getProcessDefinitionId(): string |
|
368
|
|
|
{ |
|
369
|
|
|
return $this->processDefinitionId; |
|
370
|
|
|
} |
|
371
|
|
|
|
|
372
|
|
|
public function getProcessDefinitionKey(): string |
|
373
|
|
|
{ |
|
374
|
|
|
return $this->processDefinitionKey; |
|
375
|
|
|
} |
|
376
|
|
|
|
|
377
|
|
|
public function getVariableNameIn(): array |
|
378
|
|
|
{ |
|
379
|
|
|
return $this->variableNameIn; |
|
380
|
|
|
} |
|
381
|
|
|
} |
|
382
|
|
|
|
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: