Search in sources :

Example 6 with FactMappingType

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

the class AbstractRunnerHelper method groupByFactIdentifierAndFilter.

protected Map<FactIdentifier, List<FactMappingValue>> groupByFactIdentifierAndFilter(List<FactMappingValue> factMappingValues, FactMappingType type) {
    Map<FactIdentifier, List<FactMappingValue>> groupByFactIdentifier = new HashMap<>();
    for (FactMappingValue factMappingValue : factMappingValues) {
        FactIdentifier factIdentifier = factMappingValue.getFactIdentifier();
        if (isFactMappingValueToSkip(factMappingValue)) {
            continue;
        }
        ExpressionIdentifier expressionIdentifier = factMappingValue.getExpressionIdentifier();
        if (expressionIdentifier == null) {
            throw new IllegalArgumentException("ExpressionIdentifier malformed");
        }
        if (!Objects.equals(expressionIdentifier.getType(), type)) {
            continue;
        }
        groupByFactIdentifier.computeIfAbsent(factIdentifier, key -> new ArrayList<>()).add(factMappingValue);
    }
    return groupByFactIdentifier;
}
Also used : FactMappingValueStatus(org.drools.scenariosimulation.api.model.FactMappingValueStatus) ScenarioResultMetadata(org.drools.scenariosimulation.backend.runner.model.ScenarioResultMetadata) LoggerFactory(org.slf4j.LoggerFactory) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) HashMap(java.util.HashMap) ValueWrapper.errorWithValidValue(org.drools.scenariosimulation.backend.runner.model.ValueWrapper.errorWithValidValue) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) ExpressionElement(org.drools.scenariosimulation.api.model.ExpressionElement) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) Scenario(org.drools.scenariosimulation.api.model.Scenario) ValueWrapper(org.drools.scenariosimulation.backend.runner.model.ValueWrapper) Map(java.util.Map) ValueWrapper.errorWithMessage(org.drools.scenariosimulation.backend.runner.model.ValueWrapper.errorWithMessage) ScenarioResult(org.drools.scenariosimulation.backend.runner.model.ScenarioResult) ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) ScenarioSimulationServerMessages(org.drools.scenariosimulation.backend.util.ScenarioSimulationServerMessages) Logger(org.slf4j.Logger) BackgroundData(org.drools.scenariosimulation.api.model.BackgroundData) Settings(org.drools.scenariosimulation.api.model.Settings) ScenarioExpect(org.drools.scenariosimulation.backend.runner.model.ScenarioExpect) ScenarioRunnerData(org.drools.scenariosimulation.backend.runner.model.ScenarioRunnerData) Background(org.drools.scenariosimulation.api.model.Background) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue) Set(java.util.Set) KieContainer(org.kie.api.runtime.KieContainer) ValueWrapper.of(org.drools.scenariosimulation.backend.runner.model.ValueWrapper.of) FactMappingType(org.drools.scenariosimulation.api.model.FactMappingType) ValueWrapper.errorWithCollectionPathToValue(org.drools.scenariosimulation.backend.runner.model.ValueWrapper.errorWithCollectionPathToValue) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ExpressionEvaluatorFactory(org.drools.scenariosimulation.backend.expression.ExpressionEvaluatorFactory) List(java.util.List) ExpressionEvaluator(org.drools.scenariosimulation.backend.expression.ExpressionEvaluator) Collectors.toList(java.util.stream.Collectors.toList) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) ExpressionEvaluatorResult(org.drools.scenariosimulation.backend.expression.ExpressionEvaluatorResult) ScenarioSimulationSharedUtils.isCollectionOrMap(org.drools.scenariosimulation.api.utils.ScenarioSimulationSharedUtils.isCollectionOrMap) InstanceGiven(org.drools.scenariosimulation.backend.runner.model.InstanceGiven) HashMap(java.util.HashMap) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier)

Example 7 with FactMappingType

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

the class ScenarioGridTest method getScenarioGridColumnLocal.

@Test
public void getScenarioGridColumnLocal() {
    String columnId = factMappingDescription.getExpressionIdentifier().getName();
    String instanceTitle = factMappingDescription.getFactIdentifier().getName();
    String propertyTitle = "PROPERTY TITLE";
    final FactMappingType type = factMappingDescription.getExpressionIdentifier().getType();
    String columnGroup = type.name();
    scenarioGridSpy.getScenarioGridColumnLocal(instanceTitle, propertyTitle, columnId, columnGroup, type, ScenarioSimulationEditorConstants.INSTANCE.insertValue());
    verify(scenarioGridSpy, times(1)).getHeaderBuilderLocal(eq(instanceTitle), eq(propertyTitle), eq(columnId), eq(columnGroup), eq(type));
}
Also used : FactMappingType(org.drools.scenariosimulation.api.model.FactMappingType) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 8 with FactMappingType

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

the class ScenarioGridTest method setup.

@Before
public void setup() {
    simulation = getSimulation();
    when(scenarioGridColumnMock.getPropertyHeaderMetaData()).thenReturn(propertyHeaderMetadataMock);
    when(scenarioGridModelMock.getAbstractScesimModel()).thenReturn(Optional.of(simulation));
    when(scenarioGridModelMock.getGridWidget()).thenReturn(GridWidget.SIMULATION);
    when(scenarioGridModelMock.getScenarioExpressionCellTextAreaSingletonDOMElementFactory()).thenReturn(expressionCellTextAreaSingletonDOMElementFactoryMock);
    when(scenarioGridModelMock.getCollectionEditorSingletonDOMElementFactory()).thenReturn(collectionEditorSingletonDOMElementFactory);
    factIdentifierGiven = FactIdentifier.create("GIVEN", "GIVEN");
    factIdentifierInteger = FactIdentifier.create("Integer", "java.lang.Integer");
    factMappingDescription = new FactMapping(EXPRESSION_ALIAS_DESCRIPTION, FactIdentifier.DESCRIPTION, ExpressionIdentifier.DESCRIPTION);
    factMappingGiven = new FactMapping(EXPRESSION_ALIAS_GIVEN, factIdentifierGiven, new ExpressionIdentifier("GIVEN", FactMappingType.GIVEN));
    factMappingInteger = new FactMapping(EXPRESSION_ALIAS_INTEGER, factIdentifierInteger, new ExpressionIdentifier("GIVEN", FactMappingType.GIVEN));
    scenarioGridSpy = spy(new ScenarioGrid(scenarioGridModelMock, scenarioGridLayerMock, scenarioGridRendererMock, scenarioContextMenuRegistryMock) {

        @Override
        protected <T extends AbstractScesimData> void appendRow(int rowIndex, T scesimData) {
        // do nothing
        }

        @Override
        protected ScenarioSimulationBuilders.HeaderBuilder getHeaderBuilderLocal(String instanceTitle, String propertyTitle, String columnId, String columnGroup, FactMappingType factMappingType) {
            return headerBuilderMock;
        }

        @Override
        protected ScenarioGridColumn getScenarioGridColumnLocal(ScenarioSimulationBuilders.HeaderBuilder headerBuilder, String placeHolder) {
            return scenarioGridColumnMock;
        }

        @Override
        protected BaseGridRendererHelper getBaseGridRendererHelper() {
            return rendererHelperMock;
        }

        @Override
        public Viewport getViewport() {
            return viewportMock;
        }

        @Override
        protected ScenarioHeaderMetaData getColumnScenarioHeaderMetaData(final ScenarioGridColumn scenarioGridColumn, final int rowIndex) {
            return propertyHeaderMetadataMock;
        }

        @Override
        protected EnableTestToolsEvent getEnableTestToolsEvent(final ScenarioGrid scenarioGrid, final ScenarioGridColumn scenarioGridColumn, final ScenarioHeaderMetaData scenarioHeaderMetaData, int uiColumnIndex, String group) {
            return new EnableTestToolsEvent();
        }

        @Override
        public Layer getLayer() {
            return scenarioGridLayerMock;
        }
    });
    when(rendererHelperMock.getRenderingInformation()).thenReturn(renderingInformationMock);
    when(renderingInformationMock.getHeaderRowsHeight()).thenReturn(HEADER_ROWS_HEIGHT);
    when(renderingInformationMock.getFloatingBlockInformation()).thenReturn(floatingBlockInformationMock);
    when(propertyHeaderMetadataMock.getColumnGroup()).thenReturn(GRID_COLUMN_GROUP);
    scenarioGridSpy.setEventBus(eventBusMock);
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) ScenarioSimulationBuilders(org.drools.workbench.screens.scenariosimulation.client.utils.ScenarioSimulationBuilders) HEADER_ROWS_HEIGHT(org.drools.workbench.screens.scenariosimulation.client.TestProperties.HEADER_ROWS_HEIGHT) TEST(org.drools.workbench.screens.scenariosimulation.client.TestProperties.TEST) ScenarioHeaderMetaData(org.drools.workbench.screens.scenariosimulation.client.metadata.ScenarioHeaderMetaData) AbstractScesimData(org.drools.scenariosimulation.api.model.AbstractScesimData) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) FactMappingType(org.drools.scenariosimulation.api.model.FactMappingType) EnableTestToolsEvent(org.drools.workbench.screens.scenariosimulation.client.events.EnableTestToolsEvent) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Before(org.junit.Before)

Example 9 with FactMappingType

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

the class DeleteColumnCommand method createColumnIfEmptyGroup.

/**
 * Creates a new column in the group if there is none.
 *
 * @param context
 * @param status
 * @param newColumnPosition
 */
protected void createColumnIfEmptyGroup(ScenarioSimulationContext context, ScenarioSimulationContext.Status status, int newColumnPosition) {
    if (context.getAbstractScesimGridModelByGridWidget(gridWidget).getGroupSize(status.getColumnGroup()) < 1) {
        FactMappingType factMappingType = FactMappingType.valueOf(status.getColumnGroup().toUpperCase());
        Map.Entry<String, String> validPlaceholders = context.getAbstractScesimGridModelByGridWidget(gridWidget).getValidPlaceholders();
        String instanceTitle = validPlaceholders.getKey();
        String propertyTitle = validPlaceholders.getValue();
        context.getAbstractScesimGridModelByGridWidget(gridWidget).insertColumn(newColumnPosition, getScenarioGridColumnLocal(instanceTitle, propertyTitle, String.valueOf(new Date().getTime()), status.getColumnGroup(), factMappingType, context.getScenarioHeaderTextBoxSingletonDOMElementFactory(gridWidget), context.getScenarioCellTextAreaSingletonDOMElementFactory(gridWidget), ScenarioSimulationEditorConstants.INSTANCE.defineValidType()));
    }
}
Also used : FactMappingType(org.drools.scenariosimulation.api.model.FactMappingType) Map(java.util.Map) 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