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 of update of list node info and update of project info #1706

Merged
merged 3 commits into from Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
Expand Up @@ -725,11 +725,13 @@ class ListsResponderADM(responderData: ResponderData) extends Responder(responde


_ = if (changeListRequest.labels.nonEmpty) {
if (updatedList.listinfo.labels.stringLiterals.sorted != changeListRequest.labels.sorted) throw UpdateNotPerformedException("Lists's 'labels' where not updated. Please report this as a possible bug.")
if (updatedList.listinfo.labels.stringLiterals.diff(changeListRequest.labels).nonEmpty) throw UpdateNotPerformedException("Lists's 'labels' where not updated. Please report this as a possible bug.")
}

_ = if (changeListRequest.comments.nonEmpty) {
if (updatedList.listinfo.comments.stringLiterals.sorted != changeListRequest.comments.sorted) throw UpdateNotPerformedException("List's 'comments' was not updated. Please report this as a possible bug.")
if (updatedList.listinfo.comments.stringLiterals.diff(changeListRequest.comments).nonEmpty)

throw UpdateNotPerformedException("List's 'comments' was not updated. Please report this as a possible bug.")
}

// _ = log.debug(s"listInfoChangeRequest - updatedList: {}", updatedList)
Expand Down
Expand Up @@ -716,7 +716,7 @@ class ProjectsResponderADM(responderData: ResponderData) extends Responder(respo
}

_ = if (projectUpdatePayload.description.isDefined) {
if (updatedProject.description.sorted != projectUpdatePayload.description.get.sorted) throw UpdateNotPerformedException("Project's 'description' was not updated. Please report this as a possible bug.")
if (updatedProject.description.diff(projectUpdatePayload.description.get).nonEmpty) throw UpdateNotPerformedException("Project's 'description' was not updated. Please report this as a possible bug.")
}

_ = if (projectUpdatePayload.keywords.isDefined) {
Expand Down
Expand Up @@ -641,6 +641,14 @@ object SharedTestDataADM {
| "selfjoin": true
|}""".stripMargin

val updateProjectMultipleDescriptionRequest: String =
s"""{
| "description": [
| {"value": "Test Project", "language": "en"},
| {"value": "Test Project", "language": "se"}
| ]
|}""".stripMargin

val createUserRequest: String =
s"""{
| "username": "donald.duck",
Expand Down Expand Up @@ -750,6 +758,23 @@ object SharedTestDataADM {
|}""".stripMargin
}

def updateListInfoWithRepeatedCommentAndLabelValuesRequest(listIri: IRI): String = {
s"""{
| "listIri": "$listIri",
| "projectIri": "${SharedTestDataADM.ANYTHING_PROJECT_IRI}",
| "labels": [
| {"language": "en", "value": "Test List"},
| {"language": "se", "value": "Test List"}
| ],
| "comments": [
| {"language": "en", "value": "test"},
| {"language": "de", "value": "test"},
| {"language": "fr", "value": "test"},
| {"language": "it", "value": "test"}
| ]
|}""".stripMargin
}

def addChildListNodeRequest(parentNodeIri: IRI,
name: String,
label: String,
Expand Down
Expand Up @@ -315,6 +315,26 @@ class ListsADME2ESpec extends E2ESpec(ListsADME2ESpec.config) with SessionJsonPr
comments.size should be (2)
}

"update basic list information with repeated comment and label in different languages" in {
val params = SharedTestDataADM.updateListInfoWithRepeatedCommentAndLabelValuesRequest("http://rdfh.ch/lists/0001/treeList")
val encodedListUrl = java.net.URLEncoder.encode("http://rdfh.ch/lists/0001/treeList", "utf-8")

val request = Put(baseApiUrl + s"/admin/lists/infos/" + encodedListUrl, HttpEntity(ContentTypes.`application/json`, params)) ~> addCredentials(anythingAdminUserCreds.basicHttpCredentials)
val response: HttpResponse = singleAwaitingRequest(request)
// log.debug(s"response: ${response.toString}")
response.status should be(StatusCodes.OK)

val receivedListInfo: ListRootNodeInfoADM = AkkaHttpUtils.httpResponseToJson(response).fields("listinfo").convertTo[ListRootNodeInfoADM]

receivedListInfo.projectIri should be (SharedTestDataADM.ANYTHING_PROJECT_IRI)

val labels: Seq[StringLiteralV2] = receivedListInfo.labels.stringLiterals
labels.size should be (2)

val comments = receivedListInfo.comments.stringLiterals
comments.size should be (4)
}

"return a ForbiddenException if the user updating the list is not project or system admin" in {
val params =
s"""
Expand Down Expand Up @@ -551,7 +571,6 @@ class ListsADME2ESpec extends E2ESpec(ListsADME2ESpec.config) with SessionJsonPr
"delete node if not in use" ignore {

}

}
}
}
Expand Up @@ -288,6 +288,19 @@ class ProjectsADME2ESpec extends E2ESpec(ProjectsADME2ESpec.config) with Session
result.selfjoin should be (true)
}

"UPDATE a project with multiple description" in {

val projectIriEncoded = URLEncoder.encode(newProjectIri.get, "utf-8")
val request = Put(baseApiUrl + s"/admin/projects/iri/" + projectIriEncoded, HttpEntity(ContentTypes.`application/json`, SharedTestDataADM.updateProjectMultipleDescriptionRequest)) ~> addCredentials(BasicHttpCredentials(rootEmail, testPass))
val response: HttpResponse = singleAwaitingRequest(request)
response.status should be (StatusCodes.OK)

val result: ProjectADM = AkkaHttpUtils.httpResponseToJson(response).fields("project").convertTo[ProjectADM]
result.description.size should be (2)
result.description should contain (StringLiteralV2(value = "Test Project", language = Some("en")))
result.description should contain (StringLiteralV2(value = "Test Project", language = Some("se")))
}

"DELETE a project" in {

val projectIriEncoded = URLEncoder.encode(newProjectIri.get, "utf-8")
Expand Down