Search in sources :

Example 26 with FactIdentifier

use of org.drools.scenariosimulation.api.model.FactIdentifier in project drools-wb by kiegroup.

the class ScenarioGridModel method insertRowGridOnly.

/**
 * This method <i>insert</i> a row to the grid and populate it with values taken from given <code>Scenario</code>
 * @param row
 */
@Override
public void insertRowGridOnly(final int rowIndex, final GridRow row, final Scenario scenario) {
    insertRowGridOnly(rowIndex, row);
    scenario.getUnmodifiableFactMappingValues().forEach(value -> {
        FactIdentifier factIdentifier = value.getFactIdentifier();
        ExpressionIdentifier expressionIdentifier = value.getExpressionIdentifier();
        if (value.getRawValue() == null || value.getRawValue() instanceof String) {
            // Let' put a placeholder
            String stringValue = (String) value.getRawValue();
            int columnIndex = abstractScesimModel.getScesimModelDescriptor().getIndexByIdentifier(factIdentifier, expressionIdentifier);
            final FactMapping factMappingByIndex = abstractScesimModel.getScesimModelDescriptor().getFactMappingByIndex(columnIndex);
            String placeHolder = ((ScenarioGridColumn) columns.get(columnIndex)).getPlaceHolder();
            setCell(rowIndex, columnIndex, () -> {
                ScenarioGridCell newCell = new ScenarioGridCell(new ScenarioGridCellValue(stringValue, placeHolder));
                if (ScenarioSimulationSharedUtils.isCollectionOrMap((factMappingByIndex.getClassName()))) {
                    newCell.setListMap(ScenarioSimulationSharedUtils.isList((factMappingByIndex.getClassName())));
                }
                return newCell;
            });
        } else {
            throw new UnsupportedOperationException("Only string is supported at the moment");
        }
    });
    updateIndexColumn();
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) ScenarioGridCell(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridCell) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) ScenarioGridCellValue(org.drools.workbench.screens.scenariosimulation.client.values.ScenarioGridCellValue)

Example 27 with FactIdentifier

use of org.drools.scenariosimulation.api.model.FactIdentifier in project drools-wb by kiegroup.

the class BackgroundGridModel method insertRowGridOnly.

/**
 * This method <i>insert</i> a row to the grid and populate it with values taken from given <code>Scenario</code>
 * @param row
 */
@Override
public void insertRowGridOnly(final int rowIndex, final GridRow row, final BackgroundData abstractScesimData) {
    insertRowGridOnly(rowIndex, row);
    abstractScesimData.getUnmodifiableFactMappingValues().forEach(value -> {
        FactIdentifier factIdentifier = value.getFactIdentifier();
        ExpressionIdentifier expressionIdentifier = value.getExpressionIdentifier();
        if (value.getRawValue() == null || value.getRawValue() instanceof String) {
            String stringValue = (String) value.getRawValue();
            int columnIndex = abstractScesimModel.getScesimModelDescriptor().getIndexByIdentifier(factIdentifier, expressionIdentifier);
            final FactMapping factMappingByIndex = abstractScesimModel.getScesimModelDescriptor().getFactMappingByIndex(columnIndex);
            String placeHolder = ((ScenarioGridColumn) columns.get(columnIndex)).getPlaceHolder();
            setCell(rowIndex, columnIndex, () -> {
                ScenarioGridCell newCell = new ScenarioGridCell(new ScenarioGridCellValue(stringValue, placeHolder));
                if (ScenarioSimulationSharedUtils.isCollectionOrMap((factMappingByIndex.getClassName()))) {
                    newCell.setListMap(ScenarioSimulationSharedUtils.isList((factMappingByIndex.getClassName())));
                }
                return newCell;
            });
        } else {
            throw new UnsupportedOperationException("Only string is supported at the moment");
        }
    });
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) ScenarioGridCell(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridCell) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) ScenarioGridCellValue(org.drools.workbench.screens.scenariosimulation.client.values.ScenarioGridCellValue)

Example 28 with FactIdentifier

use of org.drools.scenariosimulation.api.model.FactIdentifier in project drools-wb by kiegroup.

the class ScenarioSimulationUtilsTest method getPropertyNameElementsWithoutAlias.

@Test
public void getPropertyNameElementsWithoutAlias() {
    FactIdentifier factIdentifierMock = mock(FactIdentifier.class);
    String packageName = "com";
    String className = "ClassName";
    String fullClassName = packageName + "." + className;
    String propertyName = "propertyName";
    String aliasName = "AliasName";
    when(factIdentifierMock.getClassName()).thenReturn(fullClassName);
    when(factIdentifierMock.getClassNameWithoutPackage()).thenReturn(className);
    List<String> retrieved = ScenarioSimulationUtils.getPropertyNameElementsWithoutAlias(Collections.singletonList(propertyName), factIdentifierMock, ScenarioSimulationModel.Type.RULE);
    assertEquals(Collections.singletonList(propertyName), retrieved);
    retrieved = ScenarioSimulationUtils.getPropertyNameElementsWithoutAlias(Collections.singletonList(propertyName), factIdentifierMock, ScenarioSimulationModel.Type.DMN);
    assertEquals(Collections.singletonList(propertyName), retrieved);
    retrieved = ScenarioSimulationUtils.getPropertyNameElementsWithoutAlias(Arrays.asList(aliasName, propertyName), factIdentifierMock, ScenarioSimulationModel.Type.RULE);
    assertEquals(Arrays.asList(className, propertyName), retrieved);
    retrieved = ScenarioSimulationUtils.getPropertyNameElementsWithoutAlias(Arrays.asList(aliasName, propertyName), factIdentifierMock, ScenarioSimulationModel.Type.DMN);
    assertEquals(Arrays.asList(fullClassName, propertyName), retrieved);
}
Also used : FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) Test(org.junit.Test)

Aggregations

FactIdentifier (org.drools.scenariosimulation.api.model.FactIdentifier)28 FactMapping (org.drools.scenariosimulation.api.model.FactMapping)15 ExpressionIdentifier (org.drools.scenariosimulation.api.model.ExpressionIdentifier)12 List (java.util.List)10 ArrayList (java.util.ArrayList)9 FactMappingValue (org.drools.scenariosimulation.api.model.FactMappingValue)9 Test (org.junit.Test)9 Map (java.util.Map)8 ScesimModelDescriptor (org.drools.scenariosimulation.api.model.ScesimModelDescriptor)8 Set (java.util.Set)6 Objects (java.util.Objects)5 Collectors.toList (java.util.stream.Collectors.toList)5 ExpressionElement (org.drools.scenariosimulation.api.model.ExpressionElement)5 FactMappingType (org.drools.scenariosimulation.api.model.FactMappingType)5 ExpressionEvaluator (org.drools.scenariosimulation.backend.expression.ExpressionEvaluator)5 InstanceGiven (org.drools.scenariosimulation.backend.runner.model.InstanceGiven)5 ScenarioExpect (org.drools.scenariosimulation.backend.runner.model.ScenarioExpect)5 Supplier (java.util.function.Supplier)4 Collectors (java.util.stream.Collectors)4 FactMappingValueStatus (org.drools.scenariosimulation.api.model.FactMappingValueStatus)4