default Scenario createScenario(Simulation simulation, SimulationDescriptor simulationDescriptor) { simulationDescriptor.addFactMapping(FactIdentifier.INDEX.getName(), FactIdentifier.INDEX, ExpressionIdentifier.INDEX); simulationDescriptor.addFactMapping(FactIdentifier.DESCRIPTION.getName(), FactIdentifier.DESCRIPTION, ExpressionIdentifier.DESCRIPTION); Scenario toReturn = simulation.addScenario(); toReturn.setDescription(null); return toReturn; } }
public void removeFactMappingByIndex(int index) { cleanScenarios(simulationDescriptor.getFactMappingByIndex(index)); simulationDescriptor.removeFactMappingByIndex(index); }
public void removeFactMapping(FactMapping toRemove) { cleanScenarios(toRemove); simulationDescriptor.removeFactMapping(toRemove); }
public Simulation cloneSimulation() { Simulation toReturn = new Simulation(); toReturn.getSimulationDescriptor().setType(simulationDescriptor.getType()); toReturn.getSimulationDescriptor().setDmnFilePath(simulationDescriptor.getDmnFilePath()); toReturn.getSimulationDescriptor().setDmoSession(simulationDescriptor.getDmoSession()); final List<FactMapping> originalFactMappings = this.simulationDescriptor.getUnmodifiableFactMappings(); for (int i = 0; i < originalFactMappings.size(); i++) { final FactMapping originalFactMapping = originalFactMappings.get(i); toReturn.simulationDescriptor.addFactMapping(i, originalFactMapping); } this.scenarios.forEach(scenario -> toReturn.scenarios.add(scenario.cloneScenario())); return toReturn; }
@Before public void setup() { simulation = new Simulation(); FactIdentifier factIdentifier = FactIdentifier.create("Test", String.class.getCanonicalName()); ExpressionIdentifier expressionIdentifier = ExpressionIdentifier.create("Test", FactMappingType.GIVEN); simulation.getSimulationDescriptor().addFactMapping(factIdentifier, expressionIdentifier); originalScenario = simulation.addScenario(); originalScenario.setDescription("Test Description"); originalScenario.addMappingValue(factIdentifier, expressionIdentifier, "TEST"); }
@Override public Function<String, String> from1_2to1_3() { return rawXml -> { ScenarioSimulationXMLPersistence xmlPersistence = ScenarioSimulationXMLPersistence.getInstance(); ScenarioSimulationModel model = xmlPersistence.unmarshal(rawXml, false); for (FactMapping factMapping : model.getSimulation().getSimulationDescriptor().getUnmodifiableFactMappings()) { factMapping.getExpressionElements().add(0, new ExpressionElement(factMapping.getFactIdentifier().getName())); } return xmlPersistence.marshal(model).replaceAll("<ScenarioSimulationModel version=\"1.2\">", "<ScenarioSimulationModel version=\"1.3\">"); }; } }
@Override public Range deleteCell(int rowIndex, int columnIndex) { FactMapping factMapping = simulation.getSimulationDescriptor().getFactMappingByIndex(columnIndex); simulation.getScenarioByIndex(rowIndex) .removeFactMappingValueByIdentifiers(factMapping.getFactIdentifier(), factMapping.getExpressionIdentifier()); return super.deleteCell(rowIndex, columnIndex); }
public Optional<FactMapping> getFactMapping(FactIdentifier factIdentifier, ExpressionIdentifier ei) { List<FactMapping> factMappings = internalFilter(e -> e.getExpressionIdentifier().equals(ei) && e.getFactIdentifier().equals(factIdentifier)); return factMappings.stream().findFirst(); }
public static BiFunction<KieContainer, Simulation, AbstractScenarioRunner> getSpecificRunnerProvider(Simulation simulation) { if (Type.RULE.equals(simulation.getSimulationDescriptor().getType())) { return RuleScenarioRunner::new; } else if (Type.DMN.equals(simulation.getSimulationDescriptor().getType())) { return DMNScenarioRunner::new; } else { throw new IllegalArgumentException("Impossible to run simulation of type " + simulation.getSimulationDescriptor().getType()); } }
/** * Returns <code>true</code> if type mapped to the column at given index is the same as the provided one * @param columnIndex * @param className * @return */ public boolean isSameSelectedColumnType(int columnIndex, String className) { SimulationDescriptor simulationDescriptor = simulation.getSimulationDescriptor(); final FactMapping factMappingByIndex = simulationDescriptor.getFactMappingByIndex(columnIndex); return factMappingByIndex.getClassName().equals(className); }
/** * Returns <code>true</code> if property mapped to the column at given index is the same as the provided one * @param columnIndex * @param propertyName * @return */ public boolean isSameSelectedColumnProperty(int columnIndex, String propertyName) { SimulationDescriptor simulationDescriptor = simulation.getSimulationDescriptor(); final FactMapping factMappingByIndex = simulationDescriptor.getFactMappingByIndex(columnIndex); return factMappingByIndex.getExpressionAlias().equals(propertyName); }
public FactMappingValue addOrUpdateMappingValue(FactIdentifier factIdentifier, ExpressionIdentifier expressionIdentifier, Object value) { return getFactMappingValue(factIdentifier, expressionIdentifier).map(e -> { e.setRawValue(value); return e; }).orElseGet(() -> addMappingValue(factIdentifier, expressionIdentifier, value)); }
public FactMapping addFactMapping(int index, FactIdentifier factIdentifier, ExpressionIdentifier expressionIdentifier) { return addFactMapping(index, expressionIdentifier.getName(), factIdentifier, expressionIdentifier); }
private FactMapping(FactMapping original) { original.expressionElements.forEach(expressionElement -> this.addExpressionElement(expressionElement.getStep(), original.className)); this.expressionIdentifier = original.expressionIdentifier; this.factIdentifier = original.factIdentifier; this.className = original.className; this.factAlias = original.factAlias; this.expressionAlias = original.expressionAlias; }
FactMappingValue cloneFactMappingValue() { FactMappingValue cloned = new FactMappingValue(); cloned.expressionIdentifier = expressionIdentifier; cloned.factIdentifier = factIdentifier; cloned.rawValue = rawValue; return cloned; }
public Simulation cloneSimulation() { Simulation toReturn = new Simulation(); toReturn.getSimulationDescriptor().setType(simulationDescriptor.getType()); toReturn.getSimulationDescriptor().setDmnFilePath(simulationDescriptor.getDmnFilePath()); toReturn.getSimulationDescriptor().setDmoSession(simulationDescriptor.getDmoSession()); final List<FactMapping> originalFactMappings = this.simulationDescriptor.getUnmodifiableFactMappings(); for (int i = 0; i < originalFactMappings.size(); i++) { final FactMapping originalFactMapping = originalFactMappings.get(i); toReturn.simulationDescriptor.addFactMapping(i, originalFactMapping); } this.scenarios.forEach(scenario -> toReturn.scenarios.add(scenario.cloneScenario())); return toReturn; }
@Before public void setup() { simulation = new Simulation(); FactIdentifier factIdentifier = FactIdentifier.create("Test", String.class.getCanonicalName()); ExpressionIdentifier expressionIdentifier = ExpressionIdentifier.create("Test", FactMappingType.GIVEN); simulation.getSimulationDescriptor().addFactMapping(factIdentifier, expressionIdentifier); originalScenario = simulation.addScenario(); originalScenario.setDescription("Test Description"); originalScenario.addMappingValue(factIdentifier, expressionIdentifier, "TEST"); }
public Optional<FactMapping> getFactMapping(FactIdentifier factIdentifier, ExpressionIdentifier ei) { List<FactMapping> factMappings = internalFilter(e -> e.getExpressionIdentifier().equals(ei) && e.getFactIdentifier().equals(factIdentifier)); return factMappings.stream().findFirst(); }
public void removeFactMappingByIndex(int index) { cleanScenarios(simulationDescriptor.getFactMappingByIndex(index)); simulationDescriptor.removeFactMappingByIndex(index); }
public void removeFactMapping(FactMapping toRemove) { cleanScenarios(toRemove); simulationDescriptor.removeFactMapping(toRemove); }