BPMN-OS
BPMN for optimization and simulation
Loading...
Searching...
No Matches
ChoiceEvent.cpp
Go to the documentation of this file.
1#include "ChoiceEvent.h"
3
4using namespace BPMNOS::Execution;
5
6ChoiceEvent::ChoiceEvent(const Token* token, Values choices)
7 : Event(token)
8 , choices(choices)
9{
10}
11
12void ChoiceEvent::processBy(Engine* engine) const {
13 engine->process(this);
14}
15
16nlohmann::ordered_json ChoiceEvent::jsonify() const {
17 nlohmann::ordered_json jsonObject;
18
19 jsonObject["event"] = "choice";
20 jsonObject["processId"] = token->owner->process->id;
21 jsonObject["instanceId"] = BPMNOS::to_string((*token->data)[BPMNOS::Model::ExtensionElements::Index::Instance].get().value(),STRING);
22 jsonObject["nodeId"] = token->node->id;
23
24 jsonObject["choices"] = nlohmann::ordered_json();
25 auto extensionElements = token->node->extensionElements->as<BPMNOS::Model::ExtensionElements>();
26 for (size_t i = 0; i < extensionElements->choices.size(); i++) {
27 auto attribute = extensionElements->choices[i]->attribute;
28 if ( !choices[i].has_value() ) {
29 jsonObject["choices"][attribute->name] = nullptr ;
30 }
31 else if ( attribute->type == BOOLEAN) {
32 bool value = (bool)choices[i].value();
33 jsonObject["choices"][attribute->name] = value ;
34 }
35 else if ( attribute->type == INTEGER) {
36 int value = (int)choices[i].value();
37 jsonObject["choices"][attribute->name] = value ;
38 }
39 else if ( attribute->type == DECIMAL) {
40 double value = (double)choices[i].value();
41 jsonObject["choices"][attribute->name] = value ;
42 }
43 else if ( attribute->type == STRING) {
44 std::string value = BPMNOS::to_string(choices[i].value(),attribute->type);
45 jsonObject["choices"][attribute->name] = value ;
46 }
47 else if ( attribute->type == COLLECTION) {
48 std::string value = BPMNOS::to_string(choices[i].value(),attribute->type);
49 jsonObject["choices"][attribute->name] = value ;
50 }
51 }
52
53 return jsonObject;
54}
void process(const ReadyEvent *event)
Definition Engine.cpp:129
const BPMN::Process * process
Pointer to the top-level process.
Represents a token running through a (sub)process.
Definition Token.h:35
const BPMN::FlowNode * node
Definition Token.h:46
const StateMachine * owner
State machine owning the token.
Definition Token.h:44
SharedValues * data
Pointer to the data of the owner or owned state machine subprocesses)
Definition Token.h:58
Class holding extension elements representing execution data for nodes.
std::unique_ptr< ExtensionElements > extensionElements
Definition bpmn++.h:16299
std::string id
Id of element.
Definition bpmn++.h:16298
std::string to_string(number numericValue, const ValueType &type)
Converts a number to a string.
Definition Number.cpp:150
@ INTEGER
Definition Value.h:9
@ STRING
Definition Value.h:9
@ BOOLEAN
Definition Value.h:9
@ COLLECTION
Definition Value.h:9
@ DECIMAL
Definition Value.h:9
void processBy(Engine *engine) const
ChoiceEvent(const Token *token, Values choices)
nlohmann::ordered_json jsonify() const override
const Token * token
Definition Event.h:18