Commit 4178bc72 authored by Matthias Betz's avatar Matthias Betz
Browse files

tidy up output validation configuration files

parent 552c13fc
Pipeline #1080 passed with stage
in 1 minute and 52 seconds
......@@ -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 setParserConfiguration(ParserConfiguration parserConfig) {
public void setParserConfig(ParserConfiguration parserConfig) {
this.parserConfig = parserConfig;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment