|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Jabe\Engine\Impl\Json; |
|
4
|
|
|
|
|
5
|
|
|
use Jabe\Engine\Impl\ModificationBatchConfiguration; |
|
6
|
|
|
use Jabe\Engine\Impl\Batch\{ |
|
7
|
|
|
DeploymentMappingJsonConverter, |
|
8
|
|
|
DeploymentMappings |
|
9
|
|
|
}; |
|
10
|
|
|
use Jabe\Engine\Impl\Cmd\AbstractProcessInstanceModificationCommand; |
|
11
|
|
|
use Jabe\Engine\Impl\Util\JsonUtil; |
|
12
|
|
|
|
|
13
|
|
|
class ModificationBatchConfigurationJsonConverter extends JsonObjectConverter |
|
14
|
|
|
{ |
|
15
|
|
|
private static $INSTANCE; |
|
16
|
|
|
public const INSTRUCTIONS = "instructions"; |
|
17
|
|
|
public const PROCESS_INSTANCE_IDS = "processInstanceIds"; |
|
18
|
|
|
public const PROCESS_INSTANCE_ID_MAPPINGS = "processInstanceIdMappings"; |
|
19
|
|
|
public const SKIP_LISTENERS = "skipListeners"; |
|
20
|
|
|
public const SKIP_IO_MAPPINGS = "skipIoMappings"; |
|
21
|
|
|
public const PROCESS_DEFINITION_ID = "processDefinitionId"; |
|
22
|
|
|
|
|
23
|
|
|
public static function instance(): ModificationBatchConfigurationJsonConverter |
|
24
|
|
|
{ |
|
25
|
|
|
if (self::$INSTANCE == null) { |
|
26
|
|
|
self::$INSTANCE = new ModificationBatchConfigurationJsonConverter(); |
|
27
|
|
|
} |
|
28
|
|
|
return self::$INSTANCE; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function toJsonObject(/*ModificationBatchConfiguration*/$configuration, bool $isOrQueryActive = false): ?\stdClass |
|
32
|
|
|
{ |
|
33
|
|
|
$json = JsonUtil::createObject(); |
|
34
|
|
|
JsonUtil::addListField($json, self::INSTRUCTIONS, ModificationCmdJsonConverter::instance(), $configuration->getInstructions()); |
|
35
|
|
|
JsonUtil::addListField($json, self::PROCESS_INSTANCE_IDS, $configuration->getIds()); |
|
36
|
|
|
JsonUtil::addListField($json, self::PROCESS_INSTANCE_ID_MAPPINGS, DeploymentMappingJsonConverter::instance(), $configuration->getIdMappings()); |
|
37
|
|
|
JsonUtil::addField($json, self::PROCESS_DEFINITION_ID, $configuration->getProcessDefinitionId()); |
|
38
|
|
|
JsonUtil::addField($json, self::SKIP_LISTENERS, $configuration->isSkipCustomListeners()); |
|
39
|
|
|
JsonUtil::addField($json, self::SKIP_IO_MAPPINGS, $configuration->isSkipIoMappings()); |
|
40
|
|
|
|
|
41
|
|
|
return $json; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function toObject(\stdClass $json, bool $isOrQuery = false) |
|
45
|
|
|
{ |
|
46
|
|
|
$processInstanceIds = $this->readProcessInstanceIds($json); |
|
47
|
|
|
$mappings = $this->readIdMappings($json); |
|
48
|
|
|
$processDefinitionId = JsonUtil::getString($json, self::PROCESS_DEFINITION_ID); |
|
49
|
|
|
$instructions = JsonUtil::asList( |
|
50
|
|
|
JsonUtil::getArray($json, self::INSTRUCTIONS), |
|
51
|
|
|
ModificationCmdJsonConverter::instance() |
|
52
|
|
|
); |
|
53
|
|
|
$skipCustomListeners = JsonUtil::getBoolean($json, self::SKIP_LISTENERS); |
|
54
|
|
|
$skipIoMappings = JsonUtil::getBoolean($json, self::SKIP_IO_MAPPINGS); |
|
55
|
|
|
|
|
56
|
|
|
return new ModificationBatchConfiguration( |
|
57
|
|
|
$processInstanceIds, |
|
58
|
|
|
$mappings, |
|
59
|
|
|
$processDefinitionId, |
|
60
|
|
|
$instructions, |
|
61
|
|
|
$skipCustomListeners, |
|
62
|
|
|
$skipIoMappings |
|
63
|
|
|
); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
protected function readProcessInstanceIds($jsonObject): array |
|
67
|
|
|
{ |
|
68
|
|
|
return JsonUtil::asStringList(JsonUtil::getArray($jsonObject, self::PROCESS_INSTANCE_IDS)); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
protected function readIdMappings(\stdClass $json): DeploymentMappings |
|
72
|
|
|
{ |
|
73
|
|
|
return JsonUtil::asList(JsonUtil::getArray($json, self::PROCESS_INSTANCE_ID_MAPPINGS), DeploymentMappingJsonConverter::instance(), DeploymentMappings::class); |
|
|
|
|
|
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|