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(admin): return list labels and comments sorted by language #2074

Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -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(value) => Some(value.sortByLanguage)
mpro7 marked this conversation as resolved.
Show resolved Hide resolved
},
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