-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/optional rule name #316
Changes from all commits
0e35221
c5eb1ff
2978155
607209a
a9a9cbf
b356343
0bfc9a0
de35ffd
ef4dda6
55110fb
b25bd0f
0917cbd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ | |
* | ||
* For those usages not covered by the GNU Affero General Public License | ||
* please contact with::[[email protected]] | ||
* | ||
* Modified by: Carlos Blanco - Future Internet Consulting and Development Solutions (FICODES) | ||
*/ | ||
'use strict'; | ||
|
||
|
@@ -132,6 +134,24 @@ function putR2core(rules, callback) { | |
myutils.requestHelperWOMetrics('put', {url: config.perseoCore.rulesURL, json: rulesAndContexts}, callback); | ||
} | ||
|
||
/** | ||
* Add ruleName if necessary in rule text field | ||
* | ||
* @param rule The rule object | ||
*/ | ||
function normalizeRuleName(rule) { | ||
|
||
var newAs = '"' + rule.name + '" as ruleName'; | ||
// Add "name as ruleName" if not exist | ||
if (rule.text && rule.text.indexOf(' as ruleName') === -1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Documentation should be changed to explain that now the name is not mandatory and which happens if the name is ommited (i.e. an example of autogenerated name would be great). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have changed the documentation but I do not know if I have approached it in the right way, please check if the change seems appropriate. b356343 |
||
var offset = 'select'.length + 1; | ||
var idx = rule.text.toLowerCase().indexOf('select') + offset; | ||
rule.text = rule.text = rule.text.slice(0, idx) + newAs + ', ' + rule.text.slice(idx); | ||
} | ||
|
||
return rule; | ||
} | ||
|
||
module.exports = { | ||
FindAll: function(service, subservice, callback) { | ||
rulesStore.FindAll(service, subservice, function(err, data) { | ||
|
@@ -150,6 +170,10 @@ module.exports = { | |
myutils.logErrorIf(localError); | ||
return callback(localError); | ||
} | ||
|
||
// Normalize the rule text | ||
rule = normalizeRuleName(rule); | ||
|
||
async.series( | ||
[ | ||
function(localCallback) { | ||
|
@@ -208,6 +232,10 @@ module.exports = { | |
myutils.logErrorIf(localError); | ||
return callback(localError); | ||
} | ||
|
||
// Normalize the rule text | ||
rule = normalizeRuleName(rule); | ||
|
||
async.series( | ||
[ | ||
delR2core.bind(null, rule), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "theCorrectName", | ||
"text": "select *, \"badRuleleName\" as ruleName, ev.xPressure? as Pression, ev.id? as Meter from pattern [every ev=iotEvent(cast(cast(xPressure?,String),float)>1.5 and type=\"xMeter\")]", | ||
"action": { | ||
"type": "post", | ||
"template": "Meter ${Meter} has pression ${Pression}.", | ||
"parameters": { | ||
"url": "localhost:1111" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "x_post_auto", | ||
"text": "select *, ev.xPressure? as Pression, ev.id? as Meter from pattern [every ev=iotEvent(cast(cast(xPressure?,String),float)>1.5 and type=\"xMeter\")]", | ||
"action": { | ||
"type": "post", | ||
"template": "Meter ${Meter} has pression ${Pression}.", | ||
"parameters": { | ||
"url": "localhost:1111" | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doubt: at rule creation time (
POST /rules
, if I'm remembering correctly) it is clear that ruleName is not include in the EPL and it is automatically added.However, what about of
GET /rules/:id
? Is would be the automatically added ruleName added there?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. The ruleName is added during the creation automatically in the 'text' field. If the rule is requested using
GET / rules/:id
orGET /rules
, it will include the ruleName in the 'text' field.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's a good idea to mention it in the documentation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 0917cbd