REST: get things of type #4302
Comments
I don't see a reason not to put it here. "go" from my side. |
We didn't go into detailed filtering mechanisms on any rest resource from the start, but the it was clear that this would be required sooner or later. When adding those now for certain cases, we should make sure to find a good general scheme that we can apply to all different kinds of resources. Ideally, we should have flexible query parameters, maybe also support substring matching and somehow cleverly feed that into a stream-based get method on the registries. |
The |
Correct. We could provide something like |
If we use a single parameter filter string we can do a lot of stuff. So, e.g.
It would allow doing a lot of this, but perhaps this would be to complex. |
We would need a implementation that could be reused e.g. boolean testLdapExpression(final String expression, final Map<String, String> map) The for (final ThingDTO thing : getAllThings()) {
final Map<String,String> props = new HashMap<>();
props.put("thing-type", thing.thingType);
props.put("label", thing.label);
if (testLdapExpression(filter, props) {
result.add(thing);
}
} another implementation will put other properties... |
I am personally not a huge fan of LDAP filters and imho this is also rather unusual in the JS/REST world - but maybe we should ask some web experts on that :-) |
What I like better on the explicit query parameter name (i.e. |
I "like" the query parameter, too as it is more readable.
The query parameter seems to be not very flexible. At least it is not clear to me how to differ between a "logical and" and a "logical or". Perhaps we can agree that the parameters are always read as logical and / or, or it could be at least a global combination defined. |
In that respect the query parameters look like a dead-end. I mean, the don't need to be extremely powerful, but having both "and" and "or" sounds feasible. I personally also don't really LDAP expressions, as they are hard to read & write for humans, despite the fact that they are incredibly simple to parse for computers which would be a big plus on the positive side. However, it also somehow feels wrong to invent our own. If it's not gonna be LDAP, how about using some other popular one, e.g. the filter language from OData? It's basically what anybody would write in code in almost every language, except that the special characters are replaced by abbreviations which are already familiar from e.g. HTML. |
I agree on the fact that specific query parameters may become too basic very quick. Going with the OData filter language looks promissing. Although we have to separate the OData protocol with lots of other resource defining specs from just the query/filter part. |
Why not using the RFC 1960-based filter that is used for ServiceReference matches already by the OSGi framework. I assume that filters are (at least for OSGi bundle developers) popular (but hey isn't that LDAP 😉). On the OSGi container side it would come without any overhead (I assume that nearly all products are using components). final Filter filter = bundleContext.createFilter(userFilter);
final Stream<EnrichedThingDTO> thingStream = thingRegistry.stream().filter(thing -> {
final Dictionary<String, Object> dict = new Hashtable<>();
dict.put("thingTypeUID", thing.getThingTypeUID().getAsString());
dict.put("label", thing.getLabel());
dict.put("location", thing.getLocation());
return filter.match(dict);
}).map(t -> convertToEnrichedThingDTO(t, locale)).distinct(); |
I have added a simple demonstration for my suggestion, see diff You can use e.g.
I used that exmaples to demonstrate that wildcards could be used, too. IMHO which complex filters (AND, OR, NOT, wildcards, ...) are offered by the UI should be UI specific. At least the REST API itself, that could be used by "whatever" should be generic and this is a very simple solution as in an OSGi runtime all that magic filter handling is already present. |
Hello, please keep in mind that the LDAP-filter notation contains URL-unsafe characters which must be escaped by clients. Apache CXF provides a search functionality based on FIQL. See http://cxf.apache.org/docs/jax-rs-search.html#JAX-RSSearch-FIQL Article: https://jaxenter.com/tutorial-smarter-search-with-fiql-and-apache-cxf-106000.html |
There is currently no method to get all things of a special type only (or I didn't find them).
We are using setups that "get all things" call results into a > 2 MiB response.
Sometimes we need to know only things of a given type first.
I can create that interface in our custom product or you could extend the thing resource to support this request officially.
WDYT?
The text was updated successfully, but these errors were encountered: