Skip to content
Permalink
Browse files

fix(Lists): fix bug in deleting the single child of a node (DSP-1355) (

…#1816)

* fix (Lists): fix bug in deleting the single child of a node

* refactor (Lists): add empty line
  • Loading branch information
SepidehAlassi committed Feb 9, 2021
1 parent d037ed3 commit 1d0657205cdc96704551902b6cac4ef8fec46ccc
@@ -1867,7 +1867,8 @@
knora-base:listNodeName "node 3";
knora-base:hasRootNode <http://rdfh.ch/lists/0001/notUsedList>;
knora-base:listNodePosition 2;
rdfs:label "node 3"@en .
rdfs:label "node 3"@en ;
knora-base:hasSubListNode <http://rdfh.ch/lists/0001/notUsedList031> .

<http://rdfh.ch/lists/0001/notUsedList011> a knora-base:ListNode;
knora-base:listNodeName "child of node 1";
@@ -1898,4 +1899,10 @@
knora-base:hasRootNode <http://rdfh.ch/lists/0001/notUsedList>;
knora-base:listNodePosition 4;
rdfs:label "List015"@en .

<http://rdfh.ch/lists/0001/notUsedList031> a knora-base:ListNode;
knora-base:listNodeName "child of node 3";
knora-base:hasRootNode <http://rdfh.ch/lists/0001/notUsedList>;
knora-base:listNodePosition 0;
rdfs:label "child of node 3"@en .

@@ -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 {
@@ -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)
)
}
)
}

}
}

0 comments on commit 1d06572

Please sign in to comment.