-
Notifications
You must be signed in to change notification settings - Fork 266
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
Use options=count when getting entities #1251
Conversation
@@ -70,6 +70,11 @@ std::string getEntities | |||
string idPattern = ciP->uriParam["idPattern"]; | |||
string q = ciP->uriParam["q"]; | |||
|
|||
if (ciP->uriParam["options"] == "count") |
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.
Not sure this is enough ....
What if options == 'xxx,count', or 'count,yyy' ?
I think there is a vector somewhere, to do something similar to:
if (ciP->uriParamOptions['count'] == "true")
{
...
}
And, if there isn't, we'll have to implement it ...
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.
Found it :-)
uriParamOptionsParse() in ConnectionInfo.cpp is called by uriArgumentGet() in rest/rest.cpp.
There, all options in the URI param 'options' are put in the vector ciP->uriParamOptions.
So, I would propose to use
if (ciP->uriParamOptions["count"] == true)
wherever needed, and probably remove these four lines.
[ It is a little ugly also to add parameters to ciP->uriParam ... it's like lying ... ]
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.
I thought we were doing only one step after another one, I followed getEntityAllTypes
https://github.com/telefonicaid/fiware-orion/blob/develop/src/lib/serviceRoutinesV2/getEntityAllTypes.cpp#L59
which has an options=value possibility in api doc. As said in your PR #1171
"Good enough for now, until options itself is implemented.
options=values is not implemented."
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.
In postQueryContext we have the following line:
if ((ciP->apiVersion == "v2") && (ciP->uriParam["count"] == "true"))
Now, as there are yet another way to ask for count, we'd need to add the following code:
if ((ciP->apiVersion == "v2") && (ciP->uriParamOptions["count"] == true))
{
countP = &count;
}
With this, it's all taken care of in postQueryContext(), so no code needed in getEntities()
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.
OK, using uriParamOptions
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.
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, probably is misleanding, sorry...
What I tried to mean in #1041 is that in PR #958 "get all entities" operation was implemented using count=true
and that implementation needs to be fixed now to use count
option (not exclusively: I mean, it could happen that other operations appar from "get all entities" are currently using count=true
, in that case, they also need to be fixed to use count
option).
Bottom line: at the end only count
option will be the valid way of getting the count in any NGSIv2 operation in which counting makes sense and this PR should address that (of course, only for currently implemented operations, e.g. list subscription is not).
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.
About "Good enough for now" ...
That statement comes from before ciP->uriParamOptions was implemented.
But ... now it is implemented. That changes everything, right?
And of course, we need to fix those older 'good enough for then' to use uriParamOptions. It is not good enough any more.
I just added this to issue #1041
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.
Well, that comment was before I read your message about your "found" of the uriParamOptionsParse, which you don't remember if existed. I think both comments have crossed. Obviously, if the options param is parsed it should be used the parsed form. The strange thing is not to use the parse function before implementing the version in getEntitiesAllTypes being all commits so close in time, both on Aug 14. (a3fa6aa, 38fb8ae) (not such older the 'raw' use of options)
The original issue #1041 talked about changing from count=true
to options=count
(in getEntities, could be understood) so the use in getEntitesAllTypes looked like a similar issue. It did not talk about allowing multiple values for options (which, I think, is not supported anywhere in the code and it's a orthogonal issue to changing count=true->options=count). So the quote of "good enough" wanted to express that this issue was not the best place to implement the parsing of options param, perhaps, in case it had to do from zero (as you thought for a3fa6aa)
I think changing the code for using the parsed form of options should be an issue by itself. As you wrote, it is not only for "count" but "anything" and the original issue was not related to things like "text" or "values" or any other options value. I would use the parsed form for 'options` in this issue, maybe for all cases of "count=true" in the code but I think it will break the "integrity" of the PR if we changed a lot of different unrelated, in other way, files. Strictly speaking the change in getEntitesAllTypes should not be covered by this issue, but by another issue for refactoring of "options" param use
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 5c9ef1a41b35af8e13c0f49166970700ee632d4
Fixed 5bbfd1d
5c9ef1a
to
5bbfd1d
Compare
LGTM |
@@ -35,7 +35,7 @@ brokerStart CB | |||
# 03. POST /v2/entities, created third entity | |||
# 04. POST /v2/entities, created fourth entity | |||
# 05. POST /v2/entities, created fifth entity | |||
# 06. GET /v2/entities?limit=2&count=true | |||
# 06. GET /v2/entities?limit=2&options=count,normalized |
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.
Probably 'normalized' will not be used at the end after the end, but it is ok to use it in this test as "random" option to check that the ability to mix count with other options works.
NTC
LGTM |
…options_count Use options=count when getting entities
Use options=count when getting entities, closes #1041