parent e1bf0da5
Pipeline #22605 passed with stages
in 5 minutes and 50 seconds
......@@ -18,21 +18,25 @@
package ch.memobase.models
import org.apache.logging.log4j.scala.Logging
import scala.collection.mutable
class Records {
class Records extends Logging {
type RecordIndex = Map[String, Map[String, Seq[Record]]]
private val records = mutable.Buffer[Record]()
def addRecord(rec: Record): Records = {
logger.debug(s"Add record ${rec.recordId} to Records instance")
records += rec
this
}
def getRecordsByInstitutionAndCollections(internalMarker: String): RecordIndex = {
logger.debug(s"Creating institution / recordSet index")
val (internal, external) = records.
partition(rec => rec.internal)
external.
val index = external.
foldLeft(Map[String, Map[String, Seq[Record]]]())((index, rec) => {
val institution = index.getOrElse(rec.institutionId, Map())
val collection = institution.getOrElse(rec.collectionId, Seq())
......@@ -42,5 +46,7 @@ class Records {
val collection = index.getOrElse(rec.collectionId, Seq())
index ++ Map(rec.collectionId -> (collection :+ rec))
}))
logger.debug("Institution / recordSet index created")
index
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment