Skip to content

Commit

Permalink
add date value
Browse files Browse the repository at this point in the history
  • Loading branch information
BalduinLandolt committed Jun 18, 2024
1 parent fe2e0e6 commit 1736d23
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,62 +244,3 @@ object KnoraBaseVocab {
val valueHasCalendar = iri(kb + "valueHasCalendar")

}

object Run extends ZIOAppDefault {

override def run = Console.printLine(prettyRes)

val graphIri = InternalIri("fooGraph")
val projectIri = "fooProjectIri"
val userIri = "fooUserIri"
val resourceIri = "fooResourceIri"
val resourceClassIri = "fooClass"
val label = "fooLabel"
val creationDate = Instant.parse("2024-01-01T10:00:00.673298Z")
val permissions = "fooPermissions"

val values = List(
// date value
NewValueInfo(
resourceIri = resourceIri,
propertyIri = "fooDateProp",
valueIri = "fooDateValueIri",
valueTypeIri = "DateValue",
valueUUID = UUID.randomUUID(),
value = TypeSpecificValueInfo.DateValueInfo(
0,
0,
DatePrecisionDay,
DatePrecisionDay,
CalendarNameGregorian,
),
valuePermissions = permissions,
valueCreator = userIri,
creationDate = creationDate,
valueHasOrder = 5,
valueHasString = "2024-01-01T10:00:00.673298Z",
comment = None,
),
)

val resourceDefinition = ResourceReadyToCreate(
resourceIri = resourceIri,
resourceClassIri = resourceClassIri,
resourceLabel = label,
creationDate = creationDate,
permissions = permissions,
newValueInfos = values,
linkUpdates = Seq.empty,
)

val res = ResourcesRepoLive
.createNewResourceQueryWithBuilder(
dataGraphIri = graphIri,
resourceToCreate = resourceDefinition,
projectIri = projectIri,
creatorIri = userIri,
)
.sparql

val prettyRes = res.replace("{", "{\n").replace("}", "\n}")
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import org.knora.webapi.messages.twirl.NewValueInfo
import org.knora.webapi.messages.twirl.TypeSpecificValueInfo
import org.knora.webapi.slice.resourceinfo.domain.InternalIri
import org.knora.webapi.store.triplestore.api.TriplestoreService.Queries.Update
import org.knora.webapi.messages.util.DatePrecisionDay
import org.knora.webapi.messages.util.CalendarNameGregorian

object TestData {

Expand Down Expand Up @@ -78,7 +80,7 @@ object TestData {
comment = None,
)

def DecimalValueDefinition(uuid: UUID) =
def decimalValueDefinition(uuid: UUID) =
NewValueInfo(
resourceIri = resourceIri,
propertyIri = propertyIri,
Expand All @@ -94,7 +96,7 @@ object TestData {
comment = None,
)

def UriValueDefinition(uuid: UUID) =
def uriValueDefinition(uuid: UUID) =
NewValueInfo(
resourceIri = resourceIri,
propertyIri = propertyIri,
Expand All @@ -110,6 +112,28 @@ object TestData {
comment = None,
)

def dateValueDefinition(uuid: UUID) =
NewValueInfo(
resourceIri = resourceIri,
propertyIri = propertyIri,
valueIri = valueIri,
valueTypeIri = OntologyConstants.KnoraBase.DateValue,
valueUUID = uuid,
value = TypeSpecificValueInfo.DateValueInfo(
0,
0,
DatePrecisionDay,
DatePrecisionDay,
CalendarNameGregorian,
),
valuePermissions = valuePermissions,
valueCreator = valueCreator,
creationDate = valueCreationDate,
valueHasOrder = 1,
valueHasString = "2024-01-01",
comment = None,
)

}

object ResourcesRepoLiveSpec extends ZIOSpecDefault {
Expand Down Expand Up @@ -273,7 +297,7 @@ object ResourcesRepoLiveSpec extends ZIOSpecDefault {
test("Create a new resource with a decimal value") {
val uuid = UUID.randomUUID()
val uuidEncoded = UuidUtil.base64Encode(uuid)
val resource = resourceDefinition.copy(newValueInfos = List(DecimalValueDefinition(uuid)))
val resource = resourceDefinition.copy(newValueInfos = List(decimalValueDefinition(uuid)))

val expected = Update(
s"""|
Expand Down Expand Up @@ -323,7 +347,7 @@ object ResourcesRepoLiveSpec extends ZIOSpecDefault {
test("Create a new resource with a URI value") {
val uuid = UUID.randomUUID()
val uuidEncoded = UuidUtil.base64Encode(uuid)
val resource = resourceDefinition.copy(newValueInfos = List(UriValueDefinition(uuid)))
val resource = resourceDefinition.copy(newValueInfos = List(uriValueDefinition(uuid)))

val expected = Update(
s"""|
Expand Down Expand Up @@ -356,6 +380,60 @@ object ResourcesRepoLiveSpec extends ZIOSpecDefault {
|""".stripMargin,
)

val result = ResourcesRepoLive.createNewResourceQueryWithBuilder(
dataGraphIri = graphIri,
resourceToCreate = resource,
projectIri = projectIri,
creatorIri = userIri,
)
val reference = ResourcesRepoLive.createNewResourceQuery(
dataGraphIri = graphIri,
resourceToCreate = resource,
projectIri = projectIri,
creatorIri = userIri,
)
assertUpdateQueriesEqual(expected, result) && assertUpdateQueriesEqual(reference, result)
},
test("Create a new resource with a date value") {
val uuid = UUID.randomUUID()
val uuidEncoded = UuidUtil.base64Encode(uuid)
val resource = resourceDefinition.copy(newValueInfos = List(dateValueDefinition(uuid)))

val expected = Update(
s"""|
|PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
|PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
|PREFIX knora-base: <http://www.knora.org/ontology/knora-base#>
|
|INSERT DATA {
| GRAPH <${graphIri.value}> {
| <$resourceIri> rdf:type <$resourceClassIri> ;
| rdfs:label "$label" ;
| knora-base:isDeleted false ;
| knora-base:attachedToUser <$userIri> ;
| knora-base:attachedToProject <$projectIri> ;
| knora-base:hasPermissions "$permissions" ;
| knora-base:creationDate "$creationDate"^^xsd:dateTime ;
| <$propertyIri> <$valueIri> .
| <foo:ValueIri> rdf:type <http://www.knora.org/ontology/knora-base#DateValue> ;
| knora-base:isDeleted false ;
| knora-base:valueHasString "2024-01-01" ;
| knora-base:valueHasUUID "$uuidEncoded" ;
| knora-base:attachedToUser <$valueCreator> ;
| knora-base:hasPermissions "$valuePermissions" ;
| knora-base:valueHasOrder 1 ;
| knora-base:valueCreationDate "$valueCreationDate"^^xsd:dateTime ;
| knora-base:valueHasStartJDN 0 ;
| knora-base:valueHasEndJDN 0 ;
| knora-base:valueHasStartPrecision "DAY" ;
| knora-base:valueHasEndPrecision "DAY" ;
| knora-base:valueHasCalendar "GREGORIAN" .
| }
|}
|""".stripMargin,
)

val result = ResourcesRepoLive.createNewResourceQueryWithBuilder(
dataGraphIri = graphIri,
resourceToCreate = resource,
Expand Down Expand Up @@ -471,9 +549,6 @@ object ResourcesRepoLiveSpec extends ZIOSpecDefault {
// - link value
// - text value (unformatted)
// - text value (formatted)
// - decimal value
// - uri value
// - date value
// - color value
// - geometry value
// - still image file value
Expand Down

0 comments on commit 1736d23

Please sign in to comment.