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, std::vector<number> choices)
7 : Event(token)
8 , choices(std::move(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 ( attribute->type == BOOLEAN) {
29 bool value = (bool)choices[i];
30 jsonObject["choices"][attribute->name] = value ;
31 }
32 else if ( attribute->type == INTEGER) {
33 int value = (int)choices[i];
34 jsonObject["choices"][attribute->name] = value ;
35 }
36 else if ( attribute->type == DECIMAL) {
37 double value = (double)choices[i];
38 jsonObject["choices"][attribute->name] = value ;
39 }
40 else if ( attribute->type == STRING) {
41 std::string value = BPMNOS::to_string(choices[i],attribute->type);
42 jsonObject["choices"][attribute->name] = value ;
43 }
44 else if ( attribute->type == COLLECTION) {
45 std::string value = BPMNOS::to_string(choices[i],attribute->type);
46 jsonObject["choices"][attribute->name] = value ;
47 }
48 }
49
50 return jsonObject;
51}
void process(const ReadyEvent *event)
Definition Engine.cpp:138
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:154
@ 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
STL namespace.
std::vector< number > choices
Definition ChoiceEvent.h:18
ChoiceEvent(const Token *token, std::vector< number > choices)
void processBy(Engine *engine) const
nlohmann::ordered_json jsonify() const override
const Token * token
Definition Event.h:18