From f54594e8a80b7a138fcb98992b0e4bf22ce33bd5 Mon Sep 17 00:00:00 2001 From: Arek Burdach Date: Wed, 13 Nov 2024 17:09:04 +0100 Subject: [PATCH 1/2] [NU-1846] Fix redundant "ParameterName(...)" wrapper string in exported PDFs in nodes details --- .../nussknacker/ui/util/PdfExporter.scala | 28 ++++++++++--------- .../nussknacker/ui/util/PdfExporterSpec.scala | 28 +++++++++++++++++++ docs/Changelog.md | 1 + 3 files changed, 44 insertions(+), 13 deletions(-) diff --git a/designer/server/src/main/scala/pl/touk/nussknacker/ui/util/PdfExporter.scala b/designer/server/src/main/scala/pl/touk/nussknacker/ui/util/PdfExporter.scala index cfaa3ed0750..c6140e34bed 100644 --- a/designer/server/src/main/scala/pl/touk/nussknacker/ui/util/PdfExporter.scala +++ b/designer/server/src/main/scala/pl/touk/nussknacker/ui/util/PdfExporter.scala @@ -87,7 +87,7 @@ object PdfExporter extends LazyLogging { out.toByteArray } - private def prepareFopXml( + private[util] def prepareFopXml( svg: String, processDetails: ScenarioWithDetailsEntity[ScenarioGraph], processActivity: ProcessActivity, @@ -204,21 +204,23 @@ object PdfExporter extends LazyLogging { 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 @@ -226,7 +228,7 @@ object PdfExporter extends LazyLogging { ("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 => + parameters.map(p => p.name.value -> p.expression.expression) ++ branch.flatMap(bp => bp.parameters.map(p => s"${bp.branchId} - ${p.name}" -> p.expression.expression) ) case Split(_, _) => ("No parameters", "") :: Nil @@ -234,7 +236,7 @@ object PdfExporter extends LazyLogging { 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 @@ -250,7 +252,7 @@ object PdfExporter extends LazyLogging { { - data.map { case (key, value) => + data.map { case (key: String, value: String) => diff --git a/designer/server/src/test/scala/pl/touk/nussknacker/ui/util/PdfExporterSpec.scala b/designer/server/src/test/scala/pl/touk/nussknacker/ui/util/PdfExporterSpec.scala index 2f57c408625..38ffb68030f 100644 --- a/designer/server/src/test/scala/pl/touk/nussknacker/ui/util/PdfExporterSpec.scala +++ b/designer/server/src/test/scala/pl/touk/nussknacker/ui/util/PdfExporterSpec.scala @@ -6,11 +6,15 @@ import org.scalatest.matchers.should.Matchers import pl.touk.nussknacker.engine.api.StreamMetaData import pl.touk.nussknacker.engine.api.graph.{ProcessProperties, ScenarioGraph} import pl.touk.nussknacker.engine.api.process.{ProcessName, ScenarioVersion, VersionId} +import pl.touk.nussknacker.engine.build.ScenarioBuilder import pl.touk.nussknacker.engine.graph.node.{Filter, UserDefinedAdditionalNodeFields} +import pl.touk.nussknacker.engine.spel.SpelExtension.SpelExpresion import pl.touk.nussknacker.engine.util.ResourceLoader +import pl.touk.nussknacker.restmodel.scenariodetails.ScenarioWithDetails import pl.touk.nussknacker.test.utils.domain.{ProcessTestData, TestProcessUtil} import pl.touk.nussknacker.ui.api.description.scenarioActivity.Dtos.Legacy.{Comment, ProcessActivity} import pl.touk.nussknacker.ui.process.marshall.CanonicalProcessConverter +import pl.touk.nussknacker.ui.process.repository.ScenarioWithDetailsEntity import java.io.FileOutputStream import java.time.Instant @@ -52,6 +56,30 @@ class PdfExporterSpec extends AnyFlatSpec with Matchers { IOUtils.write(exported, new FileOutputStream("/tmp/out.pdf")) } + it should "render parameter names correctly in generated xml" in { + val givenSourceParamName = "someParamName" + val sampleScenarioGraph = + CanonicalProcessConverter.toScenarioGraph( + ScenarioBuilder + .streaming("foo") + .source("sourceId", "sourceType", givenSourceParamName -> "123".spel) + .emptySink("sinkId", "sinkType") + ) + val xml = PdfExporter.prepareFopXml( + "", + createDetails(sampleScenarioGraph), + ProcessActivity(List.empty, List.empty), + sampleScenarioGraph + ) + val blocks = xml \ "page-sequence" \ "flow" \ "block" + val blockWithSourceDetails = blocks(4) + val sourceParameterRow = (blockWithSourceDetails \ "table" \ "table-body" \ "table-row")(1) + val sourceParameterNameNode = (sourceParameterRow \ "table-cell")(0) + val sourceParameterNameText = (sourceParameterNameNode \ "block").text.trim + + sourceParameterNameText shouldBe givenSourceParamName + } + it should "export empty process to " in { val scenarioGraph: ScenarioGraph = ScenarioGraph( ProcessProperties(StreamMetaData()), diff --git a/docs/Changelog.md b/docs/Changelog.md index 80992227237..ae6cf0cf330 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -98,6 +98,7 @@ * [#6721](https://github.com/TouK/nussknacker/pull/6721) Provide a popover to display additional information about count * [#7099](https://github.com/TouK/nussknacker/pull/7099) Provide an option to embedded video to the markdown * [#7102](https://github.com/TouK/nussknacker/pull/7102) Introduce a new UI to defining aggregations within nodes +* [#7147](https://github.com/TouK/nussknacker/pull/7147) Fix redundant "ParameterName(...)" wrapper string in exported PDFs in nodes details ## 1.17 From bf3431c1510af4419c3411f3dbaa8970669a20a3 Mon Sep 17 00:00:00 2001 From: Arek Burdach Date: Thu, 14 Nov 2024 11:29:45 +0100 Subject: [PATCH 2/2] Update designer/server/src/main/scala/pl/touk/nussknacker/ui/util/PdfExporter.scala MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Mateusz SÅ‚abek --- .../main/scala/pl/touk/nussknacker/ui/util/PdfExporter.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/designer/server/src/main/scala/pl/touk/nussknacker/ui/util/PdfExporter.scala b/designer/server/src/main/scala/pl/touk/nussknacker/ui/util/PdfExporter.scala index c6140e34bed..a0e7fae5647 100644 --- a/designer/server/src/main/scala/pl/touk/nussknacker/ui/util/PdfExporter.scala +++ b/designer/server/src/main/scala/pl/touk/nussknacker/ui/util/PdfExporter.scala @@ -229,7 +229,7 @@ object PdfExporter extends LazyLogging { case Join(_, output, typ, parameters, branch, _) => ("Type", typ) :: ("Output", output.getOrElse("")) :: parameters.map(p => p.name.value -> p.expression.expression) ++ branch.flatMap(bp => - bp.parameters.map(p => s"${bp.branchId} - ${p.name}" -> p.expression.expression) + 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...