Commit 7e1125ae authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier

Added "JsonTransformV8ToV9" and extended "JsonNodeExplorer".

parent 3d31bf87
Pipeline #105854 failed with stages
in 62 minutes and 8 seconds
......@@ -20,6 +20,7 @@ public enum Version {
V0_6("0.6"),
V0_7("0.7"),
V0_8("0.8"),
V0_9("0.9"),
;
private String label;
......
......@@ -48,6 +48,16 @@ public interface JsonNodeExplorer {
parent.put(keyName, value);
}
default void addDoubleField(JsonNode root, String keyName, double value){
ObjectNode parent = (ObjectNode) root;
parent.put(keyName, value);
}
default void addBooleanField(JsonNode root, String keyName, boolean value){
ObjectNode parent = (ObjectNode) root;
parent.put(keyName, value);
}
default JsonNode pathMustExist(JsonNode root, String path) throws MigrationException {
JsonNode ret = path(root, path);
if (ret.isMissingNode()) {
......
package org.vadere.simulator.projects.migration.jsontranformation.json;
import com.fasterxml.jackson.databind.JsonNode;
import org.vadere.annotation.factories.migrationassistant.MigrationTransformation;
import org.vadere.simulator.entrypoints.Version;
import org.vadere.simulator.projects.migration.MigrationException;
import org.vadere.simulator.projects.migration.jsontranformation.SimpleJsonTransformation;
@MigrationTransformation(targetVersionLabel = "0.9")
public class JsonTransformV8ToV9 extends SimpleJsonTransformation {
public JsonTransformV8ToV9() {
super(Version.V0_9);
}
@Override
protected void initDefaultHooks() {
addPostHookLast(this::addUseSalientBehaviorToAttributesSimulation);
addPostHookLast(this::addAttributesToAttributesAgent);
addPostHookLast(this::addCommitHashWarningIfMissing);
addPostHookLast(this::sort);
}
@Override
public JsonNode applyTransformation(JsonNode node) throws MigrationException {
return super.applyTransformation(node);
}
public JsonNode addUseSalientBehaviorToAttributesSimulation(JsonNode scenarioFile) throws MigrationException {
JsonNode attributesSimulation = pathMustExist(scenarioFile, "scenario/attributesSimulation");
addBooleanField(attributesSimulation, "useSalientBehavior", false);
return scenarioFile;
}
public JsonNode addAttributesToAttributesAgent(JsonNode scenarioFile) throws MigrationException {
JsonNode attributesPedestrian = pathMustExist(scenarioFile, "scenario/topography/attributesPedestrian");
addIntegerField(attributesPedestrian, "footStepsToStore", 4);
addDoubleField(attributesPedestrian, "searchRadius", 1.0);
addToObjectNode(attributesPedestrian, "angleCalculationType", "USE_CENTER");
addDoubleField(attributesPedestrian, "targetOrientationAngleThreshold", 45.0);
return scenarioFile;
}
}
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