use of org.drools.scenariosimulation.api.model.FactMapping in project drools-wb by kiegroup.
the class ScenarioCsvImportExport method generateHeader.
protected void generateHeader(List<FactMapping> factMappings, CSVPrinter printer) throws IOException {
List<String> firstLineHeader = new ArrayList<>();
List<String> secondLineHeader = new ArrayList<>();
List<String> thirdLineHeader = new ArrayList<>();
for (FactMapping factMapping : factMappings) {
if (FactMappingType.OTHER.equals(factMapping.getExpressionIdentifier().getType())) {
// OTHER
String factAlias = factMapping.getFactAlias();
firstLineHeader.add(factAlias);
secondLineHeader.add(factAlias);
thirdLineHeader.add(factAlias);
} else {
// GIVEN/EXPECT
firstLineHeader.add(factMapping.getExpressionIdentifier().getType().name());
// Instance
secondLineHeader.add("#".equals(factMapping.getFactAlias()) ? "" : factMapping.getFactAlias());
// Property
thirdLineHeader.add(factMapping.getExpressionAlias());
}
}
printer.printRecord(firstLineHeader.toArray());
printer.printRecord(secondLineHeader.toArray());
printer.printRecord(thirdLineHeader.toArray());
}
use of org.drools.scenariosimulation.api.model.FactMapping in project drools-wb by kiegroup.
the class AbstractSelectedColumnCommandTest method getMatchingExpressionAlias.
/* This test is usable ONLY by <code>SetPropertyCommandTest</code> subclass */
protected void getMatchingExpressionAlias() {
Optional<String> retrieved = ((AbstractSelectedColumnCommand) commandSpy).getMatchingExpressionAlias(scenarioSimulationContextLocal, MULTIPART_VALUE_ELEMENTS, factIdentifierMock);
verify(simulationDescriptorMock, times(1)).getFactMappingsByFactName(eq(factIdentifierMock.getName()));
assertEquals(Optional.empty(), retrieved);
List<FactMapping> factMappingList = new ArrayList<>();
factMappingList.add(factMappingMock);
when(simulationDescriptorMock.getFactMappingsByFactName(FACT_IDENTIFIER_NAME)).thenReturn(factMappingList.stream());
String EXPRESSION_ALIAS = "EXPRESSION_ALIAS";
when(factMappingMock.getExpressionAlias()).thenReturn(EXPRESSION_ALIAS);
retrieved = ((AbstractSelectedColumnCommand) commandSpy).getMatchingExpressionAlias(scenarioSimulationContextLocal, FULL_PROPERTY_NAME_ELEMENTS, factIdentifierMock);
assertEquals(Optional.empty(), retrieved);
List<ExpressionElement> expressionElements = FULL_PROPERTY_NAME_ELEMENTS.stream().map(ExpressionElement::new).collect(Collectors.toList());
when(factMappingMock.getExpressionElements()).thenReturn(expressionElements);
when(simulationDescriptorMock.getFactMappingsByFactName(FACT_IDENTIFIER_NAME)).thenReturn(factMappingList.stream());
retrieved = ((AbstractSelectedColumnCommand) commandSpy).getMatchingExpressionAlias(scenarioSimulationContextLocal, FULL_PROPERTY_NAME_ELEMENTS, factIdentifierMock);
assertEquals(Optional.of(EXPRESSION_ALIAS), retrieved);
}
use of org.drools.scenariosimulation.api.model.FactMapping in project drools-wb by kiegroup.
the class AbstractSelectedColumnCommand method manageCollectionProperty.
/**
* @param context
* @param selectedColumn
* @param factName The name of the class to be used to retrieve the corresponding <code>FactModelTree</code>, i.e. without the <b>package</b>
* @param columnIndex
* @param fullPropertyPathElements This is the <code>List</code> of all the elements pointing to the final property (ex. Book.author.books)
*/
protected void manageCollectionProperty(ScenarioSimulationContext context, ScenarioGridColumn selectedColumn, String factName, int columnIndex, List<String> fullPropertyPathElements) {
final SortedMap<String, FactModelTree> dataObjectFieldsMap = context.getDataObjectFieldsMap();
final FactModelTree factModelTree = dataObjectFieldsMap.get(factName);
final Optional<AbstractScesimModel> selectedScenarioGridModel = context.getAbstractScesimGridModelByGridWidget(gridWidget).getAbstractScesimModel();
if (!selectedScenarioGridModel.isPresent()) {
throw new IllegalArgumentException("SelectedGrid not found");
}
final FactMapping factMapping = selectedScenarioGridModel.get().getScesimModelDescriptor().getFactMappingByIndex(columnIndex);
selectedColumn.setFactory(context.getCollectionEditorSingletonDOMElementFactory(gridWidget));
if (factModelTree.isSimple()) {
factMapping.setGenericTypes(factModelTree.getGenericTypeInfo(VALUE));
} else {
final FactModelTree nestedFactModelTree = navigateComplexObject(factModelTree, fullPropertyPathElements, dataObjectFieldsMap);
factMapping.setGenericTypes(nestedFactModelTree.getGenericTypeInfo(fullPropertyPathElements.get(fullPropertyPathElements.size() - 1)));
}
}
use of org.drools.scenariosimulation.api.model.FactMapping in project drools-wb by kiegroup.
the class DuplicateInstanceCommand method executeIfSelectedColumn.
@Override
protected void executeIfSelectedColumn(ScenarioSimulationContext context, ScenarioGridColumn selectedColumn) {
final AbstractScesimGridModel<? extends AbstractScesimModel, ? extends AbstractScesimData> selectedScenarioGridModel = context.getAbstractScesimGridModelByGridWidget(gridWidget);
/* Generating the new instance alias with following schema: <original instance name> + '_copy_' + <number of existing instances> */
int instancesCount = selectedScenarioGridModel.getInstancesCount(selectedColumn.getFactIdentifier().getClassName());
String alias = selectedColumn.getInformationHeaderMetaData().getTitle().split(COPY_LABEL)[0] + COPY_LABEL + instancesCount;
/* For every columns which belongs to the selected instance, it creates a new column and assign it the duplicated instance
* and the duplicated property, if are assigned */
int columnPosition = selectedScenarioGridModel.getInstanceLimits(selectedScenarioGridModel.getColumns().indexOf(selectedColumn)).getMaxRowIndex() + 1;
AtomicInteger nextColumnPosition = new AtomicInteger(columnPosition);
selectedScenarioGridModel.getInstanceScenarioGridColumns(selectedColumn).forEach(originalColumn -> {
ScenarioGridColumn createdColumn = insertNewColumn(context, originalColumn, nextColumnPosition.getAndIncrement(), false);
if (originalColumn.isInstanceAssigned()) {
setInstanceHeader(context, createdColumn, alias, originalColumn.getFactIdentifier().getClassName());
if (originalColumn.isPropertyAssigned()) {
int originalColumnIndex = selectedScenarioGridModel.getColumns().indexOf(originalColumn);
final FactMapping originalFactMapping = selectedScenarioGridModel.getAbstractScesimModel().get().getScesimModelDescriptor().getFactMappingByIndex(originalColumnIndex);
factMappingValueType = originalFactMapping.getFactMappingValueType();
/* Rebuilt propertyNameElements, which is composed by: factName.property . The property MUST be the original property name */
List<String> propertyNameElements = new ArrayList<>();
propertyNameElements.add(alias);
propertyNameElements.addAll(originalFactMapping.getExpressionElementsWithoutClass().stream().map(ExpressionElement::getStep).collect(Collectors.toList()));
setPropertyHeader(context, createdColumn, originalColumn.getFactIdentifier().getClassName(), propertyNameElements, originalFactMapping.getClassName(), originalColumn.getPropertyHeaderMetaData().getTitle());
/* It copies the properties values */
int createdColumnIndex = selectedScenarioGridModel.getColumns().indexOf(createdColumn);
selectedScenarioGridModel.duplicateColumnValues(originalColumnIndex, createdColumnIndex);
}
}
});
}
use of org.drools.scenariosimulation.api.model.FactMapping in project drools-wb by kiegroup.
the class SetGridCellValueCommand method internalExecute.
@Override
protected void internalExecute(ScenarioSimulationContext context) {
final ScenarioSimulationContext.Status status = context.getStatus();
AbstractScesimModel<AbstractScesimData> abstractScesimModel = context.getAbstractScesimModelByGridWidget(gridWidget);
int columnIndex = status.getColumnIndex();
FactMapping factMapping = abstractScesimModel.getScesimModelDescriptor().getFactMappingByIndex(columnIndex);
ScenarioGridColumn selectedColumn = (ScenarioGridColumn) context.getAbstractScesimGridModelByGridWidget(gridWidget).getColumns().get(columnIndex);
String placeholder = ScenarioSimulationUtils.getPlaceHolder(selectedColumn.isInstanceAssigned(), selectedColumn.isPropertyAssigned(), factMapping.getFactMappingValueType(), factMapping.getClassName());
context.getAbstractScesimGridModelByGridWidget(gridWidget).setCellValue(status.getRowIndex(), columnIndex, new ScenarioGridCellValue(status.getGridCellValue(), placeholder));
context.getAbstractScesimGridModelByGridWidget(gridWidget).resetError(status.getRowIndex(), columnIndex);
}
Aggregations