Skip to content

Commit 41bd1e9

Browse files
committed
Use case: "load an RDF document into a user graph, and be able to edit the content"
(logged as that user), which amounts to short-circuiting the history when there is none.
1 parent ddc4cf0 commit 41bd1e9

File tree

3 files changed

+46
-28
lines changed

3 files changed

+46
-28
lines changed

scala/forms/src/main/scala/deductions/runtime/abstract_syntax/UserTraceability.scala

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import org.w3.banana.RDF
77
import scala.collection.mutable
88
import scala.language.{existentials, postfixOps}
99

10-
10+
/** TODO move to package user */
1111
trait UserTraceability[Rdf <: RDF, DATASET]
1212
extends FormModule[Rdf#Node, Rdf#URI]
1313
with TimeSeries[Rdf, DATASET] {
@@ -55,15 +55,45 @@ trait UserTraceability[Rdf <: RDF, DATASET]
5555
}
5656

5757
// println(s"YYYYYYYY Before add User Info\n${formSyntax.fields.mkString("\n")}\n")
58-
val entries = for (field: Entry <- formSyntax.fields) yield {
58+
val entries =
59+
for (field: Entry <- formSyntax.fields) yield {
5960
if (resultsUser.contains( (field.property.toString, field.value.toString) ) ){
6061
// println(s"ZZZZ add User Info ${field.label} ${field.value}")
6162
field.copyEntry(
6263
fromMetadata = resultsUser( (field.property.toString, field.value.toString)),
63-
fromTimeMetadata = resultsTimestamp( (field.property.toString, field.value.toString)) )
64-
} else field
64+
fromTimeMetadata = resultsTimestamp.getOrElse( (field.property.toString, field.value.toString), 0 ) )
65+
} else {
66+
addUserFromGraph(field)
67+
}
6568
}
6669
formSyntax . fields = entries
6770
formSyntax
6871
}
72+
73+
private def addUserFromGraph(field: Entry): Entry = {
74+
val resMainDatabase = {
75+
if (nodeToString(field.value) != "") {
76+
val queryMainDatabase = s"""
77+
SELECT ?USER
78+
WHERE {
79+
GRAPH ?USER {
80+
<${field.subject}> <${field.property}> ${makeTurtleTerm(field.value)} . }
81+
} """
82+
// println(s"addUserFromGraph: queryMainDatabase $queryMainDatabase")
83+
sparqlSelectQueryVariables(
84+
queryMainDatabase,
85+
Seq("USER"),
86+
dataset)
87+
} else List(Seq())
88+
}
89+
// println(s"addUserFromGraph: resMainDatabase $resMainDatabase")
90+
val fieldWithUsers = for (
91+
row <- resMainDatabase;
92+
node <- row
93+
) yield {
94+
println(s"addUserFromGraph: ?USER node ${node.getClass()} $node")
95+
field.copyEntry(fromMetadata = node.toString)
96+
}
97+
fieldWithUsers.headOption.getOrElse(field)
98+
}
6999
}

scala/forms/src/main/scala/deductions/runtime/semlogs/TimeSeries.scala

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ with SPARQLHelpers[Rdf, DATASET] {
133133
def getMetadataAboutSubject(subject: Rdf#Node, limit: Int =100, offset: Int = 0)
134134
: List[Seq[Rdf#Node]] = {
135135

136-
/* TODO:
136+
/* NOTE:
137137
* - timestamp should be facultative
138138
* - user is both in GRAPH <$metadataGraph> ,
139139
* and typically (always?) user graph is in main TDB
@@ -160,30 +160,12 @@ with SPARQLHelpers[Rdf, DATASET] {
160160
val resHistoryDatabase = sparqlSelectQueryVariables( queryHistoryDatabase,
161161
Seq("PROP", "OBJECT", "TIME", "USER"),
162162
dataset2 )
163-
logger.debug("getMetadata: res " + resHistoryDatabase)
164-
165-
// val queryMainDatabase = s"""
166-
// ${declarePrefix(xsd)}
167-
// SELECT ?PROP ?OBJECT ?TIME ?USER
168-
// WHERE {
169-
// BIND ( 0 as ?TIME)
170-
// GRAPH ?USER {
171-
// <$subject> ?PROP ?OBJECT . }
172-
// }
173-
// # GROUP BY ?OBJECT ?PROP ?USER
174-
// LIMIT $limit
175-
// OFFSET $offset
176-
// """
177-
// val resMainDatabase = sparqlSelectQueryVariables( queryMainDatabase,
178-
// Seq("PROP", "OBJECT", "TIME", "USER"),
179-
// dataset )
180-
// TOD merge resHistoryDatabase & resMainDatabase
181-
// println(s"==== getMetadataAboutSubject: resHistoryDatabase $resHistoryDatabase")
182-
// println(s"resMainDatabase $resMainDatabase")
183-
resHistoryDatabase // ++ resMainDatabase
163+
logger.debug(s"getMetadataAboutSubject: resHistoryDatabase $resHistoryDatabase")
164+
resHistoryDatabase
184165
}
185166

186-
/** get Metadata About given triple, searching in history (TDB2) for all user updates,
167+
/** UNUSED!
168+
* get Metadata About given triple, searching in history (TDB2) for all user updates,
187169
* and keeping the most recent;
188170
* transactional
189171
* @return rows of

scala/html/src/main/scala/deductions/runtime/html/Form2HTML.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,9 @@ import deductions.runtime.utils.I18NMessages
252252

253253
val isCreateRequest = request.path.contains("create")
254254
val editableByUser =
255-
field.metadata == request.userId()
255+
field.metadata == request.userId() ||
256+
field.metadata == userURI(request)
257+
// println(s"DEBUG !!!!!!!!!! editableByUser=$editableByUser <- field.metadata=${field.metadata} =? request.userId()=${request.userId()}")
256258

257259
// hack instead of true form separator in the form spec in RDF:
258260
if (field.label.contains("----"))
@@ -310,6 +312,10 @@ import deductions.runtime.utils.I18NMessages
310312
}
311313
}
312314

315+
private def userURI(request: HTTPrequest): String = {
316+
makeAbsoluteURIForSaving(request.userId())
317+
}
318+
313319
/** make Field Data (display) Or Input (edit)
314320
* TODO: does not do much! */
315321
private def makeFieldDataOrInput(field: formMod#Entry, hrefPrefix: String = config.hrefDisplayPrefix,

0 commit comments

Comments
 (0)