Skip to content

YAML model repository: supports only version 1 with elements as map #4807

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

Merged
merged 4 commits into from
May 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/
package org.openhab.core.model.yaml.internal;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

Expand All @@ -25,19 +24,12 @@
* The {@link YamlModelWrapper} is used to store the information read from a model in the model cache.
*
* @author Jan N. Klug - Initial contribution
* @author Laurent Garnier - Introduce version 2 using map instead of table
* @author Laurent Garnier - Map used instead of table
*/
@NonNullByDefault
public class YamlModelWrapper {
private final int version;
private final boolean readOnly;
/**
* Nodes as a list in version 1
*/
private final Map<String, List<JsonNode>> nodesV1 = new ConcurrentHashMap<>();
/**
* Nodes as a map in version >= 2
*/
private final Map<String, @Nullable JsonNode> nodes = new ConcurrentHashMap<>();

public YamlModelWrapper(int version, boolean readOnly) {
Expand All @@ -53,20 +45,6 @@ public boolean isReadOnly() {
return readOnly;
}

/**
* Get the nodes for version 1
*
* @return the nodes
*/
public Map<String, List<JsonNode>> getNodesV1() {
return nodesV1;
}

/**
* Get the nodes for version >= 2
*
* @return the nodes
*/
public Map<String, @Nullable JsonNode> getNodes() {
return nodes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public Class<YamlThingDTO> getElementClass() {

@Override
public boolean isVersionSupported(int version) {
return version >= 2;
return version >= 1;
}

@Override
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
version: 1
readOnly: false
firstType:
- uid: element1
element1:
description: description1
- uid: element2
element2:
description: description2
- uid: element3
element3:
description: description3
secondType:
- id: elt1
elt1:
label: My label

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,20 @@ version: 1
# known first type
firstType:
# a valid element with uid and description
- uid: First1
First1:
description: Description1

# a valid element with uid only
- uid: First2

# an invalid element (missing uid)
- description: Description3
First2:

# known second type
secondType:
# a valid element with id and label
- id: Second1
Second1:
label: Label1

# unknown third type
thirdType:
- foo: Bar
Foobar:

nonArrayElement: Test
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
version: 1

firstType:
- uid: First
First:
description: First original
- uid: Second
Second:
description: Second original
- uid: Third
Third:
description: Third original
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
version: 1

firstType:
- uid: First
First:
description: First original
- uid: Second
Second:
description: Second modified
- uid: Fourth
Fourth:
description: Fourth original
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# A YAML test file for updating the model

version: 1

Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# version: 1 => removed in this update

firstType:
- uid: First
First:
description: First original
- uid: Second
Second:
description: Second original
- uid: Third
Third:
description: Third original
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
version: 1

firstTypeRenamed:
- uid: First
First:
description: First original
- uid: Second
Second:
description: Second original
- uid: Third
Third:
description: Third original

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 1
readOnly: false
firstType:
- uid: element1
element1:
description: description1
- uid: element2
element2:
description: description2

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version: 1
readOnly: false
firstType:
- uid: element2
element2:
description: description2

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 1
readOnly: false
firstType:
- uid: element1
element1:
description: newDescription1
- uid: element2
element2:
description: description2

This file was deleted.