Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
CityDoctor
CityDoctor2
Commits
4178bc72
Commit
4178bc72
authored
Oct 23, 2020
by
Matthias Betz
Browse files
tidy up output validation configuration files
parent
552c13fc
Pipeline
#1080
passed with stage
in 1 minute and 52 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
CityDoctorParent/CityDoctorValidation/src/main/java/de/hft/stuttgart/citydoctor2/check/ValidationConfiguration.java
View file @
4178bc72
...
...
@@ -35,6 +35,14 @@ import org.apache.logging.log4j.Logger;
import
org.yaml.snakeyaml.DumperOptions
;
import
org.yaml.snakeyaml.Yaml
;
import
org.yaml.snakeyaml.constructor.Constructor
;
import
org.yaml.snakeyaml.introspector.Property
;
import
org.yaml.snakeyaml.nodes.CollectionNode
;
import
org.yaml.snakeyaml.nodes.MappingNode
;
import
org.yaml.snakeyaml.nodes.Node
;
import
org.yaml.snakeyaml.nodes.NodeTuple
;
import
org.yaml.snakeyaml.nodes.SequenceNode
;
import
org.yaml.snakeyaml.nodes.Tag
;
import
org.yaml.snakeyaml.representer.Representer
;
import
de.hft.stuttgart.citydoctor2.checks.CheckPrototype
;
import
de.hft.stuttgart.citydoctor2.checks.Checks
;
...
...
@@ -97,7 +105,41 @@ public class ValidationConfiguration implements Serializable {
public
void
saveAs
(
File
f
)
throws
IOException
{
DumperOptions
options
=
new
DumperOptions
();
options
.
setDefaultFlowStyle
(
DumperOptions
.
FlowStyle
.
BLOCK
);
Yaml
yaml
=
new
Yaml
(
options
);
options
.
setPrettyFlow
(
true
);
Representer
rep
=
new
Representer
()
{
@Override
protected
NodeTuple
representJavaBeanProperty
(
Object
javaBean
,
Property
property
,
Object
propertyValue
,
Tag
customTag
)
{
if
(
propertyValue
==
null
)
{
return
null
;
}
else
{
NodeTuple
tuple
=
super
.
representJavaBeanProperty
(
javaBean
,
property
,
propertyValue
,
customTag
);
Node
valueNode
=
tuple
.
getValueNode
();
if
(
Tag
.
NULL
.
equals
(
valueNode
.
getTag
()))
{
return
null
;
// skip 'null' values
}
if
(
valueNode
instanceof
CollectionNode
)
{
if
(
Tag
.
SEQ
.
equals
(
valueNode
.
getTag
()))
{
SequenceNode
seq
=
(
SequenceNode
)
valueNode
;
if
(
seq
.
getValue
().
isEmpty
())
{
return
null
;
// skip empty lists
}
}
if
(
Tag
.
MAP
.
equals
(
valueNode
.
getTag
()))
{
MappingNode
seq
=
(
MappingNode
)
valueNode
;
if
(
seq
.
getValue
().
isEmpty
())
{
return
null
;
// skip empty maps
}
}
}
return
tuple
;
}
}
};
rep
.
addClassTag
(
ValidationConfiguration
.
class
,
Tag
.
MAP
);
Yaml
yaml
=
new
Yaml
(
rep
,
options
);
try
(
BufferedWriter
bw
=
new
BufferedWriter
(
new
FileWriter
(
f
)))
{
yaml
.
dump
(
this
,
bw
);
}
...
...
@@ -202,8 +244,8 @@ public class ValidationConfiguration implements Serializable {
}
return
parserConfig
;
}
public
void
setParserConfig
uration
(
ParserConfiguration
parserConfig
)
{
public
void
setParserConfig
(
ParserConfiguration
parserConfig
)
{
this
.
parserConfig
=
parserConfig
;
}
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment