Skip to content

Commit

Permalink
feat: Add JSON-LD support for POST v2/ontologies/guiorder
Browse files Browse the repository at this point in the history
  • Loading branch information
seakayone committed Feb 6, 2025
1 parent 27e4a90 commit 407b810
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -723,35 +723,6 @@ case class ChangeGuiOrderRequestV2(
requestingUser: User,
) extends OntologiesResponderRequestV2

object ChangeGuiOrderRequestV2 {

def fromJsonLd(
jsonLDDocument: JsonLDDocument,
apiRequestID: UUID,
requestingUser: User,
): ChangeGuiOrderRequestV2 = {
// Get the class definition and the ontology's last modification date from the JSON-LD.

val inputOntologiesV2 = InputOntologyV2.fromJsonLD(jsonLDDocument)
val classUpdateInfo = OntologyUpdateHelper.getClassDef(inputOntologiesV2)
val classInfoContent = classUpdateInfo.classInfoContent
val lastModificationDate = classUpdateInfo.lastModificationDate

// The request must provide cardinalities.

if (classInfoContent.directCardinalities.isEmpty) {
throw BadRequestException("No cardinalities specified")
}

ChangeGuiOrderRequestV2(
classInfoContent = classInfoContent,
lastModificationDate = lastModificationDate,
apiRequestID = apiRequestID,
requestingUser = requestingUser,
)
}
}

/**
* Requests a change in the metadata of an ontology. A successful response will be a [[ReadOntologyMetadataV2]].
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,12 @@ final case class OntologiesRouteV2()(
private def changeGuiOrder(): Route =
path(ontologiesBasePath / "guiorder") {
put {
// Change a class's cardinalities.
entity(as[String]) { jsonRequest => requestContext =>
val requestMessageTask = for {
requestingUser <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(requestContext))
requestDoc <- RouteUtilV2.parseJsonLd(jsonRequest)
apiRequestId <- RouteUtilZ.randomUuid()
msg <- ZIO.attempt(ChangeGuiOrderRequestV2.fromJsonLd(requestDoc, apiRequestId, requestingUser))
msg <- requestParser(_.changeGuiOrderRequestV2(jsonRequest, apiRequestId, requestingUser))

Check warning on line 331 in webapi/src/main/scala/org/knora/webapi/routing/v2/OntologiesRouteV2.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/org/knora/webapi/routing/v2/OntologiesRouteV2.scala#L331

Added line #L331 was not covered by tests
.mapError(BadRequestException.apply)
} yield msg
RouteUtilV2.runRdfRouteZ(requestMessageTask, requestContext)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import org.knora.webapi.messages.v2.responder.ontologymessages.AddCardinalitiesT
import org.knora.webapi.messages.v2.responder.ontologymessages.CanDeleteCardinalitiesFromClassRequestV2
import org.knora.webapi.messages.v2.responder.ontologymessages.ChangeClassLabelsOrCommentsRequestV2
import org.knora.webapi.messages.v2.responder.ontologymessages.ChangeClassLabelsOrCommentsRequestV2.LabelOrComment
import org.knora.webapi.messages.v2.responder.ontologymessages.ChangeGuiOrderRequestV2
import org.knora.webapi.messages.v2.responder.ontologymessages.ChangeOntologyMetadataRequestV2
import org.knora.webapi.messages.v2.responder.ontologymessages.ClassInfoContentV2
import org.knora.webapi.messages.v2.responder.ontologymessages.CreateClassRequestV2
Expand Down Expand Up @@ -304,6 +305,19 @@ final case class OntologyV2RequestParser(iriConverter: IriConverter) {
): IO[String, DeleteCardinalitiesFromClassRequestV2] =
constructClassRelatedRequest(jsonLd, apiRequestId, requestingUser, DeleteCardinalitiesFromClassRequestV2.apply)

Check warning on line 306 in webapi/src/main/scala/org/knora/webapi/slice/ontology/api/OntologyV2RequestParser.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/org/knora/webapi/slice/ontology/api/OntologyV2RequestParser.scala#L306

Added line #L306 was not covered by tests

def changeGuiOrderRequestV2(

Check warning on line 308 in webapi/src/main/scala/org/knora/webapi/slice/ontology/api/OntologyV2RequestParser.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/org/knora/webapi/slice/ontology/api/OntologyV2RequestParser.scala#L308

Added line #L308 was not covered by tests
jsonLd: String,
apiRequestId: UUID,
requestingUser: User,
): IO[String, ChangeGuiOrderRequestV2] =
constructClassRelatedRequest(

Check warning on line 313 in webapi/src/main/scala/org/knora/webapi/slice/ontology/api/OntologyV2RequestParser.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/org/knora/webapi/slice/ontology/api/OntologyV2RequestParser.scala#L313

Added line #L313 was not covered by tests
jsonLd,
apiRequestId,
requestingUser,
ChangeGuiOrderRequestV2.apply,
(_, classInfo) => ZIO.fail("No cardinalities specified").when(classInfo.directCardinalities.isEmpty).unit,

Check warning on line 318 in webapi/src/main/scala/org/knora/webapi/slice/ontology/api/OntologyV2RequestParser.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/org/knora/webapi/slice/ontology/api/OntologyV2RequestParser.scala#L318

Added line #L318 was not covered by tests
)

private def constructClassRelatedRequest[A](

Check warning on line 321 in webapi/src/main/scala/org/knora/webapi/slice/ontology/api/OntologyV2RequestParser.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/org/knora/webapi/slice/ontology/api/OntologyV2RequestParser.scala#L321

Added line #L321 was not covered by tests
jsonLd: String,
apiRequestId: UUID,
Expand Down

0 comments on commit 407b810

Please sign in to comment.