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 5 commits into
base: feat/artifact-store-metadataless
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions deploy/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ ds_writer.write({
super: 'Lock',
},
Artifact: {},
Scratch: {},

Snapshot: {},
Model: {
Expand Down Expand Up @@ -318,8 +319,11 @@ ds_writer.write({
implies: [
'Ref',
'Artifact',
'Scratch',
]
},
Artifact: {},
Scratch: {},
Collection: {},
Ref: {
implies: [
Expand Down Expand Up @@ -447,6 +451,8 @@ ds_writer.write({
'DeleteArtifact',
'CreateDiff',
'DeleteDiff',
'CreateScratch',
'DeleteScratch',
],
},
},
Expand Down Expand Up @@ -485,6 +491,10 @@ ds_writer.write({
crud: H_CRUD_DEFAULT,
},

Scratch: {
crud: H_CRUD_DEFAULT,
},

AccessControlAny: {
crud: {
...H_CRUD_DEFAULT,
Expand Down
13 changes: 10 additions & 3 deletions src/main/kotlin/org/openmbee/flexo/mms/AccessControl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ enum class Scope(val type: String, val id: String, vararg val extras: String) {
BRANCH("Branch", "morb"),
LOCK("Lock", "morl"),
ARTIFACT("Artifact", "mora"),
SCRATCH("Scratch", "mors"),
DIFF("Diff", "mord"),

ACCESS_CONTROL_ANY("AccessControl", "ma", "ma:Agents", "ma:Policies"),
Expand Down Expand Up @@ -66,9 +67,14 @@ enum class Permission(
DELETE_LOCK(Crud.DELETE, Scope.LOCK),

CREATE_ARTIFACT(Crud.CREATE, Scope.ARTIFACT),
READ_ARTIFACT(Crud.CREATE, Scope.ARTIFACT),
UPDATE_ARTIFACT(Crud.CREATE, Scope.ARTIFACT),
DELETE_ARTIFACT(Crud.CREATE, Scope.ARTIFACT),
READ_ARTIFACT(Crud.READ, Scope.ARTIFACT),
UPDATE_ARTIFACT(Crud.UPDATE, Scope.ARTIFACT),
DELETE_ARTIFACT(Crud.DELETE, Scope.ARTIFACT),

CREATE_SCRATCH(Crud.CREATE, Scope.SCRATCH),
READ_SCRATCH(Crud.READ, Scope.SCRATCH),
UPDATE_SCRATCH(Crud.UPDATE, Scope.SCRATCH),
DELETE_SCRATCH(Crud.DELETE, Scope.SCRATCH),

CREATE_DIFF(Crud.CREATE, Scope.DIFF),
READ_DIFF(Crud.READ, Scope.DIFF),
Expand All @@ -95,6 +101,7 @@ enum class Role(val id: String) {
ADMIN_MODEL("AdminModel"),
ADMIN_LOCK("AdminLock"),
ADMIN_BRANCH("AdminBranch"),
ADMIN_SCRATCH("AdminScratch"),
ADMIN_DIFF("AdminDiff"),
ADMIN_GROUP("AdminGroup"),
ADMIN_POLICY("AdminPolicy"),
Expand Down
19 changes: 19 additions & 0 deletions src/main/kotlin/org/openmbee/flexo/mms/Conditions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ val ARTIFACT_QUERY_CONDITIONS = SNAPSHOT_QUERY_CONDITIONS.append {
permit(Permission.READ_ARTIFACT, Scope.ARTIFACT)
}

val SCRATCH_QUERY_CONDITIONS = REPO_CRUD_CONDITIONS.append {
permit(Permission.READ_SCRATCH, Scope.SCRATCH)
}

val DIFF_QUERY_CONDITIONS = SNAPSHOT_QUERY_CONDITIONS.append {
permit(Permission.READ_DIFF, Scope.DIFF)
}
Expand Down Expand Up @@ -257,6 +261,21 @@ class ConditionsBuilder(val conditions: MutableList<Condition> = arrayListOf())
}
}

fun scratchExists() {
require("scratchExists") {
handler = { layer1 -> "Scratch <${layer1.prefixes["mors"]}> does not exist." to
if(null != layer1.ifMatch) HttpStatusCode.PreconditionFailed else HttpStatusCode.NotFound }

"""
# scratch must exist
graph mor-graph:Metadata {
mors: a mms:Scratch ;
?scratchExisting_p ?scratchExisting_o .
}
"""
}
}

/**
* Adds a pattern to the query conditions that is only evaluated upon inspection.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/org/openmbee/flexo/mms/Errors.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class InvalidQueryParameter(detail: String): Http400Exception("Request contains

class PreconditionsForbidden(detail: String): Http400Exception("Cannot use preconditions here: $detail")

class BlankNodesNotAllowedException(detail: String=""): Http404Exception("Blank nodes not allowed here: $detail")


open class Http403Exception(layer1: AnyLayer1Context, resource: String="(unspecified)"): HttpException("User ${layer1.userId} (${layer1.groups.joinToString(", ") { "<$it>" }}) is not authorized to perform specified action on resource: $resource", HttpStatusCode.Forbidden)

Expand Down
9 changes: 8 additions & 1 deletion src/main/kotlin/org/openmbee/flexo/mms/Layer1Context.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class Layer1Context<TRequestContext: GenericRequest, out TResponseContext: Gener
var lockId: String? = null
var artifactId: String? = null
var branchId: String? = null
var scratchId: String? = null
var diffId: String? = null
var policyId: String? = null

Expand All @@ -105,10 +106,11 @@ class Layer1Context<TRequestContext: GenericRequest, out TResponseContext: Gener
orgId = orgId,
collectionId = collectionId,
repoId = repoId,
branchId = branchId,
commitId = commitId,
lockId = lockId,
artifactId = artifactId,
branchId = branchId,
scratchId = scratchId,
diffId = diffId,
transactionId = transactionId,
policyId = policyId,
Expand Down Expand Up @@ -171,6 +173,11 @@ class Layer1Context<TRequestContext: GenericRequest, out TResponseContext: Gener
if(legal) assertLegalId(branchId!!)
}

fun scratch(legal: Boolean=false) {
scratchId = call.parameters["scratchId"]
if(legal) assertLegalId(scratchId!!)
}

fun diff() {
diffId = call.parameters["diffId"]
}
Expand Down
23 changes: 19 additions & 4 deletions src/main/kotlin/org/openmbee/flexo/mms/Namespaces.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import org.apache.jena.rdf.model.ResourceFactory
import org.apache.jena.shared.PrefixMapping
import java.net.URLEncoder

val OPENMBEE_MMS_RDF = "https://mms.openmbee.org/rdf"

class PrefixMapBuilder(other: PrefixMapBuilder?=null, setup: (PrefixMapBuilder.() -> PrefixMapBuilder)?=null) {
var map = HashMap<String, String>()

Expand Down Expand Up @@ -61,7 +63,7 @@ val SPARQL_PREFIXES = PrefixMapBuilder() {
"dct" to "http://purl.org/dc/terms/",
)

with("https://mms.openmbee.org/rdf") {
with(OPENMBEE_MMS_RDF) {
add(
"mms" to "$this/ontology/",
"mms-txn" to "$this/ontology/txn.",
Expand Down Expand Up @@ -91,11 +93,12 @@ fun prefixesFor(
orgId: String?=null,
collectionId: String?=null,
repoId: String?=null,
refId: String?=null,
branchId: String?=null,
commitId: String?=null,
lockId: String?=null,
artifactId: String?=null,
refId: String?=null,
lockId: String?=null,
branchId: String?=null,
scratchId: String?=null,
diffId: String?=null,
transactionId: String?=null,
policyId: String?=null,
Expand Down Expand Up @@ -206,6 +209,17 @@ fun prefixesFor(
else {
add("mora" to MMS_URNS.never)
}

if(null != scratchId) {
with("$this/scratches/$scratchId") {
add(
"mors" to this,
)
}
}
else {
add("mors" to MMS_URNS.never)
}
}
}
}
Expand Down Expand Up @@ -246,6 +260,7 @@ object MMS {
val Lock = res("Lock")
val Diff = res("Diff")
val Artifact = res("Artifact")
val Scratch = res("Scratch")

val User = res("User")
val Group = res("Group")
Expand Down
4 changes: 4 additions & 0 deletions src/main/kotlin/org/openmbee/flexo/mms/RdfModeler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ class RdfModeler(val layer1: AnyLayer1Context, val baseIri: String, val content:
return resourceFromParamPrefix("morc")
}

fun scratchNode(): Resource {
return resourceFromParamPrefix("mors")
}

fun lockNode(): Resource {
return resourceFromParamPrefix("morl")
}
Expand Down
24 changes: 23 additions & 1 deletion src/main/kotlin/org/openmbee/flexo/mms/SparqlBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import java.util.*

enum class UpdateOperationBlock(val id: String) {
NONE(""),
DELETE("DELETE"),
INSERT("INSERT"),
DELETE("DELETE"),
INSERT_DATA("INSERT_DATA"),
DELETE_DATA("DELETE_DATA"),
WHERE("WHERE"),
}

Expand Down Expand Up @@ -251,6 +253,10 @@ class InsertBuilder(
}
}

class InsertDataBuilder(
layer1: AnyLayer1Context,
indentLevel: Int,
): PatternBuilder<InsertDataBuilder>(layer1, indentLevel)

class ConstructBuilder(
private val layer1: AnyLayer1Context,
Expand Down Expand Up @@ -409,6 +415,22 @@ class UpdateBuilder(
}
}

fun insertData(setup: InsertDataBuilder.() -> Unit): UpdateBuilder {
if(operationCount++ > 0) raw(";")

previousBlock = UpdateOperationBlock.INSERT_DATA

return raw("""
insert data {
${InsertDataBuilder(layer1, 4).apply{ setup() }}

$pendingInsertDataString
}
""").apply {
pendingInsertDataString = ""
}
}

fun where(setup: WhereBuilder.() -> Unit): UpdateBuilder {
previousBlock = UpdateOperationBlock.WHERE

Expand Down
Loading