Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
hohonuuli committed Feb 29, 2024
1 parent f649abc commit 0d061cf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/main/scala/org/fathomnet/worms/Names.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright (c) Monterey Bay Aquarium Research Institute 2022
*
* worms-server code is licensed under the MIT license.
*/

package org.fathomnet.worms

final case class Names(aphiaId: Long, name: String, acceptedName: String, alternateNames: Seq[String])
20 changes: 18 additions & 2 deletions src/main/scala/org/fathomnet/worms/StateController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ object StateController:
def search(data: Data): Option[Names] =
val allNodes = data.namesMap.values
val existing = allNodes.find(n => n.aphiaId == aphiaId)
existing match
val outdated = allNodes.filter(n => n.acceptedAphiaId == aphiaId)
val candidate = existing match
case None => None
case Some(node) =>
val accepted = if (node.aphiaId == node.acceptedAphiaId)
Expand All @@ -76,10 +77,25 @@ object StateController:
allNodes.find(n => n.aphiaId == node.acceptedAphiaId)
val names = accepted match
case None => Names(node.aphiaId, node.name, node.name, node.alternateNames)
case Some(value) => Names(node.aphiaId, node.name, value.name, node.alternateNames ++ value.alternateNames)
case Some(value) =>
val alternateNames = (node.alternateNames ++ value.alternateNames)
.toSet
.toSeq
.sorted
Names(node.aphiaId, node.name, value.name, alternateNames)

Option(names)

if (outdated.isEmpty) candidate
else
candidate.map(c => {
val alternateNames = (outdated.flatMap(n => n.names) ++ c.alternateNames)
.toSet
.toSeq
.sorted
c.copy(alternateNames = alternateNames)
})

runNodeSearch(search, s"Unable to find a name with aphiaId: $aphiaId")

def descendantNames(name: String): Either[ErrorMsg, List[String]] =
Expand Down

0 comments on commit 0d061cf

Please sign in to comment.