Skip to content

Commit 08f0f2c

Browse files
committed
chore(model-server): reduce compilation warnings
Drop some deprecated usages etc.
1 parent d87a8d7 commit 08f0f2c

File tree

8 files changed

+111
-93
lines changed

8 files changed

+111
-93
lines changed

model-server/src/main/kotlin/org/modelix/model/server/handlers/DeprecatedLightModelServer.kt

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ import java.util.Date
7373

7474
class DeprecatedLightModelServer(val client: LocalModelClient) {
7575

76-
fun getStore() = client.storeCache!!
76+
fun getStore() = client.storeCache
7777

7878
fun init(application: Application) {
7979
application.apply {
@@ -88,7 +88,7 @@ class DeprecatedLightModelServer(val client: LocalModelClient) {
8888
}
8989

9090
private fun getCurrentVersion(repositoryId: RepositoryId): CLVersion {
91-
val versionHash = client.asyncStore?.get(repositoryId.getBranchKey())!!
91+
val versionHash = client.asyncStore.get(repositoryId.getBranchKey())!!
9292
return CLVersion.loadFromHash(versionHash, getStore())
9393
}
9494

@@ -144,7 +144,7 @@ class DeprecatedLightModelServer(val client: LocalModelClient) {
144144
}
145145
get<Paths.jsonRepositoryIdGet> {
146146
val repositoryId = RepositoryId(call.parameters["repositoryId"]!!)
147-
val versionHash = client.asyncStore?.get(repositoryId.getBranchKey())!!
147+
val versionHash = client.asyncStore.get(repositoryId.getBranchKey())!!
148148
// TODO 404 if it doesn't exist
149149
val version = CLVersion.loadFromHash(versionHash, getStore())
150150
respondVersion(version)
@@ -171,7 +171,7 @@ class DeprecatedLightModelServer(val client: LocalModelClient) {
171171
val deltaMutex = Mutex()
172172
val sendDelta: suspend (CLVersion) -> Unit = { newVersion ->
173173
deltaMutex.withLock {
174-
if (newVersion.hash != lastVersion?.hash) {
174+
if (newVersion.getContentHash() != lastVersion?.getContentHash()) {
175175
send(versionAsJson(newVersion, lastVersion).toString())
176176
lastVersion = newVersion
177177
}
@@ -218,7 +218,7 @@ class DeprecatedLightModelServer(val client: LocalModelClient) {
218218
null,
219219
emptyArray(),
220220
)
221-
client.asyncStore!!.put(repositoryId.getBranchKey(), newVersion.hash)
221+
client.asyncStore.put(repositoryId.getBranchKey(), newVersion.getContentHash())
222222
respondVersion(newVersion)
223223
}
224224
post<Paths.jsonRepositoryIdVersionHashUpdatePost> {
@@ -252,7 +252,7 @@ class DeprecatedLightModelServer(val client: LocalModelClient) {
252252
repositoryId: RepositoryId,
253253
userId: String?,
254254
): CLVersion {
255-
val branch = OTBranch(PBranch(baseVersion.tree, client.idGenerator), client.idGenerator, client.storeCache!!)
255+
val branch = OTBranch(PBranch(baseVersion.tree, client.idGenerator), client.idGenerator, client.storeCache)
256256
branch.computeWriteT { t ->
257257
for (nodeData in (0 until updateData.length()).map { updateData.getJSONObject(it) }) {
258258
updateNode(nodeData, containmentData = null, t)
@@ -269,24 +269,24 @@ class DeprecatedLightModelServer(val client: LocalModelClient) {
269269
operationsAndTree.first.map { it.getOriginalOp() }.toTypedArray(),
270270
)
271271
repositoryId.getBranchKey()
272-
val mergedVersion = VersionMerger(client.storeCache!!, client.idGenerator)
272+
val mergedVersion = VersionMerger(client.storeCache, client.idGenerator)
273273
.mergeChange(getCurrentVersion(repositoryId), newVersion)
274-
client.asyncStore!!.put(repositoryId.getBranchKey(), mergedVersion.hash)
274+
client.asyncStore.put(repositoryId.getBranchKey(), mergedVersion.getContentHash())
275275
// TODO handle concurrent write to the branchKey, otherwise versions might get lost. See ReplicatedRepository.
276276
return mergedVersion
277277
}
278278

279279
private fun updateNode(nodeData: JSONObject, containmentData: ContainmentData?, t: IWriteTransaction): Long {
280-
var containmentData = containmentData
280+
var actualContainmentData = containmentData
281281
val nodeId = nodeData.getString("nodeId").toLong()
282282
if (!t.containsNode(nodeId)) {
283-
if (containmentData == null) {
284-
containmentData = ContainmentData(nodeData.optLong("parent", ITree.ROOT_ID), nodeData.optString("role", null), nodeData.optInt("index", -1))
283+
if (actualContainmentData == null) {
284+
actualContainmentData = ContainmentData(nodeData.optLong("parent", ITree.ROOT_ID), nodeData.optString("role", null), nodeData.optInt("index", -1))
285285
}
286286
t.addNewChild(
287-
containmentData.parent,
288-
containmentData.role,
289-
containmentData.index,
287+
actualContainmentData.parent,
288+
actualContainmentData.role,
289+
actualContainmentData.index,
290290
nodeId,
291291
null as IConcept?,
292292
)
@@ -341,17 +341,17 @@ class DeprecatedLightModelServer(val client: LocalModelClient) {
341341
version: CLVersion,
342342
oldVersion: CLVersion?,
343343
): JSONObject {
344-
val branch = TreePointer(version.tree)
344+
val branch = TreePointer(version.getTree())
345345
val rootNode = PNodeAdapter(ITree.ROOT_ID, branch)
346346
val json = JSONObject()
347-
json.put("repositoryId", version.tree.getId())
348-
json.put("versionHash", version.hash)
347+
json.put("repositoryId", version.getTree().getId())
348+
json.put("versionHash", version.getContentHash())
349349
if (oldVersion == null) {
350350
json.put("root", node2json(rootNode, true))
351351
} else {
352352
val nodesToInclude = HashSet<Long>()
353-
version.tree.visitChanges(
354-
oldVersion.tree,
353+
version.getTree().visitChanges(
354+
oldVersion.getTree(),
355355
object : ITreeChangeVisitorEx {
356356
override fun childrenChanged(nodeId: Long, role: String?) {
357357
nodesToInclude += nodeId
@@ -380,7 +380,7 @@ class DeprecatedLightModelServer(val client: LocalModelClient) {
380380
)
381381
val changedNodes = nodesToInclude.map { node2json(PNodeAdapter(it, branch), false) }.toJsonArray()
382382
json.put("nodes", changedNodes)
383-
version.tree
383+
version.getTree()
384384
}
385385
return json
386386
}

model-server/src/main/kotlin/org/modelix/model/server/handlers/HistoryHandler.kt

Lines changed: 54 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import kotlinx.html.th
3333
import kotlinx.html.thead
3434
import kotlinx.html.tr
3535
import kotlinx.html.ul
36+
import kotlinx.html.unsafe
3637
import org.modelix.api.html.Paths
3738
import org.modelix.authorization.KeycloakScope
3839
import org.modelix.authorization.asResource
@@ -73,11 +74,15 @@ class HistoryHandler(val client: IModelClient, private val repositoriesManager:
7374
call.respondHtmlTemplate(PageWithMenuBar("repos/", "../../..")) {
7475
headContent {
7576
style {
76-
+"""
77-
body {
78-
font-family: sans-serif;
77+
unsafe {
78+
raw(
79+
"""
80+
body {
81+
font-family: sans-serif;
82+
}
83+
""".trimIndent(),
84+
)
7985
}
80-
""".trimIndent()
8186
}
8287
repositoryPageStyle()
8388
}
@@ -109,11 +114,11 @@ class HistoryHandler(val client: IModelClient, private val repositoriesManager:
109114

110115
private suspend fun revert(repositoryAndBranch: BranchReference, from: String?, to: String?, author: String?) {
111116
val version = repositoriesManager.getVersion(repositoryAndBranch) ?: throw RuntimeException("Branch doesn't exist: $repositoryAndBranch")
112-
val branch = OTBranch(PBranch(version.tree, client.idGenerator), client.idGenerator, client.storeCache!!)
117+
val branch = OTBranch(PBranch(version.getTree(), client.idGenerator), client.idGenerator, client.storeCache)
113118
branch.runWriteT { t ->
114119
t.applyOperation(RevertToOp(KVEntryReference(from!!, DESERIALIZER), KVEntryReference(to!!, DESERIALIZER)))
115120
}
116-
val (ops, tree) = branch.operationsAndTree
121+
val (ops, tree) = branch.getPendingChanges()
117122
val newVersion = createRegularVersion(
118123
client.idGenerator.generate(),
119124
LocalDateTime.now().toString(),
@@ -127,38 +132,42 @@ class HistoryHandler(val client: IModelClient, private val repositoriesManager:
127132

128133
private fun HEAD.repositoryPageStyle() {
129134
style {
130-
+"""
131-
ul {
132-
padding-left: 15px;
133-
}
134-
.hash {
135-
color: #888;
136-
white-space: nowrap;
137-
}
138-
.BtnGroup {
139-
display: inline-block;
140-
vertical-align: middle;
141-
margin: 10px;
142-
}
143-
.BtnGroup-item {
144-
background-color: #f6f8fa;
145-
border: 1px solid rgba(27,31,36,0.15);
146-
padding: 5px 16px;
147-
position: relative;
148-
float: left;
149-
border-right-width: 0;
150-
border-radius: 0;
151-
}
152-
.BtnGroup-item:first-child {
153-
border-top-left-radius: 6px;
154-
border-bottom-left-radius: 6px;
155-
}
156-
.BtnGroup-item:last-child {
157-
border-right-width: 1px;
158-
border-top-right-radius: 6px;
159-
border-bottom-right-radius: 6px;
135+
unsafe {
136+
raw(
137+
"""
138+
ul {
139+
padding-left: 15px;
140+
}
141+
.hash {
142+
color: #888;
143+
white-space: nowrap;
144+
}
145+
.BtnGroup {
146+
display: inline-block;
147+
vertical-align: middle;
148+
margin: 10px;
149+
}
150+
.BtnGroup-item {
151+
background-color: #f6f8fa;
152+
border: 1px solid rgba(27,31,36,0.15);
153+
padding: 5px 16px;
154+
position: relative;
155+
float: left;
156+
border-right-width: 0;
157+
border-radius: 0;
158+
}
159+
.BtnGroup-item:first-child {
160+
border-top-left-radius: 6px;
161+
border-bottom-left-radius: 6px;
162+
}
163+
.BtnGroup-item:last-child {
164+
border-right-width: 1px;
165+
border-top-right-radius: 6px;
166+
border-bottom-right-radius: 6px;
167+
}
168+
""".trimIndent(),
169+
)
160170
}
161-
""".trimIndent()
162171
}
163172
}
164173

@@ -169,7 +178,14 @@ class HistoryHandler(val client: IModelClient, private val repositoriesManager:
169178
skip: Int,
170179
limit: Int,
171180
) {
172-
val headVersion = if (headHash == null || headHash.length == 0) latestVersion else CLVersion(headHash, client.storeCache!!)
181+
val headVersion = if (headHash == null || headHash.length == 0) {
182+
latestVersion
183+
} else {
184+
CLVersion(
185+
headHash,
186+
client.storeCache,
187+
)
188+
}
173189
var rowIndex = 0
174190
h1 {
175191
+"History for Repository "

model-server/src/main/kotlin/org/modelix/model/server/handlers/LightModelServer.kt

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ class LightModelServer(val client: LocalModelClient) {
109109
newVersion,
110110
)
111111
}
112-
client.asyncStore.put(repositoryId.getBranchReference().getKey(), mergedVersion.hash)
113-
if (mergedVersion.hash != lastVersionToClient?.hash) {
112+
client.asyncStore.put(repositoryId.getBranchReference().getKey(), mergedVersion.getContentHash())
113+
if (mergedVersion.getContentHash() != lastVersionToClient?.getContentHash()) {
114114
sendMsg(
115115
MessageFromServer(
116116
version = versionAsJson(mergedVersion, lastVersionToClient),
@@ -131,9 +131,9 @@ class LightModelServer(val client: LocalModelClient) {
131131

132132
val versionChanges = Channel<String>(capacity = Channel.UNLIMITED)
133133
val versionChangeDetector = object : VersionChangeDetector(client.asyncStore, repositoryId.getBranchReference().getKey(), CoroutineScope(coroutineContext)) {
134-
override fun processVersionChange(oldVersionHash: String?, newVersionHash: String?) {
135-
if (newVersionHash != null) {
136-
versionChanges.trySend(newVersionHash)
134+
override fun processVersionChange(oldVersion: String?, newVersion: String?) {
135+
if (newVersion != null) {
136+
versionChanges.trySend(newVersion)
137137
}
138138
}
139139
}
@@ -142,7 +142,7 @@ class LightModelServer(val client: LocalModelClient) {
142142
val latestVersionHash = versionChanges.receiveLast()
143143
val newVersion = CLVersion.loadFromHash(latestVersionHash, client.storeCache)
144144
deltaMutex.withLock {
145-
if (latestVersionHash != lastVersionToClient?.hash) {
145+
if (latestVersionHash != lastVersionToClient?.getContentHash()) {
146146
sendDelta(newVersion, null, null)
147147
}
148148
}
@@ -211,7 +211,7 @@ class LightModelServer(val client: LocalModelClient) {
211211
repositoryId: RepositoryId,
212212
userId: String?,
213213
): CLVersion {
214-
val branch = OTBranch(PBranch(baseVersion.tree, client.idGenerator), client.idGenerator, client.storeCache!!)
214+
val branch = OTBranch(PBranch(baseVersion.getTree(), client.idGenerator), client.idGenerator, client.storeCache)
215215
branch.computeWriteT { t ->
216216
for (op in operations) {
217217
try {
@@ -256,7 +256,7 @@ class LightModelServer(val client: LocalModelClient) {
256256
t.getChildren(ITree.ROOT_ID, ITree.DETACHED_NODES_ROLE).toList().forEach { t.deleteNode(it) }
257257
}
258258

259-
val operationsAndTree = branch.operationsAndTree
259+
val operationsAndTree = branch.getPendingChanges()
260260
val newVersion = CLVersion.createRegularVersion(
261261
client.idGenerator.generate(),
262262
Date().toString(),
@@ -267,7 +267,7 @@ class LightModelServer(val client: LocalModelClient) {
267267
)
268268
val mergedVersion = VersionMerger(client.storeCache, client.idGenerator)
269269
.mergeChange(getCurrentVersion(repositoryId), newVersion)
270-
client.asyncStore.put(repositoryId.getBranchKey(), mergedVersion.hash)
270+
client.asyncStore.put(repositoryId.getBranchKey(), mergedVersion.getContentHash())
271271
// TODO handle concurrent write to the branchKey, otherwise versions might get lost. See ReplicatedRepository.
272272
return mergedVersion
273273
}
@@ -276,25 +276,25 @@ class LightModelServer(val client: LocalModelClient) {
276276
version: CLVersion,
277277
oldVersion: CLVersion?,
278278
): VersionData {
279-
val branch = TreePointer(version.tree)
279+
val branch = TreePointer(version.getTree())
280280
val nodeDataList = ArrayList<NodeData>()
281281
if (oldVersion == null) {
282282
val rootNode = PNodeAdapter(ITree.ROOT_ID, branch)
283283
node2json(rootNode, true, nodeDataList)
284284
} else {
285285
val nodesToInclude = HashSet<Long>()
286-
version.tree.visitChanges(
287-
oldVersion.tree,
286+
version.getTree().visitChanges(
287+
oldVersion.getTree(),
288288
object : ITreeChangeVisitorEx {
289289
override fun childrenChanged(nodeId: Long, role: String?) {
290290
nodesToInclude += nodeId
291291
}
292292

293293
override fun containmentChanged(nodeId: Long) {
294294
nodesToInclude.add(nodeId)
295-
if (version.tree.getParent(nodeId) == oldVersion.tree.getParent(nodeId)) {
295+
if (version.getTree().getParent(nodeId) == oldVersion.getTree().getParent(nodeId)) {
296296
// no childrenChanged event is received for the parent if only the role changed
297-
nodesToInclude.add(version.tree.getParent(nodeId))
297+
nodesToInclude.add(version.getTree().getParent(nodeId))
298298
}
299299
}
300300

@@ -320,10 +320,10 @@ class LightModelServer(val client: LocalModelClient) {
320320
nodesToInclude.forEach { node2json(PNodeAdapter(it, branch), false, nodeDataList) }
321321
}
322322
return VersionData(
323-
repositoryId = version.tree.getId(),
324-
versionHash = version.hash,
323+
repositoryId = version.getTree().getId(),
324+
versionHash = version.getContentHash(),
325325
rootNodeId = if (oldVersion == null) ITree.ROOT_ID.toString(16) else null,
326-
usesRoleIds = version.tree.usesRoleIds(),
326+
usesRoleIds = version.getTree().usesRoleIds(),
327327
nodes = nodeDataList,
328328
)
329329
}

model-server/src/main/kotlin/org/modelix/model/server/handlers/RepositoriesManager.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class RepositoriesManager(val client: LocalModelClient) : IRepositoriesManager {
143143
baseVersion = null,
144144
operations = emptyArray(),
145145
)
146-
putVersionHash(masterBranch, initialVersion.hash)
146+
putVersionHash(masterBranch, initialVersion.getContentHash())
147147
initialVersion
148148
}
149149

@@ -243,13 +243,13 @@ class RepositoriesManager(val client: LocalModelClient) : IRepositoriesManager {
243243
} else {
244244
val headVersion = CLVersion(headHash, client.storeCache)
245245
val newVersion = CLVersion(newVersionHash, client.storeCache)
246-
require(headVersion.tree.getId() == newVersion.tree.getId()) {
247-
"Attempt to merge a model with ID '${newVersion.tree.getId()}'" +
248-
" into one with ID '${headVersion.tree.getId()}'"
246+
require(headVersion.getTree().getId() == newVersion.getTree().getId()) {
247+
"Attempt to merge a model with ID '${newVersion.getTree().getId()}'" +
248+
" into one with ID '${headVersion.getTree().getId()}'"
249249
}
250250
val mergedVersion = VersionMerger(client.storeCache, client.idGenerator)
251251
.mergeChange(headVersion, newVersion)
252-
mergedVersion.hash
252+
mergedVersion.getContentHash()
253253
}
254254
putVersionHash(branch, mergedHash)
255255
ensureRepositoriesAreInList(setOf(branch.repositoryId))

model-server/src/main/kotlin/org/modelix/model/server/store/IStoreClient.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ suspend fun pollEntry(storeClient: IStoreClient, key: String, lastKnownValue: St
5454
val channel = Channel<Unit>(Channel.RENDEZVOUS)
5555

5656
val listener = object : IKeyListener {
57-
override fun changed(key_: String, newValue: String?) {
57+
override fun changed(key: String, value: String?) {
5858
launch {
59-
callHandler(newValue)
59+
callHandler(value)
6060
channel.trySend(Unit)
6161
}
6262
}

0 commit comments

Comments
 (0)