use of org.drools.scenariosimulation.api.model.FactMapping in project drools-wb by kiegroup.
the class DMNSimulationSettingsCreationStrategy method addEmptyColumnsIfNeeded.
/**
* If DMN model is empty, contains only inputs or only outputs this method add one GIVEN and/or EXPECT empty column
* @param simulation
* @param scenarioWithIndex
*/
protected void addEmptyColumnsIfNeeded(Simulation simulation, ScenarioWithIndex scenarioWithIndex) {
boolean hasGiven = false;
boolean hasExpect = false;
ScesimModelDescriptor simulationDescriptor = simulation.getScesimModelDescriptor();
for (FactMapping factMapping : simulationDescriptor.getFactMappings()) {
FactMappingType factMappingType = factMapping.getExpressionIdentifier().getType();
if (!hasGiven && GIVEN.equals(factMappingType)) {
hasGiven = true;
} else if (!hasExpect && EXPECT.equals(factMappingType)) {
hasExpect = true;
}
}
if (!hasGiven) {
createEmptyColumn(simulationDescriptor, scenarioWithIndex, 1, GIVEN, findNewIndexOfGroup(simulationDescriptor, GIVEN));
}
if (!hasExpect) {
createEmptyColumn(simulationDescriptor, scenarioWithIndex, 2, EXPECT, findNewIndexOfGroup(simulationDescriptor, EXPECT));
}
}
use of org.drools.scenariosimulation.api.model.FactMapping in project drools-wb by kiegroup.
the class DMNSimulationSettingsCreationStrategy method internalAddToScenario.
protected void internalAddToScenario(FactMappingExtractor factMappingExtractor, FactModelTree factModelTree, List<String> readOnlyPreviousSteps, Map<String, FactModelTree> hiddenValues, Set<String> alreadyVisited) {
List<String> previousSteps = new ArrayList<>(readOnlyPreviousSteps);
// if is a simple type it generates a single column
if (factModelTree.isSimple()) {
FactModelTree.PropertyTypeName factType = factModelTree.getSimpleProperties().get(VALUE);
factMappingExtractor.getFactMapping(factModelTree, VALUE, previousSteps, factType.getTypeName());
} else // otherwise it adds a column for each simple properties direct or nested
{
factModelTree.getSimpleProperties().entrySet().stream().sorted(Map.Entry.comparingByKey()).forEach(entry -> {
String factName = entry.getKey();
String factTypeName = entry.getValue().getTypeName();
FactMapping factMapping = factMappingExtractor.getFactMapping(factModelTree, factName, previousSteps, factTypeName);
if (ScenarioSimulationSharedUtils.isList(factTypeName)) {
factMapping.setGenericTypes(factModelTree.getGenericTypeInfo(factName));
}
factMapping.addExpressionElement(factName, factTypeName);
});
factModelTree.getExpandableProperties().entrySet().stream().sorted(Map.Entry.comparingByValue()).forEach(entry -> {
String factType = entry.getValue();
FactModelTree nestedModelTree = hiddenValues.get(factType);
if (previousSteps.isEmpty()) {
previousSteps.add(factModelTree.getFactName());
}
ArrayList<String> currentSteps = new ArrayList<>(previousSteps);
currentSteps.add(entry.getKey());
if (!alreadyVisited.contains(nestedModelTree.getFactName())) {
alreadyVisited.add(factModelTree.getFactName());
internalAddToScenario(factMappingExtractor, nestedModelTree, currentSteps, hiddenValues, alreadyVisited);
}
});
}
}
use of org.drools.scenariosimulation.api.model.FactMapping in project drools-wb by kiegroup.
the class ScenarioSimulationEditorI18nServerManagerTest method setup.
@Before
public void setup() {
factMapping = new FactMapping(FactIdentifier.create("myType", "tMYTYPE"), ExpressionIdentifier.create(VALUE, FactMappingType.GIVEN));
factMapping.setFactAlias("FactAlias");
factMapping.setExpressionAlias("ExpressionAlias");
}
use of org.drools.scenariosimulation.api.model.FactMapping in project drools-wb by kiegroup.
the class CollectionEditorSingletonDOMElementFactory method createDomElement.
@Override
public CollectionEditorDOMElement createDomElement(final GridLayer gridLayer, final GridWidget gridWidget) {
if (this.widget != null) {
this.widget.close();
}
this.widget = createWidget();
/* Don't propagate MouseWheel and RightClick events to the Grid */
this.widget.addDomHandler(MouseWheelEvent::stopPropagation, MouseWheelEvent.getType());
this.widget.addDomHandler(event -> {
event.stopPropagation();
event.preventDefault();
}, ContextMenuEvent.getType());
this.widget.addDomHandler(ClickEvent::stopPropagation, ClickEvent.getType());
this.widget.addDomHandler(KeyDownEvent::stopPropagation, KeyDownEvent.getType());
final AbstractScesimGridModel<? extends AbstractScesimModel, ? extends AbstractScesimData> model = ((ScenarioGrid) gridWidget).getModel();
final GridData.SelectedCell selectedCellsOrigin = model.getSelectedCellsOrigin();
final Optional<GridColumn<?>> selectedColumn = model.getColumns().stream().filter(col -> col.getIndex() == selectedCellsOrigin.getColumnIndex()).findFirst();
selectedColumn.ifPresent(col -> {
final int actualIndex = model.getColumns().indexOf(col);
final FactMapping factMapping = model.getAbstractScesimModel().get().getScesimModelDescriptor().getFactMappingByIndex(actualIndex);
setCollectionEditorStructureData(this.widget, factMapping);
this.e = createDomElementInternal(widget, gridLayer, gridWidget);
});
return e;
}
use of org.drools.scenariosimulation.api.model.FactMapping in project drools-wb by kiegroup.
the class SetHeaderCellValueCommand method validatePropertyHeader.
protected void validatePropertyHeader(ScenarioSimulationContext context, String headerCellValue, int columnIndex) {
final ScenarioSimulationModel.Type simulationModelType = context.getScenarioSimulationModel().getSettings().getType();
List<String> propertyNameElements = Collections.unmodifiableList(Arrays.asList(headerCellValue.split("\\.")));
final FactMapping factMappingByIndex = context.getAbstractScesimModelByGridWidget(gridWidget).getScesimModelDescriptor().getFactMappingByIndex(columnIndex);
String factName = simulationModelType.equals(ScenarioSimulationModel.Type.DMN) ? factMappingByIndex.getFactIdentifier().getName() : factMappingByIndex.getFactIdentifier().getClassNameWithoutPackage();
final FactModelTree factModelTree = context.getDataObjectFieldsMap().get(factName);
boolean isPropertyType = !headerCellValue.endsWith(".") && factModelTree != null && recursivelyFindIsPropertyType(context, factModelTree, propertyNameElements);
context.getAbstractScesimGridModelByGridWidget(gridWidget).validatePropertyHeaderUpdate(headerCellValue, columnIndex, isPropertyType);
}
Aggregations