From fa7e704d270528f1abd19c2ac392a9f7e44c7346 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Goworko?= Date: Tue, 22 Oct 2024 16:03:48 +0200 Subject: [PATCH] review changes --- .../pl/touk/nussknacker/engine/api/Comment.scala | 12 +++++------- .../touk/nussknacker/ui/process/ProcessService.scala | 6 +++--- .../ui/process/repository/ProcessRepository.scala | 4 ++-- .../nussknacker/test/base/it/NuResourcesTest.scala | 2 +- .../test/utils/domain/ProcessTestData.scala | 2 +- .../nussknacker/ui/api/ProcessesResourcesSpec.scala | 2 +- 6 files changed, 13 insertions(+), 15 deletions(-) diff --git a/common-api/src/main/scala/pl/touk/nussknacker/engine/api/Comment.scala b/common-api/src/main/scala/pl/touk/nussknacker/engine/api/Comment.scala index 413504335da..7bf312ac80a 100644 --- a/common-api/src/main/scala/pl/touk/nussknacker/engine/api/Comment.scala +++ b/common-api/src/main/scala/pl/touk/nussknacker/engine/api/Comment.scala @@ -2,18 +2,16 @@ package pl.touk.nussknacker.engine.api import io.circe.{Decoder, Encoder} -final case class Comment(content: String) extends AnyVal { +final case class Comment private (content: String) extends AnyVal { override def toString: String = content } -final case class NonEmptyComment private (content: String) +object Comment { -object NonEmptyComment { - def from(comment: Comment): Option[NonEmptyComment] = - if (comment.content.isEmpty) None else Some(NonEmptyComment(comment.content)) -} + def from(content: String): Option[Comment] = { + if (content.isEmpty) None else Some(Comment(content)) + } -object Comment { implicit val encoder: Encoder[Comment] = Encoder.encodeString.contramap(_.content) implicit val decoder: Decoder[Comment] = Decoder.decodeString.map(Comment.apply) } diff --git a/designer/server/src/main/scala/pl/touk/nussknacker/ui/process/ProcessService.scala b/designer/server/src/main/scala/pl/touk/nussknacker/ui/process/ProcessService.scala index 05c27827879..b61652cb428 100644 --- a/designer/server/src/main/scala/pl/touk/nussknacker/ui/process/ProcessService.scala +++ b/designer/server/src/main/scala/pl/touk/nussknacker/ui/process/ProcessService.scala @@ -11,7 +11,7 @@ import pl.touk.nussknacker.engine.api.component.ProcessingMode import pl.touk.nussknacker.engine.api.deployment.{DataFreshnessPolicy, ProcessAction, ScenarioActionName} import pl.touk.nussknacker.engine.api.graph.ScenarioGraph import pl.touk.nussknacker.engine.api.process._ -import pl.touk.nussknacker.engine.api.{Comment, NonEmptyComment, ProcessVersion} +import pl.touk.nussknacker.engine.api.{Comment, ProcessVersion} import pl.touk.nussknacker.engine.canonicalgraph.CanonicalProcess import pl.touk.nussknacker.engine.deployment.EngineSetupName import pl.touk.nussknacker.engine.marshall.ProcessMarshaller @@ -55,7 +55,7 @@ object ProcessService { @JsonCodec final case class UpdateScenarioCommand( scenarioGraph: ScenarioGraph, - comment: Option[Comment], + comment: Option[String], scenarioLabels: Option[List[String]], forwardedUserName: Option[RemoteUserName] ) @@ -421,7 +421,7 @@ class DBProcessService( val updateProcessAction = UpdateProcessAction( processId = processIdWithName.id, canonicalProcess = substituted, - comment = action.comment.flatMap(NonEmptyComment.from), + comment = action.comment.flatMap(Comment.from), labels = scenarioLabels, increaseVersionWhenJsonNotChanged = false, forwardedUserName = action.forwardedUserName diff --git a/designer/server/src/main/scala/pl/touk/nussknacker/ui/process/repository/ProcessRepository.scala b/designer/server/src/main/scala/pl/touk/nussknacker/ui/process/repository/ProcessRepository.scala index 5f62a9f1137..8592ad868ae 100644 --- a/designer/server/src/main/scala/pl/touk/nussknacker/ui/process/repository/ProcessRepository.scala +++ b/designer/server/src/main/scala/pl/touk/nussknacker/ui/process/repository/ProcessRepository.scala @@ -4,7 +4,7 @@ import akka.http.scaladsl.model.HttpHeader import com.typesafe.scalalogging.LazyLogging import db.util.DBIOActionInstances._ import io.circe.generic.JsonCodec -import pl.touk.nussknacker.engine.api.NonEmptyComment +import pl.touk.nussknacker.engine.api.Comment import pl.touk.nussknacker.engine.api.deployment._ import pl.touk.nussknacker.engine.api.process._ import pl.touk.nussknacker.engine.canonicalgraph.CanonicalProcess @@ -75,7 +75,7 @@ object ProcessRepository { final case class UpdateProcessAction( protected val processId: ProcessId, canonicalProcess: CanonicalProcess, - comment: Option[NonEmptyComment], + comment: Option[Comment], labels: List[ScenarioLabel], increaseVersionWhenJsonNotChanged: Boolean, forwardedUserName: Option[RemoteUserName] diff --git a/designer/server/src/test/scala/pl/touk/nussknacker/test/base/it/NuResourcesTest.scala b/designer/server/src/test/scala/pl/touk/nussknacker/test/base/it/NuResourcesTest.scala index b24af0d3401..fbc0e211747 100644 --- a/designer/server/src/test/scala/pl/touk/nussknacker/test/base/it/NuResourcesTest.scala +++ b/designer/server/src/test/scala/pl/touk/nussknacker/test/base/it/NuResourcesTest.scala @@ -312,7 +312,7 @@ trait NuResourcesTest doUpdateProcess( UpdateScenarioCommand( CanonicalProcessConverter.toScenarioGraph(process), - comment.map(Comment.apply), + comment, Some(List.empty), None ), diff --git a/designer/server/src/test/scala/pl/touk/nussknacker/test/utils/domain/ProcessTestData.scala b/designer/server/src/test/scala/pl/touk/nussknacker/test/utils/domain/ProcessTestData.scala index 56f8ccfbf99..47f2486fa4a 100644 --- a/designer/server/src/test/scala/pl/touk/nussknacker/test/utils/domain/ProcessTestData.scala +++ b/designer/server/src/test/scala/pl/touk/nussknacker/test/utils/domain/ProcessTestData.scala @@ -428,7 +428,7 @@ object ProcessTestData { edges = List.empty ) - UpdateScenarioCommand(scenarioGraph, comment, Some(List.empty), None) + UpdateScenarioCommand(scenarioGraph, comment.map(_.content), Some(List.empty), None) } def validProcessWithFragment( diff --git a/designer/server/src/test/scala/pl/touk/nussknacker/ui/api/ProcessesResourcesSpec.scala b/designer/server/src/test/scala/pl/touk/nussknacker/ui/api/ProcessesResourcesSpec.scala index 301690d2f77..9a3bc3c9388 100644 --- a/designer/server/src/test/scala/pl/touk/nussknacker/ui/api/ProcessesResourcesSpec.scala +++ b/designer/server/src/test/scala/pl/touk/nussknacker/ui/api/ProcessesResourcesSpec.scala @@ -1460,7 +1460,7 @@ class ProcessesResourcesSpec doUpdateProcess( UpdateScenarioCommand( CanonicalProcessConverter.toScenarioGraph(process), - comment.map(Comment.apply), + comment, Some(List.empty), None ),