public AbstractScenarioRunner(KieContainer kieContainer, Simulation simulation, String fileName, Function<ClassLoader, ExpressionEvaluator> expressionEvaluatorFactory) { this(kieContainer, simulation.getSimulationDescriptor(), toScenarioMap(simulation), fileName, expressionEvaluatorFactory); }
public static String getPropertyName(final Simulation simulation, final int columnIndex) { return String.join(".", simulation.getSimulationDescriptor().getFactMappingByIndex(columnIndex).getExpressionElementsWithoutClass() .stream() .map(ExpressionElement::getStep) .collect(Collectors.toSet())); }
/** * Method to bind the data serialized inside backend <code>ScenarioSimulationModel</code> * @param simulation */ public void bindContent(Simulation simulation) { this.simulation = simulation; checkSimulation(); columnCounter.set(simulation.getSimulationDescriptor().getUnmodifiableFactMappings().size()); }
protected void setHeaderColumns(Simulation simulation) { final List<FactMapping> factMappings = simulation.getSimulationDescriptor().getUnmodifiableFactMappings(); boolean editableHeaders = !simulation.getSimulationDescriptor().getType().equals(ScenarioSimulationModel.Type.DMN); IntStream.range(0, factMappings.size()) .forEach(columnIndex -> { setHeaderColumn(columnIndex, factMappings.get(columnIndex), editableHeaders); }); }
/** * 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); }
protected boolean isUnique(String value, int rowIndex, int columnIndex) { Range instanceLimits = getInstanceLimits(columnIndex); SimulationDescriptor simulationDescriptor = simulation.getSimulationDescriptor(); FactIdentifier factIdentifier = simulationDescriptor.getFactMappingByIndex(columnIndex).getFactIdentifier(); return IntStream.range(0, getColumnCount()) .filter(index -> index < instanceLimits.getMinRowIndex() || index > instanceLimits.getMaxRowIndex()) .filter(index -> !Objects.equals(factIdentifier, simulationDescriptor.getFactMappingByIndex(index).getFactIdentifier())) .mapToObj(index -> getColumns().get(index)) .filter(elem -> elem.getHeaderMetaData().size() > rowIndex) .map(elem -> (ScenarioHeaderMetaData) elem.getHeaderMetaData().get(rowIndex)) .noneMatch(elem -> Objects.equals(elem.getTitle(), value)); }
@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); }
@Test public void removeFactMapping() { assertEquals(2, simulation.getUnmodifiableScenarios().get(0).getUnmodifiableFactMappingValues().size()); assertEquals(1, simulation.getSimulationDescriptor().getUnmodifiableFactMappings().size()); simulation.removeFactMapping(simulation.getSimulationDescriptor().getFactMappingByIndex(0)); assertEquals(1, simulation.getUnmodifiableScenarios().get(0).getUnmodifiableFactMappingValues().size()); assertEquals(0, simulation.getSimulationDescriptor().getUnmodifiableFactMappings().size()); }
protected void commonAddRow(int rowIndex) { Scenario scenario = simulation.addScenario(rowIndex); final SimulationDescriptor simulationDescriptor = simulation.getSimulationDescriptor(); IntStream.range(1, getColumnCount()).forEach(columnIndex -> { final FactMapping factMappingByIndex = simulationDescriptor.getFactMappingByIndex(columnIndex); scenario.addMappingValue(factMappingByIndex.getFactIdentifier(), factMappingByIndex.getExpressionIdentifier(), null); String placeHolder = ((ScenarioGridColumn) columns.get(columnIndex)).isPropertyAssigned() ? ScenarioSimulationEditorConstants.INSTANCE.insertValue() : ScenarioSimulationEditorConstants.INSTANCE.defineValidType(); setCell(rowIndex, columnIndex, () -> new ScenarioGridCell(new ScenarioGridCellValue(null, placeHolder))); }); updateIndexColumn(); }
@Test public void removeFactMapping() { assertEquals(2, simulation.getUnmodifiableScenarios().get(0).getUnmodifiableFactMappingValues().size()); assertEquals(1, simulation.getSimulationDescriptor().getUnmodifiableFactMappings().size()); simulation.removeFactMapping(simulation.getSimulationDescriptor().getFactMappingByIndex(0)); assertEquals(1, simulation.getUnmodifiableScenarios().get(0).getUnmodifiableFactMappingValues().size()); assertEquals(0, simulation.getSimulationDescriptor().getUnmodifiableFactMappings().size()); }
@Test public void removeFactMappingByIndex() { assertEquals(2, simulation.getUnmodifiableScenarios().get(0).getUnmodifiableFactMappingValues().size()); assertEquals(1, simulation.getSimulationDescriptor().getUnmodifiableFactMappings().size()); simulation.removeFactMappingByIndex(0); assertEquals(1, simulation.getUnmodifiableScenarios().get(0).getUnmodifiableFactMappingValues().size()); assertEquals(0, simulation.getSimulationDescriptor().getUnmodifiableFactMappings().size()); }
@Test public void removeFactMappingByIndex() { assertEquals(2, simulation.getUnmodifiableScenarios().get(0).getUnmodifiableFactMappingValues().size()); assertEquals(1, simulation.getSimulationDescriptor().getUnmodifiableFactMappings().size()); simulation.removeFactMappingByIndex(0); assertEquals(1, simulation.getUnmodifiableScenarios().get(0).getUnmodifiableFactMappingValues().size()); assertEquals(0, simulation.getSimulationDescriptor().getUnmodifiableFactMappings().size()); }
@Test public void getParamsForBeanTest() { List<FactMappingValue> factMappingValues = new ArrayList<>(); FactMappingValue factMappingValue = new FactMappingValue(disputeFactIdentifier, amountGivenExpressionIdentifier, "NOT PARSABLE"); factMappingValues.add(factMappingValue); try { runnerHelper.getParamsForBean(simulation.getSimulationDescriptor(), disputeFactIdentifier, factMappingValues, classLoader, expressionEvaluator); fail(); } catch (ScenarioException ignored) { } Assert.assertTrue(factMappingValue.isError()); }
@Before public void init() { simulation = new Simulation(); simulationDescriptor = simulation.getSimulationDescriptor(); scenario = simulation.addScenario(); factIdentifier = FactIdentifier.create("test fact", String.class.getCanonicalName()); expressionIdentifier = ExpressionIdentifier.create("test expression", FactMappingType.EXPECT); }
@Test public void unmarshalRULE() throws Exception { String toUnmarshal = getFileContent("scesim-rule.scesim"); final ScenarioSimulationModel retrieved = ScenarioSimulationXMLPersistence.getInstance().unmarshal(toUnmarshal); assertEquals(retrieved.getSimulation().getSimulationDescriptor().getType(), ScenarioSimulationModel.Type.RULE); assertNotNull(retrieved.getSimulation().getSimulationDescriptor().getDmoSession()); assertNull(retrieved.getSimulation().getSimulationDescriptor().getDmnFilePath()); }
@Test public void unmarshalDMN() throws Exception { String toUnmarshal = getFileContent("scesim-dmn.scesim"); final ScenarioSimulationModel retrieved = ScenarioSimulationXMLPersistence.getInstance().unmarshal(toUnmarshal); assertEquals(retrieved.getSimulation().getSimulationDescriptor().getType(), ScenarioSimulationModel.Type.DMN); assertNotNull(retrieved.getSimulation().getSimulationDescriptor().getDmnFilePath()); assertNull(retrieved.getSimulation().getSimulationDescriptor().getDmoSession()); }
@Test public void migrateIfNecessary_1_2_to_1_3() throws Exception { String toMigrate = getFileContent("scesim-1-2.scesim"); String migrated = instance.migrateIfNecessary(toMigrate); assertTrue(toMigrate.contains("<ScenarioSimulationModel version=\"1.2\">")); assertFalse(migrated.contains("<ScenarioSimulationModel version=\"1.2\">")); for (FactMapping factMapping : instance.unmarshal(migrated, false).getSimulation().getSimulationDescriptor().getUnmodifiableFactMappings()) { assertTrue(factMapping.getExpressionElements().size() >= 1); } }
@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"); }
@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"); }