Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mmt-errorView
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Christian Maeder
mmt-errorView
Commits
9f9f26bc
Commit
9f9f26bc
authored
Jan 27, 2015
by
cmaeder
Browse files
Options
Downloads
Patches
Plain Diff
added assertion and refactored
parent
34bff9fd
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/scala/ParseXML.scala
+5
-3
5 additions, 3 deletions
src/main/scala/ParseXML.scala
src/main/scala/PopulateDB.scala
+8
-5
8 additions, 5 deletions
src/main/scala/PopulateDB.scala
with
13 additions
and
8 deletions
src/main/scala/ParseXML.scala
+
5
−
3
View file @
9f9f26bc
...
...
@@ -5,8 +5,7 @@ import org.slf4j.{Logger, LoggerFactory}
import
scala.xml._
/**
* Created by maeder on 13.01.15.
* try parsing <error> tags
* try parsing <error> tags and populate database via inserting
*/
class
ParseXML
(
db
:
PopulateDB
)
{
val
log
:
Logger
=
LoggerFactory
.
getLogger
(
this
.
getClass
)
...
...
@@ -52,7 +51,10 @@ class ParseXML(db: PopulateDB) {
}
catch
{
case
e
:
NumberFormatException
=>
infoMessage
(
e
.
getMessage
)
}
db
.
insertError
(
List
(
f
.
getPath
,
t
,
smsg
,
level
,
x
.
text
))
// see Table.columns for the proper argument order
val
vs
=
List
(
f
.
getPath
,
t
,
smsg
,
level
,
x
.
text
)
assert
(
vs
.
length
==
Table
.
columns
.
length
)
db
.
insertRow
(
vs
)
if
(
elems
.
nonEmpty
)
infoMessage
(
"ignored sub-elements"
)
}
...
...
This diff is collapsed.
Click to expand it.
src/main/scala/PopulateDB.scala
+
8
−
5
View file @
9f9f26bc
...
...
@@ -10,18 +10,21 @@ import scala.collection.JavaConverters._
class
PopulateDB
extends
RouteBuilder
{
def
insertError
(
vs
:
List
[
String
])
:
Unit
=
{
val
insertRoute
=
"direct:insertRow"
val
initRoute
=
"direct:initTable"
def
insertRow
(
vs
:
List
[
String
])
:
Unit
=
{
val
hm
=
new
util
.
HashMap
[
String
,
String
]((
Table
.
columns
zip
vs
).
toMap
.
asJava
)
getContext
.
createProducerTemplate
().
sendBody
(
"direct:insertValues"
,
hm
)
getContext
.
createProducerTemplate
().
sendBody
(
insertRoute
,
hm
)
}
def
initTable
()
:
Unit
=
getContext
.
createProducerTemplate
().
sendBody
(
"direct:createTables"
,
null
)
getContext
.
createProducerTemplate
().
sendBody
(
initRoute
,
null
)
"direct:insertValues"
-->
insertRoute
-->
(
"db:insert into "
+
Table
.
name
+
Table
.
columns
.
mkString
(
" ("
,
", "
,
") values "
)
+
Table
.
columns
.
map
(
":#"
+
_
).
mkString
(
"("
,
", "
,
")"
))
"direct:createTables"
-->
(
"db:drop table if exists "
+
Table
.
name
)
-->
initRoute
-->
(
"db:drop table if exists "
+
Table
.
name
)
-->
(
"db:create table "
+
Table
.
name
+
Table
.
columns
.
map
(
_
+
" STRING"
).
mkString
(
" (id integer primary key, "
,
", "
,
")"
))
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment