Skip to content

Commit

Permalink
Merge branch 'staging' into fix-scenario-tests-with-fragment-input-va…
Browse files Browse the repository at this point in the history
…lidation
  • Loading branch information
Elmacioro authored Nov 18, 2024
2 parents f4ac49f + 5ebf989 commit 8a7be19
Show file tree
Hide file tree
Showing 41 changed files with 960 additions and 267 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ class Comment private (val content: String) extends AnyVal {
object Comment {

def from(content: String): Option[Comment] = {
if (content.isEmpty) None else Some(new Comment(content))
val trimmedContent = content.trim
if (trimmedContent.nonEmpty) Some(new Comment(trimmedContent)) else None
}

def unsafeFrom(content: String): Comment = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class ScenarioActivityApiHttpService(
private def toDto(scenarioComment: ScenarioComment): Dtos.ScenarioActivityComment = scenarioComment match {
case ScenarioComment.WithContent(comment, _, _) =>
Dtos.ScenarioActivityComment(
content = Dtos.ScenarioActivityCommentContent.Available(comment),
content = Dtos.ScenarioActivityCommentContent.Available(comment.content),
lastModifiedBy = scenarioComment.lastModifiedByUserName.value,
lastModifiedAt = scenarioComment.lastModifiedAt,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,10 @@ class AutomaticMigration(
.sequenceOption(for {
migrator <- migrators.forProcessingType(processDetails.processingType)
migrationResult <- migrator.migrateProcess(processDetails, skipEmptyMigrations = true)
automaticUpdateAction = migrationResult
.toAutomaticProcessUpdateAction(
processDetails.processId,
processDetails.scenarioLabels.map(ScenarioLabel.apply)
)
automaticUpdateAction <- migrationResult.toAutomaticProcessUpdateAction(
processDetails.processId,
processDetails.scenarioLabels.map(ScenarioLabel.apply)
)
} yield {
processRepository.performAutomaticUpdate(automaticUpdateAction)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ object ScenarioActivityAuditLog {
}

private def stringify(comment: ScenarioComment): String = comment match {
case ScenarioComment.WithContent(comment, _, _) => comment
case ScenarioComment.WithContent(comment, _, _) => comment.content
case ScenarioComment.WithoutContent(_, _) => "none"
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package pl.touk.nussknacker.ui.process.migrate

import cats.data.NonEmptyList
import pl.touk.nussknacker.engine.api.graph.ScenarioGraph
import pl.touk.nussknacker.engine.api.process.{ProcessId, ProcessName}
import pl.touk.nussknacker.engine.canonicalgraph.CanonicalProcess
Expand All @@ -11,15 +12,23 @@ import pl.touk.nussknacker.ui.process.repository.ScenarioWithDetailsEntity

final case class MigrationResult(process: CanonicalProcess, migrationsApplied: List[ProcessMigration]) {

def toAutomaticProcessUpdateAction(processId: ProcessId, labels: List[ScenarioLabel]): AutomaticProcessUpdateAction =
AutomaticProcessUpdateAction(
processId = processId,
canonicalProcess = process,
labels = labels,
increaseVersionWhenJsonNotChanged = true,
forwardedUserName = None,
migrationsApplies = migrationsApplied
)
def toAutomaticProcessUpdateAction(
processId: ProcessId,
labels: List[ScenarioLabel]
): Option[AutomaticProcessUpdateAction] = {
NonEmptyList
.fromList(migrationsApplied)
.map { migrations =>
AutomaticProcessUpdateAction(
processId = processId,
canonicalProcess = process,
labels = labels,
increaseVersionWhenJsonNotChanged = true,
forwardedUserName = None,
migrationsApplied = migrations
)
}
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@ class ActivityService(
user = loggedUser.scenarioUser,
date = now,
scenarioVersionId = Some(ScenarioVersionId.from(scenarioGraphVersionId)),
comment = commentOpt match {
case Some(comment) => ScenarioComment.WithContent(comment.content, UserName(loggedUser.username), now)
case None => ScenarioComment.WithoutContent(UserName(loggedUser.username), now)
},
comment = ScenarioComment.from(commentOpt, UserName(loggedUser.username), now),
result = DeploymentResult.Success(clock.instant()),
)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pl.touk.nussknacker.ui.process.repository

import akka.http.scaladsl.model.HttpHeader
import cats.data.NonEmptyList
import com.typesafe.scalalogging.LazyLogging
import db.util.DBIOActionInstances._
import io.circe.generic.JsonCodec
Expand Down Expand Up @@ -98,7 +99,7 @@ object ProcessRepository {
labels: List[ScenarioLabel],
increaseVersionWhenJsonNotChanged: Boolean,
forwardedUserName: Option[RemoteUserName],
migrationsApplies: List[ProcessMigration]
migrationsApplied: NonEmptyList[ProcessMigration]
) extends ModifyProcessAction

final case class ProcessUpdated(processId: ProcessId, oldVersion: Option[VersionId], newVersion: Option[VersionId])
Expand Down Expand Up @@ -210,19 +211,11 @@ class DBProcessRepository(
date = Instant.now(),
previousScenarioVersionId = oldVersionId.map(ScenarioVersionId.from),
scenarioVersionId = versionId.map(ScenarioVersionId.from),
comment = updateProcessAction.comment.map(_.content) match {
case Some(content) =>
ScenarioComment.WithContent(
comment = content,
lastModifiedByUserName = UserName(loggedUser.username),
lastModifiedAt = clock.instant(),
)
case None =>
ScenarioComment.WithoutContent(
lastModifiedByUserName = UserName(loggedUser.username),
lastModifiedAt = clock.instant(),
)
},
comment = ScenarioComment.from(
content = updateProcessAction.comment,
lastModifiedByUserName = UserName(loggedUser.username),
lastModifiedAt = clock.instant(),
)
)
)
}
Expand Down Expand Up @@ -259,7 +252,7 @@ class DBProcessRepository(
user = loggedUser.scenarioUser,
date = Instant.now(),
scenarioVersionId = versionId.map(ScenarioVersionId.from),
changes = automaticProcessUpdateAction.migrationsApplies.map(_.description).mkString(", "),
changes = automaticProcessUpdateAction.migrationsApplied.map(_.description).toList.mkString(", "),
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package pl.touk.nussknacker.ui.process.repository.activities
import cats.implicits.catsSyntaxEitherId
import com.typesafe.scalalogging.LazyLogging
import db.util.DBIOActionInstances.DB
import pl.touk.nussknacker.engine.api.Comment
import pl.touk.nussknacker.engine.api.component.ProcessingMode
import pl.touk.nussknacker.engine.api.deployment.ScenarioAttachment.{AttachmentFilename, AttachmentId}
import pl.touk.nussknacker.engine.api.deployment._
Expand Down Expand Up @@ -292,8 +293,7 @@ class DbScenarioActivityRepository private (override protected val dbRef: DbRef,
toComment(
id,
activity,
ScenarioComment
.WithContent(s"Rename: [${activity.oldName}] -> [${activity.newName}]", UserName(""), activity.date),
ScenarioComment.from(s"Rename: [${activity.oldName}] -> [${activity.newName}]", UserName(""), activity.date),
None
)
case activity: ScenarioActivity.CommentAdded =>
Expand All @@ -306,8 +306,8 @@ class DbScenarioActivityRepository private (override protected val dbRef: DbRef,
toComment(
id,
activity,
ScenarioComment.WithContent(
comment = s"Scenario migrated from ${activity.sourceEnvironment.name} by ${activity.sourceUser.value}",
ScenarioComment.from(
content = s"Scenario migrated from ${activity.sourceEnvironment.name} by ${activity.sourceUser.value}",
lastModifiedByUserName = activity.user.name,
lastModifiedAt = activity.date
),
Expand All @@ -323,8 +323,8 @@ class DbScenarioActivityRepository private (override protected val dbRef: DbRef,
toComment(
id,
activity,
ScenarioComment.WithContent(
comment = s"Migrations applied: ${activity.changes}",
ScenarioComment.from(
content = s"Migrations applied: ${activity.changes}",
lastModifiedByUserName = activity.user.name,
lastModifiedAt = activity.date
),
Expand Down Expand Up @@ -505,8 +505,8 @@ class DbScenarioActivityRepository private (override protected val dbRef: DbRef,

private def comment(scenarioComment: ScenarioComment): Option[String] = {
scenarioComment match {
case ScenarioComment.WithContent(comment, _, _) if comment.nonEmpty => Some(comment.value)
case _ => None
case ScenarioComment.WithContent(comment, _, _) => Some(comment.content)
case ScenarioComment.WithoutContent(_, _) => None
}
}

Expand Down Expand Up @@ -676,21 +676,11 @@ class DbScenarioActivityRepository private (override protected val dbRef: DbRef,
for {
lastModifiedByUserName <- entity.lastModifiedByUserName.toRight("Missing lastModifiedByUserName field")
lastModifiedAt <- entity.lastModifiedAt.toRight("Missing lastModifiedAt field")
} yield {
entity.comment match {
case Some(comment) if comment.nonEmpty =>
ScenarioComment.WithContent(
comment = comment,
lastModifiedByUserName = UserName(lastModifiedByUserName),
lastModifiedAt = lastModifiedAt.toInstant
)
case Some(_) | None =>
ScenarioComment.WithoutContent(
lastModifiedByUserName = UserName(lastModifiedByUserName),
lastModifiedAt = lastModifiedAt.toInstant
)
}
}
} yield ScenarioComment.from(
content = entity.comment.flatMap(Comment.from),
lastModifiedByUserName = UserName(lastModifiedByUserName),
lastModifiedAt = lastModifiedAt.toInstant
)
}

private def attachmentFromEntity(entity: ScenarioActivityEntityData): Either[String, ScenarioAttachment] = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pl.touk.nussknacker.ui.process.repository.activities

import db.util.DBIOActionInstances.DB
import pl.touk.nussknacker.engine.api.Comment
import pl.touk.nussknacker.engine.api.deployment._
import pl.touk.nussknacker.engine.api.process.{ProcessId, VersionId}
import pl.touk.nussknacker.ui.api.description.scenarioActivity.Dtos.Legacy
Expand Down Expand Up @@ -41,8 +42,8 @@ trait ScenarioActivityRepository {
user = user.scenarioUser,
date = now,
scenarioVersionId = Some(ScenarioVersionId.from(processVersionId)),
comment = ScenarioComment.WithContent(
comment = comment,
comment = ScenarioComment.from(
content = comment,
lastModifiedByUserName = UserName(user.username),
lastModifiedAt = now,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ object PdfExporter extends LazyLogging {
out.toByteArray
}

private def prepareFopXml(
private[util] def prepareFopXml(
svg: String,
processDetails: ScenarioWithDetailsEntity[ScenarioGraph],
processActivity: ProcessActivity,
Expand Down Expand Up @@ -204,37 +204,39 @@ object PdfExporter extends LazyLogging {
</block>

private def nodeDetails(node: NodeData) = {
val nodeData = node match {
case Source(_, SourceRef(typ, params), _) => ("Type", typ) :: params.map(p => (p.name, p.expression.expression))
case Filter(_, expression, _, _) => List(("Expression", expression.expression))
val nodeData: List[(String, String)] = node match {
case Source(_, SourceRef(typ, params), _) =>
("Type", typ) :: params.map(p => (p.name.value, p.expression.expression))
case Filter(_, expression, _, _) => List(("Expression", expression.expression))
case Enricher(_, ServiceRef(typ, params), output, _) =>
("Type", typ) :: ("Output", output) :: params.map(p => (p.name, p.expression.expression))
("Type", typ) :: ("Output", output) :: params.map(p => (p.name.value, p.expression.expression))
// TODO: what about Swtich??
case Switch(_, expression, exprVal, _) => expression.map(e => ("Expression", e.expression)).toList
case Processor(_, ServiceRef(typ, params), _, _) =>
("Type", typ) :: params.map(p => (p.name, p.expression.expression))
case Sink(_, SinkRef(typ, params), _, _, _) => ("Type", typ) :: params.map(p => (p.name, p.expression.expression))
("Type", typ) :: params.map(p => (p.name.value, p.expression.expression))
case Sink(_, SinkRef(typ, params), _, _, _) =>
("Type", typ) :: params.map(p => (p.name.value, p.expression.expression))
case CustomNode(_, output, typ, params, _) =>
("Type", typ) :: ("Output", output.getOrElse("")) :: params.map(p => (p.name, p.expression.expression))
("Type", typ) :: ("Output", output.getOrElse("")) :: params.map(p => (p.name.value, p.expression.expression))
case FragmentInput(_, FragmentRef(typ, params, _), _, _, _) =>
("Type", typ) :: params.map(p => (p.name, p.expression.expression))
case FragmentInputDefinition(_, parameters, _) => parameters.map(p => p.name -> p.typ.refClazzName)
("Type", typ) :: params.map(p => (p.name.value, p.expression.expression))
case FragmentInputDefinition(_, parameters, _) => parameters.map(p => p.name.value -> p.typ.refClazzName)
case FragmentOutputDefinition(_, outputName, fields, _) =>
("Output name", outputName) :: fields.map(p => p.name -> p.expression.expression)
case Variable(_, name, expr, _) => (name -> expr.expression) :: Nil
case VariableBuilder(_, name, fields, _) =>
("Variable name", name) :: fields.map(p => p.name -> p.expression.expression)
case Join(_, output, typ, parameters, branch, _) =>
("Type", typ) :: ("Output", output.getOrElse("")) ::
parameters.map(p => p.name -> p.expression.expression) ++ branch.flatMap(bp =>
bp.parameters.map(p => s"${bp.branchId} - ${p.name}" -> p.expression.expression)
parameters.map(p => p.name.value -> p.expression.expression) ++ branch.flatMap(bp =>
bp.parameters.map(p => s"${bp.branchId} - ${p.name.value}" -> p.expression.expression)
)
case Split(_, _) => ("No parameters", "") :: Nil
// This should not happen in properly resolved scenario...
case _: BranchEndData => throw new IllegalArgumentException("Should not happen during PDF export")
case _: FragmentUsageOutput => throw new IllegalArgumentException("Should not happen during PDF export")
}
val data = node.additionalFields
val data: List[(String, String)] = node.additionalFields
.flatMap(_.description)
.map(naf => ("Description", naf))
.toList ++ nodeData
Expand All @@ -250,7 +252,7 @@ object PdfExporter extends LazyLogging {
<table-column column-width="proportional-column-width(3)"/>
<table-body>
{
data.map { case (key, value) =>
data.map { case (key: String, value: String) =>
<table-row>
<table-cell border="1pt solid black" padding-left="1pt" font-weight="bold">
<block>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class V1_057__MigrateActionsAndCommentsToScenarioActivities
user = user,
date = date,
scenarioVersionId = sv,
comment = WithContent("Deployment with scenario fix", user.name, date),
comment = ScenarioComment.from("Deployment with scenario fix", user.name, date),
result = DeploymentResult.Success(date),
)
)
Expand All @@ -139,7 +139,7 @@ class V1_057__MigrateActionsAndCommentsToScenarioActivities
user = user,
date = date,
scenarioVersionId = sv,
comment = WithContent("I'm canceling this scenario, it causes problems", user.name, date),
comment = ScenarioComment.from("I'm canceling this scenario, it causes problems", user.name, date),
result = DeploymentResult.Success(date),
)
)
Expand Down Expand Up @@ -183,7 +183,7 @@ class V1_057__MigrateActionsAndCommentsToScenarioActivities
user = user,
date = date,
scenarioVersionId = sv,
comment = WithContent("Paused because marketing campaign is paused for now", user.name, date),
comment = ScenarioComment.from("Paused because marketing campaign is paused for now", user.name, date),
result = DeploymentResult.Success(date),
)
)
Expand Down Expand Up @@ -239,7 +239,7 @@ class V1_057__MigrateActionsAndCommentsToScenarioActivities
user = user,
date = date,
scenarioVersionId = sv,
comment = WithContent("Deployed at the request of business", user.name, date),
comment = ScenarioComment.from("Deployed at the request of business", user.name, date),
result = DeploymentResult.Success(date),
)
)
Expand All @@ -256,7 +256,7 @@ class V1_057__MigrateActionsAndCommentsToScenarioActivities
date = date,
scenarioVersionId = sv,
actionName = "special action",
comment = WithContent("Special action needed to be executed", user.name, date),
comment = ScenarioComment.from("Special action needed to be executed", user.name, date),
result = DeploymentResult.Success(date),
)
)
Expand All @@ -281,15 +281,15 @@ class V1_057__MigrateActionsAndCommentsToScenarioActivities
user = ScenarioUser(None, UserName("John Doe"), None, None),
date = now.toInstant,
scenarioVersionId = Some(ScenarioVersionId(processVersionId)),
comment = WithContent("ABC1", UserName(user), now.toInstant)
comment = ScenarioComment.from("ABC1", UserName(user), now.toInstant)
),
ScenarioActivity.CommentAdded(
scenarioId = ScenarioId(process.id.value),
scenarioActivityId = activities(1).scenarioActivityId,
user = ScenarioUser(None, UserName("John Doe"), None, None),
date = now.toInstant,
scenarioVersionId = Some(ScenarioVersionId(processVersionId)),
comment = WithContent("ABC2", UserName(user), now.toInstant)
comment = ScenarioComment.from("ABC2", UserName(user), now.toInstant)
)
)
}
Expand Down
Loading

0 comments on commit 8a7be19

Please sign in to comment.