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
1354bc97
Commit
1354bc97
authored
Oct 25, 2018
by
Amelin Konstantin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add log to file, defined in application.conf
parent
10bfeca9
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
72 additions
and
38 deletions
+72
-38
README.md
+6
-4
src/main/resources/application.conf
+4
-0
src/main/scala/Main.scala
+29
-19
src/main/scala/templates/Logger.scala
+23
-3
src/main/scala/templates/RepoTemplate.scala
+3
-0
src/main/scala/templates/Template.scala
+5
-1
src/test/scala/templates/TemplateSpec.scala
+2
-11
No files found.
README.md
View file @
1354bc97
...
...
@@ -10,17 +10,16 @@
Импортировать проект.
<https://www.jetbrains.com/help/idea/sbt-support.html#import_sbt>
## Запуск проекта
## Запуск проекта
dev mode
1) Создать в корне проекта папку
**output**
.
2) Запуск из терминала
```
sbt
run
sbt
"run input output"
или
sbt
~run
sbt
"~run input output"
```
3) Запуск из IDE.
<https://www.jetbrains.com/help/idea/discover-intellij-idea-for-scala.html#RunningDebugging>
4) Запуск тестов из терминала
...
...
@@ -29,4 +28,7 @@ sbt test
или
sbt ~test
```
## Запуск проекта production mode
1) Для отключения детального логгирования установить
**debug = false**
в src/main/resources/application.conf
src/main/resources/application.conf
View file @
1354bc97
...
...
@@ -2,3 +2,6 @@
# Set debug mode
debug
=
true
# Log file name
log
=
"log.txt"
\ No newline at end of file
src/main/scala/Main.scala
View file @
1354bc97
import
com.typesafe.config.
{
Config
,
ConfigFactory
}
import
scala.xml._
import
java.nio.file.
{
Files
,
Path
,
Paths
}
import
java.nio.file.
{
Files
,
Path
,
Paths
,
StandardOpenOption
}
import
java.time.LocalDateTime
import
scala.util.
{
Failure
,
Success
,
Try
}
import
xmlvalid._
import
templates._
...
...
@@ -8,14 +11,15 @@ import templates._
object
Main
{
val
conf
:
Config
=
ConfigFactory
.
load
val
debugMode
:
Boolean
=
conf
.
getBoolean
(
"debug"
)
val
logFileName
:
String
=
conf
.
getString
(
"log"
)
implicit
def
templateFactory
(
source
:
Node
)
:
Template
with
Logger
=
{
implicit
def
templateFactory
(
source
:
Node
)
:
Template
=
{
(
source
\
"trade"
).
head
.
child
.
filter
{
case
v
:
Elem
=>
true
case
_
=>
false
}(
1
).
label
match
{
case
"repo"
=>
new
RepoTemplate
(
source
)
with
Logger
case
"repo"
=>
if
(
debugMode
)
new
RepoTemplate
(
source
)
with
Logger
else
new
RepoTemplate
(
source
)
case
v
=>
throw
new
Exception
(
"Undefined trade type"
)
}
}
...
...
@@ -26,35 +30,41 @@ object Main {
else
if
(!
Files
.
exists
(
Paths
.
get
(
args
(
1
))))
println
(
"Error: OUTPUT directory doesn`t exist"
)
else
{
val
p
=
new
PrettyPrinter
(
140
,
2
)
val
nsdXmlValid
=
XMLValid
(
"src/main/resources/nsd/nsd-ext-merged-schema.xsd"
)
val
rtsXmlValid
=
XMLValid
(
"src/main/resources/rts/fpml-recordkeeping-merged-schema.xsd"
)
var
logString
=
""
for
(
v
<-
Files
.
walk
(
Paths
.
get
(
args
(
0
))).
toArray
)
{
val
f
=
v
.
asInstanceOf
[
Path
]
if
(!
Files
.
isDirectory
(
f
))
{
val
fName
=
f
.
getFileName
.
toString
.
split
(
'.'
)
for
(
v
<-
Files
.
walk
(
Paths
.
get
(
args
(
0
))).
toArray
;
f
=
v
.
asInstanceOf
[
Path
];
if
!
Files
.
isDirectory
(
f
))
{
val
fSourceName
=
f
.
getFileName
.
toString
val
fOutputName
=
s
"Converted_$fSourceName"
val
sourceXml
=
XML
.
loadFile
(
f
.
toString
)
val
template
=
Template
(
sourceXml
)
val
outputXml
=
XML
.
loadString
(
p
.
format
(
template
.
render
))
//val outputXml = template.template
val
now
=
LocalDateTime
.
now
().
toString
//template.log()
val
sourceXmlValid
=
if
(
template
.
isStraight
)
nsdXmlValid
else
rtsXmlValid
val
outputXmlValid
=
if
(
template
.
isStraight
)
rtsXmlValid
else
nsdXmlValid
Try
{
XMLValid
(
"src/main/resources/nsd/nsd-ext-merged-schema.xsd"
)
.
loadString
(
sourceXml
.
mkString
)
val
msgCheckSource
=
Try
{
sourceXmlValid
.
loadString
(
sourceXml
.
mkString
)
}
match
{
case
Success
(
_
)
=>
println
(
"Source xml success check against NSD schema"
)
case
Failure
(
ex
)
=>
println
(
s
"Source xml isn`t wellformed or invalid: ${ex.getMessage}"
)
case
Success
(
_
)
=>
s
"'$fSourceName' successfully checked against schema"
case
Failure
(
ex
)
=>
s
"'$fSourceName' isn`t wellformed or invalid: ${ex.getMessage}"
}
Try
{
XMLValid
(
"src/main/resources/rts/fpml-recordkeeping-merged-schema.xsd"
)
.
loadString
(
outputXml
.
mkString
)
val
msgCheckOutput
=
Try
{
outputXmlValid
.
loadString
(
outputXml
.
mkString
)
}
match
{
case
Success
(
_
)
=>
println
(
"Output xml success check against RTS schema"
)
case
Failure
(
ex
)
=>
println
(
s
"Output xml isn`t wellformed or invalid: ${ex.getMessage}"
)
case
Success
(
_
)
=>
s
"'$fOutputName' successfully checked against schema"
case
Failure
(
ex
)
=>
s
"'$fOutputName' isn`t wellformed or invalid: ${ex.getMessage}"
}
XML
.
save
(
Paths
.
get
(
args
(
1
),
fName
(
0
)
+
"_RTS."
+
fName
(
1
)).
toString
,
outputXml
,
xmlDecl
=
true
)
}
XML
.
save
(
Paths
.
get
(
args
(
1
),
fOutputName
).
toString
,
outputXml
,
xmlDecl
=
true
)
logString
+=
template
.
info
(
s
"$now\n$msgCheckSource\n$msgCheckOutput"
)
+
"\n\n"
}
Files
.
write
(
Paths
.
get
(
args
(
1
),
logFileName
),
logString
.
getBytes
(
"utf-8"
),
StandardOpenOption
.
CREATE
,
StandardOpenOption
.
TRUNCATE_EXISTING
)
}
}
}
src/main/scala/templates/Logger.scala
View file @
1354bc97
...
...
@@ -21,9 +21,9 @@ trait Logger {
m
.
get
(
idx
)
match
{
case
None
=>
m
(
idx
)
=
mutable
.
Queue
((
s
"tag: ${i.label}"
,
text
,
attr
))
m
(
idx
)
=
mutable
.
Queue
((
i
.
label
,
text
,
attr
))
case
_
=>
m
(
idx
).
enqueue
((
s
"tag: ${i.label}"
,
text
,
attr
))
m
(
idx
).
enqueue
((
i
.
label
,
text
,
attr
))
}
if
(
i
.
attributes
.
nonEmpty
)
{
...
...
@@ -61,5 +61,25 @@ trait Logger {
case
_
=>
Text
(
msgNotFound
)
}
def
log
()
:
Unit
=
data
.
foreach
(
e
=>
println
(
e
.
_2
))
override
def
info
(
msg
:
String
)
:
String
=
{
val
additionalInfo
=
data
.
filter
{
case
(
k
,
v
)
if
v
.
nonEmpty
=>
true
case
_
=>
false
}
.
toVector
.
flatMap
{
case
(
k
,
v
)
=>
v
}
.
filter
{
case
(
t
,
v
,
m
)
if
v
!=
null
||
(
m
!=
null
&&
m
.
nonEmpty
)
=>
true
case
_
=>
false
}
.
map
{
case
(
t
,
v
,
m
)
=>
s
"tag: $t, value: ${if (v != null) v else ""}"
+
(
if
(
m
!=
null
&&
m
.
nonEmpty
)
", "
+
m
.
toVector
.
map
{
case
(
k
,
v1
)
=>
v1
}.
map
{
case
(
k1
,
v2
)
=>
s
"attr: $k1, value: $v2"
}.
mkString
(
", "
)
else
""
)
}
.
mkString
(
"\n"
)
s
"$msg\nNot used:\n$additionalInfo"
}
}
src/main/scala/templates/RepoTemplate.scala
View file @
1354bc97
...
...
@@ -83,4 +83,6 @@ class RepoTemplate(source: Node) extends TradeTemplate(source) {
</fpml:bond>
</fpmlext:repo>
}
def
isStraight
=
true
}
\ No newline at end of file
src/main/scala/templates/Template.scala
View file @
1354bc97
...
...
@@ -19,6 +19,8 @@ abstract class Template(protected[this] val source: Node) {
def
template
:
Node
def
isStraight
:
Boolean
def
render
:
Node
=
{
def
attrIsEmpty
(
n
:
Node
)
:
Boolean
=
n
match
{
case
v
:
Elem
if
v.child.isEmpty
=>
v
.
attributes
.
isEmpty
...
...
@@ -48,10 +50,12 @@ abstract class Template(protected[this] val source: Node) {
rt2
.
transform
(
rt1
.
transform
(
template
)).
head
}
def
info
(
msg
:
String
)
:
String
=
msg
}
object
Template
{
def
apply
[
T
<:
Template
](
source
:
Node
)(
implicit
templateFactory
:
Node
=>
T
)
:
T
=
templateFactory
(
source
)
def
apply
(
source
:
Node
)(
implicit
templateFactory
:
Node
=>
Template
)
:
Template
=
templateFactory
(
source
)
}
src/test/scala/templates/TemplateSpec.scala
View file @
1354bc97
...
...
@@ -79,6 +79,8 @@ class TemplateSpec extends WordSpec {
</
nonpublicExecutionReport
>
</
document
>
}
def
isStraight
:
Boolean
=
true
}
"Template"
should
{
...
...
@@ -127,17 +129,6 @@ class TemplateSpec extends WordSpec {
assertThrows
[
Exception
]
{
val
template
=
Template
(
sourceXml
)
}
}
}
it
should
{
"generate valid RTS output xml using valid NSD source xml"
ignore
{
val
sourceXml
:
Node
=
XML
.
loadFile
(
"src/test/resources/templates/nsd/Example repo NSD.xml"
)
val
outputXml
=
new
RepoTemplate
(
sourceXml
).
template
val
checkedXml
=
XMLValid
(
"src/test/resources/templates/rts/fpml-recordkeeping-merged-schema.xsd"
).
loadString
(
outputXml
.
mkString
)
assert
(
checkedXml
.
isInstanceOf
[
Node
])
}
}
}
...
...
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