Skip to content

Commit 704f6cc

Browse files
author
Oleksandr Dzhychko
committed
fix(model-api): do not require registered concept for serialization to NodeData
1 parent e453922 commit 704f6cc

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

model-api/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ kotlin {
3030
}
3131
val commonTest by getting {
3232
dependencies {
33+
implementation(project(":model-datastructure"))
3334
implementation(kotlin("test"))
3435
implementation(libs.kotest.assertions.core)
3536
}

model-api/src/commonMain/kotlin/org/modelix/model/data/ModelData.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ fun ModelData.nodeUID(node: NodeData): String = node.uid(this)
126126

127127
fun INode.asData(): NodeData = NodeData(
128128
id = reference.serialize(),
129-
concept = concept?.getUID(),
129+
concept = getConceptReference()?.getUID(),
130130
role = roleInParent,
131131
properties = getPropertyRoles().associateWithNotNull { getPropertyValue(it) },
132132
references = getReferenceRoles().associateWithNotNull { getReferenceTargetRef(it)?.serialize() },
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 2024.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.modelix.model.data
18+
19+
import org.modelix.model.api.ChildLinkFromName
20+
import org.modelix.model.api.ConceptReference
21+
import org.modelix.model.api.INode
22+
import org.modelix.model.api.TreePointer
23+
import org.modelix.model.api.getRootNode
24+
import org.modelix.model.client.IdGenerator
25+
import org.modelix.model.lazy.CLTree
26+
import org.modelix.model.lazy.NonCachingObjectStore
27+
import org.modelix.model.persistent.MapBasedStore
28+
import kotlin.test.Test
29+
import kotlin.test.assertEquals
30+
31+
class ModelDataTest {
32+
33+
@Test
34+
fun nodeWithConceptReferenceButWithoutRegisteredConceptCanSerialized() {
35+
val aChildLink = ChildLinkFromName("aChildLink")
36+
val aConceptReference = ConceptReference("aConceptReference")
37+
val rootNode = createEmptyRootNode()
38+
rootNode.addNewChild(aChildLink, -1, aConceptReference)
39+
40+
val nodeData = rootNode.asData()
41+
42+
val child = nodeData.children.single { child -> child.role == aChildLink.getUID() }
43+
assertEquals(aConceptReference.getUID(), child.concept)
44+
}
45+
}
46+
47+
internal fun createEmptyRootNode(): INode {
48+
val tree = CLTree(NonCachingObjectStore(MapBasedStore()))
49+
val branch = TreePointer(tree, IdGenerator.getInstance(1))
50+
return branch.getRootNode()
51+
}

0 commit comments

Comments
 (0)