Skip to content

Commit cee89f4

Browse files
author
Doris Lam
committed
dev: use model load instead of update for commit to get around update issues, return fake commits, fix parsing project responses
1 parent b7d6bf2 commit cee89f4

2 files changed

Lines changed: 58 additions & 18 deletions

File tree

src/main/kotlin/org/openmbee/flexo/sysmlv2/apis/CommitApi.kt

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ fun Route.CommitApi() {
230230
}
231231

232232
// parse the response model, convert it to JSON, and reply to client
233-
call.respond(flexoResponse.parseModel {
233+
/*call.respond(flexoResponse.parseModel {
234234
// each commit node
235235
for(commit in indexInv(MMS.Commit.uri)[RDF.type]?: emptySet()) {
236236
// reference the commit's IRI
@@ -239,7 +239,15 @@ fun Route.CommitApi() {
239239
// generate commit object
240240
commitFromModel(commitIri, indexOut(commitIri), getCommits.projectId)
241241
}
242-
})
242+
})*/
243+
call.respond(Commit(
244+
atId = getCommits.commitId,
245+
atType = Commit.AtType.Commit,
246+
created = OffsetDateTime.now(),
247+
description = "",
248+
owningProject = Identified(atId = getCommits.projectId),
249+
previousCommit = emptyList()
250+
))
243251
}
244252

245253
get<Paths.getCommitsByProject> { getCommits ->
@@ -254,7 +262,7 @@ fun Route.CommitApi() {
254262
}
255263

256264
// parse the response model, convert it to JSON, and reply to client
257-
call.respond(flexoResponse.parseModel {
265+
/*call.respond(flexoResponse.parseModel {
258266
// each commit node
259267
for(commit in indexInv(MMS.Commit.uri)[RDF.type]?: emptySet()) {
260268
// reference the commit's IRI
@@ -263,7 +271,15 @@ fun Route.CommitApi() {
263271
// generate commit object
264272
commitFromModel(commitIri, indexOut(commitIri), getCommits.projectId)
265273
}
266-
})
274+
})*/
275+
call.respond(listOf(Commit(
276+
atId = UUID.randomUUID(),
277+
atType = Commit.AtType.Commit,
278+
created = OffsetDateTime.now(),
279+
description = "",
280+
owningProject = Identified(atId = getCommits.projectId),
281+
previousCommit = emptyList()
282+
)))
267283
}
268284

269285
post<CommitRequest>("/projects/{projectId}/commits") { commit ->
@@ -422,7 +438,7 @@ fun Route.CommitApi() {
422438
423439
values ?element_n {
424440
${values.joinToString("\n").reindent(5)}
425-
}
441+
}
426442
"""
427443

428444
// only delete incoming if there are elements being deleted
@@ -457,25 +473,48 @@ fun Route.CommitApi() {
457473
// trim indent for better inspectability
458474
sparqlUpdateString = sparqlUpdateString.trimIndent()
459475

476+
// to get around flexo update issue
477+
val turtleLoad = """
478+
${DEFAULT_PREFIX_MAPPING.nsPrefixMap.filter { (id, iri) ->
479+
iri.startsWith(SYSMLV2.BASE)
480+
}.toList().joinToString("\n") { (id, iri) ->
481+
"@prefix $id: <$iri> ."
482+
}.reindent(3)}
483+
484+
${inserts.joinToString("\n\n").reindent(4)}
485+
"""
460486
// submit POST request to commit model
461-
val flexoResponseUpdate = flexoRequestPost {
487+
/*val flexoResponseUpdate = flexoRequestPost {
462488
orgPath("/repos/$projectId/branches/master/update")
463489
464490
// construct body payload
465491
sparqlUpdate {
466492
sparqlUpdateString
467493
}
494+
}*/
495+
val flexoResponseLoad = flexoRequestPut {
496+
orgPath("/repos/$projectId/branches/master/graph")
497+
turtle {
498+
turtleLoad
499+
}
468500
}
469-
470501
// forward failures to client
471-
if(flexoResponseUpdate.isFailure()) {
472-
return@post forward(flexoResponseUpdate)
502+
if(flexoResponseLoad.isFailure()) {
503+
return@post forward(flexoResponseLoad)
473504
}
474505

475506
// parse the response model, convert it to JSON, and reply to client
476-
call.respond(flexoResponseUpdate.parseLdp {
477-
commitFromModel(focalIri!!, focalOutgoing, UUID.fromString(projectId))
478-
})
507+
// TODO load model doesn't return location header or commit info
508+
//call.respond(flexoResponseLoad.parseLdp {
509+
// commitFromModel(focalIri!!, focalOutgoing, UUID.fromString(projectId))
510+
//})
511+
call.respond(Commit(
512+
atId = UUID.randomUUID(),
513+
atType = Commit.AtType.Commit,
514+
created = OffsetDateTime.now(),
515+
description = "",
516+
owningProject = Identified(atId = UUID.fromString(projectId)),
517+
previousCommit = emptyList()
518+
))
479519
}
480-
481520
}

src/main/kotlin/org/openmbee/flexo/sysmlv2/apis/ProjectApi.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ fun Route.ProjectApi() {
7070
}
7171

7272
// parse the response model, convert it JSON, and reply to client
73-
call.respond(flexoResponse.parseLdp {
74-
projectFromResponse(focalOutgoing)
73+
call.respond(flexoResponse.parseModel {
74+
val outgoing = indexOut("$ROOT_CONTEXT/orgs/${GlobalFlexoConfig.org}/repos/${getProject.projectId}")
75+
projectFromResponse(outgoing)
7576
})
7677
}
7778

@@ -83,9 +84,9 @@ fun Route.ProjectApi() {
8384
}
8485

8586
// parse the response model, convert it to JSON, and reply to client
86-
call.respond(flexoResponse.parseLdp {
87+
call.respond(flexoResponse.parseModel {
8788
// find all repos and transform each one into a project by its outgoing triples
88-
model.listSubjectsWithProperty(RDF.type, model.createResource(MMS.Repo)).mapWith {
89+
model.listSubjectsWithProperty(RDF.type, MMS.Repo).mapWith {
8990
projectFromResponse(it.outgoing())
9091
}.toList()
9192
})
@@ -95,7 +96,7 @@ fun Route.ProjectApi() {
9596
post<ProjectRequest>("/projects") { projectRequest ->
9697
// generate a UUID for the repo
9798
val repoUuid = UUID.randomUUID()
98-
99+
99100
// generate a UUID for the default branch
100101
val branchUuid = UUID.randomUUID()
101102

0 commit comments

Comments
 (0)