Skip to content

Commit

Permalink
feature (webapi): list admin api additions part 1 (#990)
Browse files Browse the repository at this point in the history
* feature (webapi): add create list child node

* doc (webapi): update release notes
  • Loading branch information
subotic authored Sep 13, 2018
1 parent dce986f commit c0da73d
Show file tree
Hide file tree
Showing 38 changed files with 4,632 additions and 6,884 deletions.
631 changes: 592 additions & 39 deletions docs/src/api-admin/swagger.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/src/paradox/00-release-notes/v1.8.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ See the
- remove Kamon monitoring (for now) since we don't see anything meaningful there. We probably will have to instrument Knora by hand and then use Kamon for access. (@github[#979](#979))
- update Dockerfiles for `webapi` and `salsah1` (@github[#979](#979))
- Follow subClassOf when including ontologies in XML import schemas (@github[#991](#991))
- add support for adding list child nodes (@github[#991](#990))

## Bugfixes:

Expand Down
2 changes: 1 addition & 1 deletion docs/src/paradox/03-apis/api-admin/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ documentation purposes. To try it out, run webapi and open
http://host/api-docs/swagger.json in <http://petstore.swagger.io> .
Alternatively, the documentation can be looked at by using
[ReDoc](https://github.com/Rebilly/ReDoc), which is provided in
`knora/docs/redoc/index.html`.
`knora/docs/redoc/index.html` and is published under <https://docs.knora.org/api-admin/index.html>.

## Admin API Endpoints

Expand Down
6 changes: 5 additions & 1 deletion knora-ontologies/knora-base.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -2018,7 +2018,11 @@
[ rdf:type owl:Restriction ;
owl:onProperty :attachedToProject ;
owl:maxCardinality "1"^^xsd:nonNegativeInteger
] ;
] ,
[ rdf:type owl:Restriction ;
owl:onProperty rdfs:label ;
owl:minCardinality "1"^^xsd:nonNegativeInteger
];

rdfs:comment "Represents a flat or hierarchical list"@en .

Expand Down
3 changes: 3 additions & 0 deletions webapi/_test_data/all_data/anything-data.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,10 @@

<http://rdfh.ch/lists/0001/treeList> a knora-base:ListNode ;
knora-base:isRootNode true ;
knora-base:listNodeName "treelistroot" ;
rdfs:label "Tree list root"@en ;
rdfs:label "Listenwurzel"@de ;
rdfs:comment "Anything Tree List"@en ;
knora-base:attachedToProject <http://rdfh.ch/projects/0001> ;
knora-base:hasSubListNode <http://rdfh.ch/lists/0001/treeList01> , <http://rdfh.ch/lists/0001/treeList02> , <http://rdfh.ch/lists/0001/treeList03> .

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package org.knora.webapi.messages.v2.responder.listsmessages

import org.knora.webapi._
import org.knora.webapi.messages.admin.responder.listsmessages.{ListADM, ListNodeADM, ListNodeInfoADM}
import org.knora.webapi.messages.admin.responder.listsmessages._
import org.knora.webapi.messages.admin.responder.usersmessages.UserADM
import org.knora.webapi.messages.store.triplestoremessages.StringLiteralSequenceV2
import org.knora.webapi.messages.v2.responder.{KnoraRequestV2, KnoraResponseV2}
Expand Down Expand Up @@ -71,7 +71,7 @@ trait ListResponderResponseV2 {
/**
* Represents a response to a [[ListGetRequestV2]].
*
* @param list the list the are to be returned.
* @param list the list to be returned.
* @param userLang the user's preferred language.
* @param fallbackLang the fallback language if the preferred language is not available.
*/
Expand All @@ -81,35 +81,24 @@ case class ListGetResponseV2(list: ListADM, userLang: String, fallbackLang: Stri

implicit val stringFormatter: StringFormatter = StringFormatter.getGeneralInstance

val nodeHasRootNode: Map[IRI, JsonLDObject] = Map(
OntologyConstants.KnoraBase.HasRootNode.toSmartIri.toOntologySchema(ApiV2WithValueObjects).toString -> JsonLDUtil.iriToJsonLDObject(list.listinfo.id)
)

/**
* Given a [[ListNodeADM]], constructs a [[JsonLDObject]].
*
* @param node the node to be turned into JSON-LD.
* @return a [[JsonLDObject]] representing the node.
*/
def makeNode(node: ListNodeADM): JsonLDObject = {
def makeNode(node: ListChildNodeADM): JsonLDObject = {

val label: Map[IRI, JsonLDString] = makeMapIriToJSONLDString(OntologyConstants.Rdfs.Label, node.labels, userLang, fallbackLang)

val comment: Map[IRI, JsonLDString] = makeMapIriToJSONLDString(OntologyConstants.Rdfs.Comment, node.comments, userLang, fallbackLang)

val position: Map[IRI, JsonLDInt] = node.position match {
case Some(pos: Int) => Map(
OntologyConstants.KnoraBase.ListNodePosition.toSmartIri.toOntologySchema(ApiV2WithValueObjects).toString -> JsonLDInt(pos)
)

case None => Map.empty[IRI, JsonLDInt]
}
val position: Map[IRI, JsonLDInt] = Map(OntologyConstants.KnoraBase.ListNodePosition.toSmartIri.toOntologySchema(ApiV2WithValueObjects).toString -> JsonLDInt(node.position))

val children: Map[IRI, JsonLDArray] = if (node.children.nonEmpty) {
Map(
OntologyConstants.KnoraBase.HasSubListNode.toSmartIri.toOntologySchema(ApiV2WithValueObjects).toString -> JsonLDArray(
node.children.map {
childNode: ListNodeADM =>
childNode: ListChildNodeADM =>
makeNode(childNode) // recursion
})
)
Expand All @@ -118,6 +107,10 @@ case class ListGetResponseV2(list: ListADM, userLang: String, fallbackLang: Stri
Map.empty[IRI, JsonLDArray]
}

val nodeHasRootNode: Map[IRI, JsonLDObject] = Map(
OntologyConstants.KnoraBase.HasRootNode.toSmartIri.toOntologySchema(ApiV2WithValueObjects).toString -> JsonLDUtil.iriToJsonLDObject(node.hasRootNode)
)

JsonLDObject(
Map(
"@id" -> JsonLDString(node.id),
Expand All @@ -126,26 +119,27 @@ case class ListGetResponseV2(list: ListADM, userLang: String, fallbackLang: Stri
)
}

val label: Map[IRI, JsonLDString] = makeMapIriToJSONLDString(OntologyConstants.Rdfs.Label, list.listinfo.labels, userLang, fallbackLang)
val listinfo = list.listinfo

val label: Map[IRI, JsonLDString] = makeMapIriToJSONLDString(OntologyConstants.Rdfs.Label, listinfo.labels, userLang, fallbackLang)

val comment: Map[IRI, JsonLDString] = makeMapIriToJSONLDString(OntologyConstants.Rdfs.Comment, list.listinfo.comments, userLang, fallbackLang)
val comment: Map[IRI, JsonLDString] = makeMapIriToJSONLDString(OntologyConstants.Rdfs.Comment, listinfo.comments, userLang, fallbackLang)

val children: Map[IRI, JsonLDArray] = if (list.children.nonEmpty) {
Map(
OntologyConstants.KnoraBase.HasSubListNode.toSmartIri.toOntologySchema(ApiV2WithValueObjects).toString -> JsonLDArray(list.children.map {
childNode: ListNodeADM =>
makeNode(childNode)
childNode: ListNodeADM => makeNode(childNode.asInstanceOf[ListChildNodeADM])
}))
} else {
Map.empty[IRI, JsonLDArray]
}

val project: Map[IRI, JsonLDObject] = Map(
OntologyConstants.KnoraBase.AttachedToProject.toSmartIri.toOntologySchema(ApiV2WithValueObjects).toString -> JsonLDUtil.iriToJsonLDObject(list.listinfo.projectIri)
OntologyConstants.KnoraBase.AttachedToProject.toSmartIri.toOntologySchema(ApiV2WithValueObjects).toString -> JsonLDUtil.iriToJsonLDObject(listinfo.projectIri)
)

val body = JsonLDObject(Map(
"@id" -> JsonLDString(list.listinfo.id),
"@id" -> JsonLDString(listinfo.id),
"@type" -> JsonLDString(OntologyConstants.KnoraBase.ListNode.toSmartIri.toOntologySchema(ApiV2WithValueObjects).toString),
OntologyConstants.KnoraBase.IsRootNode.toSmartIri.toOntologySchema(ApiV2WithValueObjects).toString -> JsonLDBoolean(true)
) ++ project ++ children ++ label ++ comment)
Expand Down Expand Up @@ -183,32 +177,45 @@ case class NodeGetResponseV2(node: ListNodeInfoADM, userLang: String, fallbackLa

implicit val stringFormatter: StringFormatter = StringFormatter.getGeneralInstance

val label: Map[IRI, JsonLDString] = makeMapIriToJSONLDString(OntologyConstants.Rdfs.Label, node.labels, userLang, fallbackLang)
val body: JsonLDObject = node match {

val comment: Map[IRI, JsonLDString] = makeMapIriToJSONLDString(OntologyConstants.Rdfs.Comment, node.comments, userLang, fallbackLang)
case root: ListRootNodeInfoADM => {

val position: Map[IRI, JsonLDInt] = node.position match {
case Some(pos: Int) => Map(
OntologyConstants.KnoraBase.ListNodePosition.toSmartIri.toOntologySchema(ApiV2WithValueObjects).toString -> JsonLDInt(pos)
)
val label: Map[IRI, JsonLDString] = makeMapIriToJSONLDString(OntologyConstants.Rdfs.Label, root.labels, userLang, fallbackLang)

case None => Map.empty[IRI, JsonLDInt]
}
val comment: Map[IRI, JsonLDString] = makeMapIriToJSONLDString(OntologyConstants.Rdfs.Comment, root.comments, userLang, fallbackLang)

val rootNode = node.rootNode match {
case Some(rNode: IRI) =>
Map(
OntologyConstants.KnoraBase.HasRootNode.toSmartIri.toOntologySchema(ApiV2WithValueObjects).toString -> JsonLDUtil.iriToJsonLDObject(rNode)
val position: Map[IRI, JsonLDInt] = Map.empty[IRI, JsonLDInt]

val rootNode = Map.empty[IRI, JsonLDString]

JsonLDObject(
Map(
"@id" -> JsonLDString(root.id),
"@type" -> JsonLDString(OntologyConstants.KnoraBase.ListNode.toSmartIri.toOntologySchema(ApiV2WithValueObjects).toString)
) ++ rootNode ++ label ++ comment ++ position
)
}

case child: ListChildNodeInfoADM => {

val label: Map[IRI, JsonLDString] = makeMapIriToJSONLDString(OntologyConstants.Rdfs.Label, child.labels, userLang, fallbackLang)

val comment: Map[IRI, JsonLDString] = makeMapIriToJSONLDString(OntologyConstants.Rdfs.Comment, child.comments, userLang, fallbackLang)

val position: Map[IRI, JsonLDInt] = Map(OntologyConstants.KnoraBase.ListNodePosition.toSmartIri.toOntologySchema(ApiV2WithValueObjects).toString -> JsonLDInt(child.position))

val rootNode = Map(OntologyConstants.KnoraBase.HasRootNode.toSmartIri.toOntologySchema(ApiV2WithValueObjects).toString -> JsonLDUtil.iriToJsonLDObject(child.hasRootNode))

JsonLDObject(
Map(
"@id" -> JsonLDString(child.id),
"@type" -> JsonLDString(OntologyConstants.KnoraBase.ListNode.toSmartIri.toOntologySchema(ApiV2WithValueObjects).toString)
) ++ rootNode ++ label ++ comment ++ position
)
case None => Map.empty[IRI, JsonLDString]
}
}

val body = JsonLDObject(
Map(
"@id" -> JsonLDString(node.id),
"@type" -> JsonLDString(OntologyConstants.KnoraBase.ListNode.toSmartIri.toOntologySchema(ApiV2WithValueObjects).toString)
) ++ rootNode ++ label ++ comment ++ position
)

val context = JsonLDObject(Map(
OntologyConstants.KnoraApi.KnoraApiOntologyLabel -> JsonLDString(OntologyConstants.KnoraApiV2WithValueObjects.KnoraApiV2PrefixExpansion),
Expand Down
Loading

0 comments on commit c0da73d

Please sign in to comment.