-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #316 from Ficodes/feature/optionalRuleName
Feature/optional rule name
- Loading branch information
Showing
8 changed files
with
144 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
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), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |