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

db.migration.V1_054__FragmentAddComponentGroupProperty.scala Maven / Gradle / Ivy

There is a newer version: 1.18.1
Show newest version
package db.migration

import io.circe._
import pl.touk.nussknacker.ui.db.migration.ProcessJsonMigration

trait V1_054__FragmentAddComponentGroupPropertyDefinition extends ProcessJsonMigration {

  override def updateProcessJson(jsonProcess: Json): Option[Json] =
    V1_054__FragmentAddComponentGroupProperty.migrateMetadata(jsonProcess)

}

object V1_054__FragmentAddComponentGroupProperty {

  private[migration] def migrateMetadata(jsonProcess: Json): Option[Json] = {
    for {
      typeSpecificDataType <- jsonProcess.hcursor
        .downField("metaData")
        .downField("typeSpecificData")
        .downField("type")
        .as[String]
        .toOption
      if typeSpecificDataType == "FragmentSpecificData"
      withAddedComponentGroupIfMissing <- jsonProcess.hcursor
        .downField("metaData")
        .downField("additionalFields")
        .downField("properties")
        .withFocus { properties =>
          properties.hcursor.downField("componentGroup").focus.flatMap(_.asString) match {
            case Some(_) => properties
            case None    => properties.mapObject(_.add("componentGroup", Json.fromString("fragments")))
          }
        }
        .top
    } yield withAddedComponentGroupIfMissing

  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy