From 9b5d371914c926191a7255865d6f331557fd3109 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Del=C3=A8gue?= Date: Thu, 10 Oct 2024 10:33:56 +0200 Subject: [PATCH] WIP --- nio-server/app/models/ConsentFact.scala | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/nio-server/app/models/ConsentFact.scala b/nio-server/app/models/ConsentFact.scala index c12c7c7..eacf652 100644 --- a/nio-server/app/models/ConsentFact.scala +++ b/nio-server/app/models/ConsentFact.scala @@ -197,7 +197,7 @@ object PartialConsent { def merge(pcs: Seq[PartialConsent], consents: Seq[Consent], permission: Seq[Permission]): Seq[Consent] = { val keyToPermission = permission.groupBy(_.key) consents.map { c => - val mayBePermission: Option[Permission] = keyToPermission(c.key).headOption + val mayBePermission: Option[Permission] = keyToPermission.get(c.key).flatMap(_.headOption) pcs.find(pc => pc.key == c.key).fold(c) { pc => c.copy( label = pc.label.getOrElse(c.label), @@ -206,7 +206,7 @@ object PartialConsent { ) } } ++ pcs.filter(pc => !consents.exists(c => c.key == pc.key)).map { pc => - val mayBePermission: Option[Permission] = keyToPermission(pc.key).headOption + val mayBePermission: Option[Permission] = keyToPermission.get(pc.key).flatMap(_.headOption) Consent(pc.key, pc.label.getOrElse(""), pc.checked, mayBePermission.flatMap(_.getValidityPeriod)) } } @@ -225,17 +225,17 @@ case class PartialConsentGroup (key: String, label: Option[String], consents: Op object PartialConsentGroup { def merge(partialGroups: Seq[PartialConsentGroup], existingGroups: Seq[ConsentGroup], permissionGroups: Seq[PermissionGroup]): Seq[ConsentGroup] = { - val permissionsByKey = permissionGroups.groupBy(_.key) + val permissionsByKey: Map[String, Seq[PermissionGroup]] = permissionGroups.groupBy(_.key) existingGroups.map { g => partialGroups.find(pg => pg.key == g.key).fold( g ) { pg => - val mayBePermission = permissionsByKey(pg.key).headOption + val mayBePermission: Option[PermissionGroup] = permissionsByKey.get(pg.key).flatMap(_.headOption) g.copy( label = pg.label.getOrElse(g.label), consents = pg.consents.map(pcs => PartialConsent.merge(pcs, g.consents, mayBePermission.toList.flatMap(_.permissions))).getOrElse(g.consents) ) } } ++ partialGroups.filter(pg => !existingGroups.exists(g => pg.key == g.key)).map { pcg => - val mayBePermission = permissionsByKey(pcg.key).headOption.toList.flatMap(_.permissions) + val mayBePermission: List[Permission] = permissionsByKey.get(pcg.key).toList.flatMap(_.headOption).flatMap(_.permissions) ConsentGroup( pcg.key, pcg.label.getOrElse(""),