-
-
Notifications
You must be signed in to change notification settings - Fork 429
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
Add semantic tag registry + REST API to manage user tags #3636
Conversation
It is already working well (managing custom tags through the REST API). |
Build is failing but apparently with no link with my PR:
|
The build is now failing in automation integration tests:
Is it something that could be linked to my changes ?? |
Since GitHUB CI succeeded, it's probably just an unstable test. |
We will see at next compile when I add commits. |
c4ef256
to
f82c644
Compare
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.
A conceptual question: Why don't we refactor the system tags to be provided by a tag provider and use the registry for everything?
...enhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/tag/TagDTO.java
Outdated
Show resolved
Hide resolved
...s/org.openhab.core.semantics/src/main/java/org/openhab/core/semantics/CustomTagRegistry.java
Outdated
Show resolved
Hide resolved
...s/org.openhab.core.semantics/src/main/java/org/openhab/core/semantics/CustomTagRegistry.java
Outdated
Show resolved
Hide resolved
....core.semantics/src/main/java/org/openhab/core/semantics/internal/CustomTagRegistryImpl.java
Outdated
Show resolved
Hide resolved
....core.semantics/src/main/java/org/openhab/core/semantics/internal/CustomTagRegistryImpl.java
Outdated
Show resolved
Hide resolved
I understand what you mean and that is a good remark. |
That would mean we even do not need all the tag classes anymore? |
I don't think we can remove the tag classes. The parent/child relationship is implemented by class inheritance. Regarding the YAML: I'll try to figure out how to to that. I'm also interested in that because in the long-term I would like to replace the XText files with YAML, which would also allow us simply copy & paste from UI code-tab to files (and back). |
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 been watching in which direction custom tags are going since #3519. Here I just reflect briefly my humble option that semantic tags been built for fixed purpose and they beg for ready markers, own start level and second thought. I do question the way in which they function right now. Below description is not opinion on this PR, but problem statement which I try to outline.
Because you mutate SemanticTag
singleton instance you will face a lot of reliability issues. Depending on invocation order it will behave completely differently. More over there is currently no synchronization point which would deffer startup of code which register tags from code which intends to uses it. More over, since methods are visible to anyone it is possible to append tags at runtime. It is likely to see situations where execution of a rule with a blind SemanticsTag.add
call will amend its internal state without invalidation of caches built elsewhere.
Two main notes:
TagInfo
mapping which rely on annotation attributes bring no benefit to anyone. It is useless at runtime.- All
TagInfo
attributes could in fact become methods of Equipment/Point/Location types. - There is special meaning of
TagInfo#id
attribute, which is a leaking logic. Others have to preserve format of it, even if there is proper inheritance information (i.e.id=Equipment_AlarmSystem
, reflectinterface AlarmSystem extends Equipment
, makingid=AlarmSystem
will ignore tag!). - You can't reliably validate information placed in annotations without building an annotation processor fired before any code is loaded (see Java Annotation Processing Tool).
- Registration of tags which rely on
SemanticsTag.add()
and generated classes at runtime is an workaround for above point and attempts to escape static nature ofSemanticTags
, why not making aCustomEquipment
/CustomLocation
classes and use them instead?
If you keep going with changes made in #3519 please make sure that user documentation have big fat warning about risks it brings to them and how to properly use these across different places.
Custom tags will not be properly recognized by SemanticsMetadataProvider
, if they are registered later. There is fair chance that they will work on random basis, depending on initialization order of elements which register tags at runtime.
I'm aware of that, also links can't be provided at the moment. It was just a PoC for reading from YAML in a |
Agree & ack, it will cut by half amount of WTF moments new comers have when looking at UI definitions and file configurations. |
I propose config files to be supported in a next PR. |
Or label/description/synonyms could be a static member of each tag class? |
Built-in tags can for sure rely on static values, user supplied tags can be initialized with data stored in JSON or any other format. You will need a |
In case we refactor to have the system tags in the registry (as suggested by @J-N-K ), the label/description/synonyms are probably no more needed on the tag class itself, they will be present in the registry. This was not my intention to fully refactored all the semantic tags. |
Sorry, I don't understand why. |
Its up to you to decide how to approach this issue. I refereed to |
Having all tags in the registry is I believe possible. We could have a system tag provider that will fill the registry with all system default tags. |
8023ca2
to
741d481
Compare
I have now finished the refactoring of semantic tags to handle all of them in a new registry. Unit tests are now ok, integration tests also and I have done robust manual tests with the REST API. |
...ore.semantics/src/main/java/org/openhab/core/semantics/internal/SemanticTagRegistryImpl.java
Outdated
Show resolved
Hide resolved
This PR is of course a breaking API change but only HABot is impacted. I am now preparing the small adjustment required in HABot. As soon as this PR is merged, the HABot PR should also be merged. |
Related to openhab#3619 New registry for semantic tags. New default semantic tags provider for all built-in semantic tags. New managed provider to add/remove/update user semantic tags. Storage of user semantic tags in a JSON DB file. New REST API to add/remove/update user tags in the semantic model. New REST API to get a sub-tree of the semantic tags. Tag label/description/synonyms are now in the registry, no more as part of the semantic class annotation. Signed-off-by: Laurent Garnier <lg.hc@free.fr>
...ore.semantics/src/main/java/org/openhab/core/semantics/internal/SemanticTagRegistryImpl.java
Outdated
Show resolved
Hide resolved
...ore.semantics/src/main/java/org/openhab/core/semantics/internal/SemanticTagRegistryImpl.java
Outdated
Show resolved
Hide resolved
...hab.core.semantics/src/main/java/org/openhab/core/semantics/model/equipment/AlarmSystem.java
Outdated
Show resolved
Hide resolved
Depends on openhab/openhab-core#3636 Signed-off-by: Laurent Garnier <lg.hc@free.fr>
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
…in the right order Signed-off-by: Laurent Garnier <lg.hc@free.fr>
@J-N-K : it is again ready for an additional review. Now, the tag classes are created at runtime. |
Looking all remaining places where TagInfo is still used, I now believe that the annotation could be removed, we just need a method that would build the UID for a tag class considering the class hierarchy. |
It is done. Unfortunately, the PR does not update (even if I do a force) ! I do not understand why. |
As the PR does not synchronize, I close it and I will open a new one. |
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 had a quick look on it, leaving some remarks in case if you are interested in them.
* @author Jimmy Tanagra - initial contribution | ||
* @author Laurent Garnier - Class renamed and members uid, description and editable added | ||
*/ | ||
public class EnrichedSemanticTagDTO { |
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.
Small note on consistency - it doesn't seem to be much enriched compared to other enriched DTO types we have at REST layer, its just an regular representation which does not ship anything beyond SementicTag itself. Or I am wrong?
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.
Enriched just because of the "editable" property.
....core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/tag/TagResource.java
Show resolved
Hide resolved
.sorted((element1, element2) -> element2.compareTo(element1)).collect(Collectors.toList()); | ||
for (String id : uids) { | ||
// ask whether the tag exists as a managed tag, so it can get updated, 405 otherwise | ||
if (managedSemanticTagProvider.get(id) == null) { |
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.
Can this be simplified to a place where we just confirm given tag id
is managed or not? I suppose we will not reach a place where parent tag might be managed and its children might 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.
This is currently not possible but could become possible later when an unmanaged provider is added.
I am not yet sure if we should or not allow unmanaged tags to be added as childs to a managed tag and vice-versa. Because this will make loading of unmanaged and managed providers very difficult.
...re.model.script/src.moved/test/java/org/openhab/core/model/script/actions/SemanticsTest.java
Show resolved
Hide resolved
bundles/org.openhab.core.semantics/src/main/java/org/openhab/core/semantics/Properties.java
Show resolved
Hide resolved
.collect(Collectors.toList()); | ||
List<Class<? extends Tag>> tagList = new ArrayList<>(); | ||
tags.forEach(t -> { | ||
Class<? extends Tag> tag = SemanticTags.getById(t.getUID()); |
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 think the Tag classes are not serving any major purpose any more, you can simply rely on SemanticTag
instances all over this place and related ones.
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.
At least some of them are for compatibility reasons with HABot. That is exactly the case for method getByLabelOrSynonym
But I will remove the others not necessary (not used in core or HABot).
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 removed some of the methods I previously added in this class.
But the method you pointed is required for HABot compatibility.
…ass (#1916) Depends on openhab/openhab-core#3636 Signed-off-by: Laurent Garnier <lg.hc@free.fr>
Related to #3619
New registry for semantic tags.
New default semantic tags provider for all built-in semantic tags.
New managed provider to add/remove/update user semantic tags.
Storage of user semantic tags in a JSON DB file.
New REST API to add/remove/update user tags in the semantic model.
New REST API to get a sub-tree of the semantic tags.
Tag label/description/synonyms are now in the registry, no more as part of the semantic class annotation.
Semantic tag class annotation are removed.
Semantic tag classes are now created at runtime.
Signed-off-by: Laurent Garnier lg.hc@free.fr