FIWARE Orion: change entity type

2019-08-09 07:35发布

In Orion, is it possible to change the type of an entity? Related question, it is possible to change the type of an attribute?

Edit: Changing the type of an entity doesn't seem to be possible. So creating a new entity seems to be a solution. But how to preserve dateCreated and dateModified?

1条回答
姐就是有狂的资本
2楼-- · 2019-08-09 08:24

In Orion, is it possible to change the type of an entity

Not directly. Entity id and entity type are immutable. However, you can create a copy of the entity with the new type, then delete the old entity. That will have effectively the same effect.

Related question, it is possible to change the type of an attribute?

Yes, it is. When you update an attribute, not only the value but also the type (and metadata) can be changed.

EDIT: dateModified and dateCreation attributes and metadata are designed to be managed by Context Broker automatically. Clients cannot modify them, they are "read-only". The idea is that a given context consumer client (which, in principle, is independent of the context producer client creating/updating the entity) has a trustable timestamp that nobody could alter.

So, you have basically two alternatives:

  1. Use your custom timestamp attributes and metadata. They can be "moved" to the new entity when you create it. However, CB will not maintain them automatically so your application would have to do it.

  2. Use an out-of-API process, moving the entity at DB level. However, this can be complicated, as you need direct access to DB.

EDIT2: for the second case (DB based process) take into account the Orion DB model. In particular:

  • _id.type is for the entity type
  • creDate is for the entity creation date
  • modDate is for the entity modification date
  • attrs.A.creDate is for the attribute A creation date
  • attrs.A.modDate is for the attribute A modification date
查看更多
登录 后发表回答