Skip to content

Commit

Permalink
fix(Lists): fix bug in deleting the single child of a node (DSP-1355) (
Browse files Browse the repository at this point in the history
…#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 1d06572
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 23 deletions.
9 changes: 8 additions & 1 deletion test_data/all_data/anything-data.ttl
Expand Up @@ -1867,7 +1867,8 @@
knora-base:listNodeName "node 3"; knora-base:listNodeName "node 3";
knora-base:hasRootNode <http://rdfh.ch/lists/0001/notUsedList>; knora-base:hasRootNode <http://rdfh.ch/lists/0001/notUsedList>;
knora-base:listNodePosition 2; 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; <http://rdfh.ch/lists/0001/notUsedList011> a knora-base:ListNode;
knora-base:listNodeName "child of node 1"; knora-base:listNodeName "child of node 1";
Expand Down Expand Up @@ -1898,4 +1899,10 @@
knora-base:hasRootNode <http://rdfh.ch/lists/0001/notUsedList>; knora-base:hasRootNode <http://rdfh.ch/lists/0001/notUsedList>;
knora-base:listNodePosition 4; knora-base:listNodePosition 4;
rdfs:label "List015"@en . 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. // shift the siblings that were positioned after the deleted node, one place to left.
updatedChildren <- shiftNodes( updatedChildren <- if (remainingChildren.size > 1) {
startPos = positionOfDeletedNode + 1, for {
endPos = remainingChildren.last.position, shiftedChildren <- shiftNodes(
nodes = remainingChildren, startPos = positionOfDeletedNode + 1,
shiftToLeft = true, endPos = remainingChildren.last.position,
dataNamedGraph = dataNamedGraph, nodes = remainingChildren,
featureFactoryConfig = featureFactoryConfig shiftToLeft = true,
) dataNamedGraph = dataNamedGraph,
featureFactoryConfig = featureFactoryConfig
)
} yield shiftedChildren
} else {
Future.successful(remainingChildren)
}


// return updated parent node with shifted children. // return updated parent node with shifted children.
updatedParentNode = parentNode match { updatedParentNode = parentNode match {
Expand Down
Expand Up @@ -110,6 +110,7 @@ class DeleteListItemsRouteADME2ESpec
val lastChild = children.last val lastChild = children.last
lastChild.id should be("http://rdfh.ch/lists/0001/notUsedList03") lastChild.id should be("http://rdfh.ch/lists/0001/notUsedList03")
lastChild.position should be(1) lastChild.position should be(1)
lastChild.children.size should be(1)
// first child must have its child // first child must have its child
val firstChild = children.head val firstChild = children.head
firstChild.children.size should be(5) firstChild.children.size should be(5)
Expand All @@ -126,26 +127,39 @@ class DeleteListItemsRouteADME2ESpec
) )
} }


"delete a list entirely with all its children" in { "delete the single child of a node" in {
val encodedNodeUrl = java.net.URLEncoder.encode("http://rdfh.ch/lists/0001/notUsedList", "utf-8") val encodedNodeUrl = java.net.URLEncoder.encode("http://rdfh.ch/lists/0001/notUsedList031", "utf-8")
val request = Delete(baseApiUrl + s"/admin/lists/" + encodedNodeUrl) ~> addCredentials( val request = Delete(baseApiUrl + s"/admin/lists/" + encodedNodeUrl) ~> addCredentials(
BasicHttpCredentials(anythingAdminUserCreds.user.email, anythingAdminUserCreds.password)) BasicHttpCredentials(anythingAdminUserCreds.user.email, anythingAdminUserCreds.password))
val response: HttpResponse = singleAwaitingRequest(request) val response: HttpResponse = singleAwaitingRequest(request)
response.status should be(StatusCodes.OK) response.status should be(StatusCodes.OK)
val deletedStatus = AkkaHttpUtils.httpResponseToJson(response).fields("deleted") val node = AkkaHttpUtils.httpResponseToJson(response).fields("node").convertTo[ListNodeADM]
deletedStatus.convertTo[Boolean] should be(true) node.getNodeId should be("http://rdfh.ch/lists/0001/notUsedList03")
val children = node.getChildren
children.size should be(0)
}
}


clientTestDataCollector.addFile( "delete a list entirely with all its children" in {
TestDataFileContent( val encodedNodeUrl = java.net.URLEncoder.encode("http://rdfh.ch/lists/0001/notUsedList", "utf-8")
filePath = TestDataFilePath( val request = Delete(baseApiUrl + s"/admin/lists/" + encodedNodeUrl) ~> addCredentials(
directoryPath = clientTestDataPath, BasicHttpCredentials(anythingAdminUserCreds.user.email, anythingAdminUserCreds.password))
filename = "delete-list-response", val response: HttpResponse = singleAwaitingRequest(request)
fileExtension = "json" response.status should be(StatusCodes.OK)
), val deletedStatus = AkkaHttpUtils.httpResponseToJson(response).fields("deleted")
text = responseToString(response) 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.