Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scratches: unversioned named graphs #184

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
dev: delete
blake-regalia committed Jan 29, 2025
commit abe32cdf828bc08c27700609dfe471a839da9bbf
4 changes: 4 additions & 0 deletions src/main/kotlin/org/openmbee/flexo/mms/Conditions.kt
Original file line number Diff line number Diff line change
@@ -163,6 +163,10 @@ val LOCK_UPDATE_CONDITIONS = LOCK_CRUD_CONDITIONS.append {
permit(Permission.UPDATE_LOCK, Scope.LOCK)
}

val SCRATCH_DELETE_CONDITIONS = REPO_CRUD_CONDITIONS.append {
permit(Permission.DELETE_SCRATCH, Scope.SCRATCH)
}

enum class ConditionType {
INSPECT,
REQUIRE,
26 changes: 25 additions & 1 deletion src/main/kotlin/org/openmbee/flexo/mms/UserQuery.kt
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ suspend fun AnyLayer1Context.processAndSubmitUserQuery(queryRequest: SparqlQuery
prefixes["mor"] -> {
"${prefixes["mor-graph"]}Metadata"
}
"${prefixes["mor-graph"]}Scratch" -> {
"${prefixes["mor-graph"]}Scratch.$scratchId" -> {
refIri
}
else -> {
@@ -474,3 +474,27 @@ suspend fun Layer1Context<GspRequest, *>.loadGraph(loadGraphUri: String) {
}
}
}

/**
* Takes a Graph Store Protocol delete request and forwards it to Layer 0, optionally providing custom WHERE pattern
*/
suspend fun Layer1Context<GspRequest, *>.deleteGraph(deleteGraphUri: String, where: (WhereBuilder.() -> Unit)?) {
// create update string
val deleteUpdateString = buildSparqlUpdate {
delete {
graph(escapeIri(deleteGraphUri)) {
raw("?s ?p ?o")
}
}
where {
where?.let { it() }

graph(escapeIri(deleteGraphUri)) {
raw("?s ?p ?o")
}
}
}

// execute update
executeSparqlUpdate(deleteUpdateString)
}
17 changes: 13 additions & 4 deletions src/main/kotlin/org/openmbee/flexo/mms/routes/Scratches.kt
Original file line number Diff line number Diff line change
@@ -124,10 +124,19 @@ fun Route.crudScratch() {
//
// }

// // 5.4 DELETE: delete
// delete {
//
// }
// 5.4 DELETE: delete (drop)
delete {
// delete the graph
deleteGraph("${prefixes["mor-graph"]}Scratch.$scratchId") {
// permissions check
graph("mor-graph:Metadata") {
auth(Permission.DELETE_SCRATCH.scope.id, SCRATCH_DELETE_CONDITIONS)
}
}

// close response
call.respondText("", status = HttpStatusCode.NoContent)
}

otherwiseNotAllowed("store scratch")
}
10 changes: 10 additions & 0 deletions src/main/kotlin/org/openmbee/flexo/mms/server/GraphStore.kt
Original file line number Diff line number Diff line change
@@ -101,6 +101,11 @@ class GspPutResponse(requestContext: GenericRequest): GspMutateResponse(requestC
*/
class GspPatchResponse(requestContext: GenericRequest): GspMutateResponse(requestContext)

/**
* Response context for DELETE to graph
*/
class GspDeleteResponse(requestContext: GenericRequest): GspMutateResponse(requestContext)


/**
* A Graph Store Protocol (GSP) endpoint
@@ -227,6 +232,11 @@ class GraphStoreProtocolRoute<TRequestContext: GenericRequest>(
SparqlUpdateRequest(call, updateString)
}
}

// DELETE
fun delete(body: Layer1Handler<TRequestContext, GspDeleteResponse>) {
super.delete(body, { GspDeleteResponse(it) }, null)
}
}

/**