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

pl.touk.nussknacker.engine.api.component.DesignerWideComponentId.scala Maven / Gradle / Ivy

There is a newer version: 1.18.0
Show newest version
package pl.touk.nussknacker.engine.api.component

import io.circe.generic.extras.semiauto.{deriveUnwrappedDecoder, deriveUnwrappedEncoder}
import io.circe.{Decoder, Encoder}

// TODO This class is used as a work around for the problem that the components are duplicated across processing types.
//      We plan to get rid of this. After that, we could replace usages of this class by usage of ComponentId
//      and remove the option to configure it via componentsUiConfig
final case class DesignerWideComponentId private (value: String) extends AnyVal {
  override def toString: String = value
}

object DesignerWideComponentId {
  implicit val encoder: Encoder[DesignerWideComponentId] = deriveUnwrappedEncoder
  implicit val decoder: Decoder[DesignerWideComponentId] = deriveUnwrappedDecoder

  def apply(value: String): DesignerWideComponentId = new DesignerWideComponentId(value.toLowerCase)

  def forBuiltInComponent(componentId: ComponentId): DesignerWideComponentId = {
    if (componentId.`type` != ComponentType.BuiltIn) {
      throw new IllegalArgumentException(s"Component type: ${componentId.`type`} is not built-in component type")
    }
    // Built-in components are the same for each processing type so original id is the same across them
    apply(componentId.toString)
  }

  def default(processingType: String, componentId: ComponentId): DesignerWideComponentId = {
    if (componentId.`type` == ComponentType.BuiltIn) {
      forBuiltInComponent(componentId)
    } else
      apply(s"$processingType-$componentId")
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy