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

com.ing.baker.runtime.serialization.protomappings.SensoryEventResultMapping.scala Maven / Gradle / Ivy

There is a newer version: 4.1.0-RC3
Show newest version
package com.ing.baker.runtime.serialization.protomappings

import cats.implicits._
import com.ing.baker.runtime.akka.actor.protobuf
import com.ing.baker.runtime.serialization.ProtoMap.{ctxFromProto, ctxToProto, versioned}
import com.ing.baker.runtime.scaladsl.SensoryEventResult
import com.ing.baker.runtime.serialization.ProtoMap
import com.ing.baker.types.Value
import scalapb.GeneratedMessageCompanion

import scala.util.Try

class SensoryEventResultMapping(implicit valueProto: ProtoMap[Value, protobuf.Value]) extends ProtoMap[SensoryEventResult, protobuf.SensoryEventResult] {

  override def companion: GeneratedMessageCompanion[protobuf.SensoryEventResult] =
    protobuf.SensoryEventResult

  override def toProto(a: SensoryEventResult): protobuf.SensoryEventResult =
    protobuf.SensoryEventResult(
      Some(SensoryEventStatusMappingHelper.toProto(a.sensoryEventStatus)),
      a.eventNames,
      a.ingredients.view.map { case (key, value) => (key, ctxToProto(value))}.toMap
    )

  override def fromProto(message: protobuf.SensoryEventResult): Try[SensoryEventResult] =
    for {
      protoStatus <- versioned(message.status, "status")
      status <- SensoryEventStatusMappingHelper.fromProto(protoStatus)
      events = message.events.toIndexedSeq
      ingredients <- message.ingredients.toList.traverse { case (name, value) =>
        ctxFromProto(value).map(name -> _)
      }
    } yield SensoryEventResult(status, events, ingredients.toMap)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy