Search in sources :

Example 1 with FactMappingType

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

the class AbstractInsertColumnCommand method commonInsertColumnCommand.

public void commonInsertColumnCommand(ScenarioSimulationContext context, ScenarioSimulationContext.Status status, int index) {
    FactMappingType factMappingType = FactMappingType.valueOf(status.getColumnGroup().toUpperCase());
    Map.Entry<String, String> validPlaceholders = context.getAbstractScesimGridModelByGridWidget(gridWidget).getValidPlaceholders();
    String instanceTitle = validPlaceholders.getKey();
    String propertyTitle = validPlaceholders.getValue();
    final ScenarioGridColumn scenarioGridColumnLocal = getScenarioGridColumnLocal(instanceTitle, propertyTitle, status.getColumnId(), status.getColumnGroup(), factMappingType, context.getScenarioHeaderTextBoxSingletonDOMElementFactory(gridWidget), context.getScenarioCellTextAreaSingletonDOMElementFactory(gridWidget), ScenarioSimulationEditorConstants.INSTANCE.defineValidType());
    context.getAbstractScesimGridModelByGridWidget(gridWidget).insertColumn(index, scenarioGridColumnLocal);
    context.getSelectedScenarioGridLayer().ifPresent(layer -> layer.getScenarioGrid().selectCurrentHeaderCellGroup());
}
Also used : FactMappingType(org.drools.scenariosimulation.api.model.FactMappingType) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) Map(java.util.Map)

Example 2 with FactMappingType

use of org.drools.scenariosimulation.api.model.FactMappingType 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 3 with FactMappingType

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

the class ScenarioGridTest method setHeaderColumn.

@Test
public void setHeaderColumn() {
    String columnId = factMappingDescription.getExpressionIdentifier().getName();
    FactMappingType type = factMappingDescription.getExpressionIdentifier().getType();
    String columnGroup = type.name();
    scenarioGridSpy.setType(ScenarioSimulationModel.Type.RULE);
    scenarioGridSpy.setHeaderColumn(1, factMappingDescription, true);
    verify(scenarioGridSpy, times(1)).isPropertyAssigned(eq(true), eq(factMappingDescription));
    verify(scenarioGridSpy, times(1)).getPlaceHolder(eq(true), eq(true), isA(FactMappingValueType.class), anyString());
    verify(scenarioGridSpy, times(1)).getScenarioGridColumnLocal(eq(EXPRESSION_ALIAS_DESCRIPTION), any(), eq(columnId), eq(columnGroup), eq(type), anyString());
    verify(scenarioGridColumnMock, times(1)).setColumnWidthMode(ColumnWidthMode.FIXED);
    verify(scenarioGridModelMock, times(1)).getDOMElementFactory(anyString(), eq(ScenarioSimulationModel.Type.RULE), eq(FactMappingValueType.NOT_EXPRESSION));
    reset(scenarioGridSpy);
    reset(scenarioGridColumnMock);
    reset(scenarioGridModelMock);
    columnId = factMappingGiven.getExpressionIdentifier().getName();
    type = factMappingGiven.getExpressionIdentifier().getType();
    columnGroup = type.name();
    scenarioGridSpy.setHeaderColumn(1, factMappingGiven, true);
    verify(scenarioGridSpy, times(1)).isPropertyAssigned(eq(true), eq(factMappingGiven));
    verify(scenarioGridSpy, times(1)).getPlaceHolder(eq(true), eq(false), eq(FactMappingValueType.NOT_EXPRESSION), anyString());
    verify(scenarioGridSpy, times(1)).getScenarioGridColumnLocal(eq(EXPRESSION_ALIAS_GIVEN), any(), eq(columnId), eq(columnGroup), eq(type), anyString());
    verify(scenarioGridColumnMock, never()).setColumnWidthMode(any());
    verify(scenarioGridModelMock, never()).getDOMElementFactory(any(), any(), any());
}
Also used : FactMappingValueType(org.drools.scenariosimulation.api.model.FactMappingValueType) FactMappingType(org.drools.scenariosimulation.api.model.FactMappingType) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 4 with FactMappingType

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

the class AbstractSelectedColumnCommandTest method insertNewColumnCommon.

protected void insertNewColumnCommon(int columnIndex, boolean cloneInstance) {
    int instanceNum = simulationDescriptorMock.getUnmodifiableFactMappings().size();
    ScenarioGridColumn createdColumn = ((AbstractSelectedColumnCommand) commandSpy).insertNewColumn(scenarioSimulationContextLocal, gridColumnMock, columnIndex, cloneInstance);
    String columnGroup = gridColumnMock.getInformationHeaderMetaData().getColumnGroup();
    String originalInstanceTitle = gridColumnMock.getInformationHeaderMetaData().getTitle();
    String instanceTitle = cloneInstance ? originalInstanceTitle : "INSTANCE " + instanceNum;
    String propertyTitle = "PROPERTY " + instanceNum;
    final FactMappingType factMappingType = FactMappingType.valueOf(columnGroup.toUpperCase());
    verify(commandSpy, times(1)).getScenarioGridColumnLocal(eq(instanceTitle), eq(propertyTitle), anyString(), eq(columnGroup), eq(factMappingType), eq(scenarioHeaderTextBoxSingletonDOMElementFactorySpy), eq(scenarioCellTextAreaSingletonDOMElementFactorySpy), eq(ScenarioSimulationEditorConstants.INSTANCE.defineValidType()));
    if (cloneInstance) {
        verify(createdColumn, times(1)).setFactIdentifier(eq(gridColumnMock.getFactIdentifier()));
    } else {
        verify(createdColumn, never()).setFactIdentifier(any());
    }
    verify(createdColumn, times(1)).setInstanceAssigned(eq(cloneInstance));
    verify(scenarioGridModelMock, times(1)).insertColumn(COLUMN_INDEX, createdColumn);
}
Also used : FactMappingType(org.drools.scenariosimulation.api.model.FactMappingType) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)

Example 5 with FactMappingType

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

the class AbstractSelectedColumnCommand method insertNewColumn.

/**
 * It inserts a new <code>ScenarioGridColumn</code> in <code>ScenarioGridModel</code>
 * @param context It contains the <b>Context</b> inside which the commands will be executed
 * @param selectedColumn The selected <code>ScenarioGridColumn</code> where the command was launched
 * @param columnPosition Used to define in which position the new column should be added
 * @param cloneInstance If true, it create a new column inside the same instance of the selected column
 * @return The created <code>ScenarioGridColumn</code>
 */
protected ScenarioGridColumn insertNewColumn(ScenarioSimulationContext context, ScenarioGridColumn selectedColumn, int columnPosition, boolean cloneInstance) {
    final ScenarioHeaderMetaData selectedInformationHeaderMetaData = selectedColumn.getInformationHeaderMetaData();
    String columnGroup = selectedInformationHeaderMetaData.getColumnGroup();
    String originalInstanceTitle = selectedInformationHeaderMetaData.getTitle();
    final FactMappingType factMappingType = FactMappingType.valueOf(columnGroup.toUpperCase());
    final Map.Entry<String, String> validPlaceholders = context.getAbstractScesimGridModelByGridWidget(gridWidget).getValidPlaceholders();
    String instanceTitle = cloneInstance ? originalInstanceTitle : validPlaceholders.getKey();
    String propertyTitle = validPlaceholders.getValue();
    String placeHolder = ScenarioSimulationEditorConstants.INSTANCE.defineValidType();
    final ScenarioGridColumn scenarioGridColumnLocal = getScenarioGridColumnLocal(instanceTitle, propertyTitle, String.valueOf(new Date().getTime()), columnGroup, factMappingType, context.getScenarioHeaderTextBoxSingletonDOMElementFactory(gridWidget), context.getScenarioCellTextAreaSingletonDOMElementFactory(gridWidget), placeHolder);
    if (cloneInstance) {
        scenarioGridColumnLocal.setFactIdentifier(selectedColumn.getFactIdentifier());
    }
    scenarioGridColumnLocal.setInstanceAssigned(cloneInstance);
    scenarioGridColumnLocal.setPropertyAssigned(false);
    context.getAbstractScesimGridModelByGridWidget(gridWidget).insertColumn(columnPosition, scenarioGridColumnLocal);
    return scenarioGridColumnLocal;
}
Also used : ScenarioHeaderMetaData(org.drools.workbench.screens.scenariosimulation.client.metadata.ScenarioHeaderMetaData) FactMappingType(org.drools.scenariosimulation.api.model.FactMappingType) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) Map(java.util.Map) SortedMap(java.util.SortedMap) Date(java.util.Date)

Aggregations

FactMappingType (org.drools.scenariosimulation.api.model.FactMappingType)9 Map (java.util.Map)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 FactMapping (org.drools.scenariosimulation.api.model.FactMapping)3 ScenarioGridColumn (org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)3 Date (java.util.Date)2 ExpressionIdentifier (org.drools.scenariosimulation.api.model.ExpressionIdentifier)2 ScesimModelDescriptor (org.drools.scenariosimulation.api.model.ScesimModelDescriptor)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Objects (java.util.Objects)1 Set (java.util.Set)1 SortedMap (java.util.SortedMap)1 Supplier (java.util.function.Supplier)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1 AbstractScesimData (org.drools.scenariosimulation.api.model.AbstractScesimData)1 Background (org.drools.scenariosimulation.api.model.Background)1 BackgroundData (org.drools.scenariosimulation.api.model.BackgroundData)1