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 static ExpressionIdentifier create(String name, FactMappingType type) { return new ExpressionIdentifier(name, type); }
public FactMapping(FactIdentifier factIdentifier, ExpressionIdentifier expressionIdentifier) { this(expressionIdentifier.getName(), factIdentifier, expressionIdentifier); }
public int getIndexByIdentifier(FactIdentifier factIdentifier, ExpressionIdentifier expressionIdentifier) { return IntStream.range(0, factMappings.size()).filter(index -> { FactMapping factMapping = factMappings.get(index); return factMapping.getExpressionIdentifier().equals(expressionIdentifier) && factMapping.getFactIdentifier().equals(factIdentifier); }).findFirst().orElseThrow(() -> new IllegalArgumentException( new StringBuilder().append("Impossible to find a FactMapping with factIdentifier '").append(factIdentifier.getName()) .append("' and expressionIdentifier '").append(expressionIdentifier.getName()).append("'").toString())); }
@Test public void getScenarioGridColumnLocal() { String columnId = factMappingDescription.getExpressionIdentifier().getName(); String instanceTitle = factMappingDescription.getFactIdentifier().getName(); String propertyTitle = "PROPERTY TITLE"; final FactMappingType type = factMappingDescription.getExpressionIdentifier().getType(); String columnGroup = type.name(); scenarioGrid.getScenarioGridColumnLocal(instanceTitle, propertyTitle, columnId, columnGroup, type, ScenarioSimulationEditorConstants.INSTANCE.insertValue()); verify(scenarioGrid, times(1)).getScenarioHeaderTextBoxSingletonDOMElementFactory(); verify(scenarioGrid, times(1)).getHeaderBuilderLocal(eq(instanceTitle), eq(propertyTitle), eq(columnId), eq(columnGroup), eq(type), eq(scenarioHeaderTextBoxSingletonDOMElementFactoryMock)); }
public List<ScenarioExpect> extractExpectedValues(List<FactMappingValue> factMappingValues) { List<ScenarioExpect> scenarioExpect = new ArrayList<>(); Map<FactIdentifier, List<FactMappingValue>> groupByFactIdentifier = groupByFactIdentifierAndFilter(factMappingValues, FactMappingType.EXPECT); Set<FactIdentifier> inputFacts = factMappingValues.stream() .filter(elem -> FactMappingType.GIVEN.equals(elem.getExpressionIdentifier().getType())) .map(FactMappingValue::getFactIdentifier) .collect(Collectors.toSet()); for (Map.Entry<FactIdentifier, List<FactMappingValue>> entry : groupByFactIdentifier.entrySet()) { FactIdentifier factIdentifier = entry.getKey(); scenarioExpect.add(new ScenarioExpect(factIdentifier, entry.getValue(), !inputFacts.contains(factIdentifier))); } return scenarioExpect; }
public Optional<FactMappingValue> getFactMappingValue(FactIdentifier factIdentifier, ExpressionIdentifier expressionIdentifier) { return factMappingValues.stream().filter(e -> e.getFactIdentifier().equals(factIdentifier) && e.getExpressionIdentifier().equals(expressionIdentifier)).findFirst(); }
@Test public void setHeaderColumn() { String columnId = factMappingDescription.getExpressionIdentifier().getName(); FactMappingType type = factMappingDescription.getExpressionIdentifier().getType(); String columnGroup = type.name(); scenarioGrid.setHeaderColumn(1, factMappingDescription, true); reset(scenarioGridColumnMock); reset(scenarioGridModelMock); columnId = factMappingGiven.getExpressionIdentifier().getName(); type = factMappingGiven.getExpressionIdentifier().getType(); columnGroup = type.name(); scenarioGrid.setHeaderColumn(1, factMappingGiven, true);
public int getIndexByIdentifier(FactIdentifier factIdentifier, ExpressionIdentifier expressionIdentifier) { return IntStream.range(0, factMappings.size()).filter(index -> { FactMapping factMapping = factMappings.get(index); return factMapping.getExpressionIdentifier().equals(expressionIdentifier) && factMapping.getFactIdentifier().equals(factIdentifier); }).findFirst().orElseThrow(() -> new IllegalArgumentException( new StringBuilder().append("Impossible to find a FactMapping with factIdentifier '").append(factIdentifier.getName()) .append("' and expressionIdentifier '").append(expressionIdentifier.getName()).append("'").toString())); }
public Map<FactIdentifier, List<FactMappingValue>> groupByFactIdentifierAndFilter(List<FactMappingValue> factMappingValues, FactMappingType type) { Map<FactIdentifier, List<FactMappingValue>> groupByFactIdentifier = new HashMap<>(); for (FactMappingValue factMappingValue : factMappingValues) { FactIdentifier factIdentifier = factMappingValue.getFactIdentifier(); // null means skip if (factMappingValue.getRawValue() == null) { continue; } ExpressionIdentifier expressionIdentifier = factMappingValue.getExpressionIdentifier(); if (expressionIdentifier == null) { throw new IllegalArgumentException("ExpressionIdentifier malformed"); } if (!Objects.equals(expressionIdentifier.getType(), type)) { continue; } groupByFactIdentifier.computeIfAbsent(factIdentifier, key -> new ArrayList<>()) .add(factMappingValue); } return groupByFactIdentifier; }
public Optional<FactMappingValue> getFactMappingValue(FactIdentifier factIdentifier, ExpressionIdentifier expressionIdentifier) { return factMappingValues.stream().filter(e -> e.getFactIdentifier().equals(factIdentifier) && e.getExpressionIdentifier().equals(expressionIdentifier)).findFirst(); }
/** * This method update the type mapped inside a give column and updates the underlying model * @param columnIndex * @param column * @param value * @param lastLevelClassName * @param keepData */ public void updateColumnProperty(int columnIndex, final GridColumn<?> column, String value, String lastLevelClassName, boolean keepData) { checkSimulation(); List<GridCellValue<?>> originalValues = new ArrayList<>(); if (keepData) { IntStream.range(0, getRowCount()) .forEach(rowIndex -> originalValues.add(getCell(rowIndex, columnIndex).getValue())); } deleteColumn(columnIndex); String group = ((ScenarioGridColumn) column).getInformationHeaderMetaData().getColumnGroup(); String columnId = ((ScenarioGridColumn) column).getInformationHeaderMetaData().getColumnId(); String[] elements = value.split("\\."); ExpressionIdentifier ei = ExpressionIdentifier.create(columnId, FactMappingType.valueOf(group)); commonAddColumn(columnIndex, column, ei); final FactMapping factMappingByIndex = simulation.getSimulationDescriptor().getFactMappingByIndex(columnIndex); IntStream.range(0, elements.length) .forEach(stepIndex -> factMappingByIndex.addExpressionElement(elements[stepIndex], lastLevelClassName)); if (keepData) { IntStream.range(0, getRowCount()) .forEach(rowIndex -> setCellValue(rowIndex, columnIndex, originalValues.get(rowIndex))); } }
protected void setHeaderColumn(int columnIndex, FactMapping factMapping, boolean editableHeaders) { final FactIdentifier factIdentifier = factMapping.getFactIdentifier(); String columnId = factMapping.getExpressionIdentifier().getName(); String instanceTitle = factMapping.getFactAlias(); String propertyTitle = factMapping.getExpressionAlias(); String columnGroup = factMapping.getExpressionIdentifier().getType().name(); boolean isInstanceAssigned = isInstanceAssigned(factIdentifier); boolean isPropertyAssigned = isPropertyAssigned(isInstanceAssigned, factMapping); String placeHolder = getPlaceholder(isPropertyAssigned); ScenarioGridColumn scenarioGridColumn = getScenarioGridColumnLocal(instanceTitle, propertyTitle, columnId, columnGroup, factMapping.getExpressionIdentifier().getType(), placeHolder); scenarioGridColumn.setInstanceAssigned(isInstanceAssigned); scenarioGridColumn.setPropertyAssigned(isPropertyAssigned); scenarioGridColumn.setFactIdentifier(factIdentifier); scenarioGridColumn.setEditableHeaders(editableHeaders); // by default ScenarioGridColumnBuilders.ScenarioGridColumnBuilder.build() set ColumnWidthMode.auto to all generated columns if (FactMappingType.OTHER.equals(factMapping.getExpressionIdentifier().getType())) { scenarioGridColumn.setColumnWidthMode(ColumnWidthMode.FIXED); scenarioGridColumn.setMinimumWidth(scenarioGridColumn.getWidth()); } ((ScenarioGridModel) model).insertColumnGridOnly(columnIndex, scenarioGridColumn); }
public FactMapping(FactIdentifier factIdentifier, ExpressionIdentifier expressionIdentifier) { this(expressionIdentifier.getName(), factIdentifier, expressionIdentifier); }
public static ExpressionIdentifier create(String name, FactMappingType type) { return new ExpressionIdentifier(name, type); }
protected SortedMap<String, FactModelTree> getInstanceMap(SortedMap<String, FactModelTree> sourceMap) { SortedMap<String, FactModelTree> toReturn = new TreeMap<>(); // map instance name to base class if (model != null) { final SimulationDescriptor simulationDescriptor = model.getSimulation().getSimulationDescriptor(); simulationDescriptor.getUnmodifiableFactMappings() .stream() .filter(factMapping -> !Objects.equals(FactMappingType.OTHER, factMapping.getExpressionIdentifier().getType())) .forEach(factMapping -> { String dataObjectName = factMapping.getFactIdentifier().getClassName(); if (dataObjectName.contains(".")) { dataObjectName = dataObjectName.substring(dataObjectName.lastIndexOf(".") + 1); } final String instanceName = factMapping.getFactAlias(); if (!instanceName.equals(dataObjectName)) { final FactModelTree factModelTree = sourceMap.get(dataObjectName); if (factModelTree != null) { toReturn.put(instanceName, factModelTree); } } }); } return toReturn; }
public String getDescription() { return factMappingValues.stream() .filter(e -> e.getExpressionIdentifier().equals(ExpressionIdentifier.DESCRIPTION) && e.getFactIdentifier().equals(FactIdentifier.DESCRIPTION) && e.getRawValue() != null) .map(e -> (String) e.getRawValue()) .findFirst().orElse(""); }
@Before public void init() { simulationDescriptor = new SimulationDescriptor(); factIdentifier = FactIdentifier.create("test fact", String.class.getCanonicalName()); expressionIdentifier = ExpressionIdentifier.create("test expression", FactMappingType.EXPECT); }
public FactMapping addFactMapping(int index, FactIdentifier factIdentifier, ExpressionIdentifier expressionIdentifier) { return addFactMapping(index, expressionIdentifier.getName(), factIdentifier, expressionIdentifier); }
@Test public void getExpressionElementsWithoutClass() { FactMapping original = new FactMapping("FACT_ALIAS", new FactIdentifier("FI_TEST", "com.test.Foo"), new ExpressionIdentifier("EI_TEST", FactMappingType.GIVEN)); assertThatThrownBy(original::getExpressionElementsWithoutClass) .isInstanceOf(IllegalStateException.class) .hasMessage("ExpressionElements malformed"); assertEquals(0, original.getExpressionElements().size()); original.addExpressionElement("STEP", String.class.getCanonicalName()); assertEquals(0, original.getExpressionElementsWithoutClass().size()); assertEquals(1, original.getExpressionElements().size()); } }