Skip to content

Commit 9f8af4f

Browse files
authored
Merge pull request #863 from telefonicaid/fix/jexl_parser_json_value_attr
fix jexl transformation expression when is a JSON based value
2 parents d7aeef1 + 1a2507c commit 9f8af4f

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

lib/plugins/jexlParser.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function parse(expression, context, callback) {
4646
try {
4747

4848
result = jexl.evalSync (expression, context);
49-
49+
logger.debug(logContext, 'parse expression result "[%j]" ', result);
5050
} catch (e) {
5151
error = new errors.InvalidExpression(expression);
5252
if (callback) {
@@ -93,7 +93,10 @@ function extractContext(attributeList) {
9393
}
9494

9595
function applyExpression(expression, context, typeInformation) {
96-
return jexl.evalSync (expression, context);
96+
var result;
97+
result = jexl.evalSync (expression, context);
98+
logger.debug(logContext, 'applyExpression result "[%j]" ', result);
99+
return result;
97100
}
98101

99102
function expressionApplier(context, typeInformation) {
@@ -133,13 +136,16 @@ function expressionApplier(context, typeInformation) {
133136
else if (attribute.type === 'None') {
134137
newAttribute.value = null;
135138
}
136-
else if (attribute.type === 'Text') {
139+
else if (attribute.type === 'Text' || attribute.type === 'String') {
137140
newAttribute.value = String(newAttribute.value);
138141
}
139-
else if (attribute.type !== 'StructuredValue') {
142+
else if (attribute.type.toLowerCase().includes('structuredvalue') ||
143+
attribute.type.toLowerCase().startsWith('geo') ||
144+
attribute.type.toLowerCase().includes('json') ) {
145+
newAttribute.value = newAttribute.value;
146+
} else {
140147
newAttribute.value = String(newAttribute.value);
141148
}
142-
143149
return newAttribute;
144150
};
145151
}
@@ -161,7 +167,11 @@ function contextAvailable(expression, context) {
161167
if (!keys.includes(element.value) && !isTransform(element.value)) {
162168
validContext = false;
163169
logger.warn(logContext, 'For expression "[%s]" context does not have element %s' , expression, element.value);
164-
}
170+
}
171+
// FIXME: Workaround to allow keys of JSON geopoints
172+
if (element.value === 'type' || element.value === 'coordinates') {
173+
validContext = true;
174+
}
165175
return validContext === false;
166176
});
167177
if(validContext) {

0 commit comments

Comments
 (0)