From 14b460edbebb1d5c39809dbc591b786edec9fa8e Mon Sep 17 00:00:00 2001 From: Kseniya Tomskikh Date: Mon, 2 Oct 2017 15:21:58 +0700 Subject: TRIAL-17 Added 'inclusion' field to Criterion --- .../formats/json/criterion/ApiCriterion.scala | 12 ++++++++---- .../formats/json/criterion/ApiNewCriterion.scala | 9 ++++++--- .../formats/json/criterion/ApiUpdateCriterion.scala | 6 +++++- .../formats/json/sprayformats/criterion.scala | 19 ++++++++++++++++--- 4 files changed, 35 insertions(+), 11 deletions(-) (limited to 'src/main/scala/xyz/driver/pdsuidomain/formats') diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiCriterion.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiCriterion.scala index 4986b17..43b5494 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiCriterion.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiCriterion.scala @@ -14,7 +14,8 @@ final case class ApiCriterion(id: Long, text: Option[String], isCompound: Boolean, labels: Seq[ApiCriterionLabel], - trialId: String) { + trialId: String, + inclusion: Option[Boolean]) { def toDomain = RichCriterion( criterion = Criterion( @@ -22,7 +23,8 @@ final case class ApiCriterion(id: Long, trialId = StringId[Trial](trialId), text, isCompound, - meta.getOrElse("") + meta.getOrElse(""), + inclusion ), armIds = arms.map(LongId[Arm]), labels = labels.map(_.toDomain(LongId[Criterion](id))) @@ -40,7 +42,8 @@ object ApiCriterion { (JsPath \ "text").formatNullable[String] and (JsPath \ "isCompound").format[Boolean] and (JsPath \ "labels").format(seqJsonFormat[ApiCriterionLabel]) and - (JsPath \ "trialId").format[String] + (JsPath \ "trialId").format[String] and + (JsPath \ "inclusion").formatNullable[Boolean] )(ApiCriterion.apply, unlift(ApiCriterion.unapply)) def fromDomain(richCriterion: RichCriterion) = ApiCriterion( @@ -50,6 +53,7 @@ object ApiCriterion { text = richCriterion.criterion.text, isCompound = richCriterion.criterion.isCompound, labels = richCriterion.labels.map(ApiCriterionLabel.fromDomain), - trialId = richCriterion.criterion.trialId.id + trialId = richCriterion.criterion.trialId.id, + inclusion = richCriterion.criterion.inclusion ) } diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiNewCriterion.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiNewCriterion.scala index ab7641f..d72a9b4 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiNewCriterion.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiNewCriterion.scala @@ -13,7 +13,8 @@ final case class ApiNewCriterion(meta: Option[String], text: Option[String], isCompound: Option[Boolean], labels: Seq[ApiCriterionLabel], - trialId: String) { + trialId: String, + inclusion: Option[Boolean]) { def toDomain = RichCriterion( criterion = Criterion( @@ -21,7 +22,8 @@ final case class ApiNewCriterion(meta: Option[String], meta = meta.getOrElse(""), trialId = StringId(trialId), isCompound = isCompound.getOrElse(false), - text = text + text = text, + inclusion = inclusion ), armIds = arms.getOrElse(Seq.empty).map(LongId[Arm]), labels = labels.map(_.toDomain(LongId(Long.MaxValue))) // A developer should specify right criterionId himself @@ -38,6 +40,7 @@ object ApiNewCriterion { (JsPath \ "text").formatNullable[String] and (JsPath \ "isCompound").formatNullable[Boolean] and (JsPath \ "labels").format(seqJsonFormat[ApiCriterionLabel]) and - (JsPath \ "trialId").format[String] + (JsPath \ "trialId").format[String] and + (JsPath \ "inclusion").formatNullable[Boolean] )(ApiNewCriterion.apply, unlift(ApiNewCriterion.unapply)) } diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiUpdateCriterion.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiUpdateCriterion.scala index 2bcda56..77989f0 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiUpdateCriterion.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiUpdateCriterion.scala @@ -14,6 +14,7 @@ final case class ApiUpdateCriterion(meta: Tristate[String], arms: Tristate[Seq[Long]], text: Option[String], isCompound: Option[Boolean], + inclusion: Tristate[Boolean], labels: Tristate[Seq[ApiCriterionLabel]]) { def applyTo(orig: RichCriterion): RichCriterion = RichCriterion( @@ -27,7 +28,8 @@ final case class ApiUpdateCriterion(meta: Tristate[String], meta = meta.cata(identity, "{}", orig.meta), text = text.orElse(orig.text), isCompound = isCompound.getOrElse(orig.isCompound), - trialId = orig.trialId + trialId = orig.trialId, + inclusion = inclusion.cata(x => Some(x), None, orig.inclusion) ) } @@ -45,6 +47,7 @@ object ApiUpdateCriterion { (JsPath \ "arms").readTristate(seqJsonFormat[Long]) and (JsPath \ "text").readNullable[String] and (JsPath \ "isCompound").readNullable[Boolean] and + (JsPath \ "inclusion").readTristate[Boolean] and (JsPath \ "labels").readTristate(seqJsonFormat[ApiCriterionLabel]) )(ApiUpdateCriterion.apply _) @@ -53,6 +56,7 @@ object ApiUpdateCriterion { (JsPath \ "arms").writeTristate(seqJsonFormat[Long]) and (JsPath \ "text").writeNullable[String] and (JsPath \ "isCompound").writeNullable[Boolean] and + (JsPath \ "inclusion").writeTristate[Boolean] and (JsPath \ "labels").writeTristate(seqJsonFormat[ApiCriterionLabel]) )(unlift(ApiUpdateCriterion.unapply)) diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/criterion.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/criterion.scala index 743f885..8da719c 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/criterion.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/criterion.scala @@ -73,6 +73,11 @@ object criterion { .map(_.convertTo[Option[String]].getOrElse("{}")) .getOrElse(orig.criterion.meta) + val inclusion = fields + .get("inclusion") + .map(_.convertTo[Option[Boolean]]) + .getOrElse(orig.criterion.inclusion) + val arms = fields .get("arms") .map(_.convertTo[Option[List[LongId[Arm]]]].getOrElse(List.empty[LongId[Arm]])) @@ -88,7 +93,8 @@ object criterion { criterion = orig.criterion.copy( meta = meta, text = text, - isCompound = isCompound + isCompound = isCompound, + inclusion = inclusion ), armIds = arms, labels = labels @@ -106,7 +112,8 @@ object criterion { "text" -> obj.criterion.text.toJson, "isCompound" -> obj.criterion.isCompound.toJson, "labels" -> obj.labels.map(_.toJson).toJson, - "trialId" -> obj.criterion.trialId.toJson + "trialId" -> obj.criterion.trialId.toJson, + "inclusion" -> obj.criterion.inclusion.toJson ) override def read(json: JsValue): RichCriterion = json match { @@ -129,6 +136,11 @@ object criterion { .map(_.convertTo[String]) .getOrElse("") + val inclusion = fields + .get("inclusion") + .map(_.convertTo[Option[Boolean]]) + .getOrElse(None) + val arms = fields .get("arms") .map(_.convertTo[List[LongId[Arm]]]) @@ -146,7 +158,8 @@ object criterion { trialId = trialId, text = text, isCompound = isCompound, - meta = meta + meta = meta, + inclusion = inclusion ), armIds = arms, labels = labels -- cgit v1.2.3