public Collection<String> getFactNames() { return factMappingValues.stream().map(e -> e.getFactIdentifier().getName()).collect(toSet()); }
public Collection<String> getFactNames() { return factMappingValues.stream().map(e -> e.getFactIdentifier().getName()).collect(toSet()); }
public FactMappingValue addMappingValue(FactIdentifier factIdentifier, ExpressionIdentifier expressionIdentifier, Object value) { String factName = factIdentifier.getName(); if (getFactMappingValue(factIdentifier, expressionIdentifier).isPresent()) { throw new IllegalArgumentException( new StringBuilder().append("A fact value for expression '").append(expressionIdentifier.getName()) .append("' and fact '").append(factName).append("' already exist").toString()); } FactMappingValue factMappingValue = new FactMappingValue(factIdentifier, expressionIdentifier, value); factMappingValues.add(factMappingValue); return factMappingValue; }
public FactMappingValue addMappingValue(FactIdentifier factIdentifier, ExpressionIdentifier expressionIdentifier, Object value) { String factName = factIdentifier.getName(); if (getFactMappingValue(factIdentifier, expressionIdentifier).isPresent()) { throw new IllegalArgumentException( new StringBuilder().append("A fact value for expression '").append(expressionIdentifier.getName()) .append("' and fact '").append(factName).append("' already exist").toString()); } FactMappingValue factMappingValue = new FactMappingValue(factIdentifier, expressionIdentifier, value); factMappingValues.add(factMappingValue); return factMappingValue; }
public FactMapping addFactMapping(int index, String factAlias, FactIdentifier factIdentifier, ExpressionIdentifier expressionIdentifier) { if (getFactMapping(factIdentifier, expressionIdentifier).isPresent()) { throw new IllegalArgumentException( new StringBuilder().append("An expression with name '").append(expressionIdentifier.getName()) .append("' already exists for the fact '").append(factIdentifier.getName()).append("'").toString()); } if (index > factMappings.size()) { throw new IllegalArgumentException( new StringBuilder().append("Impossible to add an element at position ").append(index) .append(" because there are only ").append(factMappings.size()).append(" elements").toString()); } FactMapping factMapping = new FactMapping(factAlias, factIdentifier, expressionIdentifier); factMappings.add(index, factMapping); return factMapping; }
public FactMapping addFactMapping(int index, String factAlias, FactIdentifier factIdentifier, ExpressionIdentifier expressionIdentifier) { if (getFactMapping(factIdentifier, expressionIdentifier).isPresent()) { throw new IllegalArgumentException( new StringBuilder().append("An expression with name '").append(expressionIdentifier.getName()) .append("' already exists for the fact '").append(factIdentifier.getName()).append("'").toString()); } if (index > factMappings.size()) { throw new IllegalArgumentException( new StringBuilder().append("Impossible to add an element at position ").append(index) .append(" because there are only ").append(factMappings.size()).append(" elements").toString()); } FactMapping factMapping = new FactMapping(factAlias, factIdentifier, expressionIdentifier); factMappings.add(index, factMapping); return factMapping; }
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 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 List<FactMapping> getFactMappingsByFactName(String factName) { return internalFilter(e -> e.getFactIdentifier().getName().equalsIgnoreCase(factName)); }
public List<FactMapping> getFactMappingsByFactName(String factName) { return internalFilter(e -> e.getFactIdentifier().getName().equalsIgnoreCase(factName)); }
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; } }
protected void updateIndexColumn() { final Optional<GridColumn<?>> indexColumn = this.getColumns() // Retrieving the column list .stream() // streaming .filter(gridColumn -> ((ScenarioGridColumn) gridColumn).getInformationHeaderMetaData().getTitle().equals(FactIdentifier.INDEX.getName())) // filtering by group name .findFirst(); indexColumn.ifPresent(column -> { int indexOfColumn = getColumns().indexOf(column); IntStream.range(0, getRowCount()) .forEach(rowIndex -> { String value = String.valueOf(rowIndex + 1); setCellValue(rowIndex, indexOfColumn, new ScenarioGridCellValue(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\">"); }; } }
@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)); }
@Override public void verifyConditions(SimulationDescriptor simulationDescriptor, ScenarioRunnerData scenarioRunnerData, ExpressionEvaluator expressionEvaluator, RequestContext requestContext) { DMNResult dmnResult = requestContext.getOutput(DMNScenarioExecutableBuilder.DMN_RESULT); for (ScenarioExpect output : scenarioRunnerData.getExpects()) { FactIdentifier factIdentifier = output.getFactIdentifier(); String decisionName = factIdentifier.getName(); DMNDecisionResult decisionResult = dmnResult.getDecisionResultByName(decisionName); if (decisionResult == null) { throw new ScenarioException("DMN execution has not generated a decision result with name " + decisionName); } for (FactMappingValue expectedResult : output.getExpectedResult()) { ExpressionIdentifier expressionIdentifier = expectedResult.getExpressionIdentifier(); FactMapping factMapping = simulationDescriptor.getFactMapping(factIdentifier, expressionIdentifier) .orElseThrow(() -> new IllegalStateException("Wrong expression, this should not happen")); ScenarioResult scenarioResult = fillResult(expectedResult, factIdentifier, () -> getSingleFactValueResult(factMapping, expectedResult, decisionResult, expressionEvaluator)); scenarioRunnerData.addResult(scenarioResult); } } }
@Override public RequestContext executeScenario(KieContainer kieContainer, ScenarioRunnerData scenarioRunnerData, ExpressionEvaluator expressionEvaluator, SimulationDescriptor simulationDescriptor) { if (!ScenarioSimulationModel.Type.DMN.equals(simulationDescriptor.getType())) { throw new ScenarioException("Impossible to run a not-DMN simulation with DMN runner"); } DMNScenarioExecutableBuilder executableBuilder = DMNScenarioExecutableBuilder.createBuilder(kieContainer); executableBuilder.setActiveModel(simulationDescriptor.getDmnFilePath()); for (ScenarioGiven input : scenarioRunnerData.getGivens()) { executableBuilder.setValue(input.getFactIdentifier().getName(), input.getValue()); } return executableBuilder.run(); }
private Simulation getSimulation() { Simulation toReturn = new Simulation(); SimulationDescriptor simulationDescriptor = toReturn.getSimulationDescriptor(); simulationDescriptor.setType(ScenarioSimulationModel.Type.RULE); simulationDescriptor.addFactMapping(FactIdentifier.INDEX.getName(), FactIdentifier.INDEX, ExpressionIdentifier.INDEX); simulationDescriptor.addFactMapping(FactIdentifier.DESCRIPTION.getName(), FactIdentifier.DESCRIPTION, ExpressionIdentifier.DESCRIPTION); Scenario scenario = toReturn.addScenario(); int row = toReturn.getUnmodifiableScenarios().indexOf(scenario); scenario.setDescription(null); // Add GIVEN Facts IntStream.range(2, 4).forEach(id -> { ExpressionIdentifier givenExpression = ExpressionIdentifier.create(row + "|" + id, FactMappingType.GIVEN); simulationDescriptor.addFactMapping(FactMapping.getInstancePlaceHolder(id), FactIdentifier.EMPTY, givenExpression); scenario.addMappingValue(FactIdentifier.EMPTY, givenExpression, null); }); // Add EXPECT Facts IntStream.range(2, 4).forEach(id -> { id += 2; // This is to have consistent labels/names even when adding columns at runtime ExpressionIdentifier expectedExpression = ExpressionIdentifier.create(row + "|" + id, FactMappingType.EXPECT); simulationDescriptor.addFactMapping(FactMapping.getInstancePlaceHolder(id), FactIdentifier.EMPTY, expectedExpression); scenario.addMappingValue(FactIdentifier.EMPTY, expectedExpression, null); }); return toReturn; } }