From bc214b695abcce73a9f6437a8ea8e92e84f2b976 Mon Sep 17 00:00:00 2001 From: danielfeismann Date: Thu, 4 Jul 2024 14:44:37 +0200 Subject: [PATCH] refactor providing controllingEm to reviewers comments --- .../simona/agent/grid/GridAgentController.scala | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/scala/edu/ie3/simona/agent/grid/GridAgentController.scala b/src/main/scala/edu/ie3/simona/agent/grid/GridAgentController.scala index aa97f858d8..43c111a47f 100644 --- a/src/main/scala/edu/ie3/simona/agent/grid/GridAgentController.scala +++ b/src/main/scala/edu/ie3/simona/agent/grid/GridAgentController.scala @@ -202,8 +202,16 @@ class GridAgentController( val node = participant.getNode val controllingEm = - participant.getControllingEm.toScala.flatMap(em => Option(em.getUuid)) - val emActorRef = controllingEm.flatMap(uuid => allEms.get(uuid)) + participant.getControllingEm.toScala + .map(_.getUuid) + .map(uuid => + allEms.getOrElse( + uuid, + throw new CriticalFailureException( + s"EM actor with UUID $uuid not found." + ), + ) + ) val actorRef = buildParticipantActor( participantsConfig.requestVoltageDeviationThreshold, @@ -212,7 +220,7 @@ class GridAgentController( participant, thermalIslandGridsByBusId, environmentRefs, - emActorRef, + controllingEm, ) introduceAgentToEnvironment(actorRef) // return uuid to actorRef