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
Improve YAML model repository #4024
Conversation
Signed-off-by: Jan N. Klug <github@klug.nrw>
Signed-off-by: Jan N. Klug <github@klug.nrw>
Signed-off-by: Jan N. Klug <github@klug.nrw>
Signed-off-by: Jan N. Klug <github@klug.nrw>
Signed-off-by: Jan N. Klug <github@klug.nrw>
Signed-off-by: Jan N. Klug <github@klug.nrw>
Signed-off-by: Jan N. Klug <github@klug.nrw>
Signed-off-by: Jan N. Klug <github@klug.nrw>
This reverts commit 1c4e6c7eb2afdc55628ca327e8cd9f7453d354a7. Signed-off-by: Jan N. Klug <github@klug.nrw>
@wborn How do we proceed here? |
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 have only found some minor issues so far. 😉
*/ | ||
@NonNullByDefault |
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.
Why was this removed?
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 essentially a DTO. Missing elements in the data are de-serialized as null
.
If we decide to make the DTO classes @NonNullByDefault
we would need to either annotate all fields with @Nullable
(which is the similar to not annotating the class at all) or provide default values (which doesn't make sense in most cases).
bundles/org.openhab.core.model.yaml/src/test/resources/modelFileUpdatePre.yaml
Outdated
Show resolved
Hide resolved
Signed-off-by: Jan N. Klug <github@klug.nrw>
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.
Thanks for the improvements!
I did not take time to have a look. Does this PR break user YAML files containing custom tags ? |
No, I don't think so. The format is the same, just some more options added and code refactoring |
Related to #3666
This improves the existing YAML model parser and repository. In detail:
YamlFile
has been removed. This simplifies code for consumers, because they only need to implementYamlModelListener
and the DTO as inheritor ofYamlDTO
.getRootName
has been removed fromYamlModelListener
. The information is now provided by the@YamlElementName
annotation on the respective DTO class.addedModel
,updatedModel
andremovedModel
methods inYamlModelListener
have been changed to acceptCollection<T>
instead ofCollection<? extends YamlDTO>
which simplifies code in the listener.YamlModelRepository
has been refactored to an interface with methods for adding/updating/removing elements from a model. The implementation isYamlModelRepositoryImpl
. This interface is public and can be implemented to modify an existing model or create a new one. This allows to dynamically update the content.YamlModelRepositoryImpl
now parses the elements usingJsonNode
instead of de-serializing the file directly.JsonNode
s are cached by model (file) name and type. This allows to mix different inheritors ofYamlDTO
in one file. Since all elements are cached asJsonNode
, they can also be read before the respectiveYamlModelListener
is registered. In addition, this removes the coupling between directory and model type.YamlModelRepository
have been added.readOnly
flag (defaults totrue
) has been added. Models without this flag (orreadOnly: true
) cannot be modified. This is to prevent changing user-defined models. On deserialization comments in the file are lost, so they would be missing in an updated model.@lolodomo I would especially like to hear your comments since you did the original implementation.