Recently i've been working on an application which allow the users to query enities from a ContextBroker , Cosmos and so on . One feature of the application is to initialize an entity which will be used by a connected object to store data .
The creation works fine , but I have a little problem .
As said in the documentation for the Orion ContextBroker , when an Entity already exists the APPEND action is interpreted as a UPDATE (I sincerely don't understand why) . So here's a scenario , the user have a Entity called Room1 , the sensors give him his data and stores it . One day , he want to create a new entity , but make an error and call it Room1 . All the current data from Room1 will be reset to the default value I put in my application .
Here is my question , is there a way to check if the entity already exist other than doing a manual query (which will take a much longer time to process) in the application before the creation ?
Thank you for reading my question and have a good day .
Guillaume Jourdain .
Currently (Orion 0.22.0), the only way is the one you mention: check that the entity already exist doing a query.
The reason to implement update in this way is that for many uses cases, the desired behavious is exactly the oposites: the client doen't want to get an error if the entity previously doesn't exist and the "append or update" semantics works fine. Unfortunatelly, making happy one use case makes sad the other :(
The best solution would be making this behaviour configurable. We are now defining a new version of the FIWARE NGSI API that Orion implements, including a URL option to set the behaviour, e.g.
?options=append
to set "strict append" semantics (opossite to "append or update" semantics).EDIT: Orion 0.24.0 introduces the APPEND_STRICT action, which returns an error if the attribute to add already exists.