Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
SPB_Exchange_Repo
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Amelin Konstantin
SPB_Exchange_Repo
Commits
ee6e333a
Commit
ee6e333a
authored
Oct 22, 2018
by
Amelin Konstantin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Define correct type to template factory. Add attrIsEmty to render, fix RepoTemplate
parent
0abb089c
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
13 additions
and
14 deletions
+13
-14
src/main/scala/Main.scala
+2
-3
src/main/scala/templates/Logger.scala
+1
-6
src/main/scala/templates/RepoTemplate.scala
+2
-2
src/main/scala/templates/Template.scala
+7
-2
src/test/scala/templates/TemplateSpec.scala
+1
-1
No files found.
src/main/scala/Main.scala
View file @
ee6e333a
...
...
@@ -5,13 +5,13 @@ import templates._
object
Main
extends
App
{
implicit
def
templateFactory
(
source
:
Node
)
:
Template
with
Logger
=
{
implicit
def
templateFactory
(
source
:
Node
)
:
Template
with
Logger
=
{
(
source
\
"trade"
).
head
.
child
.
filter
{
case
v
:
Elem
=>
true
case
_
=>
false
}(
1
).
label
match
{
case
"repo"
=>
new
RepoTemplate
(
source
)
with
Debug
Logger
case
"repo"
=>
new
RepoTemplate
(
source
)
with
Logger
case
v
=>
throw
new
Exception
(
"Undefined trade type"
)
}
}
...
...
@@ -24,7 +24,6 @@ object Main extends App {
template
.
log
()
Try
{
XMLValid
(
"src/main/resources/nsd/nsd-ext-merged-schema.xsd"
).
loadString
(
sourceXml
.
mkString
)
}
match
{
...
...
src/main/scala/templates/
l
ogger.scala
→
src/main/scala/templates/
L
ogger.scala
View file @
ee6e333a
...
...
@@ -6,11 +6,6 @@ import scala.xml.{Node, Text}
trait
Logger
{
this:
Template
=>
def
log
()
:
Unit
=
()
}
trait
DebugLogger
extends
Logger
{
this:
Template
=>
private
[
this
]
val
data
=
{
val
m
:
mutable.LinkedHashMap
[
Int
,
mutable.Queue
[(
String
,
String
,
mutable.LinkedHashMap
[
Int
,
(
String
,
String
)])]]
=
...
...
@@ -65,5 +60,5 @@ trait DebugLogger extends Logger {
case
_
=>
Text
(
msgNotFound
)
}
override
def
log
()
:
Unit
=
data
.
foreach
(
e
=>
println
(
e
.
_2
))
def
log
()
:
Unit
=
data
.
foreach
(
e
=>
println
(
e
.
_2
))
}
src/main/scala/templates/RepoTemplate.scala
View file @
ee6e333a
...
...
@@ -181,10 +181,10 @@ class RepoTemplate(source: Node) extends TradeTemplate(source) {
*/
}
</fpmlext:forwardLeg>
<fpml:equity
id
={
get
(
Try
{
(
source
\
"trade"
\
"repo"
\
"equity"
).
head
},
"id"
)
}>
<
fpml
:
instrumentId
instrumentIdScheme
=
""
>{
get
(
Try
{
(
source
\
"trade"
\
"repo"
\
"equity"
\
"instrumentId"
).
head
})
}</
fpml
:
instrumentId>
<
fpml
:
instrumentId
instrumentIdScheme
=
{
get
(
Try
{
(
source
\
"trade"
\
"repo"
\
"equity"
\
"instrumentId"
).
head
},
"instrumentIdScheme"
)
}
>{
get
(
Try
{
(
source
\
"trade"
\
"repo"
\
"equity"
\
"instrumentId"
).
head
})
}</
fpml
:
instrumentId>
</fpml:equity>
<fpml:bond
id
={
get
(
Try
{
(
source
\
"trade"
\
"repo"
\
"bond"
).
head
},
"id"
)
}>
<
fpml
:
instrumentId
instrumentIdScheme
=
""
>{
get
(
Try
{
(
source
\
"trade"
\
"repo"
\
"bond"
\
"instrumentId"
).
head
})
}</
fpml
:
instrumentId>
<
fpml
:
instrumentId
instrumentIdScheme
=
{
get
(
Try
{
(
source
\
"trade"
\
"repo"
\
"bond"
\
"instrumentId"
).
head
},
"instrumentIdScheme"
)
}
>{
get
(
Try
{
(
source
\
"trade"
\
"repo"
\
"bond"
\
"instrumentId"
).
head
})
}</
fpml
:
instrumentId>
</fpml:bond>
</fpmlext:repo>
<fpml:documentation>
...
...
src/main/scala/templates/Template.scala
View file @
ee6e333a
...
...
@@ -19,6 +19,11 @@ abstract class Template(protected[this] val source: Node) {
def
template
:
Node
def
render
:
Node
=
{
def
attrIsEmpty
(
n
:
Node
)
:
Boolean
=
n
match
{
case
v
:
Elem
if
v.child.isEmpty
=>
v
.
attributes
.
isEmpty
case
v
=>
v
.
attributes
.
isEmpty
&&
v
.
child
.
forall
(
attrIsEmpty
)
}
val
rule1
:
RewriteRule
=
new
RewriteRule
{
override
def
transform
(
n
:
Node
)
:
NodeSeq
=
n
match
{
case
v
:
Elem
if
v.attributes.nonEmpty
&&
v.attributes.value.text.contains
(
msgNotFound
)
=>
...
...
@@ -31,7 +36,7 @@ abstract class Template(protected[this] val source: Node) {
override
def
transform
(
n
:
Node
)
:
NodeSeq
=
n
match
{
case
v
if
v
.
text
==
msgNotFound
=>
NodeSeq
.
Empty
case
v
:
Elem
if
v.text.filterNot
(
_
.isWhitespace
)
.isEmpty
=>
case
v
:
Elem
if
attrIsEmpty
(
v
)
&&
v.text.filterNot
(
_
.isWhitespace
)
.isEmpty
=>
NodeSeq
.
Empty
case
_
=>
n
}
...
...
@@ -45,7 +50,7 @@ abstract class Template(protected[this] val source: Node) {
}
object
Template
{
def
apply
(
source
:
Node
)(
implicit
templateFactory
:
Node
=>
Template
with
Logger
)
:
Template
with
Logger
=
templateFactory
(
source
)
def
apply
[
T
<:
Template
](
source
:
Node
)(
implicit
templateFactory
:
Node
=>
T
)
:
T
=
templateFactory
(
source
)
}
src/test/scala/templates/TemplateSpec.scala
View file @
ee6e333a
...
...
@@ -56,7 +56,7 @@ class TemplateSpec extends WordSpec {
{
get
(
Try
{
(
source
\\
"repo"
\
"from"
).
head
})
}
</
from
>
<
to
href
={
get
(
Try
{
(
source
\\
"repo"
\
"to"
).
head
},
"href"
)
}>
{
get
(
Try
{
(
source
\\
"repo"
\
"
to
"
).
head
})
}
{
get
(
Try
{
(
source
\\
"repo"
\
"
notExist
"
).
head
})
}
</
to
>
</
repo
>
<
notFoundpart
>{
get
(
Try
{
(
source
\\
"notFoundpart"
).
head
})
}</
notFoundpart
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment