From 1736d23ca0f89b90cf66a4f8dfe385d5a864e637 Mon Sep 17 00:00:00 2001 From: Balduin Landolt <33053745+BalduinLandolt@users.noreply.github.com> Date: Tue, 18 Jun 2024 16:22:29 +0200 Subject: [PATCH] add date value --- .../repo/service/ResourcesRepoLive.scala | 59 ------------ .../repo/service/ResourcesRepoLiveSpec.scala | 89 +++++++++++++++++-- 2 files changed, 82 insertions(+), 66 deletions(-) diff --git a/webapi/src/main/scala/org/knora/webapi/slice/resources/repo/service/ResourcesRepoLive.scala b/webapi/src/main/scala/org/knora/webapi/slice/resources/repo/service/ResourcesRepoLive.scala index fd3a2879ff..6bb2d0f2f4 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/resources/repo/service/ResourcesRepoLive.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/resources/repo/service/ResourcesRepoLive.scala @@ -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}") -} diff --git a/webapi/src/test/scala/org/knora/webapi/slice/resources/repo/service/ResourcesRepoLiveSpec.scala b/webapi/src/test/scala/org/knora/webapi/slice/resources/repo/service/ResourcesRepoLiveSpec.scala index af808b13fb..ca32ea4e8c 100644 --- a/webapi/src/test/scala/org/knora/webapi/slice/resources/repo/service/ResourcesRepoLiveSpec.scala +++ b/webapi/src/test/scala/org/knora/webapi/slice/resources/repo/service/ResourcesRepoLiveSpec.scala @@ -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 { @@ -78,7 +80,7 @@ object TestData { comment = None, ) - def DecimalValueDefinition(uuid: UUID) = + def decimalValueDefinition(uuid: UUID) = NewValueInfo( resourceIri = resourceIri, propertyIri = propertyIri, @@ -94,7 +96,7 @@ object TestData { comment = None, ) - def UriValueDefinition(uuid: UUID) = + def uriValueDefinition(uuid: UUID) = NewValueInfo( resourceIri = resourceIri, propertyIri = propertyIri, @@ -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 { @@ -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"""| @@ -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"""| @@ -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: + |PREFIX rdfs: + |PREFIX xsd: + |PREFIX 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> . + | rdf:type ; + | 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, @@ -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