Commit 170acad8 authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier
Browse files

Moved psychology-related attributes to own JSON node "attributesPsychology"...

Moved psychology-related attributes to own JSON node "attributesPsychology" and display these attributes in an own tab in GUI

Implemented "TargetVersionV1_7" to reflect this change in the JSON file.

- Renamed "AttributesPsychology" to "AttributesPsychologyLayer".
- The new class "AttributesPsychology" is now the wrapper to hold
  all psychology-related parameters. The existing psychology parameters
  from "AttributesSimulation" moved to this class.
parent f4d34b0f
......@@ -359,6 +359,7 @@ Tab.Model.addAttributesMenu.title=Add Attributes
Tab.Model.insertModelNameMenu.title=Insert model name
Tab.Model.insertModelNameSubMenu.title=Main models
Tab.Pedestrians.title=Pedestrians
Tab.Psychology.title=Psychology
Tab.Topography.title=Topography
Tab.Stimuli.title=Stimuli
Tab.OutputProcessors.title=Data output
......
......@@ -353,6 +353,7 @@ Tab.Model.addAttributesMenu.title=Attributes hinzuf\u00fcgen
Tab.Model.insertModelNameMenu.title=Model-Name einf\u00fcgen
Tab.Model.insertModelNameSubMenu.title=Hauptmodelle
Tab.Pedestrians.title=Fu\u00dfg\u00e4nger
Tab.Psychology.title=Psychologie
Tab.Topography.title=Topographie
Tab.Stimuli.title=Stimuli
Tab.OutputProcessors.title=Datenausgabe
......
package org.vadere.gui.projectview.view;
public enum AttributeType {
SIMULATION, MODEL, PEDESTRIAN, CAR, TOPOGRAPHY, OUTPUTPROCESSOR, STIMULUS;
SIMULATION, MODEL, PSYCHOLOGY, PEDESTRIAN, CAR, TOPOGRAPHY, OUTPUTPROCESSOR, STIMULUS;
public final static String simulationAttributes = "simulation attributes";
public final static String modelAttributes = "panelModel attributes";
public final static String psychologyAttributes = "psychology attributes";
public final static String pedestrianAttributes = "pedestrian attributes";
public final static String scenarioAttributes = "scenario attributes";
public final static String carAttributes = "car attributes";
......@@ -16,6 +17,8 @@ public enum AttributeType {
return SIMULATION;
case modelAttributes:
return MODEL;
case psychologyAttributes:
return PSYCHOLOGY;
case pedestrianAttributes:
return PEDESTRIAN;
case scenarioAttributes:
......
......@@ -39,6 +39,7 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
private List<JMenu> menusInTabs = new ArrayList<>();
private TextView attributesSimulationView; // Simulation tab
private TextView attributesModelView; // Model tab
private TextView attributesPsychologyView; // Psychology tab
private TextView topographyFileView; // Topography tab
private TextView eventFileView; // Stimulus tab
private DataProcessingView dataProcessingGUIview; // DataProcessing
......@@ -108,7 +109,6 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
attributesSimulationView =
new TextView("ProjectView.defaultDirectoryAttributes", AttributeType.SIMULATION);
attributesSimulationView.setScenarioChecker(model);
tabbedPane.addTab(Messages.getString("Tab.Simulation.title"), attributesSimulationView);
//Tab
......@@ -192,6 +192,11 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
attributesModelView.getPanelTop().add(presetMenuBar, 0); // the 0 puts it at the leftmost position instead of the rightmost
tabbedPane.addTab(Messages.getString("Tab.Model.title"), attributesModelView);
attributesPsychologyView =
new TextView("ProjectView.defaultDirectoryAttributes", AttributeType.PSYCHOLOGY);
attributesPsychologyView.isEditable(true);
tabbedPane.addTab(Messages.getString("Tab.Psychology.title"), attributesPsychologyView);
topographyFileView = new TextView("ProjectView.defaultDirectoryScenarios", AttributeType.TOPOGRAPHY);
topographyFileView.setScenarioChecker(model);
tabbedPane.addTab(Messages.getString("Tab.Topography.title"), topographyFileView);
......@@ -276,11 +281,14 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
postVisualizationView.getDefaultModel().resetTopographySize();
}
this.attributesSimulationView.setVadereScenario(scenario);
this.attributesSimulationView.isEditable(isEditable);
this.attributesModelView.setVadereScenario(scenario);
this.attributesModelView.isEditable(isEditable);
this.attributesSimulationView.setVadereScenario(scenario);
this.attributesSimulationView.isEditable(isEditable);
this.attributesPsychologyView.setVadereScenario(scenario);
this.attributesPsychologyView.isEditable(isEditable);
this.topographyFileView.setVadereScenario(scenario);
this.topographyFileView.isEditable(isEditable);
......
......@@ -176,27 +176,31 @@ public class TextView extends JPanel implements IJsonView {
try {
switch (attributeType) {
case MODEL:
ModelDefinition modelDefinition = JsonConverter.deserializeModelDefinition(json);
currentScenario.getScenarioStore().setMainModel(modelDefinition.getMainModel());
currentScenario.setAttributesModel(modelDefinition.getAttributesList());
break;
case SIMULATION:
currentScenario
.setAttributesSimulation(StateJsonConverter.deserializeAttributesSimulation(json));
break;
case OUTPUTPROCESSOR:
currentScenario.setDataProcessingJsonManager(DataProcessingJsonManager.deserialize(json));
break;
case TOPOGRAPHY:
currentScenario.setTopography(StateJsonConverter.deserializeTopography(json));
break;
case STIMULUS:
StimulusInfoStore stimulusInfoStore = StateJsonConverter.deserializeStimuli(json);
currentScenario.getScenarioStore().setStimulusInfoStore(stimulusInfoStore);
break;
default:
throw new RuntimeException("attribute type not implemented.");
case MODEL:
ModelDefinition modelDefinition = JsonConverter.deserializeModelDefinition(json);
currentScenario.getScenarioStore().setMainModel(modelDefinition.getMainModel());
currentScenario.setAttributesModel(modelDefinition.getAttributesList());
break;
case SIMULATION:
currentScenario
.setAttributesSimulation(StateJsonConverter.deserializeAttributesSimulation(json));
break;
case PSYCHOLOGY:
currentScenario
.setAttributesPsychology(StateJsonConverter.deserializeAttributesPsychology(json));
break;
case OUTPUTPROCESSOR:
currentScenario.setDataProcessingJsonManager(DataProcessingJsonManager.deserialize(json));
break;
case TOPOGRAPHY:
currentScenario.setTopography(StateJsonConverter.deserializeTopography(json));
break;
case STIMULUS:
StimulusInfoStore stimulusInfoStore = StateJsonConverter.deserializeStimuli(json);
currentScenario.getScenarioStore().setStimulusInfoStore(stimulusInfoStore);
break;
default:
throw new RuntimeException("attribute type not implemented.");
}
currentScenario.updateCurrentStateSerialized();
ScenarioPanel.removeJsonParsingErrorMsg();
......@@ -267,6 +271,10 @@ public class TextView extends JPanel implements IJsonView {
textfileTextarea
.setText(StateJsonConverter.serializeAttributesSimulation(scenario.getAttributesSimulation()));
break;
case PSYCHOLOGY:
textfileTextarea
.setText(StateJsonConverter.serializeAttributesPsychology(scenario.getAttributesPsychology()));
break;
case OUTPUTPROCESSOR:
textfileTextarea.setText(scenario.getDataProcessingJsonManager().serialize());
break;
......
......@@ -15,7 +15,7 @@ public class CognitionModelBuilder {
public static final String JAVA_PACKAGE_SEPARATOR = ".";
public static ICognitionModel instantiateModel(ScenarioStore scenarioStore) {
String simpleClassName = scenarioStore.getAttributesSimulation().getPsychologyLayer().getCognition();
String simpleClassName = scenarioStore.getAttributesPsychology().getPsychologyLayer().getCognition();
String classSearchPath = ICognitionModel.class.getPackageName();
String fullyQualifiedClassName = classSearchPath + JAVA_PACKAGE_SEPARATOR + simpleClassName;
......
......@@ -20,7 +20,7 @@ public class PerceptionModelBuilder {
public static final String JAVA_PACKAGE_SEPARATOR = ".";
public static IPerceptionModel instantiateModel(ScenarioStore scenarioStore) {
String simpleClassName = scenarioStore.getAttributesSimulation().getPsychologyLayer().getPerception();
String simpleClassName = scenarioStore.getAttributesPsychology().getPsychologyLayer().getPerception();
String classSearchPath = IPerceptionModel.class.getPackageName();
String fullyQualifiedClassName = classSearchPath + JAVA_PACKAGE_SEPARATOR + simpleClassName;
......
......@@ -393,7 +393,7 @@ public class Simulation {
Collection<Pedestrian> pedestrians = topography.getElements(Pedestrian.class);
perceptionModel.update(pedestrians, stimuli);
if (attributesSimulation.isUsePsychologyLayer()) {
if (scenarioStore.getAttributesPsychology().isUsePsychologyLayer()) {
cognitionModel.update(pedestrians);
}
......
......@@ -31,6 +31,7 @@ public enum Version {
V1_4(1,4),
V1_5(1,5),
V1_6(1,6),
V1_7(1,7),
;
......
......@@ -4,6 +4,7 @@ import org.jetbrains.annotations.NotNull;
import org.vadere.simulator.projects.dataprocessing.DataProcessingJsonManager;
import org.vadere.simulator.projects.io.JsonConverter;
import org.vadere.state.attributes.Attributes;
import org.vadere.state.attributes.AttributesPsychology;
import org.vadere.state.attributes.AttributesSimulation;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.scenario.Topography;
......@@ -131,6 +132,10 @@ public class Scenario {
return scenarioStore.getAttributesSimulation();
}
public AttributesPsychology getAttributesPsychology() {
return scenarioStore.getAttributesPsychology();
}
public Topography getTopography() {
return scenarioStore.getTopography();
}
......@@ -147,6 +152,10 @@ public class Scenario {
this.scenarioStore.setAttributesSimulation(attributesSimulation);
}
public void setAttributesPsychology(@NotNull final AttributesPsychology attributesPsychology) {
this.scenarioStore.setAttributesPsychology(attributesPsychology);
}
public void setTopography(@NotNull final Topography topography) {
scenarioStore.setTopography(topography);
}
......
......@@ -5,6 +5,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import org.jetbrains.annotations.NotNull;
import org.vadere.simulator.projects.io.JsonConverter;
import org.vadere.state.attributes.Attributes;
import org.vadere.state.attributes.AttributesPsychology;
import org.vadere.state.attributes.AttributesSimulation;
import org.vadere.state.attributes.scenario.AttributesCar;
import org.vadere.state.psychology.perception.json.StimulusInfoStore;
......@@ -32,22 +33,23 @@ public class ScenarioStore {
private String mainModel;
private List<Attributes> attributesList;
private AttributesSimulation attributesSimulation;
private AttributesPsychology attributesPsychology;
private Topography topography;
private StimulusInfoStore stimulusInfoStore;
public ScenarioStore(final String name, final String description, final String mainModel, final List<Attributes> attributesModel,
final AttributesSimulation attributesSimulation, final Topography topography) {
// Provide empty "StimulusInfoStore".
this(name, description, mainModel, attributesModel, attributesSimulation, topography, new StimulusInfoStore());
this(name, description, mainModel, attributesModel, attributesSimulation, new AttributesPsychology(), topography, new StimulusInfoStore());
}
public ScenarioStore(final String name, final String description, final String mainModel, final List<Attributes> attributesModel,
final AttributesSimulation attributesSimulation, final Topography topography, final StimulusInfoStore stimulusInfoStore) {
final AttributesSimulation attributesSimulation, final AttributesPsychology attributesPsychology, final Topography topography, final StimulusInfoStore stimulusInfoStore) {
this.name = name;
this.description = description;
this.mainModel = mainModel;
this.attributesList = attributesModel;
this.attributesSimulation = attributesSimulation;
this.attributesPsychology = attributesPsychology;
this.topography = topography;
this.stimulusInfoStore = stimulusInfoStore;
}
......@@ -86,6 +88,7 @@ public class ScenarioStore {
public void sealAllAttributes() {
attributesList.forEach(a -> a.seal());
attributesSimulation.seal();
attributesPsychology.seal();
topography.sealAllAttributes();
}
......@@ -101,6 +104,10 @@ public class ScenarioStore {
this.attributesSimulation = attributesSimulation;
}
public void setAttributesPsychology(final AttributesPsychology attributesPsychology) {
this.attributesPsychology = attributesPsychology;
}
public void removeAttributesIf(@NotNull final Predicate<Attributes> predicate) {
attributesList.removeIf(predicate);
}
......@@ -127,6 +134,8 @@ public class ScenarioStore {
return attributesSimulation;
}
public AttributesPsychology getAttributesPsychology() { return attributesPsychology; }
public List<Attributes> getAttributesList() {
return attributesList;
}
......
......@@ -8,6 +8,7 @@ import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.projects.ScenarioStore;
import org.vadere.simulator.projects.dataprocessing.DataProcessingJsonManager;
import org.vadere.state.attributes.Attributes;
import org.vadere.state.attributes.AttributesPsychology;
import org.vadere.state.attributes.AttributesSimulation;
import org.vadere.state.attributes.ModelDefinition;
import org.vadere.state.psychology.perception.json.StimulusInfoStore;
......@@ -48,14 +49,18 @@ public class JsonConverter {
String scenarioName = rootNode.get("name").asText();
String scenarioDescription = rootNode.get("description").asText();
AttributesSimulation attributesSimulation = StateJsonConverter.deserializeAttributesSimulationFromNode(scenarioNode.get("attributesSimulation"));
AttributesSimulation attributesSimulation = StateJsonConverter.deserializeAttributesSimulationFromNode(scenarioNode.get(AttributesSimulation.JSON_KEY));
AttributesPsychology attributesPsychology = StateJsonConverter.deserializeAttributesPsychologyFromNode(scenarioNode.get(AttributesPsychology.JSON_KEY));
JsonNode attributesModelNode = scenarioNode.get("attributesModel");
String mainModel = scenarioNode.get(StateJsonConverter.MAIN_MODEL_KEY).isNull() ? null : scenarioNode.get(StateJsonConverter.MAIN_MODEL_KEY).asText();
List<Attributes> attributesModel = StateJsonConverter.deserializeAttributesListFromNode(attributesModelNode);
Topography topography = StateJsonConverter.deserializeTopographyFromNode(scenarioNode.get("topography"));
StimulusInfoStore stimulusInfoStore = StateJsonConverter.deserializeStimuliFromArrayNode(scenarioNode.get("stimulusInfos"));
ScenarioStore scenarioStore = new ScenarioStore(scenarioName, scenarioDescription, mainModel, attributesModel, attributesSimulation, topography, stimulusInfoStore);
ScenarioStore scenarioStore = new ScenarioStore(scenarioName, scenarioDescription,
mainModel, attributesModel,
attributesSimulation, attributesPsychology,
topography, stimulusInfoStore);
Scenario scenarioRunManager = new Scenario(scenarioStore);
scenarioRunManager.setDataProcessingJsonManager(DataProcessingJsonManager.deserializeFromNode(rootNode.get(DataProcessingJsonManager.DATAPROCCESSING_KEY)));
......@@ -103,18 +108,15 @@ public class JsonConverter {
vadereNode.put(StateJsonConverter.MAIN_MODEL_KEY, scenarioStore.getMainModel());
// vadere > attributesModel
ObjectNode attributesModelNode = StateJsonConverter.serializeAttributesModelToNode(scenarioStore.getAttributesList());
vadereNode.set("attributesModel", attributesModelNode);
// vadere > attributesSimulation
vadereNode.set("attributesSimulation", StateJsonConverter.convertValue(scenarioStore.getAttributesSimulation(), JsonNode.class));
vadereNode.set(AttributesSimulation.JSON_KEY, StateJsonConverter.convertValue(scenarioStore.getAttributesSimulation(), JsonNode.class));
vadereNode.set(AttributesPsychology.JSON_KEY, StateJsonConverter.convertValue(scenarioStore.getAttributesPsychology(), JsonNode.class));
// vadere > topography
ObjectNode topographyNode = StateJsonConverter.serializeTopographyToNode(scenarioStore.getTopography());
vadereNode.set("topography", topographyNode);
// vadere > eventInfos
// We get a complete tree here and not only a node. Therefore, use "setAll()" instead of "set()".
ObjectNode eventNode = StateJsonConverter.serializeStimuliToNode(scenarioStore.getStimulusInfoStore());
vadereNode.setAll(eventNode);
......@@ -129,6 +131,7 @@ public class JsonConverter {
public static ScenarioStore cloneScenarioStore(ScenarioStore scenarioStore) throws IOException {
JsonNode attributesSimulationNode = StateJsonConverter.convertValue(scenarioStore.getAttributesSimulation(), JsonNode.class);
JsonNode attributesPsychologyNode = StateJsonConverter.convertValue(scenarioStore.getAttributesPsychology(), JsonNode.class);
ObjectNode attributesModelNode = StateJsonConverter.serializeAttributesModelToNode(scenarioStore.getAttributesList());
ObjectNode topographyNode = StateJsonConverter.serializeTopographyToNode(scenarioStore.getTopography());
ObjectNode stimulusNode = StateJsonConverter.serializeStimuliToNode(scenarioStore.getStimulusInfoStore());
......@@ -141,6 +144,7 @@ public class JsonConverter {
return new ScenarioStore(scenarioStore.getName(), scenarioStore.getDescription(), scenarioStore.getMainModel(),
StateJsonConverter.deserializeAttributesListFromNode(attributesModelNode),
StateJsonConverter.deserializeAttributesSimulationFromNode(attributesSimulationNode),
StateJsonConverter.deserializeAttributesPsychologyFromNode(attributesPsychologyNode),
StateJsonConverter.deserializeTopographyFromNode(topographyNode),
StateJsonConverter.deserializeStimuliFromArrayNode(stimulusInfosArrayNode));
}
......
......@@ -17,6 +17,7 @@ import org.vadere.simulator.projects.migration.incident.incidents.RenameInArrayI
import org.vadere.simulator.projects.migration.incident.incidents.RenameIncident;
import org.vadere.simulator.projects.migration.incident.incidents.specialized.AttributesPotentialCompactVSosmIncident;
import org.vadere.simulator.projects.migration.incident.incidents.specialized.MoveSpawnDelayIntoDistributionParametersIncident;
import org.vadere.state.attributes.AttributesSimulation;
import org.vadere.state.util.StateJsonConverter;
import static org.vadere.simulator.entrypoints.Version.*;
......@@ -41,7 +42,7 @@ public class IncidentDatabase {
addIncident(NOT_A_RELEASE, new RelocationIncident(
"finishTime",
path("vadere", "topography", "attributes"),
path("vadere", "attributesSimulation")));
path("vadere", AttributesSimulation.JSON_KEY)));
addIncident(NOT_A_RELEASE, new RelocationIncident(
"attributesPedestrian",
......
......@@ -7,6 +7,8 @@ import org.vadere.simulator.entrypoints.Version;
import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.projects.io.JsonConverter;
import org.vadere.simulator.projects.migration.MigrationException;
import org.vadere.state.attributes.AttributesPsychology;
import org.vadere.state.attributes.AttributesSimulation;
import org.vadere.state.util.StateJsonConverter;
import org.vadere.util.logging.Logger;
......@@ -131,7 +133,9 @@ public abstract class AbstractJsonTransformation implements JsonTransformation,
// choose sort order based on targetVersion.
public JsonNode sort (JsonNode node) {
if (getTargetVersion().equalOrBigger(Version.V1_5)){
if (getTargetVersion().equalOrBigger(Version.V1_7)) {
node = sort_since_V1_7(node);
} else if (getTargetVersion().equalOrBigger(Version.V1_5)){
node = sort_since_V1_5(node);
} else if (getTargetVersion().equalOrBigger(Version.V0_8)){
node = sort_since_V08(node);
......@@ -142,6 +146,19 @@ public abstract class AbstractJsonTransformation implements JsonTransformation,
return node;
}
private JsonNode sort_since_V1_7(JsonNode node) {
LinkedHashMap source = (LinkedHashMap) StateJsonConverter.convertJsonNodeToObject(node);
LinkedHashMap<Object, Object> sortedRoot = new LinkedHashMap<>();
putObject(sortedRoot, source, "name");
putObject(sortedRoot, source, "description");
putObject(sortedRoot, source, "release");
putObject(sortedRoot, source, "commithash");
putObject(sortedRoot, source, "processWriters","files", "processors", "isTimestamped", "isWriteMetaData");
putObject(sortedRoot, source, "scenario", "mainModel", "attributesModel", AttributesSimulation.JSON_KEY, AttributesPsychology.JSON_KEY, "topography", "stimulusInfos");
return StateJsonConverter.deserializeToNode(sortedRoot);
}
private JsonNode sort_since_V1_5(JsonNode node) {
LinkedHashMap source = (LinkedHashMap) StateJsonConverter.convertJsonNodeToObject(node);
LinkedHashMap<Object, Object> sortedRoot = new LinkedHashMap<>();
......@@ -150,7 +167,7 @@ public abstract class AbstractJsonTransformation implements JsonTransformation,
putObject(sortedRoot, source, "release");
putObject(sortedRoot, source, "commithash");
putObject(sortedRoot, source, "processWriters","files", "processors", "isTimestamped", "isWriteMetaData");
putObject(sortedRoot, source, "scenario", "mainModel", "attributesModel", "attributesSimulation", "topography", "stimulusInfos");
putObject(sortedRoot, source, "scenario", "mainModel", "attributesModel", AttributesSimulation.JSON_KEY, "topography", "stimulusInfos");
return StateJsonConverter.deserializeToNode(sortedRoot);
}
......@@ -163,7 +180,7 @@ public abstract class AbstractJsonTransformation implements JsonTransformation,
putObject(sortedRoot, source, "release");
putObject(sortedRoot, source, "commithash");
putObject(sortedRoot, source, "processWriters","files", "processors", "isTimestamped", "isWriteMetaData");
putObject(sortedRoot, source, "scenario", "mainModel", "attributesModel", "attributesSimulation", "topography", "eventInfos");
putObject(sortedRoot, source, "scenario", "mainModel", "attributesModel", AttributesSimulation.JSON_KEY, "topography", "eventInfos");
return StateJsonConverter.deserializeToNode(sortedRoot);
}
......@@ -176,7 +193,7 @@ public abstract class AbstractJsonTransformation implements JsonTransformation,
putObject(sortedRoot, source, "release");
putObject(sortedRoot, source, "commithash");
putObject(sortedRoot, source, "processWriters","files", "processors", "isTimestamped");
putObject(sortedRoot, source, "scenario", "mainModel", "attributesModel", "attributesSimulation", "topography");
putObject(sortedRoot, source, "scenario", "mainModel", "attributesModel", AttributesSimulation.JSON_KEY, "topography");
return StateJsonConverter.deserializeToNode(sortedRoot);
}
......
......@@ -274,14 +274,14 @@ public class JsonMigrationAssistant extends MigrationAssistant {
JsonNode transformedNode = node;
// apply all transformation from current to latest version.
for (Version v : Version.listToLatest(version)) {
migrationLogger.info("<" + node.get("name").asText() + "> Start Transform to Version: " + v.label());
migrationLogger.info("<" + node.get("name").asText() + "> Transform to: " + v.label());
logger.debug(migrationLogger.last());
transformedNode = transform(transformedNode, v);
}
// will always be Version.latest()
transformedNode = AbstractJsonTransformation.addNewMembersWithDefaultValues(transformedNode);
if (legacyDir != null) {
migrationLogger.info("Scenario Migrated - OK. Move copy of old version to legacllyDir");
migrationLogger.info("Migration successful. Move copy of old version to \"legacy\" directory");
logger.debug(migrationLogger.last());
moveFileAddExtension(scenarioFilePath, legacyDir, migrationOptions.getLegacyExtension(), false);
}
......
......@@ -8,6 +8,7 @@ import org.vadere.simulator.entrypoints.Version;
import org.vadere.simulator.projects.migration.MigrationException;
import org.vadere.simulator.projects.migration.jsontranformation.AbstractJsonTransformation;
import org.vadere.simulator.projects.migration.jsontranformation.JoltTransformation;
import org.vadere.state.attributes.AttributesSimulation;
import java.util.Random;
......@@ -25,7 +26,7 @@ public class JoltTransformV3toV4 extends JoltTransformation {
}
public JsonNode presetSeedValues(JsonNode node) throws MigrationException {
JsonNode attSim = node.findPath("scenario").findPath("attributesSimulation");
JsonNode attSim = node.findPath("scenario").findPath(AttributesSimulation.JSON_KEY);
if (attSim.isMissingNode())
throw new MigrationException("attributesSimulation is not part of Scenario.");
......
package org.vadere.simulator.projects.migration.jsontranformation.json;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
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;
import org.vadere.state.attributes.AttributesPsychology;
/**
* Introduce new node "scenario.attributesPsychology" into JSON.
*
* Move "scenario.attributesSimulation.usePsychologyLayer"
* to this new node.
*
* This new node "scenario.attributesPsychology" holds
* also the newly introduced "AttributesPsychologyLayer"
* which is populated with default values when the migration
* assistant runs.
*
* The final JSON looks like this then:
*
* {
* "name" : "ScenarioName",
* ...
* "scenario" : {
* "attributesSimulation": { ... },
* "attributesPsychology": {
* "usePsychologyLayer": true,
* "psychologyLayer": {
* "perception": "SimplePerceptionModel",
* "cognition": "CooperativeCognitionModel"
* }
* },
* ...
* }
* }
*/
@MigrationTransformation(targetVersionLabel = "1.7")
public class TargetVersionV1_7 extends SimpleJsonTransformation {
public TargetVersionV1_7(){
super(Version.V1_7);
}
@Override
protected void initDefaultHooks() {
addPostHookFirst(this::moveUsePsychologyLayer);
addPostHookLast(this::sort);
}
public JsonNode moveUsePsychologyLayer(JsonNode node) throws MigrationException {
String usePsychologyLayerKey = "usePsychologyLayer";
JsonNode attributesSimulationNode = path(node, "scenario/attributesSimulation");
JsonNode usePsychologyLayerNode = path(attributesSimulationNode, usePsychologyLayerKey);
if (!usePsychologyLayerNode.isMissingNode()) {
remove(attributesSimulationNode, usePsychologyLayerKey);
}
String newPsychologyNodeName = AttributesPsychology.JSON_KEY;
JsonNode scenarioNode = path(node, "scenario");
ObjectNode newPsychologyNode = ((ObjectNode)scenarioNode).putObject(newPsychologyNodeName);
newPsychologyNode.set(usePsychologyLayerKey, usePsychologyLayerNode);
return node;
}
}
......@@ -23,6 +23,7 @@ public class StimulusControllerTest {
null,
null,
null,
null,
store);
}
......@@ -33,6 +34,7 @@ public class StimulusControllerTest {
null,
null,
null,
null,
getStimulusInfoStoreContainingRecurringStimulus(isRecurring));
}
......@@ -115,6 +117,7 @@ public class StimulusControllerTest {
null,
null,
null,
null,
stimulusInfoStoreWithBothStimuli);
StimulusController stimulusController = new StimulusController(scenarioStoreContainingOneTimeAndRecurringStimulus);
......