Skip to content

Commit

Permalink
feat: Make create value endpoint fully support JSON-LD (DEV-4305) (#3410
Browse files Browse the repository at this point in the history
)
  • Loading branch information
seakayone authored Nov 5, 2024
1 parent f398bf8 commit cc42d41
Show file tree
Hide file tree
Showing 31 changed files with 1,625 additions and 385 deletions.
2 changes: 1 addition & 1 deletion integration/src/test/scala/org/knora/webapi/E2ESpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ abstract class E2ESpec
protected def singleAwaitingRequest(
request: HttpRequest,
timeout: Option[zio.Duration] = None,
printFailure: Boolean = false,
printFailure: Boolean = true,
): HttpResponse =
UnsafeZioRun.runOrThrow(
ZIO.serviceWithZIO[TestClientService](_.singleAwaitingRequest(request, timeout, printFailure)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ object LayersTest {
TapirToPekkoInterpreter.layer,
TestClientService.layer,
TriplestoreServiceLive.layer,
ValuesResponderV2Live.layer,
ValuesResponderV2.layer,
)

private val commonLayersForAllIntegrationTests2 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import org.knora.webapi.messages.store.triplestoremessages.*
import org.knora.webapi.messages.twirl.queries.sparql
import org.knora.webapi.messages.util.CalendarNameGregorian
import org.knora.webapi.messages.util.DatePrecisionYear
import org.knora.webapi.messages.util.KnoraSystemInstances
import org.knora.webapi.messages.util.PermissionUtilADM
import org.knora.webapi.messages.v2.responder.SuccessResponseV2
import org.knora.webapi.messages.v2.responder.resourcemessages.*
Expand Down Expand Up @@ -537,10 +536,7 @@ class ResourcesResponderV2Spec extends CoreSpec with ImplicitSender {
override implicit val timeout: FiniteDuration = 30.seconds

"Load test data" in {
appActor ! GetMappingRequestV2(
mappingIri = "http://rdfh.ch/standoff/mappings/StandardMapping",
requestingUser = KnoraSystemInstances.Users.SystemUser,
)
appActor ! GetMappingRequestV2("http://rdfh.ch/standoff/mappings/StandardMapping")

expectMsgPF(timeout) { case mappingResponse: GetMappingResponseV2 =>
standardMapping = Some(mappingResponse.mapping)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import org.knora.webapi.messages.StringFormatter
import org.knora.webapi.messages.store.triplestoremessages.*
import org.knora.webapi.messages.util.CalendarNameGregorian
import org.knora.webapi.messages.util.DatePrecisionYear
import org.knora.webapi.messages.util.KnoraSystemInstances
import org.knora.webapi.messages.util.PermissionUtilADM
import org.knora.webapi.messages.util.search.gravsearch.GravsearchParser
import org.knora.webapi.messages.v2.responder.resourcemessages.*
Expand Down Expand Up @@ -400,10 +399,7 @@ class ValuesResponderV2Spec extends CoreSpec with ImplicitSender {
}

"Load test data" in {
appActor ! GetMappingRequestV2(
mappingIri = "http://rdfh.ch/standoff/mappings/StandardMapping",
requestingUser = KnoraSystemInstances.Users.SystemUser,
)
appActor ! GetMappingRequestV2("http://rdfh.ch/standoff/mappings/StandardMapping")

expectMsgPF(timeout) { case mappingResponse: GetMappingResponseV2 =>
standardMapping = Some(mappingResponse.mapping)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ object LayersLive {
StringFormatter.live,
TapirToPekkoInterpreter.layer,
TriplestoreServiceLive.layer,
ValuesResponderV2Live.layer,
ValuesResponderV2.layer,
org.knora.webapi.core.ActorSystem.layer,
// ZLayer.Debug.mermaid,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ object ValuesValidator {
* @return [[Option]] of [[Instant]].
*/
def xsdDateTimeStampToInstant(s: String): Option[Instant] =
Try(Instant.from(DateTimeFormatter.ISO_OFFSET_DATE_TIME.parse(s))).toOption
parseXsdDateTimeStamp(s).toOption

def parseXsdDateTimeStamp(s: String): Either[String, Instant] =
Try(Instant.from(DateTimeFormatter.ISO_OFFSET_DATE_TIME.parse(s))).toEither.left.map(e =>
s"Invalid xsd:dateTimeStamp value '$s': ${e.getMessage}",
)

/**
* Parses a DSP ARK timestamp.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ object DateEraV2 {
* @return a [[DateEraV2]] representing the era.
*/
def parse(eraStr: String, errorFun: => Nothing): DateEraV2 =
fromString(eraStr).getOrElse(errorFun)

def fromString(eraStr: String): Either[String, DateEraV2] =
eraStr match {
case StringFormatter.Era_AD | StringFormatter.Era_CE => DateEraCE
case StringFormatter.Era_BC | StringFormatter.Era_BCE => DateEraBCE
case _ => errorFun
case StringFormatter.Era_AD | StringFormatter.Era_CE => Right(DateEraCE)
case StringFormatter.Era_BC | StringFormatter.Era_BCE => Right(DateEraBCE)
case _ => Left(s"Invalid era: $eraStr")
}
}

Expand Down Expand Up @@ -110,11 +113,14 @@ object CalendarNameV2 {
* @return a [[CalendarNameV2]] representing the name of the calendar.
*/
def parse(calendarNameStr: String, errorFun: => Nothing): CalendarNameV2 =
fromString(calendarNameStr).getOrElse(errorFun)

def fromString(calendarNameStr: String): Either[String, CalendarNameV2] =
calendarNameStr match {
case StringFormatter.CalendarGregorian => CalendarNameGregorian
case StringFormatter.CalendarJulian => CalendarNameJulian
case StringFormatter.CalendarIslamic => CalendarNameIslamic
case _ => errorFun
case StringFormatter.CalendarGregorian => Right(CalendarNameGregorian)
case StringFormatter.CalendarJulian => Right(CalendarNameJulian)
case StringFormatter.CalendarIslamic => Right(CalendarNameIslamic)
case _ => Left(s"Invalid calendar name: $calendarNameStr")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1674,7 +1674,7 @@ final case class ConstructResponseUtilV2Live(

// get all the mappings
val mappingResponsesFuture = mappingIris.map { (mappingIri: IRI) =>
messageRelay.ask[GetMappingResponseV2](GetMappingRequestV2(mappingIri, requestingUser))
messageRelay.ask[GetMappingResponseV2](GetMappingRequestV2(mappingIri))
}

for {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ final case class StandoffTagUtilV2Live(messageRelay: MessageRelay)(implicit val
StandoffEntityInfoGetRequestV2(
standoffClassIris = standoffClassIris,
standoffPropertyIris = standoffPropertyIris,
requestingUser = requestingUser,
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1127,9 +1127,8 @@ case class EntityInfoGetResponseV2(
* @param requestingUser the user making the request.
*/
case class StandoffEntityInfoGetRequestV2(
standoffClassIris: Set[SmartIri] = Set.empty[SmartIri],
standoffPropertyIris: Set[SmartIri] = Set.empty[SmartIri],
requestingUser: User,
standoffClassIris: Set[SmartIri] = Set.empty,
standoffPropertyIris: Set[SmartIri] = Set.empty,
) extends OntologiesResponderRequestV2

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ case class CreateMappingResponseV2(mappingIri: IRI, label: String, projectIri: S
* @param mappingIri the IRI of the mapping.
* @param requestingUser the the user making the request.
*/
case class GetMappingRequestV2(mappingIri: IRI, requestingUser: User) extends StandoffResponderRequestV2
case class GetMappingRequestV2(mappingIri: IRI) extends StandoffResponderRequestV2

/**
* Represents a response to a [[GetMappingRequestV2]].
Expand Down
Loading

0 comments on commit cc42d41

Please sign in to comment.