Skip to content

Commit

Permalink
review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mgoworko committed Oct 22, 2024
1 parent 47ed819 commit fa7e704
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
)
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ trait NuResourcesTest
doUpdateProcess(
UpdateScenarioCommand(
CanonicalProcessConverter.toScenarioGraph(process),
comment.map(Comment.apply),
comment,
Some(List.empty),
None
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1460,7 +1460,7 @@ class ProcessesResourcesSpec
doUpdateProcess(
UpdateScenarioCommand(
CanonicalProcessConverter.toScenarioGraph(process),
comment.map(Comment.apply),
comment,
Some(List.empty),
None
),
Expand Down

0 comments on commit fa7e704

Please sign in to comment.