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

pl.touk.nussknacker.engine.api.process.ProcessId.scala Maven / Gradle / Ivy

There is a newer version: 1.18.1
Show newest version
package pl.touk.nussknacker.engine.api.process

import io.circe.{Decoder, Encoder}

import scala.util.{Failure, Success, Try}

// It is a synthetic, autoincremental id of scenario in the database.
// TODO: We should avoid exposing it anywhere, especially in the API as it is not safe to pass such information externally.
// TODO: Also we'd rather not use a synthetic identifier, ProcessName (which meant to be a human friendly id) should be sufficient
final case class ProcessId(value: Long) {
  override def toString: String = value.toString
}

object ProcessId {
  implicit val encoder: Encoder[ProcessId] = Encoder.encodeLong.contramap(_.value)
  implicit val decoder: Decoder[ProcessId] = Decoder.decodeLong.map(ProcessId(_))

  def apply(value: String): ProcessId = Try(value.toLong) match {
    case Success(id) => ProcessId(id)
    case Failure(_)  => throw new IllegalArgumentException(s"Value '$value' is not valid ProcessId.")
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy