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();
}
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");
}
});
}
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);
}
Aggregations