Commit 0b248a30 authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier
Browse files

Implemented "TargetVersionV1_8" to rename "Bang" to "Threat" in JSON scenario files

parent 863ae060
......@@ -32,6 +32,7 @@ public enum Version {
V1_5(1,5),
V1_6(1,6),
V1_7(1,7),
V1_8(1, 8),
;
......
package org.vadere.simulator.projects.migration.jsontranformation.json;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
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;
/**
* Rename stimulus "Bang" to general term "Threat" under node "stimulusInfos":
*
* <pre>
* "stimulusInfos" : [ {
* "timeframe" : {...},
* "stimuli" : [ {
* "type" : "Bang",
* ...
* } ]
* } ]
* </pre>
*/
@MigrationTransformation(targetVersionLabel = "1.8")
public class TargetVersionV1_8 extends SimpleJsonTransformation {
public TargetVersionV1_8(){
super(Version.V1_8);
}
@Override
protected void initDefaultHooks() {
addPostHookFirst(this::renameBangToThreat);
addPostHookLast(this::sort);
}
public JsonNode renameBangToThreat(JsonNode node) throws MigrationException {
String oldName = "Bang";
String newName = "Threat";
JsonNode stimulusInfosNode = path(node, "scenario/stimulusInfos");
if (stimulusInfosNode.isArray()) {
for (JsonNode stimulusInfoNode : stimulusInfosNode) {
JsonNode stimuliNode = path(stimulusInfoNode, "stimuli");
if (stimuliNode.isArray()) {
for (JsonNode stimulusNode : stimuliNode) {
if (stimulusNode.get("type").asText("").equals(oldName)) {
changeStringValue(stimulusNode, "type", newName);
}
}
}
}
}
return node;
}
}
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