Encode success/failure in setting query response

This commit is contained in:
Dale Wijnand 2017-03-21 10:06:02 +00:00
parent 875cf6f4dc
commit 70ac55d0b4
No known key found for this signature in database
GPG Key ID: 4F256E3D151DF5EF
10 changed files with 163 additions and 52 deletions

View File

@ -98,19 +98,21 @@ object SettingQuery {
case Left(_) => Converter toJsonUnsafe x.toString
}
def getSettingJsonStringValue[A](structure: BuildStructure, key: Def.ScopedKey[A]): Either[String, JValue] =
def getSettingJsonValue[A](structure: BuildStructure, key: Def.ScopedKey[A]): Either[String, JValue] =
getSettingValue(structure, key) map (toJson(_)(key.key.manifest))
def handleSettingQuery(req: SettingQuery, structure: BuildStructure): SettingQueryResponse = {
val key = Parser.parse(req.setting, scopedKeyParser(structure))
val result: Either[String, JValue] = key flatMap (getSettingJsonStringValue(structure, _))
val result =
for {
key <- key
json <- getSettingJsonValue(structure, key)
} yield SettingQuerySuccess(json, key.key.manifest.toString)
val finalResult: JValue = result match {
case Right(j) => j
case Left(s) => Converter toJsonUnsafe s
result match {
case Right(x) => x
case Left(s) => SettingQueryFailure(s)
}
SettingQueryResponse(finalResult)
}
}

View File

@ -0,0 +1,32 @@
/**
* This code is generated using [[http://www.scala-sbt.org/contraband/ sbt-contraband]].
*/
// DO NOT EDIT MANUALLY
package sbt.protocol
final class SettingQueryFailure private (
val message: String) extends sbt.protocol.SettingQueryResponse() with Serializable {
override def equals(o: Any): Boolean = o match {
case x: SettingQueryFailure => (this.message == x.message)
case _ => false
}
override def hashCode: Int = {
37 * (17 + message.##)
}
override def toString: String = {
"SettingQueryFailure(" + message + ")"
}
protected[this] def copy(message: String = message): SettingQueryFailure = {
new SettingQueryFailure(message)
}
def withMessage(message: String): SettingQueryFailure = {
copy(message = message)
}
}
object SettingQueryFailure {
def apply(message: String): SettingQueryFailure = new SettingQueryFailure(message)
}

View File

@ -4,29 +4,22 @@
// DO NOT EDIT MANUALLY
package sbt.protocol
final class SettingQueryResponse private (
val value: scala.json.ast.unsafe.JValue) extends sbt.protocol.EventMessage() with Serializable {
override def equals(o: Any): Boolean = o match {
case x: SettingQueryResponse => (this.value == x.value)
case _ => false
}
override def hashCode: Int = {
37 * (17 + value.##)
}
override def toString: String = {
"SettingQueryResponse(" + value + ")"
}
protected[this] def copy(value: scala.json.ast.unsafe.JValue = value): SettingQueryResponse = {
new SettingQueryResponse(value)
}
def withValue(value: scala.json.ast.unsafe.JValue): SettingQueryResponse = {
copy(value = value)
}
abstract class SettingQueryResponse() extends sbt.protocol.EventMessage() with Serializable {
override def equals(o: Any): Boolean = o match {
case x: SettingQueryResponse => true
case _ => false
}
override def hashCode: Int = {
17
}
override def toString: String = {
"SettingQueryResponse()"
}
}
object SettingQueryResponse {
def apply(value: scala.json.ast.unsafe.JValue): SettingQueryResponse = new SettingQueryResponse(value)
}

View File

@ -0,0 +1,36 @@
/**
* This code is generated using [[http://www.scala-sbt.org/contraband/ sbt-contraband]].
*/
// DO NOT EDIT MANUALLY
package sbt.protocol
final class SettingQuerySuccess private (
val value: scala.json.ast.unsafe.JValue,
val contentType: String) extends sbt.protocol.SettingQueryResponse() with Serializable {
override def equals(o: Any): Boolean = o match {
case x: SettingQuerySuccess => (this.value == x.value) && (this.contentType == x.contentType)
case _ => false
}
override def hashCode: Int = {
37 * (37 * (17 + value.##) + contentType.##)
}
override def toString: String = {
"SettingQuerySuccess(" + value + ", " + contentType + ")"
}
protected[this] def copy(value: scala.json.ast.unsafe.JValue = value, contentType: String = contentType): SettingQuerySuccess = {
new SettingQuerySuccess(value, contentType)
}
def withValue(value: scala.json.ast.unsafe.JValue): SettingQuerySuccess = {
copy(value = value)
}
def withContentType(contentType: String): SettingQuerySuccess = {
copy(contentType = contentType)
}
}
object SettingQuerySuccess {
def apply(value: scala.json.ast.unsafe.JValue, contentType: String): SettingQuerySuccess = new SettingQuerySuccess(value, contentType)
}

View File

@ -5,6 +5,6 @@
// DO NOT EDIT MANUALLY
package sbt.protocol.codec
import _root_.sjsonnew.{ deserializationError, serializationError, Builder, JsonFormat, Unbuilder }
trait EventMessageFormats { self: sjsonnew.BasicJsonProtocol with sbt.protocol.codec.ChannelAcceptedEventFormats with sbt.protocol.codec.LogEventFormats with sbt.protocol.codec.ExecStatusEventFormats with sbt.internal.JValueFormat with sbt.protocol.codec.SettingQueryResponseFormats =>
implicit lazy val EventMessageFormat: JsonFormat[sbt.protocol.EventMessage] = flatUnionFormat4[sbt.protocol.EventMessage, sbt.protocol.ChannelAcceptedEvent, sbt.protocol.LogEvent, sbt.protocol.ExecStatusEvent, sbt.protocol.SettingQueryResponse]("type")
trait EventMessageFormats { self: sjsonnew.BasicJsonProtocol with sbt.protocol.codec.ChannelAcceptedEventFormats with sbt.protocol.codec.LogEventFormats with sbt.protocol.codec.ExecStatusEventFormats with sbt.internal.JValueFormat with sbt.protocol.codec.SettingQuerySuccessFormats with sbt.protocol.codec.SettingQueryFailureFormats =>
implicit lazy val EventMessageFormat: JsonFormat[sbt.protocol.EventMessage] = flatUnionFormat5[sbt.protocol.EventMessage, sbt.protocol.ChannelAcceptedEvent, sbt.protocol.LogEvent, sbt.protocol.ExecStatusEvent, sbt.protocol.SettingQuerySuccess, sbt.protocol.SettingQueryFailure]("type")
}

View File

@ -12,7 +12,9 @@ trait JsonProtocol extends sjsonnew.BasicJsonProtocol
with sbt.protocol.codec.LogEventFormats
with sbt.protocol.codec.ExecStatusEventFormats
with sbt.internal.JValueFormat
with sbt.protocol.codec.SettingQueryResponseFormats
with sbt.protocol.codec.SettingQuerySuccessFormats
with sbt.protocol.codec.SettingQueryFailureFormats
with sbt.protocol.codec.EventMessageFormats
with sbt.protocol.codec.SettingQueryResponseFormats
with sbt.protocol.codec.ExecutionEventFormats
object JsonProtocol extends JsonProtocol

View File

@ -0,0 +1,27 @@
/**
* This code is generated using [[http://www.scala-sbt.org/contraband/ sbt-contraband]].
*/
// DO NOT EDIT MANUALLY
package sbt.protocol.codec
import _root_.sjsonnew.{ deserializationError, serializationError, Builder, JsonFormat, Unbuilder }
trait SettingQueryFailureFormats { self: sjsonnew.BasicJsonProtocol =>
implicit lazy val SettingQueryFailureFormat: JsonFormat[sbt.protocol.SettingQueryFailure] = new JsonFormat[sbt.protocol.SettingQueryFailure] {
override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): sbt.protocol.SettingQueryFailure = {
jsOpt match {
case Some(js) =>
unbuilder.beginObject(js)
val message = unbuilder.readField[String]("message")
unbuilder.endObject()
sbt.protocol.SettingQueryFailure(message)
case None =>
deserializationError("Expected JsObject but found None")
}
}
override def write[J](obj: sbt.protocol.SettingQueryFailure, builder: Builder[J]): Unit = {
builder.beginObject()
builder.addField("message", obj.message)
builder.endObject()
}
}
}

View File

@ -5,23 +5,6 @@
// DO NOT EDIT MANUALLY
package sbt.protocol.codec
import _root_.sjsonnew.{ deserializationError, serializationError, Builder, JsonFormat, Unbuilder }
trait SettingQueryResponseFormats { self: sbt.internal.JValueFormat with sjsonnew.BasicJsonProtocol =>
implicit lazy val SettingQueryResponseFormat: JsonFormat[sbt.protocol.SettingQueryResponse] = new JsonFormat[sbt.protocol.SettingQueryResponse] {
override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): sbt.protocol.SettingQueryResponse = {
jsOpt match {
case Some(js) =>
unbuilder.beginObject(js)
val value = unbuilder.readField[scala.json.ast.unsafe.JValue]("value")
unbuilder.endObject()
sbt.protocol.SettingQueryResponse(value)
case None =>
deserializationError("Expected JsObject but found None")
}
}
override def write[J](obj: sbt.protocol.SettingQueryResponse, builder: Builder[J]): Unit = {
builder.beginObject()
builder.addField("value", obj.value)
builder.endObject()
}
}
trait SettingQueryResponseFormats { self: sbt.internal.JValueFormat with sjsonnew.BasicJsonProtocol with sbt.protocol.codec.SettingQuerySuccessFormats with sbt.protocol.codec.SettingQueryFailureFormats =>
implicit lazy val SettingQueryResponseFormat: JsonFormat[sbt.protocol.SettingQueryResponse] = flatUnionFormat2[sbt.protocol.SettingQueryResponse, sbt.protocol.SettingQuerySuccess, sbt.protocol.SettingQueryFailure]("type")
}

View File

@ -0,0 +1,29 @@
/**
* This code is generated using [[http://www.scala-sbt.org/contraband/ sbt-contraband]].
*/
// DO NOT EDIT MANUALLY
package sbt.protocol.codec
import _root_.sjsonnew.{ deserializationError, serializationError, Builder, JsonFormat, Unbuilder }
trait SettingQuerySuccessFormats { self: sbt.internal.JValueFormat with sjsonnew.BasicJsonProtocol =>
implicit lazy val SettingQuerySuccessFormat: JsonFormat[sbt.protocol.SettingQuerySuccess] = new JsonFormat[sbt.protocol.SettingQuerySuccess] {
override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): sbt.protocol.SettingQuerySuccess = {
jsOpt match {
case Some(js) =>
unbuilder.beginObject(js)
val value = unbuilder.readField[scala.json.ast.unsafe.JValue]("value")
val contentType = unbuilder.readField[String]("contentType")
unbuilder.endObject()
sbt.protocol.SettingQuerySuccess(value, contentType)
case None =>
deserializationError("Expected JsObject but found None")
}
}
override def write[J](obj: sbt.protocol.SettingQuerySuccess, builder: Builder[J]): Unit = {
builder.beginObject()
builder.addField("value", obj.value)
builder.addField("contentType", obj.contentType)
builder.endObject()
}
}
}

View File

@ -40,8 +40,15 @@ type ExecStatusEvent implements EventMessage {
commandQueue: [String]
}
type SettingQueryResponse implements EventMessage {
interface SettingQueryResponse implements EventMessage {}
type SettingQuerySuccess implements SettingQueryResponse {
value: scala.json.ast.unsafe.JValue!
contentType: String!
}
type SettingQueryFailure implements SettingQueryResponse {
message: String!
}
# enum Status {