Skip to content

Commit 53ddb0c

Browse files
authored
YAML model repository: supports only version 1 with elements as map (#4807)
* YAML model repository: supports only version 1 with elements as map Signed-off-by: Laurent Garnier <lg.hc@free.fr>
1 parent 6ecd6c3 commit 53ddb0c

24 files changed

+105
-534
lines changed

bundles/org.openhab.core.model.yaml/src/main/java/org/openhab/core/model/yaml/internal/YamlModelRepositoryImpl.java

Lines changed: 49 additions & 175 deletions
Large diffs are not rendered by default.

bundles/org.openhab.core.model.yaml/src/main/java/org/openhab/core/model/yaml/internal/YamlModelWrapper.java

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
*/
1313
package org.openhab.core.model.yaml.internal;
1414

15-
import java.util.List;
1615
import java.util.Map;
1716
import java.util.concurrent.ConcurrentHashMap;
1817

@@ -25,19 +24,12 @@
2524
* The {@link YamlModelWrapper} is used to store the information read from a model in the model cache.
2625
*
2726
* @author Jan N. Klug - Initial contribution
28-
* @author Laurent Garnier - Introduce version 2 using map instead of table
27+
* @author Laurent Garnier - Map used instead of table
2928
*/
3029
@NonNullByDefault
3130
public class YamlModelWrapper {
3231
private final int version;
3332
private final boolean readOnly;
34-
/**
35-
* Nodes as a list in version 1
36-
*/
37-
private final Map<String, List<JsonNode>> nodesV1 = new ConcurrentHashMap<>();
38-
/**
39-
* Nodes as a map in version >= 2
40-
*/
4133
private final Map<String, @Nullable JsonNode> nodes = new ConcurrentHashMap<>();
4234

4335
public YamlModelWrapper(int version, boolean readOnly) {
@@ -53,20 +45,6 @@ public boolean isReadOnly() {
5345
return readOnly;
5446
}
5547

56-
/**
57-
* Get the nodes for version 1
58-
*
59-
* @return the nodes
60-
*/
61-
public Map<String, List<JsonNode>> getNodesV1() {
62-
return nodesV1;
63-
}
64-
65-
/**
66-
* Get the nodes for version >= 2
67-
*
68-
* @return the nodes
69-
*/
7048
public Map<String, @Nullable JsonNode> getNodes() {
7149
return nodes;
7250
}

bundles/org.openhab.core.model.yaml/src/main/java/org/openhab/core/model/yaml/internal/things/YamlThingProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public Class<YamlThingDTO> getElementClass() {
157157

158158
@Override
159159
public boolean isVersionSupported(int version) {
160-
return version >= 2;
160+
return version >= 1;
161161
}
162162

163163
@Override

bundles/org.openhab.core.model.yaml/src/test/java/org/openhab/core/model/yaml/internal/YamlModelRepositoryImplTest.java

Lines changed: 29 additions & 203 deletions
Large diffs are not rendered by default.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
version: 1
22
readOnly: false
33
firstType:
4-
- uid: element1
4+
element1:
55
description: description1
6-
- uid: element2
6+
element2:
77
description: description2
8-
- uid: element3
8+
element3:
99
description: description3
1010
secondType:
11-
- id: elt1
11+
elt1:
1212
label: My label

bundles/org.openhab.core.model.yaml/src/test/resources/model/addToModelV2ExpectedContent.yaml

Lines changed: 0 additions & 12 deletions
This file was deleted.

bundles/org.openhab.core.model.yaml/src/test/resources/model/modelFileAddedOrRemoved.yaml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,20 @@ version: 1
66
# known first type
77
firstType:
88
# a valid element with uid and description
9-
- uid: First1
9+
First1:
1010
description: Description1
1111

1212
# a valid element with uid only
13-
- uid: First2
14-
15-
# an invalid element (missing uid)
16-
- description: Description3
13+
First2:
1714

1815
# known second type
1916
secondType:
2017
# a valid element with id and label
21-
- id: Second1
18+
Second1:
2219
label: Label1
2320

2421
# unknown third type
2522
thirdType:
26-
- foo: Bar
23+
Foobar:
2724

2825
nonArrayElement: Test

bundles/org.openhab.core.model.yaml/src/test/resources/model/modelFileUpdatePost.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
version: 1
44

55
firstType:
6-
- uid: First
6+
First:
77
description: First original
8-
- uid: Second
8+
Second:
99
description: Second original
10-
- uid: Third
10+
Third:
1111
description: Third original

bundles/org.openhab.core.model.yaml/src/test/resources/model/modelFileUpdatePre.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
version: 1
44

55
firstType:
6-
- uid: First
6+
First:
77
description: First original
8-
- uid: Second
8+
Second:
99
description: Second modified
10-
- uid: Fourth
10+
Fourth:
1111
description: Fourth original
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
# A YAML test file for updating the model
22

33
version: 1
4-

bundles/org.openhab.core.model.yaml/src/test/resources/model/modelFileUpdateRemovedVersion.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
# version: 1 => removed in this update
44

55
firstType:
6-
- uid: First
6+
First:
77
description: First original
8-
- uid: Second
8+
Second:
99
description: Second original
10-
- uid: Third
10+
Third:
1111
description: Third original

bundles/org.openhab.core.model.yaml/src/test/resources/model/modelFileUpdateRenamedElements.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
version: 1
44

55
firstTypeRenamed:
6-
- uid: First
6+
First:
77
description: First original
8-
- uid: Second
8+
Second:
99
description: Second original
10-
- uid: Third
10+
Third:
1111
description: Third original

bundles/org.openhab.core.model.yaml/src/test/resources/model/modelV2FileAddedOrRemoved.yaml

Lines changed: 0 additions & 25 deletions
This file was deleted.

bundles/org.openhab.core.model.yaml/src/test/resources/model/modelV2FileUpdatePost.yaml

Lines changed: 0 additions & 11 deletions
This file was deleted.

bundles/org.openhab.core.model.yaml/src/test/resources/model/modelV2FileUpdatePre.yaml

Lines changed: 0 additions & 11 deletions
This file was deleted.

bundles/org.openhab.core.model.yaml/src/test/resources/model/modelV2FileUpdateRemovedElements.yaml

Lines changed: 0 additions & 3 deletions
This file was deleted.

bundles/org.openhab.core.model.yaml/src/test/resources/model/modelV2FileUpdateRemovedVersion.yaml

Lines changed: 0 additions & 11 deletions
This file was deleted.

bundles/org.openhab.core.model.yaml/src/test/resources/model/modelV2FileUpdateRenamedElements.yaml

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: 1
22
readOnly: false
33
firstType:
4-
- uid: element1
4+
element1:
55
description: description1
6-
- uid: element2
6+
element2:
77
description: description2

bundles/org.openhab.core.model.yaml/src/test/resources/model/modifyModelV2InitialContent.yaml

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
version: 1
22
readOnly: false
33
firstType:
4-
- uid: element2
4+
element2:
55
description: description2

bundles/org.openhab.core.model.yaml/src/test/resources/model/removeFromModelV2ExpectedContent.yaml

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: 1
22
readOnly: false
33
firstType:
4-
- uid: element1
4+
element1:
55
description: newDescription1
6-
- uid: element2
6+
element2:
77
description: description2

bundles/org.openhab.core.model.yaml/src/test/resources/model/updateInModelV2ExpectedContent.yaml

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)