All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pl.touk.nussknacker.ui.process.NewProcessPreparer.scala Maven / Gradle / Ivy

There is a newer version: 1.17.0
Show newest version
package pl.touk.nussknacker.ui.process

import pl.touk.nussknacker.engine.MetaDataInitializer
import pl.touk.nussknacker.engine.api.component.{AdditionalUIConfigProvider, ScenarioPropertyConfig}
import pl.touk.nussknacker.engine.api.process.ProcessName
import pl.touk.nussknacker.engine.api.{FragmentSpecificData, MetaData, ProcessAdditionalFields}
import pl.touk.nussknacker.engine.canonicalgraph.CanonicalProcess
import pl.touk.nussknacker.ui.definition.ScenarioPropertiesConfigFinalizer
import pl.touk.nussknacker.ui.process.NewProcessPreparer.initialFragmentFields

object NewProcessPreparer {

  private val initialFragmentFields: ProcessAdditionalFields = ProcessAdditionalFields(
    None,
    Map(FragmentSpecificData.docsUrlName -> ""),
    FragmentSpecificData.typeName
  )

}

class NewProcessPreparer(
    creator: MetaDataInitializer,
    scenarioProperties: Map[String, ScenarioPropertyConfig],
    scenarioPropertiesConfigFinalizer: ScenarioPropertiesConfigFinalizer
) {

  def prepareEmptyProcess(processName: ProcessName, isFragment: Boolean): CanonicalProcess = {
    val finalizedScenarioProperties = scenarioPropertiesConfigFinalizer.finalizeScenarioProperties(scenarioProperties)

    val initialProperties = finalizedScenarioProperties.map { case (key, config) =>
      (key, config.defaultValue.getOrElse(""))
    }
    val initialMetadata =
      if (isFragment) MetaData(processName.value, initialFragmentFields)
      else creator.create(processName, initialProperties)

    val emptyCanonical = CanonicalProcess(
      metaData = initialMetadata,
      nodes = List.empty,
      additionalBranches = List.empty
    )
    emptyCanonical
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy