diff --git a/src/main/scala/org/broadinstitute/dsde/firecloud/model/DUOS.scala b/src/main/scala/org/broadinstitute/dsde/firecloud/model/DUOS.scala deleted file mode 100644 index 773a4476a..000000000 --- a/src/main/scala/org/broadinstitute/dsde/firecloud/model/DUOS.scala +++ /dev/null @@ -1,119 +0,0 @@ -package org.broadinstitute.dsde.firecloud.model - -import spray.json._ -import spray.json.{JsObject, JsValue} - -object DUOS { - - case class DuosDataUse( - generalUse: Option[Boolean] = None, - hmbResearch: Option[Boolean] = None, - diseaseRestrictions: Option[Seq[String]] = None, - populationOriginsAncestry: Option[Boolean] = None, - populationStructure: Option[Boolean] = None, - commercialUse: Option[Boolean] = None, - methodsResearch: Option[Boolean] = None, - aggregateResearch: Option[String] = None, - controlSetOption: Option[String] = None, - gender: Option[String] = None, - pediatric: Option[Boolean] = None, - populationRestrictions: Option[Seq[String]] = None, - dateRestriction: Option[String] = None, - recontactingDataSubjects: Option[Boolean] = None, - recontactMay: Option[String] = None, - recontactMust: Option[String] = None, - genomicPhenotypicData: Option[String] = None, - otherRestrictions: Option[Boolean] = None, - cloudStorage: Option[String] = None, - ethicsApprovalRequired: Option[Boolean] = None, - geographicalRestrictions: Option[String] = None, - other: Option[String] = None, - illegalBehavior: Option[Boolean] = None, - addiction: Option[Boolean] = None, - sexualDiseases: Option[Boolean] = None, - stigmatizeDiseases: Option[Boolean] = None, - vulnerablePopulations: Option[Boolean] = None, - psychologicalTraits: Option[Boolean] = None, - nonBiomedical: Option[Boolean] = None - ) - - object DuosDataUse { - def apply(jsValues: Map[String, JsValue]): DuosDataUse = { - def getBoolean(f: String): Option[Boolean] = { - jsValues.get(f) match { - case Some(b: JsBoolean) => Some(b.value) - case _ => None - } - } - def getSeqString(f: String): Option[Seq[String]] = { - jsValues.get(f) match { - case Some(l: JsArray) => Some(l.elements.collect { case s: JsString => s.value }) - case _ => None - } - } - def getString(f: String): Option[String] = { - jsValues.get(f) match { - case Some(s: JsString) => Some(s.value) - case _ => None - } - } - new DuosDataUse( - generalUse = getBoolean("generalUse"), - hmbResearch = getBoolean("hmbResearch"), - diseaseRestrictions = getSeqString("diseaseRestrictions"), - populationOriginsAncestry = getBoolean("populationOriginsAncestry"), - populationStructure = getBoolean("populationStructure"), - commercialUse = getBoolean("commercialUse"), - methodsResearch = getBoolean("methodsResearch"), - aggregateResearch = getString("aggregateResearch"), - controlSetOption = getString("controlSetOption"), - gender = getString("gender"), - pediatric = getBoolean("pediatric"), - populationRestrictions = getSeqString("populationRestrictions"), - dateRestriction = getString("dateRestriction"), - recontactingDataSubjects = getBoolean("recontactingDataSubjects"), - recontactMay = getString("recontactMay"), - recontactMust = getString("recontactMust"), - genomicPhenotypicData = getString("genomicPhenotypicData"), - otherRestrictions = getBoolean("otherRestrictions"), - cloudStorage = getString("cloudStorage"), - ethicsApprovalRequired = getBoolean("ethicsApprovalRequired"), - geographicalRestrictions = getString("geographicalRestrictions"), - other = getString("other"), - illegalBehavior = getBoolean("illegalBehavior"), - addiction = getBoolean("addiction"), - sexualDiseases = getBoolean("sexualDiseases"), - stigmatizeDiseases = getBoolean("stigmatizeDiseases"), - vulnerablePopulations = getBoolean("vulnerablePopulations"), - psychologicalTraits = getBoolean("psychologicalTraits"), - nonBiomedical = getBoolean("nonBiomedical") - ) - } - } - - case class Consent( - consentId: String, - name: String, - createDate: Option[Long] = None, - lastUpdate: Option[Long] = None, - sortDate: Option[Long] = None, - requiresManualReview: Option[Boolean] = None, - dataUseLetter: Option[String] = None, - useRestriction: Option[JsObject] = None, - dulName: Option[String] = None, - translatedUseRestriction: Option[String] = None, - dataUse: Option[DuosDataUse] = None - ) - - case class ConsentError( - message: String, - code: Int - ) - - case class ConsentStatus( - ok: Option[Boolean], - degraded: Option[Boolean], - systems: Option[Map[String, DropwizardHealth]] - ) - -} diff --git a/src/main/scala/org/broadinstitute/dsde/firecloud/model/ModelJsonProtocol.scala b/src/main/scala/org/broadinstitute/dsde/firecloud/model/ModelJsonProtocol.scala index 804d106d0..65d47cd41 100644 --- a/src/main/scala/org/broadinstitute/dsde/firecloud/model/ModelJsonProtocol.scala +++ b/src/main/scala/org/broadinstitute/dsde/firecloud/model/ModelJsonProtocol.scala @@ -5,7 +5,6 @@ import akka.http.scaladsl.model.StatusCode import akka.http.scaladsl.model.StatusCodes._ import akka.http.scaladsl.server.Directives._ import akka.http.scaladsl.server.{MalformedRequestContentRejection, RejectionHandler} -import org.broadinstitute.dsde.firecloud.model.DUOS._ import org.broadinstitute.dsde.firecloud.model.DataUse._ import org.broadinstitute.dsde.firecloud.model.ManagedGroupRoles.ManagedGroupRole import org.broadinstitute.dsde.firecloud.model.OrchMethodRepository._ @@ -20,7 +19,7 @@ import org.broadinstitute.dsde.rawls.model._ import org.broadinstitute.dsde.workbench.model.ValueObjectFormat import org.broadinstitute.dsde.workbench.model.WorkbenchIdentityJsonSupport._ import org.broadinstitute.dsde.workbench.model.google.GoogleModelJsonSupport.InstantFormat -import spray.json.{JsString, _} +import spray.json._ import scala.util.{Failure, Success, Try} @@ -279,38 +278,11 @@ object ModelJsonProtocol extends WorkspaceJsonSupport with SprayJsonSupport { implicit val impStructuredDataRequest: RootJsonFormat[StructuredDataRequest] = jsonFormat12(StructuredDataRequest) implicit val impStructuredDataResponse: RootJsonFormat[StructuredDataResponse] = jsonFormat4(StructuredDataResponse) - implicit object impDuosDataUse extends RootJsonFormat[DuosDataUse] { - override def write(ddu: DuosDataUse): JsValue = { - val existingProps: Seq[(String, JsValue)] = Try(ddu.getClass.getDeclaredFields.map { f => - f.setAccessible(true) - f.get(ddu) match { - case Some(x: Boolean) => f.getName -> x.toJson - case Some(y: String) => f.getName -> y.toJson - case Some((h: String) :: tail) => f.getName -> (h +: tail.collect { case z: String => z }).toJson - case _ => f.getName -> JsNull - } - }) match { - case Success(props) => props.toIndexedSeq.filterNot(_._2 == JsNull) - case Failure(ex) => serializationError(ex.getMessage) - } - JsObject(existingProps.toMap) - } - override def read(json: JsValue): DuosDataUse = { - Try(DuosDataUse.apply(json.asJsObject.fields)) match { - case Success(ddu) => ddu - case Failure(ex) => deserializationError(s"Could not read DuosDataUse value: $json", ex) - } - } - } - implicit val impDuosConsent: RootJsonFormat[Consent] = jsonFormat11(Consent) - implicit val impDuosConsentError: RootJsonFormat[ConsentError] = jsonFormat2(ConsentError) implicit val impOntologyTermParent: RootJsonFormat[TermParent] = jsonFormat5(TermParent) implicit val impOntologyTermResource: RootJsonFormat[TermResource] = jsonFormat7(TermResource) implicit val impOntologyESTermParent: RootJsonFormat[ESTermParent] = jsonFormat2(ESTermParent) implicit val impThurloeStatus: RootJsonFormat[ThurloeStatus] = jsonFormat2(ThurloeStatus) - implicit val impDropwizardHealth: RootJsonFormat[DropwizardHealth] = jsonFormat2(DropwizardHealth) - implicit val impDuosConsentStatus: RootJsonFormat[ConsentStatus] = jsonFormat3(ConsentStatus) // don't make this implicit! It would be pulled in by anything including ModelJsonProtocol._ val entityExtractionRejectionHandler = RejectionHandler.newBuilder().handle { diff --git a/src/main/scala/org/broadinstitute/dsde/firecloud/model/SystemStatus.scala b/src/main/scala/org/broadinstitute/dsde/firecloud/model/SystemStatus.scala index 204a5da8b..cdf214b75 100644 --- a/src/main/scala/org/broadinstitute/dsde/firecloud/model/SystemStatus.scala +++ b/src/main/scala/org/broadinstitute/dsde/firecloud/model/SystemStatus.scala @@ -4,4 +4,3 @@ package org.broadinstitute.dsde.firecloud.model * Created by anichols on 4/7/17. */ case class ThurloeStatus(status: String, error: Option[String]) -case class DropwizardHealth(healthy: Boolean, message: Option[String]) diff --git a/src/test/scala/org/broadinstitute/dsde/firecloud/model/DuosModelSpec.scala b/src/test/scala/org/broadinstitute/dsde/firecloud/model/DuosModelSpec.scala deleted file mode 100644 index 7c199a228..000000000 --- a/src/test/scala/org/broadinstitute/dsde/firecloud/model/DuosModelSpec.scala +++ /dev/null @@ -1,237 +0,0 @@ -package org.broadinstitute.dsde.firecloud.model - -import org.broadinstitute.dsde.firecloud.model.DUOS.DuosDataUse -import org.scalatest.freespec.AnyFreeSpec -import org.scalatest.matchers.should.Matchers -import spray.json._ - -class DuosModelSpec extends AnyFreeSpec with Matchers { - - private implicit val impDuosDataUse: ModelJsonProtocol.impDuosDataUse.type = ModelJsonProtocol.impDuosDataUse - - "DUOS DuosDataUse" - { - - "Partially formed valid data use json should parse what's valid" - { - "generalUse: true, fooBar: 7" in { - val jsValues: Map[String, JsValue] = Map( - "generalUse" -> JsBoolean(true), - "fooBar" -> JsNumber(7) - ) - val duosDataUse: DuosDataUse = DuosDataUse.apply(jsValues) - duosDataUse.generalUse.getOrElse(false) shouldBe true - } - } - - "Incorrectly formed data use json should parse to an empty object" - { - - "generalUse: FOO" in { - val jsValues: Map[String, JsValue] = Map("generalUse" -> JsString("FOO")) - val duosDataUse: DuosDataUse = DuosDataUse.apply(jsValues) - assertIsUndefined(duosDataUse) - } - - "diseaseRestrictions: true" in { - val jsValues: Map[String, JsValue] = Map("diseaseRestrictions" -> JsBoolean(true)) - val duosDataUse: DuosDataUse = DuosDataUse.apply(jsValues) - assertIsUndefined(duosDataUse) - } - - "aggregateResearch: true" in { - val jsValues: Map[String, JsValue] = Map("aggregateResearch" -> JsBoolean(true)) - val duosDataUse: DuosDataUse = DuosDataUse.apply(jsValues) - assertIsUndefined(duosDataUse) - } - - "fooBar: 7, barBaz: [FOO, BAR]" in { - val vals = JsArray(JsString("FOO"), JsString("BAR")) - val jsValues: Map[String, JsValue] = Map( - "barBaz" -> JsArray(vals), - "fooBar" -> JsNumber(7) - ) - val duosDataUse: DuosDataUse = DuosDataUse.apply(jsValues) - assertIsUndefined(duosDataUse) - } - } - - "Correctly formed duos data use json should parse to a DuosDataUse" - { - "generalUse: true" in { - val jsValues: Map[String, JsValue] = Map("generalUse" -> JsBoolean(true)) - val duosDataUse: DuosDataUse = DuosDataUse.apply(jsValues) - duosDataUse.generalUse.getOrElse(false) shouldBe true - } - "hmbResearch: true" in { - val jsValues: Map[String, JsValue] = Map("hmbResearch" -> JsBoolean(true)) - val duosDataUse: DuosDataUse = DuosDataUse.apply(jsValues) - duosDataUse.hmbResearch.getOrElse(false) shouldBe true - } - "diseaseRestrictions: [DOID_1]" in { - val diseases = JsArray(JsString("DOID_1")) - val jsValues: Map[String, JsValue] = Map("diseaseRestrictions" -> diseases) - val duosDataUse: DuosDataUse = DuosDataUse.apply(jsValues) - val duosDiseases: Seq[String] = duosDataUse.diseaseRestrictions.getOrElse(Seq.empty[String]) - duosDiseases should not be empty - duosDiseases should contain theSameElementsInOrderAs Seq("DOID_1") - } - "diseaseRestrictions: [DOID_1, DOID_2]" in { - val diseases = JsArray(JsString("DOID_1"), JsString("DOID_2")) - val jsValues: Map[String, JsValue] = Map("diseaseRestrictions" -> diseases) - val duosDataUse: DuosDataUse = DuosDataUse.apply(jsValues) - val duosDiseases: Seq[String] = duosDataUse.diseaseRestrictions.getOrElse(Seq.empty[String]) - duosDiseases should not be empty - duosDiseases should contain theSameElementsInOrderAs Seq("DOID_1", "DOID_2") - } - "diseaseRestrictions: [DOID_1, DOID_2, DOID_2]" in { - val diseases = JsArray(JsString("DOID_1"), JsString("DOID_2"), JsString("DOID_3")) - val jsValues: Map[String, JsValue] = Map("diseaseRestrictions" -> diseases) - val duosDataUse: DuosDataUse = DuosDataUse.apply(jsValues) - val duosDiseases: Seq[String] = duosDataUse.diseaseRestrictions.getOrElse(Seq.empty[String]) - duosDiseases should not be empty - duosDiseases should contain theSameElementsInOrderAs Seq("DOID_1", "DOID_2", "DOID_3") - } - "populationOriginsAncestry: true" in { - val jsValues: Map[String, JsValue] = Map("populationOriginsAncestry" -> JsBoolean(true)) - val duosDataUse: DuosDataUse = DuosDataUse.apply(jsValues) - duosDataUse.populationOriginsAncestry.getOrElse(false) shouldBe true - } - "populationStructure: true" in { - val jsValues: Map[String, JsValue] = Map("populationStructure" -> JsBoolean(true)) - val duosDataUse: DuosDataUse = DuosDataUse.apply(jsValues) - duosDataUse.populationStructure.getOrElse(false) shouldBe true - } - "commercialUse: true" in { - val jsValues: Map[String, JsValue] = Map("commercialUse" -> JsBoolean(true)) - val duosDataUse: DuosDataUse = DuosDataUse.apply(jsValues) - duosDataUse.commercialUse.getOrElse(false) shouldBe true - } - "methodsResearch: true" in { - val jsValues: Map[String, JsValue] = Map("methodsResearch" -> JsBoolean(true)) - val duosDataUse: DuosDataUse = DuosDataUse.apply(jsValues) - duosDataUse.methodsResearch.getOrElse(false) shouldBe true - } - "aggregateResearch: Yes" in { - val jsValues: Map[String, JsValue] = Map("aggregateResearch" -> JsString("Yes")) - val duosDataUse: DuosDataUse = DuosDataUse.apply(jsValues) - duosDataUse.aggregateResearch.getOrElse(false) should equal("Yes") - } - "controlSetOption: No" in { - val jsValues: Map[String, JsValue] = Map("controlSetOption" -> JsString("No")) - val duosDataUse: DuosDataUse = DuosDataUse.apply(jsValues) - duosDataUse.controlSetOption.getOrElse(false) should equal("No") - } - "gender: F" in { - val jsValues: Map[String, JsValue] = Map("gender" -> JsString("F")) - val duosDataUse: DuosDataUse = DuosDataUse.apply(jsValues) - duosDataUse.gender.getOrElse(false) should equal("F") - } - "pediatric: true" in { - val jsValues: Map[String, JsValue] = Map("pediatric" -> JsBoolean(true)) - val duosDataUse: DuosDataUse = DuosDataUse.apply(jsValues) - duosDataUse.pediatric.getOrElse(false) shouldBe true - } - "populationRestrictions: [POP_1, POP_2]" in { - val pops = JsArray(JsString("POP_1"), JsString("POP_2")) - val jsValues: Map[String, JsValue] = Map("populationRestrictions" -> pops) - val duosDataUse: DuosDataUse = DuosDataUse.apply(jsValues) - val duosPops: Seq[String] = duosDataUse.populationRestrictions.getOrElse(Seq.empty[String]) - duosPops should not be empty - duosPops should contain theSameElementsInOrderAs Seq("POP_1", "POP_2") - } - "dateRestriction: 1/1/2018" in { - val jsValues: Map[String, JsValue] = Map("dateRestriction" -> JsString("1/1/2018")) - val duosDataUse: DuosDataUse = DuosDataUse.apply(jsValues) - duosDataUse.dateRestriction.getOrElse(false) should equal("1/1/2018") - } - "recontactingDataSubjects: true" in { - val jsValues: Map[String, JsValue] = Map("recontactingDataSubjects" -> JsBoolean(true)) - val duosDataUse: DuosDataUse = DuosDataUse.apply(jsValues) - duosDataUse.recontactingDataSubjects.getOrElse(false) shouldBe true - } - "recontactMay: No" in { - val jsValues: Map[String, JsValue] = Map("recontactMay" -> JsString("No")) - val duosDataUse: DuosDataUse = DuosDataUse.apply(jsValues) - duosDataUse.recontactMay.getOrElse(false) should equal("No") - } - "recontactMust: Yes" in { - val jsValues: Map[String, JsValue] = Map("recontactMust" -> JsString("Yes")) - val duosDataUse: DuosDataUse = DuosDataUse.apply(jsValues) - duosDataUse.recontactMust.getOrElse(false) should equal("Yes") - } - "genomicPhenotypicData: Yes" in { - val jsValues: Map[String, JsValue] = Map("genomicPhenotypicData" -> JsString("Yes")) - val duosDataUse: DuosDataUse = DuosDataUse.apply(jsValues) - duosDataUse.genomicPhenotypicData.getOrElse(false) should equal("Yes") - } - "otherRestrictions: true" in { - val jsValues: Map[String, JsValue] = Map("otherRestrictions" -> JsBoolean(true)) - val duosDataUse: DuosDataUse = DuosDataUse.apply(jsValues) - duosDataUse.otherRestrictions.getOrElse(false) shouldBe true - } - "cloudStorage: No" in { - val jsValues: Map[String, JsValue] = Map("cloudStorage" -> JsString("No")) - val duosDataUse: DuosDataUse = DuosDataUse.apply(jsValues) - duosDataUse.cloudStorage.getOrElse(false) should equal("No") - } - "ethicsApprovalRequired: true" in { - val jsValues: Map[String, JsValue] = Map("ethicsApprovalRequired" -> JsBoolean(true)) - val duosDataUse: DuosDataUse = DuosDataUse.apply(jsValues) - duosDataUse.ethicsApprovalRequired.getOrElse(false) shouldBe true - } - "geographicalRestrictions: US" in { - val jsValues: Map[String, JsValue] = Map("geographicalRestrictions" -> JsString("US")) - val duosDataUse: DuosDataUse = DuosDataUse.apply(jsValues) - duosDataUse.geographicalRestrictions.getOrElse(false) should equal("US") - } - "other: Other" in { - val jsValues: Map[String, JsValue] = Map("other" -> JsString("Other")) - val duosDataUse: DuosDataUse = DuosDataUse.apply(jsValues) - duosDataUse.other.getOrElse(false) should equal("Other") - } - "illegalBehavior: true" in { - val jsValues: Map[String, JsValue] = Map("illegalBehavior" -> JsBoolean(true)) - val duosDataUse: DuosDataUse = DuosDataUse.apply(jsValues) - duosDataUse.illegalBehavior.getOrElse(false) shouldBe true - } - "addiction: true" in { - val jsValues: Map[String, JsValue] = Map("addiction" -> JsBoolean(true)) - val duosDataUse: DuosDataUse = DuosDataUse.apply(jsValues) - duosDataUse.addiction.getOrElse(false) shouldBe true - } - "sexualDiseases: true" in { - val jsValues: Map[String, JsValue] = Map("sexualDiseases" -> JsBoolean(true)) - val duosDataUse: DuosDataUse = DuosDataUse.apply(jsValues) - duosDataUse.sexualDiseases.getOrElse(false) shouldBe true - } - "stigmatizeDiseases: true" in { - val jsValues: Map[String, JsValue] = Map("stigmatizeDiseases" -> JsBoolean(true)) - val duosDataUse: DuosDataUse = DuosDataUse.apply(jsValues) - duosDataUse.stigmatizeDiseases.getOrElse(false) shouldBe true - } - "vulnerablePopulations: true" in { - val jsValues: Map[String, JsValue] = Map("vulnerablePopulations" -> JsBoolean(true)) - val duosDataUse: DuosDataUse = DuosDataUse.apply(jsValues) - duosDataUse.vulnerablePopulations.getOrElse(false) shouldBe true - } - "psychologicalTraits: true" in { - val jsValues: Map[String, JsValue] = Map("psychologicalTraits" -> JsBoolean(true)) - val duosDataUse: DuosDataUse = DuosDataUse.apply(jsValues) - duosDataUse.psychologicalTraits.getOrElse(false) shouldBe true - } - "nonBiomedical: true" in { - val jsValues: Map[String, JsValue] = Map("nonBiomedical" -> JsBoolean(true)) - val duosDataUse: DuosDataUse = DuosDataUse.apply(jsValues) - duosDataUse.nonBiomedical.getOrElse(false) shouldBe true - } - } - } - - private def assertIsUndefined(duosDataUse: DuosDataUse): Unit = { - duosDataUse.getClass.getDeclaredFields map { f => - f.setAccessible(true) - f.get(duosDataUse) match { - case Some(x) => fail(s"Field ${f.getName} should not be defined") - case None => // passing cass - } - } - } - -}