Select Git revision
MasterDevs.ChromeDevTools.Sample.csproj
ErrorStore.scala 2.52 KiB
package info.kwarc.mmt.errorview
import java.util
import org.apache.camel.model.RouteDefinition
import org.apache.camel.scala.dsl.builder.RouteBuilder
import scala.collection.JavaConverters._
import scala.collection.immutable.HashMap
/**
* Created by maeder on 13.01.15.
* an interface to store errors
*/
trait ErrorStore {
def insertError(f: String, t: String, smsg: String, level: String, lmsg: String): Unit
def queryValues(count: Boolean, subString: String, field: String): Unit
}
class SQLiteStore extends RouteBuilder with ErrorStore {
def insertError(f: String, t: String, smsg: String, level: String, lmsg: String): Unit = {
val hm = HashMap("fileName" -> f, "errType" -> t,
"shortMsg" -> smsg, "errLevel" -> level, "longMsg" -> lmsg)
getContext.createProducerTemplate().sendBody("direct:insertValues", hm.asJava)
}
def initTable(): Unit =
getContext.createProducerTemplate().sendBody("direct:createTables", null)
def body2str(dir: String, count: Boolean, subString: String, field: String, b: Object): String = {
b match {
case lm: util.ArrayList[_] =>
(lm.asScala map {
case jm: util.HashMap[String, Integer] if count =>
"count where " + field + " contains " + subString + ": " +
jm.asScala.getOrElse("count(*)", 0)
case jm: util.HashMap[String, String] if !count =>
val sm = jm.asScala
sm.getOrElse("fileName", "").stripPrefix(dir) +
": " + sm.getOrElse(field, "")
}).mkString("\n")
case x => "unexpected body type: " + x.getClass
}
}
def queryValues(count: Boolean, subString: String, field: String): Unit = {
val w = field + " like '%" + subString + "%'"
val q = "db:select " + (if (count) "count(*)" else "*") + " from errStore where " + w
val d = "direct:" + q
val r: RouteDefinition = d ==> {
-->(q).transform(ex =>
body2str("/local/maeder/tptp/Distribution/errors/", count, subString, field, ex.getIn.getBody))
-->("stream:out")
}
getContext.addRouteDefinition(r)
getContext.createProducerTemplate().sendBody(d, null)
getContext.removeRouteDefinition(r)
}
"direct:insertValues" -->
"db:insert into errStore (fileName, errType, shortMsg, errLevel, longMsg) values (:#fileName, :#errType, :#shortMsg, :#errLevel, :#longMsg)"
"direct:createTables" --> "db:drop table if exists errStore" -->
"db:create table errStore (id integer primary key, fileName string, errType string, shortMsg string, errLevel string, longMsg string)"
}