Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NU-1846] Fix redundant "ParameterName(...)" wrapper string in export… #7147

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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
Expand Down Expand Up @@ -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(
"<empty/>",
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()),
Expand Down
1 change: 1 addition & 0 deletions docs/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading