Skip to content
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

Merged
merged 12 commits into from
Feb 1, 2019

Conversation

cblanco
Copy link
Contributor

@cblanco cblanco commented Jan 28, 2019

Edit: fixes #307

@cblanco cblanco mentioned this pull request Jan 28, 2019
@@ -10,3 +10,4 @@
* sinon-chai
* grunt and grunt related module
* closure-linter-wrapper
- Add Rule auto-naming on rule creation time
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand issue #307 should be mentioned.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, #307 should be mentioned. Is enough with these comments?

By the way... it could be that the description that I established in the CNR for this functionality is not the most correct. It would seem appropriate to you if I change it to something like - Add 'ruleName' as variable automatically in rule text field on rule creation time?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think is a good alternative. Maybe an explicit mention to EPL is clarifying. I mean in sum something like this:

- Add 'ruleName' as variable automatically in rule text field (EPL) on rule creation time (#208)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0bfc9a0


var newAs = '"' + rule.name + '" as ruleName';
// Add "name as ruleName" if not exist
if (rule.text && rule.text.indexOf(' as ruleName') === -1) {
Copy link
Member

Choose a reason for hiding this comment

The 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).

Copy link
Contributor Author

@cblanco cblanco Jan 30, 2019

Choose a reason for hiding this comment

The 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

@@ -10,3 +10,4 @@
* sinon-chai
* grunt and grunt related module
* closure-linter-wrapper
- Add 'ruleName' as variable automatically in rule text field (EPL) on rule creation time (#208)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argg... issue number is #307, not #208.

My fault sorry :(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in ef4dda6

* The *from* pattern must name the event as **ev** and the event stream from which take events must be **iotEvent**
* A *type=* condition must be concatenated for avoiding mixing different kinds of entities
* The name of the rule is not mandatory, but for backward compatibility, it can be present as ** ruleName ** alias (`e.g: select *, "blood_rule_update" as ruleName...`) in the select clause. If present, it must be equal to the ‘name’ field of the rule object. If it is not present, you can still use the variable 'ruleName' in the actions, because it will be included automatically.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest split this and include part as in a a remarked "backward compatibility note". In particular I mean:

To leave this in the bullet list:

* The variable 'ruleName' in automatically added to the action, even if it is not present in the EPL text.
**Backward compatibility note:** since version 1.8.0 it is not mandatory to specify the name of the rule as part of the EPL text. In fact, it is not recommendable to do that. However, for backward compatibility, it can be present as *ruleName* alias (`e.g: select *, "blood_rule_update" as ruleName...`) in the select clause. If present, it must be equal to the ‘name’ field of the rule object.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 55110fb

@@ -191,7 +191,7 @@ A simplified format in JSON can be used to represent rules. The former visual ru
```json
{
"name" : "prueba-test",
"text" : "select *,\"prueba-test\" as ruleName from pattern [every ev=iotEvent((cast(id?, String) regexp \"asd\"))]",
"text" : "select * from pattern [every ev=iotEvent((cast(id?, String) regexp \"asd\"))]",
Copy link
Member

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?

Copy link
Contributor Author

@cblanco cblanco Feb 1, 2019

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 or GET /rules, it will include the ruleName in the 'text' field.

Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0917cbd

var newAs = '"' + rule.name + '" as ruleName';
// Add "name as ruleName" if not exist
if (rule.text && rule.text.indexOf(' as ruleName') === -1) {
var idx = rule.text.toLowerCase().indexOf('select') + 7;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

7 seems to be a magic number, a bit obscure :)

Where it comes from? It seems to be len(select) +1, so maybe it would be more clear (i.e. less magical ;) something like this:

var offset = length('select') + 1;
var idx = rule.text.toLowerCase().indexOf('select') + offset;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in b25bd0f

Copy link
Member

@fgalan fgalan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@fgalan fgalan merged commit 2e8b2ba into telefonicaid:master Feb 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Automatically set the name of the rule
2 participants