Search in sources :

Example 11 with FactMapping

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));
    }
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) FactMappingType(org.drools.scenariosimulation.api.model.FactMappingType)

Example 12 with FactMapping

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);
            }
        });
    }
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) ArrayList(java.util.ArrayList) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree)

Example 13 with FactMapping

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");
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) Before(org.junit.Before)

Example 14 with FactMapping

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;
}
Also used : RULE(org.drools.scenariosimulation.api.model.ScenarioSimulationModel.Type.RULE) ContextMenuEvent(com.google.gwt.event.dom.client.ContextMenuEvent) ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn) HashMap(java.util.HashMap) CollectionEditorDOMElement(org.drools.workbench.screens.scenariosimulation.client.domelements.CollectionEditorDOMElement) ScenarioSimulationContext(org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext) AbstractScesimModel(org.drools.scenariosimulation.api.model.AbstractScesimModel) GridLienzoPanel(org.uberfire.ext.wires.core.grids.client.widget.layer.impl.GridLienzoPanel) CollectionViewImpl(org.drools.workbench.screens.scenariosimulation.client.collectioneditor.CollectionViewImpl) VALUE(org.drools.scenariosimulation.api.utils.ConstantsHolder.VALUE) ScenarioSimulationSharedUtils(org.drools.scenariosimulation.api.utils.ScenarioSimulationSharedUtils) Map(java.util.Map) AbstractScesimGridModel(org.drools.workbench.screens.scenariosimulation.client.models.AbstractScesimGridModel) ViewsProvider(org.drools.workbench.screens.scenariosimulation.client.utils.ViewsProvider) KeyDownEvent(com.google.gwt.event.dom.client.KeyDownEvent) ScenarioSimulationUtils(org.drools.workbench.screens.scenariosimulation.client.utils.ScenarioSimulationUtils) BaseSingletonDOMElementFactory(org.uberfire.ext.wires.core.grids.client.widget.dom.single.impl.BaseSingletonDOMElementFactory) ScenarioSimulationUtils.isSimpleJavaType(org.drools.workbench.screens.scenariosimulation.client.utils.ScenarioSimulationUtils.isSimpleJavaType) ScenarioGrid(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGrid) MouseWheelEvent(com.google.gwt.event.dom.client.MouseWheelEvent) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) Collectors(java.util.stream.Collectors) GridWidget(org.uberfire.ext.wires.core.grids.client.widget.grid.GridWidget) GridLayer(org.uberfire.ext.wires.core.grids.client.widget.layer.GridLayer) List(java.util.List) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) Optional(java.util.Optional) AbstractScesimData(org.drools.scenariosimulation.api.model.AbstractScesimData) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) KeyDownEvent(com.google.gwt.event.dom.client.KeyDownEvent) MouseWheelEvent(com.google.gwt.event.dom.client.MouseWheelEvent) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ScenarioGrid(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGrid) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn)

Example 15 with FactMapping

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);
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree) ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel)

Aggregations

FactMapping (org.drools.scenariosimulation.api.model.FactMapping)55 ScesimModelDescriptor (org.drools.scenariosimulation.api.model.ScesimModelDescriptor)13 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)11 FactIdentifier (org.drools.scenariosimulation.api.model.FactIdentifier)11 ExpressionIdentifier (org.drools.scenariosimulation.api.model.ExpressionIdentifier)10 List (java.util.List)9 FactMappingValue (org.drools.scenariosimulation.api.model.FactMappingValue)8 Simulation (org.drools.scenariosimulation.api.model.Simulation)8 HashMap (java.util.HashMap)6 AbstractScesimData (org.drools.scenariosimulation.api.model.AbstractScesimData)6 ScenarioGridCellValue (org.drools.workbench.screens.scenariosimulation.client.values.ScenarioGridCellValue)6 ScenarioGridCell (org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridCell)6 AbstractScesimModel (org.drools.scenariosimulation.api.model.AbstractScesimModel)5 ScenarioGridColumn (org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)5 FactModelTree (org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree)5 ScenarioSimulationModel (org.drools.scenariosimulation.api.model.ScenarioSimulationModel)4 FactMappingValidationError (org.drools.workbench.screens.scenariosimulation.model.FactMappingValidationError)4 Before (org.junit.Before)4 Map (java.util.Map)3