public FactMapping getFactMapping(FactModelTree factModelTree, String propertyName, List<String> previousSteps, String factType) { String factAlias = previousSteps.size() > 0 ? previousSteps.get(0) : factModelTree.getFactName(); ExpressionIdentifier expressionIdentifier = ExpressionIdentifier.create(row + "|" + id.getAndIncrement(), type); final FactMapping factMapping = simulationDescriptor.addFactMapping(factAlias, factIdentifier, expressionIdentifier); List<String> localPreviousStep = new ArrayList<>(previousSteps); localPreviousStep.add(propertyName); String expressionAlias = String.join(".", localPreviousStep.size() > 1 ? localPreviousStep.subList(1, localPreviousStep.size()) : localPreviousStep); factMapping.setExpressionAlias(expressionAlias); previousSteps.forEach(step -> factMapping.addExpressionElement(step, factType)); if (previousSteps.isEmpty()) { factMapping.addExpressionElement(factModelTree.getFactName(), factType); } scenario.addMappingValue(factIdentifier, expressionIdentifier, null); return factMapping; } }
public void updateHeader(int columnIndex, int headerRowIndex, String value) { final ScenarioHeaderMetaData editedMetadata = (ScenarioHeaderMetaData) getColumns().get(columnIndex).getHeaderMetaData().get(headerRowIndex); // do not update if old and new value are the same if (Objects.equals(editedMetadata.getTitle(), value)) { return; } SimulationDescriptor simulationDescriptor = simulation.getSimulationDescriptor(); FactMapping factMappingToEdit = simulationDescriptor.getFactMappingByIndex(columnIndex); if (editedMetadata.isInstanceHeader()) { // we have to update title and value for every column of the group IntStream.range(0, getColumnCount()).forEach(index -> { updateFactMapping(simulationDescriptor, factMappingToEdit, index, value); }); eventBus.fireEvent(new ReloadRightPanelEvent(false)); } else { editedMetadata.setTitle(value); factMappingToEdit.setExpressionAlias(value); } }
@Override public Simulation createSimulation(Path context, String value) throws Exception { Simulation toReturn = new Simulation(); SimulationDescriptor simulationDescriptor = toReturn.getSimulationDescriptor(); simulationDescriptor.setType(ScenarioSimulationModel.Type.RULE); simulationDescriptor.setDmoSession(value); Scenario scenario = createScenario(toReturn, simulationDescriptor); int row = toReturn.getUnmodifiableScenarios().indexOf(scenario); // Add GIVEN Fact int id = 1; ExpressionIdentifier givenExpression = ExpressionIdentifier.create(row + "|" + id, FactMappingType.GIVEN); final FactMapping givenFactMapping = simulationDescriptor.addFactMapping(FactMapping.getInstancePlaceHolder(id), FactIdentifier.EMPTY, givenExpression); givenFactMapping.setExpressionAlias(FactMapping.getPropertyPlaceHolder(id)); scenario.addMappingValue(FactIdentifier.EMPTY, givenExpression, null); // Add EXPECT Fact id = 2; ExpressionIdentifier expectedExpression = ExpressionIdentifier.create(row + "|" + id, FactMappingType.EXPECT); final FactMapping expectedFactMapping = simulationDescriptor.addFactMapping(FactMapping.getInstancePlaceHolder(id), FactIdentifier.EMPTY, expectedExpression); expectedFactMapping.setExpressionAlias(FactMapping.getPropertyPlaceHolder(id)); scenario.addMappingValue(FactIdentifier.EMPTY, expectedExpression, null); return toReturn; } }
try { final FactMapping createdFactMapping = simulationDescriptor.addFactMapping(columnIndex, instanceTitle, ((ScenarioGridColumn) column).getFactIdentifier(), ei); createdFactMapping.setExpressionAlias(propertyTitle); if (index == -1) { // This is actually an append super.appendColumn(column);
@Test public void cloneFactMapping() { FactMapping original = new FactMapping("FACT_ALIAS", new FactIdentifier("FI_TEST", "com.test.Foo"), new ExpressionIdentifier("EI_TEST", FactMappingType.GIVEN)); original.addExpressionElement("FIRST_STEP", String.class.getName()); original.setExpressionAlias("EA_TEST"); FactMapping retrieved = original.cloneFactMapping(); assertTrue(retrieved.equals(original)); }
@Test public void cloneFactMapping() { FactMapping original = new FactMapping("FACT_ALIAS", new FactIdentifier("FI_TEST", "com.test.Foo"), new ExpressionIdentifier("EI_TEST", FactMappingType.GIVEN)); original.addExpressionElement("FIRST_STEP", String.class.getName()); original.setExpressionAlias("EA_TEST"); FactMapping retrieved = original.cloneFactMapping(); assertTrue(retrieved.equals(original)); }
ExpressionIdentifier givenExpression = ExpressionIdentifier.create(row + "|" + id, FactMappingType.GIVEN); final FactMapping givenFactMapping = simulationDescriptor.addFactMapping(FactMapping.getInstancePlaceHolder(id), FactIdentifier.EMPTY, givenExpression); givenFactMapping.setExpressionAlias(FactMapping.getPropertyPlaceHolder(id)); scenario.addMappingValue(FactIdentifier.EMPTY, givenExpression, null); ExpressionIdentifier expectedExpression = ExpressionIdentifier.create(row + "|" + id, FactMappingType.EXPECT); final FactMapping expectedFactMapping = simulationDescriptor.addFactMapping(FactMapping.getInstancePlaceHolder(id), FactIdentifier.EMPTY, expectedExpression); expectedFactMapping.setExpressionAlias(FactMapping.getPropertyPlaceHolder(id)); scenario.addMappingValue(FactIdentifier.EMPTY, expectedExpression, null); return toReturn;