Skip to content

Commit

Permalink
ok fine separate method
Browse files Browse the repository at this point in the history
  • Loading branch information
calypsomatic committed Aug 14, 2023
1 parent a1487a3 commit 7e29d1f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,7 @@ trait TSVFileSupport {
if (value.equals("__DELETE__"))
RemoveAttribute(AttributeName.fromDelimitedName(name))
else {
//stringToTypedAttribute
AddUpdateAttribute(AttributeName.fromDelimitedName(name), stringToTypedAttribute(StringContext.processEscapes(value)))
// AddUpdateAttribute(AttributeName.fromDelimitedName(name), AttributeString(StringContext.processEscapes(value)))
AddUpdateAttribute(AttributeName.fromDelimitedName(name), checkForJson(StringContext.processEscapes(value)))
}
}
}
Expand Down Expand Up @@ -163,20 +161,22 @@ trait TSVFileSupport {
case _ => Try(BooleanUtils.toBoolean(value.toLowerCase, "true", "false")) match {
case Success(booleanValue) => AttributeBoolean(booleanValue)
case Failure(_) =>
Try(value.parseJson) match {
case Success(jsVal) =>
Try(jsVal.convertTo[AttributeEntityReference]) match {
case Success(ref) => ref
case Failure(_) => AttributeValueRawJson(value)
}
Try(value.parseJson.convertTo[AttributeEntityReference]) match {
case Success(ref) => ref
case Failure(_) => AttributeString(value)
}

}
}
}
}

def checkForJson(value: String): Attribute = {
Try(value.parseJson) match {
case Success(jsVal) => AttributeValueRawJson(value)
case Failure(_) => AttributeString(value)
}
}

def matchesLiteral(value: String): Boolean = {
value.toLowerCase().endsWith("d") || value.toLowerCase().endsWith("f")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.broadinstitute.dsde.firecloud.mock
import akka.http.scaladsl.model.Multipart
import akka.http.scaladsl.model.Multipart.FormData.BodyPart
import org.broadinstitute.dsde.firecloud.utils.TSVLoadFile
import org.broadinstitute.dsde.rawls.model.AttributeValueRawJson

object MockTSVStrings {

Expand Down Expand Up @@ -309,7 +310,7 @@ object MockTSVLoadFiles {
Seq("foo", "bar", "baz"),
Seq(Seq("woop", "", "doo")))

val validWorkspaceAttributes = TSVLoadFile("workspace", Seq("a1", "a2", "a3"), Seq(Seq("v1", "2", "[1,2,3]")))
val validWorkspaceAttributes = TSVLoadFile("workspace", Seq("a1", "a2", "a3", "a4"), Seq(Seq("v1", "2", "[1,2,3]","""{"tables":{"sample":{"save":["participant",false,"sample",true]}}}""")))
val validOneWorkspaceAttribute = TSVLoadFile("workspace", Seq("a1"), Seq(Seq("v1")))
val validEmptyStrWSAttribute = TSVLoadFile("workspace", Seq("a1"), Seq(Seq("")))
val validRemoveWSAttribute = TSVLoadFile("workspace", Seq("a1"), Seq(Seq("__DELETE__")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ class TSVFileSupportSpec extends AnyFreeSpec with TSVFileSupport {
val attributes = getWorkspaceAttributeCalls(MockTSVLoadFiles.validWorkspaceAttributes)
assertResult(attributes) {
List(AddUpdateAttribute(AttributeName("default", "a1"), AttributeString("v1")),
AddUpdateAttribute(AttributeName("default", "a2"), AttributeString("2")),
AddUpdateAttribute(AttributeName("default", "a3"), AttributeValueRawJson("[1,2,3]")))
AddUpdateAttribute(AttributeName("default", "a2"), AttributeValueRawJson("2")),
AddUpdateAttribute(AttributeName("default", "a3"), AttributeValueRawJson("[1,2,3]")),
AddUpdateAttribute(AttributeName("default", "a4"), AttributeValueRawJson("""{"tables":{"sample":{"save":["participant",false,"sample",true]}}}""")
))
}
}

Expand Down Expand Up @@ -142,13 +144,13 @@ class TSVFileSupportSpec extends AnyFreeSpec with TSVFileSupport {
}
}

"should detect json values when applicable" in {
jsonTestCases foreach {
case (input, expected) => withClue(s"should handle potential reference: $input") {
stringToTypedAttribute(input) shouldBe expected
}
}
}
// "should detect json values when applicable" in {
// jsonTestCases foreach {
// case (input, expected) => withClue(s"should handle potential reference: $input") {
// stringToTypedAttribute(input) shouldBe expected
// }
// }
// }

"should detect string values when applicable" in {
stringTestCases foreach {
Expand Down

0 comments on commit 7e29d1f

Please sign in to comment.