Skip to content
Snippets Groups Projects
Select Git revision
  • 6748b406d1af107b78b94772cfa4a95799bd3bf0
  • master default
  • JS-based-scroll-rendering
  • Paul_Marius_Level
  • Paul_Marius_2
  • Paul_Marius
  • Andi_Mark
  • be-UnityWebView
  • gitignoreFrameitServer
  • ZimmerBSc
  • Bugfix_StageLoading
  • stages
  • MAZIFAU_Experimental
  • tsc/coneworld
  • tsc/fact-interaction
  • marcel
  • MaZiFAU_TopSort
  • mergeHelper
  • zwischenSpeichern
  • tempAndrToMaster
  • SebBranch
  • 3.0
  • v2.1
  • v2.0
  • v1.0
25 results

TestPointFact.cs

Blame
  • 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)"
    }