Commit 18920b58 authored by Peter van 't Hof's avatar Peter van 't Hof

Fixed filter bug

parent 7eab836c
......@@ -118,7 +118,9 @@ object Schema {
}
val files = TableQuery[Files]
case class Executable(runId: Int, toolName: String, version: Option[String], path: Option[String], javaVersion: Option[String], exeMd5: Option[String], javaMd5: Option[String], jarPath: Option[String])
case class Executable(runId: Int, toolName: String, version: Option[String] = None,
path: Option[String] = None, javaVersion: Option[String] = None,
exeMd5: Option[String] = None, javaMd5: Option[String] = None, jarPath: Option[String] = None)
class Executables(tag: Tag) extends Table[Executable](tag, "Executables") {
def runId = column[Int]("runId")
def toolName = column[String]("toolName")
......
......@@ -164,7 +164,8 @@ class SummaryDb(db: Database) extends Closeable {
private def statsFilter(runId: Option[Int] = None, pipelineId: Option[Int] = None, moduleId: Option[Option[Int]] = None,
sampleId: Option[Option[Int]] = None, libId: Option[Option[Int]] = None) = {
var f = stats.filter(_.runId === runId)
var f: Query[Stats, Stats#TableElementType, Seq] = stats
runId.foreach(r => f = f.filter(_.runId === r))
pipelineId.foreach(r => f = f.filter(_.pipelineId === r))
moduleId.foreach(r => f = (if (r.isDefined) f.filter(_.moduleId === r.get) else f.filter(_.moduleId.isEmpty)))
sampleId.foreach(r => f = (if (r.isDefined) f.filter(_.sampleId === r.get) else f.filter(_.sampleId.isEmpty)))
......@@ -198,7 +199,9 @@ class SummaryDb(db: Database) extends Closeable {
def settingsFilter(runId: Option[Int] = None, pipelineId: Option[Int] = None, moduleId: Option[Option[Int]] = None,
sampleId: Option[Option[Int]] = None, libId: Option[Option[Int]] = None) = {
var f = settings.filter(_.runId === runId).filter(_.pipelineId === pipelineId)
var f: Query[Settings, Settings#TableElementType, Seq] = settings
runId.foreach(r => f = f.filter(_.runId === r))
pipelineId.foreach(r => f = f.filter(_.pipelineId === r))
moduleId.foreach(r => f = (if (r.isDefined) f.filter(_.moduleId === r.get) else f.filter(_.moduleId.isEmpty)))
sampleId.foreach(r => f = (if (r.isDefined) f.filter(_.sampleId === r.get) else f.filter(_.sampleId.isEmpty)))
libId.foreach(r => f = (if (r.isDefined) f.filter(_.libraryId === r.get) else f.filter(_.libraryId.isEmpty)))
......@@ -235,7 +238,10 @@ class SummaryDb(db: Database) extends Closeable {
def filesFilter(runId: Option[Int] = None, pipelineId: Option[Int] = None, moduleId: Option[Option[Int]],
sampleId: Option[Option[Int]] = None, libId: Option[Option[Int]] = None,
key: Option[String] = None) = {
var f = files.filter(_.runId === runId).filter(_.pipelineId === pipelineId).filter(_.key === key)
var f: Query[Files, Files#TableElementType, Seq] = files
runId.foreach(r => f = f.filter(_.runId === r))
pipelineId.foreach(r => f = f.filter(_.pipelineId === r))
key.foreach(r => f = f.filter(_.key === r))
moduleId.foreach(r => f = (if (r.isDefined) f.filter(_.moduleId === r.get) else f.filter(_.moduleId.isEmpty)))
sampleId.foreach(r => f = (if (r.isDefined) f.filter(_.sampleId === r.get) else f.filter(_.sampleId.isEmpty)))
libId.foreach(r => f = (if (r.isDefined) f.filter(_.libraryId === r.get) else f.filter(_.libraryId.isEmpty)))
......@@ -264,10 +270,13 @@ class SummaryDb(db: Database) extends Closeable {
}
def executablesFilter(runId: Option[Int], toolName: Option[String]) = {
executables.filter(_.runId === runId).filter(_.toolName === toolName)
var q: Query[Executables, Executables#TableElementType, Seq] = executables
runId.foreach(r => q = q.filter(_.runId === r))
toolName.foreach(r => q = q.filter(_.toolName === r))
q
}
def getExecutables(runId: Option[Int], toolName: Option[String]) = {
def getExecutables(runId: Option[Int] = None, toolName: Option[String] = None) = {
db.run(executablesFilter(runId, toolName).result)
}
......
......@@ -26,7 +26,7 @@ class SummaryDbTest extends TestNGSuite with Matchers {
Await.result(db.getSetting(0,0, None, None, None), Duration.Inf) shouldBe Some(Map("content" -> "test"))
Await.result(db.createOrUpdateSetting(0, 0, None, None, None, """{"content": "test2" }"""), Duration.Inf)
Await.result(db.getSetting(0,0, None, None, None), Duration.Inf) shouldBe Some(Map("content" -> "test2"))
db.close()
}
@Test
......@@ -40,6 +40,21 @@ class SummaryDbTest extends TestNGSuite with Matchers {
Await.result(db.getStat(0, 0, None, None, None), Duration.Inf) shouldBe Some(Map("content" -> "test"))
Await.result(db.createOrUpdateStat(0, 0, None, None, None, """{"content": "test2" }"""), Duration.Inf)
Await.result(db.getStat(0, 0, None, None, None), Duration.Inf) shouldBe Some(Map("content" -> "test2"))
db.close()
}
@Test
def testExecutable: Unit = {
val dbFile = File.createTempFile("summary.", ".db")
dbFile.deleteOnExit()
val db = SummaryDb.openSqliteSummary(dbFile)
db.createTables()
Await.result(db.createOrUpdateExecutable(0, "name"), Duration.Inf)
val bla1 = Await.result(db.getExecutables(Some(0)), Duration.Inf)
Await.result(db.createOrUpdateExecutable(0, "name", Some("test")), Duration.Inf)
Await.result(db.getExecutables(Some(0)), Duration.Inf).head shouldBe Schema.Executable(0, "name", Some("test"))
db.close()
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment