Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(admin): return list labels and comments sorted by language (#2074)
* add sortByLanguage method & use it to sort comments and labels

* remove redundant sorting from responder

* update test data
  • Loading branch information
mpro7 committed Jun 8, 2022
1 parent 54446bc commit f3a66cb
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 29 deletions.
Expand Up @@ -580,8 +580,8 @@ case class ListRootNodeInfoADM(
id = id,
projectIri = projectIri,
name = name,
labels = labels.sortByStringValue,
comments = comments.sortByStringValue
labels = labels.sortByLanguage,
comments = comments.sortByLanguage
)

/**
Expand Down Expand Up @@ -642,8 +642,8 @@ case class ListChildNodeInfoADM(
ListChildNodeInfoADM(
id = id,
name = name,
labels = labels.sortByStringValue,
comments = comments,
labels = labels.sortByLanguage,
comments = comments.sortByLanguage,
position = position,
hasRootNode = hasRootNode
)
Expand Down Expand Up @@ -769,8 +769,8 @@ case class ListRootNodeADM(
id = id,
projectIri = projectIri,
name = name,
labels = labels.sortByStringValue,
comments = comments.sortByStringValue,
labels = labels.sortByLanguage,
comments = comments.sortByLanguage,
children = children.sortBy(_.position).map(_.sorted)
)

Expand Down Expand Up @@ -848,8 +848,11 @@ case class ListChildNodeADM(
ListChildNodeADM(
id = id,
name = name,
labels = labels.sortByStringValue,
comments = comments,
labels = labels.sortByLanguage,
comments = comments match {
case None => None
case Some(c) => Some(c.sortByLanguage)
},
position = position,
hasRootNode = hasRootNode,
children = children.sortBy(_.position).map(_.sorted)
Expand Down
Expand Up @@ -600,6 +600,13 @@ case class StringLiteralSequenceV2(stringLiterals: Vector[StringLiteralV2]) {
def sortByStringValue: StringLiteralSequenceV2 =
StringLiteralSequenceV2(stringLiterals.sortBy(_.value))

/**
* Sort sequence of [[StringLiteralV2]] by their language value.
*
* @return a [[StringLiteralSequenceV2]] sorted by language value.
*/
def sortByLanguage: StringLiteralSequenceV2 = StringLiteralSequenceV2(stringLiterals.sortBy(_.language))

/**
* Gets the string value of the [[StringLiteralV2]] corresponding to the preferred language.
* If not available, returns the string value of the fallback language or any available language.
Expand Down
Expand Up @@ -162,8 +162,8 @@ class ListsResponderADM(responderData: ResponderData) extends Responder(responde
.asInstanceOf[IriLiteralV2]
.value,
name = name,
labels = StringLiteralSequenceV2(labels.toVector.sortBy(_.language)),
comments = StringLiteralSequenceV2(comments.toVector.sortBy(_.language))
labels = StringLiteralSequenceV2(labels.toVector),
comments = StringLiteralSequenceV2(comments.toVector)
).unescape
}

Expand Down Expand Up @@ -414,17 +414,17 @@ class ListsResponderADM(responderData: ResponderData) extends Responder(responde
name = propsMap
.get(OntologyConstants.KnoraBase.ListNodeName.toSmartIri)
.map(_.head.asInstanceOf[StringLiteralV2].value),
labels = StringLiteralSequenceV2(labels.toVector.sortBy(_.language)),
comments = StringLiteralSequenceV2(comments.toVector.sortBy(_.language))
labels = StringLiteralSequenceV2(labels.toVector),
comments = StringLiteralSequenceV2(comments.toVector)
).unescape
} else {
ListChildNodeInfoADM(
id = nodeIri.toString,
name = propsMap
.get(OntologyConstants.KnoraBase.ListNodeName.toSmartIri)
.map(_.head.asInstanceOf[StringLiteralV2].value),
labels = StringLiteralSequenceV2(labels.toVector.sortBy(_.language)),
comments = StringLiteralSequenceV2(comments.toVector.sortBy(_.language)),
labels = StringLiteralSequenceV2(labels.toVector),
comments = StringLiteralSequenceV2(comments.toVector),
position = positionOption.getOrElse(
throw InconsistentRepositoryDataException(
s"Required position property missing for list node $nodeIri."
Expand Down Expand Up @@ -592,8 +592,8 @@ class ListsResponderADM(responderData: ResponderData) extends Responder(responde
name = propsMap
.get(OntologyConstants.KnoraBase.ListNodeName.toSmartIri)
.map(_.head.asInstanceOf[StringLiteralV2].value),
labels = StringLiteralSequenceV2(labels.toVector.sortBy(_.language)),
comments = StringLiteralSequenceV2(comments.toVector.sortBy(_.language)),
labels = StringLiteralSequenceV2(labels.toVector),
comments = StringLiteralSequenceV2(comments.toVector),
children = children
)
} else {
Expand All @@ -602,8 +602,8 @@ class ListsResponderADM(responderData: ResponderData) extends Responder(responde
name = propsMap
.get(OntologyConstants.KnoraBase.ListNodeName.toSmartIri)
.map(_.head.asInstanceOf[StringLiteralV2].value),
labels = StringLiteralSequenceV2(labels.toVector.sortBy(_.language)),
comments = Some(StringLiteralSequenceV2(comments.toVector.sortBy(_.language))),
labels = StringLiteralSequenceV2(labels.toVector),
comments = Some(StringLiteralSequenceV2(comments.toVector)),
position = positionOption.getOrElse(
throw InconsistentRepositoryDataException(
s"Required position property missing for list node $nodeIri."
Expand Down Expand Up @@ -700,8 +700,8 @@ class ListsResponderADM(responderData: ResponderData) extends Responder(responde
ListChildNodeADM(
id = nodeIri,
name = nameOption,
labels = StringLiteralSequenceV2(labels.toVector.sortBy(_.language)),
comments = Some(StringLiteralSequenceV2(comments.toVector.sortBy(_.language))),
labels = StringLiteralSequenceV2(labels.toVector),
comments = Some(StringLiteralSequenceV2(comments.toVector)),
children = children.map(_.sorted),
position = position,
hasRootNode = hasRootNode
Expand Down
Expand Up @@ -41,9 +41,7 @@ class ListsResponderV2Spec extends CoreSpec() with ImplicitSender {
private val timeout = 10.seconds

"The lists responder v2" should {

"return a list" in {

responderManager ! ListGetRequestV2(
listIri = "http://rdfh.ch/lists/0001/treeList",
featureFactoryConfig = defaultFeatureFactoryConfig,
Expand All @@ -52,12 +50,10 @@ class ListsResponderV2Spec extends CoreSpec() with ImplicitSender {

expectMsgPF(timeout) { case response: ListGetResponseV2 =>
assert(response == listsResponderV2SpecFullData.treeList)

}
}

"return a node" in {

responderManager ! NodeGetRequestV2(
nodeIri = "http://rdfh.ch/lists/0001/treeList11",
featureFactoryConfig = defaultFeatureFactoryConfig,
Expand All @@ -67,9 +63,6 @@ class ListsResponderV2Spec extends CoreSpec() with ImplicitSender {
expectMsgPF(timeout) { case response: NodeGetResponseV2 =>
assert(response == listsResponderV2SpecFullData.treeNode)
}

}

}

}
Expand Up @@ -74,8 +74,8 @@ object SharedListsTestDataADM {
name = Some("treelistroot"),
labels = StringLiteralSequenceV2(
Vector(
StringLiteralV2(value = "Listenwurzel", language = Some("de")),
StringLiteralV2(value = "Tree list root", language = Some("en"))
StringLiteralV2(value = "Tree list root", language = Some("en")),
StringLiteralV2(value = "Listenwurzel", language = Some("de"))
)
),
comments = StringLiteralSequenceV2(Vector(StringLiteralV2(value = "Anything Tree List", language = Some("en"))))
Expand Down

0 comments on commit f3a66cb

Please sign in to comment.