diff --git a/test_data/all_data/anything-data.ttl b/test_data/all_data/anything-data.ttl index f494868d99..2ca73a175e 100644 --- a/test_data/all_data/anything-data.ttl +++ b/test_data/all_data/anything-data.ttl @@ -1867,7 +1867,8 @@ knora-base:listNodeName "node 3"; knora-base:hasRootNode ; knora-base:listNodePosition 2; - rdfs:label "node 3"@en . + rdfs:label "node 3"@en ; + knora-base:hasSubListNode . a knora-base:ListNode; knora-base:listNodeName "child of node 1"; @@ -1898,4 +1899,10 @@ knora-base:hasRootNode ; knora-base:listNodePosition 4; rdfs:label "List015"@en . + + a knora-base:ListNode; + knora-base:listNodeName "child of node 3"; + knora-base:hasRootNode ; + knora-base:listNodePosition 0; + rdfs:label "child of node 3"@en . \ No newline at end of file diff --git a/webapi/src/main/scala/org/knora/webapi/responders/admin/ListsResponderADM.scala b/webapi/src/main/scala/org/knora/webapi/responders/admin/ListsResponderADM.scala index 3b0287a5ba..aa3dbe9151 100644 --- a/webapi/src/main/scala/org/knora/webapi/responders/admin/ListsResponderADM.scala +++ b/webapi/src/main/scala/org/knora/webapi/responders/admin/ListsResponderADM.scala @@ -1794,14 +1794,20 @@ class ListsResponderADM(responderData: ResponderData) extends Responder(responde } // shift the siblings that were positioned after the deleted node, one place to left. - updatedChildren <- shiftNodes( - startPos = positionOfDeletedNode + 1, - endPos = remainingChildren.last.position, - nodes = remainingChildren, - shiftToLeft = true, - dataNamedGraph = dataNamedGraph, - featureFactoryConfig = featureFactoryConfig - ) + updatedChildren <- if (remainingChildren.size > 1) { + for { + shiftedChildren <- shiftNodes( + startPos = positionOfDeletedNode + 1, + endPos = remainingChildren.last.position, + nodes = remainingChildren, + shiftToLeft = true, + dataNamedGraph = dataNamedGraph, + featureFactoryConfig = featureFactoryConfig + ) + } yield shiftedChildren + } else { + Future.successful(remainingChildren) + } // return updated parent node with shifted children. updatedParentNode = parentNode match { diff --git a/webapi/src/test/scala/org/knora/webapi/e2e/admin/lists/DeleteListItemsRouteADME2ESpec.scala b/webapi/src/test/scala/org/knora/webapi/e2e/admin/lists/DeleteListItemsRouteADME2ESpec.scala index c932ae9fdd..53aea57f5e 100644 --- a/webapi/src/test/scala/org/knora/webapi/e2e/admin/lists/DeleteListItemsRouteADME2ESpec.scala +++ b/webapi/src/test/scala/org/knora/webapi/e2e/admin/lists/DeleteListItemsRouteADME2ESpec.scala @@ -110,6 +110,7 @@ class DeleteListItemsRouteADME2ESpec val lastChild = children.last lastChild.id should be("http://rdfh.ch/lists/0001/notUsedList03") lastChild.position should be(1) + lastChild.children.size should be(1) // first child must have its child val firstChild = children.head firstChild.children.size should be(5) @@ -126,26 +127,39 @@ class DeleteListItemsRouteADME2ESpec ) } - "delete a list entirely with all its children" in { - val encodedNodeUrl = java.net.URLEncoder.encode("http://rdfh.ch/lists/0001/notUsedList", "utf-8") + "delete the single child of a node" in { + val encodedNodeUrl = java.net.URLEncoder.encode("http://rdfh.ch/lists/0001/notUsedList031", "utf-8") val request = Delete(baseApiUrl + s"/admin/lists/" + encodedNodeUrl) ~> addCredentials( BasicHttpCredentials(anythingAdminUserCreds.user.email, anythingAdminUserCreds.password)) val response: HttpResponse = singleAwaitingRequest(request) response.status should be(StatusCodes.OK) - val deletedStatus = AkkaHttpUtils.httpResponseToJson(response).fields("deleted") - deletedStatus.convertTo[Boolean] should be(true) + val node = AkkaHttpUtils.httpResponseToJson(response).fields("node").convertTo[ListNodeADM] + node.getNodeId should be("http://rdfh.ch/lists/0001/notUsedList03") + val children = node.getChildren + children.size should be(0) + } + } - clientTestDataCollector.addFile( - TestDataFileContent( - filePath = TestDataFilePath( - directoryPath = clientTestDataPath, - filename = "delete-list-response", - fileExtension = "json" - ), - text = responseToString(response) - ) + "delete a list entirely with all its children" in { + val encodedNodeUrl = java.net.URLEncoder.encode("http://rdfh.ch/lists/0001/notUsedList", "utf-8") + val request = Delete(baseApiUrl + s"/admin/lists/" + encodedNodeUrl) ~> addCredentials( + BasicHttpCredentials(anythingAdminUserCreds.user.email, anythingAdminUserCreds.password)) + val response: HttpResponse = singleAwaitingRequest(request) + response.status should be(StatusCodes.OK) + val deletedStatus = AkkaHttpUtils.httpResponseToJson(response).fields("deleted") + deletedStatus.convertTo[Boolean] should be(true) + + clientTestDataCollector.addFile( + TestDataFileContent( + filePath = TestDataFilePath( + directoryPath = clientTestDataPath, + filename = "delete-list-response", + fileExtension = "json" + ), + text = responseToString(response) ) - } + ) } + } }