/** * Generated by API Builder - https://www.apibuilder.io * Service version: 0.0.1 * User agent: apibuilder app.apibuilder.io/nccloud/registry-api/0.0.1/play_2_x_standalone_json */ package de.nccloud.registry.api.v0.models { sealed trait ServiceEvent extends _root_.scala.Product with _root_.scala.Serializable { def serviceEventType: ServiceEventType } /** * Defines the valid type values for the type ServiceEvent */ sealed trait ServiceEventType extends _root_.scala.Product with _root_.scala.Serializable object ServiceEventType { case object ServiceUpsertedEvent extends ServiceEventType { override def toString = "service_upserted_event" } case object ServiceDeletedEvent extends ServiceEventType { override def toString = "service_deleted_event" } final case class UNDEFINED(override val toString: String) extends ServiceEventType val all: scala.List[ServiceEventType] = scala.List(ServiceUpsertedEvent, ServiceDeletedEvent) private val byName: Map[String, ServiceEventType] = all.map(x => x.toString.toLowerCase -> x).toMap def apply(value: String): ServiceEventType = fromString(value).getOrElse(UNDEFINED(value)) def fromString(value: String): _root_.scala.Option[ServiceEventType] = byName.get(value.toLowerCase) } /** * A single available service. * * @param uri URI under which this service is deployed. * @param title A human-readable title of the service. * @param description A human-readable description of the service. */ final case class Service( name: String, version: String, state: de.nccloud.registry.api.v0.models.ServiceState, `type`: de.nccloud.registry.api.v0.models.ServiceType = de.nccloud.registry.api.v0.models.ServiceType.Public, uri: String, title: _root_.scala.Option[String] = None, description: _root_.scala.Option[String] = None ) /** * A service has been undeployed is not reachable anymore. * * @param name Name of the service that has been undeployed. */ final case class ServiceDeletedEvent( name: String, timestamp: _root_.org.joda.time.DateTime ) extends ServiceEvent { override val serviceEventType: ServiceEventType = ServiceEventType.ServiceDeletedEvent } /** * A service has been newly deployed or updated. */ final case class ServiceUpsertedEvent( service: de.nccloud.registry.api.v0.models.Service, timestamp: _root_.org.joda.time.DateTime ) extends ServiceEvent { override val serviceEventType: ServiceEventType = ServiceEventType.ServiceUpsertedEvent } /** * Provides future compatibility in clients - in the future, when a type is added * to the union ServiceEvent, it will need to be handled in the client code. This * implementation will deserialize these future types as an instance of this class. * * @param description Information about the type that we received that is undefined in this version of * the client. */ final case class ServiceEventUndefinedType( description: String ) extends ServiceEvent { override val serviceEventType: ServiceEventType = ServiceEventType.UNDEFINED(description) } /** * The current state of a single service. */ sealed trait ServiceState extends _root_.scala.Product with _root_.scala.Serializable object ServiceState { /** * This service is currently not deployed. */ case object Unavailable extends ServiceState { override def toString = "unavailable" } /** * This service is deployed and reachable. */ case object Available extends ServiceState { override def toString = "available" } /** * This service is deployed but not reachable due to an error. */ case object Error extends ServiceState { override def toString = "error" } /** * UNDEFINED captures values that are sent either in error or * that were added by the server after this library was * generated. We want to make it easy and obvious to users of * this library to handle this case gracefully. * * We use all CAPS for the variable name to avoid collisions * with the camel cased values above. */ final case class UNDEFINED(override val toString: String) extends ServiceState /** * all returns a list of all the valid, known values. We use * lower case to avoid collisions with the camel cased values * above. */ val all: scala.List[ServiceState] = scala.List(Unavailable, Available, Error) private val byName: Map[String, ServiceState] = all.map(x => x.toString.toLowerCase -> x).toMap def apply(value: String): ServiceState = fromString(value).getOrElse(UNDEFINED(value)) def fromString(value: String): _root_.scala.Option[ServiceState] = byName.get(value.toLowerCase) } /** * Indicates where a service is reachable. */ sealed trait ServiceType extends _root_.scala.Product with _root_.scala.Serializable object ServiceType { /** * This service is publicly reachable. */ case object Public extends ServiceType { override def toString = "public" } /** * This service only reachable internally in the cluster. */ case object Internal extends ServiceType { override def toString = "internal" } /** * UNDEFINED captures values that are sent either in error or * that were added by the server after this library was * generated. We want to make it easy and obvious to users of * this library to handle this case gracefully. * * We use all CAPS for the variable name to avoid collisions * with the camel cased values above. */ final case class UNDEFINED(override val toString: String) extends ServiceType /** * all returns a list of all the valid, known values. We use * lower case to avoid collisions with the camel cased values * above. */ val all: scala.List[ServiceType] = scala.List(Public, Internal) private val byName: Map[String, ServiceType] = all.map(x => x.toString.toLowerCase -> x).toMap def apply(value: String): ServiceType = fromString(value).getOrElse(UNDEFINED(value)) def fromString(value: String): _root_.scala.Option[ServiceType] = byName.get(value.toLowerCase) } } package de.nccloud.registry.api.v0.models { package object json { import play.api.libs.json.__ import play.api.libs.json.JsString import play.api.libs.json.Writes import play.api.libs.functional.syntax._ import de.nccloud.common.v0.models.json._ import de.nccloud.registry.api.v0.models.json._ private[v0] implicit val jsonReadsUUID: play.api.libs.json.Reads[_root_.java.util.UUID] = __.read[String].map { str => _root_.java.util.UUID.fromString(str) } private[v0] implicit val jsonWritesUUID: play.api.libs.json.Writes[_root_.java.util.UUID] = (x: _root_.java.util.UUID) => play.api.libs.json.JsString(x.toString) private[v0] implicit val jsonReadsJodaDateTime: play.api.libs.json.Reads[_root_.org.joda.time.DateTime] = __.read[String].map { str => _root_.org.joda.time.format.ISODateTimeFormat.dateTimeParser.parseDateTime(str) } private[v0] implicit val jsonWritesJodaDateTime: play.api.libs.json.Writes[_root_.org.joda.time.DateTime] = (x: _root_.org.joda.time.DateTime) => { play.api.libs.json.JsString(_root_.org.joda.time.format.ISODateTimeFormat.dateTime.print(x)) } private[v0] implicit val jsonReadsJodaLocalDate: play.api.libs.json.Reads[_root_.org.joda.time.LocalDate] = __.read[String].map { str => _root_.org.joda.time.format.ISODateTimeFormat.dateTimeParser.parseLocalDate(str) } private[v0] implicit val jsonWritesJodaLocalDate: play.api.libs.json.Writes[_root_.org.joda.time.LocalDate] = (x: _root_.org.joda.time.LocalDate) => { play.api.libs.json.JsString(_root_.org.joda.time.format.ISODateTimeFormat.date.print(x)) } implicit val jsonReadsRegistryApiServiceState: play.api.libs.json.Reads[de.nccloud.registry.api.v0.models.ServiceState] = new play.api.libs.json.Reads[de.nccloud.registry.api.v0.models.ServiceState] { def reads(js: play.api.libs.json.JsValue): play.api.libs.json.JsResult[de.nccloud.registry.api.v0.models.ServiceState] = { js match { case v: play.api.libs.json.JsString => play.api.libs.json.JsSuccess(de.nccloud.registry.api.v0.models.ServiceState(v.value)) case _ => { (js \ "value").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(de.nccloud.registry.api.v0.models.ServiceState(v)) case _: play.api.libs.json.JsError => (js \ "service_state").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(de.nccloud.registry.api.v0.models.ServiceState(v)) case err: play.api.libs.json.JsError => err } } } } } } def jsonWritesRegistryApiServiceState(obj: de.nccloud.registry.api.v0.models.ServiceState) = { play.api.libs.json.JsString(obj.toString) } def jsObjectServiceState(obj: de.nccloud.registry.api.v0.models.ServiceState) = { play.api.libs.json.Json.obj("value" -> play.api.libs.json.JsString(obj.toString)) } implicit def jsonWritesRegistryApiServiceState: play.api.libs.json.Writes[ServiceState] = { (obj: de.nccloud.registry.api.v0.models.ServiceState) => { de.nccloud.registry.api.v0.models.json.jsonWritesRegistryApiServiceState(obj) } } implicit val jsonReadsRegistryApiServiceType: play.api.libs.json.Reads[de.nccloud.registry.api.v0.models.ServiceType] = new play.api.libs.json.Reads[de.nccloud.registry.api.v0.models.ServiceType] { def reads(js: play.api.libs.json.JsValue): play.api.libs.json.JsResult[de.nccloud.registry.api.v0.models.ServiceType] = { js match { case v: play.api.libs.json.JsString => play.api.libs.json.JsSuccess(de.nccloud.registry.api.v0.models.ServiceType(v.value)) case _ => { (js \ "value").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(de.nccloud.registry.api.v0.models.ServiceType(v)) case _: play.api.libs.json.JsError => (js \ "service_type").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(de.nccloud.registry.api.v0.models.ServiceType(v)) case err: play.api.libs.json.JsError => err } } } } } } def jsonWritesRegistryApiServiceType(obj: de.nccloud.registry.api.v0.models.ServiceType) = { play.api.libs.json.JsString(obj.toString) } def jsObjectServiceType(obj: de.nccloud.registry.api.v0.models.ServiceType) = { play.api.libs.json.Json.obj("value" -> play.api.libs.json.JsString(obj.toString)) } implicit def jsonWritesRegistryApiServiceType: play.api.libs.json.Writes[ServiceType] = { (obj: de.nccloud.registry.api.v0.models.ServiceType) => { de.nccloud.registry.api.v0.models.json.jsonWritesRegistryApiServiceType(obj) } } implicit def jsonReadsRegistryApiService: play.api.libs.json.Reads[de.nccloud.registry.api.v0.models.Service] = { for { name <- (__ \ "name").read[String] version <- (__ \ "version").read[String] state <- (__ \ "state").read[de.nccloud.registry.api.v0.models.ServiceState] `type` <- (__ \ "type").read[de.nccloud.registry.api.v0.models.ServiceType] uri <- (__ \ "uri").read[String] title <- (__ \ "title").readNullable[String] description <- (__ \ "description").readNullable[String] } yield Service(name, version, state, `type`, uri, title, description) } def jsObjectService(obj: de.nccloud.registry.api.v0.models.Service): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "name" -> play.api.libs.json.JsString(obj.name), "version" -> play.api.libs.json.JsString(obj.version), "state" -> play.api.libs.json.JsString(obj.state.toString), "type" -> play.api.libs.json.JsString(obj.`type`.toString), "uri" -> play.api.libs.json.JsString(obj.uri) ) ++ (obj.title match { case None => play.api.libs.json.Json.obj() case Some(x) => play.api.libs.json.Json.obj("title" -> play.api.libs.json.JsString(x)) }) ++ (obj.description match { case None => play.api.libs.json.Json.obj() case Some(x) => play.api.libs.json.Json.obj("description" -> play.api.libs.json.JsString(x)) }) } implicit def jsonWritesRegistryApiService: play.api.libs.json.Writes[Service] = { (obj: de.nccloud.registry.api.v0.models.Service) => { de.nccloud.registry.api.v0.models.json.jsObjectService(obj) } } implicit def jsonReadsRegistryApiServiceDeletedEvent: play.api.libs.json.Reads[de.nccloud.registry.api.v0.models.ServiceDeletedEvent] = { for { name <- (__ \ "name").read[String] timestamp <- (__ \ "timestamp").read[_root_.org.joda.time.DateTime] } yield ServiceDeletedEvent(name, timestamp) } def jsObjectServiceDeletedEvent(obj: de.nccloud.registry.api.v0.models.ServiceDeletedEvent): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "name" -> play.api.libs.json.JsString(obj.name), "timestamp" -> play.api.libs.json.JsString(_root_.org.joda.time.format.ISODateTimeFormat.dateTime.print(obj.timestamp)) ) ++ play.api.libs.json.Json.obj("type" -> "service_deleted_event") } implicit def jsonWritesRegistryApiServiceDeletedEvent: play.api.libs.json.Writes[ServiceDeletedEvent] = { (obj: de.nccloud.registry.api.v0.models.ServiceDeletedEvent) => { de.nccloud.registry.api.v0.models.json.jsObjectServiceDeletedEvent(obj) } } implicit def jsonReadsRegistryApiServiceUpsertedEvent: play.api.libs.json.Reads[de.nccloud.registry.api.v0.models.ServiceUpsertedEvent] = { for { service <- (__ \ "service").read[de.nccloud.registry.api.v0.models.Service] timestamp <- (__ \ "timestamp").read[_root_.org.joda.time.DateTime] } yield ServiceUpsertedEvent(service, timestamp) } def jsObjectServiceUpsertedEvent(obj: de.nccloud.registry.api.v0.models.ServiceUpsertedEvent): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "service" -> de.nccloud.registry.api.v0.models.json.jsObjectService(obj.service), "timestamp" -> play.api.libs.json.JsString(_root_.org.joda.time.format.ISODateTimeFormat.dateTime.print(obj.timestamp)) ) ++ play.api.libs.json.Json.obj("type" -> "service_upserted_event") } implicit def jsonWritesRegistryApiServiceUpsertedEvent: play.api.libs.json.Writes[ServiceUpsertedEvent] = { (obj: de.nccloud.registry.api.v0.models.ServiceUpsertedEvent) => { de.nccloud.registry.api.v0.models.json.jsObjectServiceUpsertedEvent(obj) } } implicit def jsonReadsRegistryApiServiceEvent: play.api.libs.json.Reads[de.nccloud.registry.api.v0.models.ServiceEvent] = (js: play.api.libs.json.JsValue) => { def readDiscriminator(discriminator: String) = { discriminator match { case "service_upserted_event" => de.nccloud.registry.api.v0.models.json.jsonReadsRegistryApiServiceUpsertedEvent.reads(js) case "service_deleted_event" => de.nccloud.registry.api.v0.models.json.jsonReadsRegistryApiServiceDeletedEvent.reads(js) case other => play.api.libs.json.JsSuccess(de.nccloud.registry.api.v0.models.ServiceEventUndefinedType(other)) } } (js \ "type").validate[String] match { case e: play.api.libs.json.JsError => e case s: play.api.libs.json.JsSuccess[String] => readDiscriminator(s.value) } } def jsObjectServiceEvent(obj: de.nccloud.registry.api.v0.models.ServiceEvent): play.api.libs.json.JsObject = { obj match { case x: de.nccloud.registry.api.v0.models.ServiceUpsertedEvent => de.nccloud.registry.api.v0.models.json.jsObjectServiceUpsertedEvent(x) case x: de.nccloud.registry.api.v0.models.ServiceDeletedEvent => de.nccloud.registry.api.v0.models.json.jsObjectServiceDeletedEvent(x) case other => { sys.error(s"The type[${other.getClass.getName}] has no JSON writer") } } } implicit def jsonWritesRegistryApiServiceEvent: play.api.libs.json.Writes[ServiceEvent] = { (obj: de.nccloud.registry.api.v0.models.ServiceEvent) => { de.nccloud.registry.api.v0.models.json.jsObjectServiceEvent(obj) } } } }