Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions test_data/all_data/anything-data.ttl
Expand Up @@ -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";
Expand Down Expand Up @@ -1898,4 +1899,9 @@
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 .
Expand Up @@ -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 {
Expand Down
Expand Up @@ -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)
Expand All @@ -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)
)
}
)
}

}
}