Skip to content

Commit 81a5ca4

Browse files
authored
Merge pull request #1461 from modelix/sync-plugin-ui
Sync Plugin Improvements
2 parents 513ba15 + 7446295 commit 81a5ca4

File tree

245 files changed

+6638
-3533
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

245 files changed

+6638
-3533
lines changed

authorization/src/main/kotlin/org/modelix/authorization/AuthorizationPlugin.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ object ModelixAuthorization : BaseRouteScopedPlugin<IModelixAuthorizationConfig,
169169
|
170170
|Validation result: $validationError
171171
|
172+
|User ID: ${config.jwtUtil.extractUserId(jwt)}
173+
|Roles: ${config.jwtUtil.extractUserRoles(jwt).joinToString(", ")}
174+
|Permissions: ${config.jwtUtil.extractPermissions(jwt)?.joinToString(", ")}
175+
|
172176
|$claims
173177
|
174178
""".trimMargin(),

bulk-model-sync-lib/src/commonMain/kotlin/org/modelix/model/sync/bulk/ModelSynchronizer.kt

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,26 @@ class ModelSynchronizer(
4242
) {
4343
private val nodesToRemove: MutableSet<IWritableNode> = HashSet()
4444
private val pendingReferences: MutableList<PendingReference> = ArrayList()
45+
private val syncStack = ArrayList<IReadableNode>()
46+
47+
fun getCurrentSyncStack(): List<IReadableNode> = syncStack.toList()
48+
49+
private inline fun <R> withPushSyncStack(element: IReadableNode, body: () -> R): R {
50+
syncStack.add(element)
51+
try {
52+
return body()
53+
} finally {
54+
syncStack.removeLast()
55+
}
56+
}
4557

4658
private fun <R> runSafe(body: () -> R): Result<R> {
4759
return if (onException == null) {
4860
Result.success(body())
4961
} else {
5062
runCatching(body)
51-
.onFailure { LOG.error(it) { "Ignoring exception during synchronization" } }
5263
.onFailure { onException(it) }
64+
.onFailure { LOG.error(it) { "Ignoring exception during synchronization" } }
5365
}
5466
}
5567

@@ -71,11 +83,21 @@ class ModelSynchronizer(
7183
}
7284
}
7385
LOG.debug { "Removing extra nodes..." }
74-
nodesToRemove.filter { it.isValid() }.forEach { it.remove() }
86+
nodesToRemove.forEach {
87+
runSafe {
88+
if (it.isValid()) {
89+
it.remove()
90+
}
91+
}
92+
}
7593
LOG.debug { "Synchronization finished." }
7694
}
7795

78-
private fun synchronizeNode(sourceNode: IReadableNode, targetNode: IWritableNode, forceSyncDescendants: Boolean) {
96+
private fun synchronizeNode(
97+
sourceNode: IReadableNode,
98+
targetNode: IWritableNode,
99+
forceSyncDescendants: Boolean,
100+
): Unit = withPushSyncStack(sourceNode) {
79101
nodeAssociation.associate(sourceNode, targetNode)
80102
if (forceSyncDescendants || filter.needsSynchronization(sourceNode)) {
81103
LOG.trace { "Synchronizing changed node. sourceNode = $sourceNode" }

bulk-model-sync-lib/src/commonMain/kotlin/org/modelix/model/sync/bulk/NodeAssociationToModelServer.kt

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,48 @@
11
package org.modelix.model.sync.bulk
22

3-
import org.modelix.model.ModelIndex
43
import org.modelix.model.api.IBranch
54
import org.modelix.model.api.IMutableModel
65
import org.modelix.model.api.IReadableNode
76
import org.modelix.model.api.IWritableNode
87
import org.modelix.model.api.NodeReference
98
import org.modelix.model.api.PNodeAdapter
9+
import org.modelix.model.api.getDescendants
1010
import org.modelix.model.api.getOriginalOrCurrentReference
1111
import org.modelix.model.api.getOriginalReference
12+
import org.modelix.model.api.getRootNode
1213
import org.modelix.model.area.PArea
1314
import org.modelix.model.data.NodeData
1415

16+
private val LOG = mu.KotlinLogging.logger { }
17+
1518
class NodeAssociationToModelServer(val branch: IBranch) : INodeAssociation {
1619

17-
private val modelIndex
18-
get() = ModelIndex.get(branch.transaction, NodeData.Companion.ID_PROPERTY_KEY)
20+
private val associations: MutableMap<String, IWritableNode> by lazy {
21+
val map = HashMap<String, IWritableNode>()
22+
try {
23+
for (node in branch.getRootNode().getDescendants(true).map { it.asWritableNode() }) {
24+
try {
25+
map[node.getPropertyValue(NodeData.ID_PROPERTY_REF) ?: continue] = node
26+
} catch (ex: Exception) {
27+
LOG.error(ex) { "Reading associations from $node failed" }
28+
}
29+
}
30+
} catch (ex: Exception) {
31+
LOG.error(ex) { "Reading associations from $branch failed" }
32+
}
33+
map
34+
}
1935

2036
override fun resolveTarget(sourceNode: IReadableNode): IWritableNode? {
2137
val ref = sourceNode.getOriginalOrCurrentReference()
22-
return modelIndex.find(ref).map { PNodeAdapter(it, branch) }.firstOrNull()?.asWritableNode()
38+
return associations[ref]
2339
?: PArea(branch).resolveNode(NodeReference(ref))?.asWritableNode()
2440
}
2541

2642
override fun associate(sourceNode: IReadableNode, targetNode: IWritableNode) {
2743
val expected = sourceNode.getOriginalOrCurrentReference()
2844
if (expected != targetNode.getOriginalOrCurrentReference()) {
45+
associations[expected] = targetNode
2946
targetNode.setPropertyValue(NodeData.ID_PROPERTY_REF, expected)
3047
}
3148
}

bulk-model-sync-lib/src/commonTest/kotlin/org/modelix/model/sync/bulk/AbstractModelSyncTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import org.modelix.model.api.getRootNode
88
import org.modelix.model.client.IdGenerator
99
import org.modelix.model.data.ModelData
1010
import org.modelix.model.lazy.CLTree
11-
import org.modelix.model.lazy.ObjectStoreCache
11+
import org.modelix.model.lazy.createObjectStoreCache
1212
import org.modelix.model.operations.AddNewChildOp
1313
import org.modelix.model.operations.DeleteNodeOp
1414
import org.modelix.model.operations.IOperation
@@ -601,11 +601,11 @@ abstract class AbstractModelSyncTest {
601601
internal fun OTBranch.getNumOfUsedOperationsByType() = getPendingChanges().first.numOpsByType()
602602

603603
internal fun createOTBranchFromModel(model: ModelData): OTBranch {
604-
val pBranch = PBranch(CLTree(ObjectStoreCache(MapBasedStore())), IdGenerator.getInstance(1))
604+
val pBranch = PBranch(CLTree(createObjectStoreCache(MapBasedStore())), IdGenerator.getInstance(1))
605605
pBranch.runWrite {
606606
ModelImporter(pBranch.getRootNode()).import(model)
607607
}
608-
return OTBranch(pBranch, IdGenerator.getInstance(1), ObjectStoreCache(MapBasedStore()))
608+
return OTBranch(pBranch, IdGenerator.getInstance(1))
609609
}
610610

611611
internal fun IBranch.importIncrementally(model: ModelData) {

bulk-model-sync-lib/src/commonTest/kotlin/org/modelix/model/sync/bulk/ModelExporterTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import org.modelix.model.api.getRootNode
66
import org.modelix.model.client.IdGenerator
77
import org.modelix.model.data.ModelData
88
import org.modelix.model.lazy.CLTree
9-
import org.modelix.model.lazy.ObjectStoreCache
9+
import org.modelix.model.lazy.createObjectStoreCache
1010
import org.modelix.model.persistent.MapBasedStore
1111
import kotlin.js.JsName
1212
import kotlin.test.Test
@@ -52,7 +52,7 @@ class ModelExporterTest {
5252
private val model = ModelData.fromJson(serializedModel)
5353

5454
private fun runTest(body: IBranch.() -> Unit) {
55-
val branch = PBranch(CLTree(ObjectStoreCache(MapBasedStore())), IdGenerator.getInstance(1))
55+
val branch = PBranch(CLTree(createObjectStoreCache(MapBasedStore())), IdGenerator.getInstance(1))
5656
branch.runWrite {
5757
model.load(branch)
5858
}

bulk-model-sync-lib/src/commonTest/kotlin/org/modelix/model/sync/bulk/ModelImporterOrderPropertyTest.kt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import org.modelix.model.api.getRootNode
1010
import org.modelix.model.client.IdGenerator
1111
import org.modelix.model.data.ModelData
1212
import org.modelix.model.lazy.CLTree
13-
import org.modelix.model.lazy.ObjectStoreCache
13+
import org.modelix.model.lazy.createObjectStoreCache
1414
import org.modelix.model.persistent.MapBasedStore
1515
import org.modelix.model.withAutoTransactions
1616
import kotlin.js.JsName
@@ -61,13 +61,8 @@ class ModelImporterOrderPropertyTest {
6161
}
6262

6363
private fun loadModelIntoBranch(modelData: ModelData): IBranch {
64-
val store = ObjectStoreCache(MapBasedStore())
65-
val tree = CLTree(
66-
data = null,
67-
repositoryId_ = null,
68-
store_ = store,
69-
useRoleIds = true,
70-
)
64+
val store = createObjectStoreCache(MapBasedStore())
65+
val tree = CLTree.builder(store).useRoleIds(true).build()
7166
val idGenerator = IdGenerator.getInstance(1)
7267
val pBranch = PBranch(tree, idGenerator)
7368

bulk-model-sync-lib/src/commonTest/kotlin/org/modelix/model/sync/bulk/ModelImporterTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import org.modelix.model.data.ModelData
88
import org.modelix.model.data.NodeData
99
import org.modelix.model.data.NodeData.Companion.ID_PROPERTY_KEY
1010
import org.modelix.model.lazy.CLTree
11-
import org.modelix.model.lazy.ObjectStoreCache
11+
import org.modelix.model.lazy.createObjectStoreCache
1212
import org.modelix.model.operations.OTBranch
1313
import org.modelix.model.persistent.MapBasedStore
1414
import org.modelix.model.test.RandomModelChangeGenerator
@@ -24,7 +24,7 @@ class ModelImporterTest : AbstractModelSyncTest() {
2424
}
2525

2626
override fun runRandomTest(seed: Int) {
27-
val tree0 = CLTree(ObjectStoreCache(MapBasedStore()))
27+
val tree0 = CLTree(createObjectStoreCache(MapBasedStore()))
2828
val branch0 = PBranch(tree0, IdGenerator.getInstance(1))
2929

3030
println("Seed for random change test: $seed")
@@ -49,7 +49,7 @@ class ModelImporterTest : AbstractModelSyncTest() {
4949
specification = rootNode.asExported()
5050
}
5151

52-
val store = ObjectStoreCache(MapBasedStore())
52+
val store = createObjectStoreCache(MapBasedStore())
5353
val tree1 = CLTree(store)
5454
val idGenerator = IdGenerator.getInstance(1)
5555
val branch1 = PBranch(tree1, idGenerator)
@@ -58,7 +58,7 @@ class ModelImporterTest : AbstractModelSyncTest() {
5858
val importer = ModelImporter(branch1.getRootNode())
5959
importer.import(ModelData(root = initialState))
6060
}
61-
val otBranch = OTBranch(branch1, idGenerator, store)
61+
val otBranch = OTBranch(branch1, idGenerator)
6262

6363
otBranch.runWrite {
6464
val importer = ModelImporter(otBranch.getRootNode())

bulk-model-sync-lib/src/commonTest/kotlin/org/modelix/model/sync/bulk/ModelSynchronizerTest.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import org.modelix.model.client.IdGenerator
1111
import org.modelix.model.data.ModelData
1212
import org.modelix.model.data.NodeData
1313
import org.modelix.model.lazy.CLTree
14-
import org.modelix.model.lazy.ObjectStoreCache
14+
import org.modelix.model.lazy.createObjectStoreCache
1515
import org.modelix.model.operations.AddNewChildOp
1616
import org.modelix.model.operations.AddNewChildrenOp
1717
import org.modelix.model.operations.DeleteNodeOp
@@ -141,7 +141,7 @@ open class ModelSynchronizerTest : AbstractModelSyncTest() {
141141
}
142142

143143
override fun runRandomTest(seed: Int) {
144-
val tree0 = CLTree(ObjectStoreCache(MapBasedStore()))
144+
val tree0 = CLTree(createObjectStoreCache(MapBasedStore()))
145145
val sourceBranch = PBranch(tree0, IdGenerator.getInstance(1))
146146

147147
println("Seed for random change test: $seed")
@@ -162,7 +162,7 @@ open class ModelSynchronizerTest : AbstractModelSyncTest() {
162162
}
163163
}
164164

165-
val store = ObjectStoreCache(MapBasedStore())
165+
val store = createObjectStoreCache(MapBasedStore())
166166
val tree1 = CLTree(store)
167167
val idGenerator = IdGenerator.getInstance(1)
168168
val targetBranch = PBranch(tree1, idGenerator)
@@ -173,7 +173,7 @@ open class ModelSynchronizerTest : AbstractModelSyncTest() {
173173
importer.import(ModelData(root = sourceBranch.getRootNode().asExported()))
174174
}
175175
}
176-
val otBranch = OTBranch(targetBranch, idGenerator, store)
176+
val otBranch = OTBranch(targetBranch, idGenerator)
177177

178178
otBranch.runWrite {
179179
ModelSynchronizer(
@@ -196,5 +196,5 @@ open class ModelSynchronizerTest : AbstractModelSyncTest() {
196196
}
197197

198198
private fun IBranch.toOTBranch(): OTBranch {
199-
return OTBranch(this, IdGenerator.getInstance(1), ObjectStoreCache(MapBasedStore()))
199+
return OTBranch(this, IdGenerator.getInstance(1))
200200
}

bulk-model-sync-lib/src/jvmTest/kotlin/org/modelix/model/sync/bulk/ModelSynchronizerWithInvalidationTreeTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import org.modelix.model.client.IdGenerator
88
import org.modelix.model.data.ModelData
99
import org.modelix.model.data.NodeData.Companion.ID_PROPERTY_KEY
1010
import org.modelix.model.lazy.CLTree
11-
import org.modelix.model.lazy.ObjectStoreCache
11+
import org.modelix.model.lazy.createObjectStoreCache
1212
import org.modelix.model.operations.OTBranch
1313
import org.modelix.model.persistent.MapBasedStore
1414
import org.modelix.model.test.RandomModelChangeGenerator
@@ -46,7 +46,7 @@ class ModelSynchronizerWithInvalidationTreeTest : ModelSynchronizerTest() {
4646
}
4747

4848
override fun runRandomTest(seed: Int) {
49-
val tree0 = CLTree(ObjectStoreCache(MapBasedStore()))
49+
val tree0 = CLTree(createObjectStoreCache(MapBasedStore()))
5050
val sourceBranch = PBranch(tree0, IdGenerator.getInstance(1))
5151

5252
println("Seed for random change test: $seed")
@@ -67,7 +67,7 @@ class ModelSynchronizerWithInvalidationTreeTest : ModelSynchronizerTest() {
6767
}
6868
}
6969

70-
val store = ObjectStoreCache(MapBasedStore())
70+
val store = createObjectStoreCache(MapBasedStore())
7171
val tree1 = CLTree(store)
7272
val idGenerator = IdGenerator.getInstance(1)
7373
val targetBranch = PBranch(tree1, idGenerator)
@@ -83,7 +83,7 @@ class ModelSynchronizerWithInvalidationTreeTest : ModelSynchronizerTest() {
8383
sourceTree.visitChanges(targetTree, InvalidatingVisitor(sourceTree, invalidationTree))
8484
}
8585
}
86-
val otBranch = OTBranch(targetBranch, idGenerator, store)
86+
val otBranch = OTBranch(targetBranch, idGenerator)
8787
otBranch.runWrite {
8888
ModelSynchronizer(
8989
filter = invalidationTree,

bulk-model-sync-mps/src/main/kotlin/org/modelix/mps/model/sync/bulk/MPSProjectSyncMask.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import jetbrains.mps.project.MPSProject
44
import org.modelix.model.api.BuiltinLanguages
55
import org.modelix.model.api.IChildLinkReference
66
import org.modelix.model.api.IReadableNode
7+
import org.modelix.model.api.getName
78
import org.modelix.model.mpsadapters.MPSModuleAsNode
89
import org.modelix.model.mpsadapters.MPSProjectAsNode
910
import org.modelix.model.sync.bulk.IModelMask
@@ -39,7 +40,18 @@ class MPSProjectSyncMask(val projects: List<MPSProject>, val isMPSSide: Boolean)
3940
BuiltinLanguages.MPSRepositoryConcepts.Project.getReference() -> when {
4041
else -> children
4142
}
42-
else -> children
43+
else -> when {
44+
role.matches(BuiltinLanguages.MPSRepositoryConcepts.Module.models.toReference()) -> {
45+
children.filterNot { isStubModel(it.getName()) }
46+
}
47+
else -> children
48+
}
4349
}
4450
}
51+
52+
private fun isStubModel(name: String?): Boolean {
53+
if (name == null) return false
54+
val stereotype = name.substringAfter('@')
55+
return stereotype.contains("stub")
56+
}
4557
}

0 commit comments

Comments
 (0)