Skip to content

Commit

Permalink
Merge pull request #693 from telefonicaid/fix/expand_var_object_value
Browse files Browse the repository at this point in the history
fix when expanding a var which is a object in action of rule
  • Loading branch information
fgalan authored Jun 22, 2022
2 parents 3604ad4 + e3cc560 commit 120999c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Fix: expanding an object variable in action of rule (#692)
- Fix: for EPL with context + insert + select rule (without expression) (#652)
- Fix: format of internalCurrentTime fixed to ISO 8601
- Fix: typo in non signal event internalCurentTime -> internalCurrentTime
Expand Down
1 change: 1 addition & 0 deletions lib/models/noSignal.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ function alertFunc(nsLineRule, entity) {
if (lastTime !== undefined && lastTime !== null) {
event.lastTime = lastTime;
}
logger.debug(context, 'event available is %j', event);
var delay;
if (config.isMaster) {
delay = 0;
Expand Down
2 changes: 1 addition & 1 deletion lib/models/updateAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ function processOptionParams(action, event) {
});
changes.id = myutils.expandVar(action.parameters.id, event);
changes.type = myutils.expandVar(action.parameters.type, event);

logger.debug('processOptionParams changes: %j', changes);
return changes;
}

Expand Down
11 changes: 10 additions & 1 deletion lib/myutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,19 @@ function logErrorIf(err, message, context) {

function expandVar(val, mapping, trycast) {
if (typeof val === 'string') {
var expanded = false;
var valObj = null;
Object.keys(mapping).forEach(function(p) {
val = val.replace(new RegExp('\\$\\{' + p + '\\}', 'g'), mapping[p]);
// javascript replace always return a string: we need to keep object value
if (!expanded && val === '[object Object]') {
valObj = mapping[p]; // for cases where mapping[p] is an object like { type: 'Point', coordinates: [] }
expanded = true;
}
});
var expanded = false;
if (valObj) {
val = valObj;
}
if (trycast) {
try {
// Check if "${num}" and expand it as real value, non string
Expand Down

0 comments on commit 120999c

Please sign in to comment.