Search in sources :

Example 6 with ScesimModelDescriptor

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

the class AbstractScesimGridModel method refreshErrorsRow.

protected void refreshErrorsRow(int rowIndex) {
    ScesimModelDescriptor simulationDescriptor = abstractScesimModel.getScesimModelDescriptor();
    E scesimDataByIndex = abstractScesimModel.getDataByIndex(rowIndex);
    IntStream.range(0, getColumnCount()).forEach(columnIndex -> {
        ScenarioGridCell cell = (ScenarioGridCell) getCell(rowIndex, columnIndex);
        if (cell == null) {
            return;
        }
        final FactMapping factMappingByIndex = simulationDescriptor.getFactMappingByIndex(columnIndex);
        Optional<FactMappingValue> factMappingValue = scesimDataByIndex.getFactMappingValue(factMappingByIndex.getFactIdentifier(), factMappingByIndex.getExpressionIdentifier());
        if (factMappingValue.isPresent()) {
            cell.setErrorMode(FactMappingValueStatus.SUCCESS != factMappingValue.get().getStatus());
        } else {
            cell.setErrorMode(false);
        }
    });
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) ScenarioGridCell(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridCell) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue)

Example 7 with ScesimModelDescriptor

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

the class AbstractScesimGridModel method checkSamePropertyHeader.

/**
 * Check if given <b>headerName</b> is the same as the <b>element steps</b> mapped to the given column
 * @param columnIndex
 * @param propertyNameElements
 * @throws IllegalStateException if the given <b>propertyNameElements</b> (corrected for the class name) represents the <b>element steps</b> of the given column
 */
public void checkSamePropertyHeader(int columnIndex, List<String> propertyNameElements) {
    ScesimModelDescriptor simulationDescriptor = abstractScesimModel.getScesimModelDescriptor();
    final FactMapping factMapping = simulationDescriptor.getFactMappingByIndex(columnIndex);
    List<String> columnPropertyName = factMapping.getExpressionElementsWithoutClass().stream().map(ExpressionElement::getStep).collect(Collectors.toList());
    if (!Objects.equals(columnPropertyName, propertyNameElements)) {
        throw new IllegalStateException(String.join(".", propertyNameElements) + " is not the same property of the current column.");
    }
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) FactMapping(org.drools.scenariosimulation.api.model.FactMapping)

Example 8 with ScesimModelDescriptor

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

the class AbstractScesimGridModel method checkValidAndUniqueInstanceHeaderTitle.

/**
 * Verify the given value is not already used as instance header name <b>between different groups</b>
 * @param instanceHeaderCellValue
 * @param columnIndex
 * @throws IllegalArgumentException if the given <b>instanceHeaderCellValue</b> contains a <i>dot</i> <b>OR</b>
 * it has already been used inside the <b>group (GIVEN/EXPECT)</b> of the given column
 */
protected void checkValidAndUniqueInstanceHeaderTitle(String instanceHeaderCellValue, int columnIndex) {
    if (instanceHeaderCellValue.contains(".")) {
        throw new IllegalArgumentException(ScenarioSimulationEditorConstants.INSTANCE.instanceTitleWithPeriodsError());
    }
    Range instanceLimits = getInstanceLimits(columnIndex);
    ScesimModelDescriptor simulationDescriptor = abstractScesimModel.getScesimModelDescriptor();
    FactIdentifier factIdentifier = simulationDescriptor.getFactMappingByIndex(columnIndex).getFactIdentifier();
    if (IntStream.range(0, getColumnCount()).filter(index -> index < instanceLimits.getMinRowIndex() || index > instanceLimits.getMaxRowIndex()).filter(index -> !Objects.equals(factIdentifier, simulationDescriptor.getFactMappingByIndex(index).getFactIdentifier())).mapToObj(index -> (ScenarioGridColumn) getColumns().get(index)).filter(elem -> elem.getInformationHeaderMetaData() != null).map(ScenarioGridColumn::getInformationHeaderMetaData).anyMatch(elem -> Objects.equals(elem.getTitle(), instanceHeaderCellValue))) {
        throw new IllegalArgumentException(ScenarioSimulationEditorConstants.INSTANCE.instanceTitleAssignedError(instanceHeaderCellValue));
    }
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) Arrays(java.util.Arrays) ScenarioNotificationEvent(org.drools.workbench.screens.scenariosimulation.client.events.ScenarioNotificationEvent) ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel) GridWidget(org.drools.workbench.screens.scenariosimulation.client.enums.GridWidget) GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn) NotificationEvent(org.uberfire.workbench.events.NotificationEvent) FactMappingValueType(org.drools.scenariosimulation.api.model.FactMappingValueType) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) ScenarioSimulationUtils(org.drools.workbench.screens.scenariosimulation.client.utils.ScenarioSimulationUtils) BaseSingletonDOMElementFactory(org.uberfire.ext.wires.core.grids.client.widget.dom.single.impl.BaseSingletonDOMElementFactory) EventBus(com.google.gwt.event.shared.EventBus) GridCell(org.uberfire.ext.wires.core.grids.client.model.GridCell) Set(java.util.Set) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ScenarioHeaderMetaData(org.drools.workbench.screens.scenariosimulation.client.metadata.ScenarioHeaderMetaData) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) List(java.util.List) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) GridCellValue(org.uberfire.ext.wires.core.grids.client.model.GridCellValue) ScenarioHeaderTextBoxSingletonDOMElementFactory(org.drools.workbench.screens.scenariosimulation.client.factories.ScenarioHeaderTextBoxSingletonDOMElementFactory) Optional(java.util.Optional) ScenarioSimulationEditorConstants(org.drools.workbench.screens.scenariosimulation.client.resources.i18n.ScenarioSimulationEditorConstants) ReloadTestToolsEvent(org.drools.workbench.screens.scenariosimulation.client.events.ReloadTestToolsEvent) ScenarioGridCell(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridCell) ScenarioGridReloadEvent(org.drools.workbench.screens.scenariosimulation.client.events.ScenarioGridReloadEvent) IntStream(java.util.stream.IntStream) ScenarioSimulationUtils.getPropertyNameElementsWithoutAlias(org.drools.workbench.screens.scenariosimulation.client.utils.ScenarioSimulationUtils.getPropertyNameElementsWithoutAlias) CollectionEditorSingletonDOMElementFactory(org.drools.workbench.screens.scenariosimulation.client.factories.CollectionEditorSingletonDOMElementFactory) FactMappingValueStatus(org.drools.scenariosimulation.api.model.FactMappingValueStatus) OptionalDouble(java.util.OptionalDouble) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) ExpressionElement(org.drools.scenariosimulation.api.model.ExpressionElement) AbstractScesimModel(org.drools.scenariosimulation.api.model.AbstractScesimModel) ScenarioGridCellValue(org.drools.workbench.screens.scenariosimulation.client.values.ScenarioGridCellValue) GridRow(org.uberfire.ext.wires.core.grids.client.model.GridRow) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) ScenarioSimulationSharedUtils(org.drools.scenariosimulation.api.utils.ScenarioSimulationSharedUtils) ScenarioCellTextAreaSingletonDOMElementFactory(org.drools.workbench.screens.scenariosimulation.client.factories.ScenarioCellTextAreaSingletonDOMElementFactory) ScenarioExpressionCellTextAreaSingletonDOMElementFactory(org.drools.workbench.screens.scenariosimulation.client.factories.ScenarioExpressionCellTextAreaSingletonDOMElementFactory) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue) FactMappingType(org.drools.scenariosimulation.api.model.FactMappingType) AbstractMap(java.util.AbstractMap) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) Collections(java.util.Collections) AbstractScesimData(org.drools.scenariosimulation.api.model.AbstractScesimData) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)

Example 9 with ScesimModelDescriptor

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

the class AbstractScesimGridModel method checkUniquePropertyHeaderTitle.

/**
 * Verify if the given value is not already used as property header name <b>inside the same instance</b>
 * @param propertyHeaderCellValue
 * @param columnIndex
 * @throws IllegalArgumentException if the given <b>propertyHeaderCellValue</b> has already been used
 * inside the <b>instance</b> of the given column
 */
protected void checkUniquePropertyHeaderTitle(String propertyHeaderCellValue, int columnIndex) {
    ScesimModelDescriptor simulationDescriptor = abstractScesimModel.getScesimModelDescriptor();
    FactIdentifier factIdentifier = simulationDescriptor.getFactMappingByIndex(columnIndex).getFactIdentifier();
    if (IntStream.range(0, getColumnCount()).filter(index -> index != columnIndex).filter(index -> Objects.equals(factIdentifier, simulationDescriptor.getFactMappingByIndex(index).getFactIdentifier())).mapToObj(index -> (ScenarioGridColumn) getColumns().get(index)).filter(elem -> elem.getPropertyHeaderMetaData() != null).map(ScenarioGridColumn::getPropertyHeaderMetaData).anyMatch(elem -> Objects.equals(elem.getTitle(), propertyHeaderCellValue))) {
        throw new IllegalArgumentException(ScenarioSimulationEditorConstants.INSTANCE.propertyTitleAssignedError(propertyHeaderCellValue));
    }
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) Arrays(java.util.Arrays) ScenarioNotificationEvent(org.drools.workbench.screens.scenariosimulation.client.events.ScenarioNotificationEvent) ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel) GridWidget(org.drools.workbench.screens.scenariosimulation.client.enums.GridWidget) GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn) NotificationEvent(org.uberfire.workbench.events.NotificationEvent) FactMappingValueType(org.drools.scenariosimulation.api.model.FactMappingValueType) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) ScenarioSimulationUtils(org.drools.workbench.screens.scenariosimulation.client.utils.ScenarioSimulationUtils) BaseSingletonDOMElementFactory(org.uberfire.ext.wires.core.grids.client.widget.dom.single.impl.BaseSingletonDOMElementFactory) EventBus(com.google.gwt.event.shared.EventBus) GridCell(org.uberfire.ext.wires.core.grids.client.model.GridCell) Set(java.util.Set) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ScenarioHeaderMetaData(org.drools.workbench.screens.scenariosimulation.client.metadata.ScenarioHeaderMetaData) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) List(java.util.List) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) GridCellValue(org.uberfire.ext.wires.core.grids.client.model.GridCellValue) ScenarioHeaderTextBoxSingletonDOMElementFactory(org.drools.workbench.screens.scenariosimulation.client.factories.ScenarioHeaderTextBoxSingletonDOMElementFactory) Optional(java.util.Optional) ScenarioSimulationEditorConstants(org.drools.workbench.screens.scenariosimulation.client.resources.i18n.ScenarioSimulationEditorConstants) ReloadTestToolsEvent(org.drools.workbench.screens.scenariosimulation.client.events.ReloadTestToolsEvent) ScenarioGridCell(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridCell) ScenarioGridReloadEvent(org.drools.workbench.screens.scenariosimulation.client.events.ScenarioGridReloadEvent) IntStream(java.util.stream.IntStream) ScenarioSimulationUtils.getPropertyNameElementsWithoutAlias(org.drools.workbench.screens.scenariosimulation.client.utils.ScenarioSimulationUtils.getPropertyNameElementsWithoutAlias) CollectionEditorSingletonDOMElementFactory(org.drools.workbench.screens.scenariosimulation.client.factories.CollectionEditorSingletonDOMElementFactory) FactMappingValueStatus(org.drools.scenariosimulation.api.model.FactMappingValueStatus) OptionalDouble(java.util.OptionalDouble) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) ExpressionElement(org.drools.scenariosimulation.api.model.ExpressionElement) AbstractScesimModel(org.drools.scenariosimulation.api.model.AbstractScesimModel) ScenarioGridCellValue(org.drools.workbench.screens.scenariosimulation.client.values.ScenarioGridCellValue) GridRow(org.uberfire.ext.wires.core.grids.client.model.GridRow) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) ScenarioSimulationSharedUtils(org.drools.scenariosimulation.api.utils.ScenarioSimulationSharedUtils) ScenarioCellTextAreaSingletonDOMElementFactory(org.drools.workbench.screens.scenariosimulation.client.factories.ScenarioCellTextAreaSingletonDOMElementFactory) ScenarioExpressionCellTextAreaSingletonDOMElementFactory(org.drools.workbench.screens.scenariosimulation.client.factories.ScenarioExpressionCellTextAreaSingletonDOMElementFactory) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue) FactMappingType(org.drools.scenariosimulation.api.model.FactMappingType) AbstractMap(java.util.AbstractMap) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) Collections(java.util.Collections) AbstractScesimData(org.drools.scenariosimulation.api.model.AbstractScesimData) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)

Example 10 with ScesimModelDescriptor

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

the class AbstractScesimGridModel method checkAlreadyAssignedProperty.

/**
 * Check if property mapped to the column at given index is already assigned to
 * another column of the same <b>instance</b>
 * @param columnIndex
 * @param propertyNameElements
 * @throws IllegalStateException if the given <code>propertyNameElements</code> are already mapped to a column of the same <b>instance</b>
 */
public void checkAlreadyAssignedProperty(int columnIndex, List<String> propertyNameElements) {
    Range instanceLimits = getInstanceLimits(columnIndex);
    ScesimModelDescriptor simulationDescriptor = abstractScesimModel.getScesimModelDescriptor();
    FactIdentifier factIdentifier = simulationDescriptor.getFactMappingByIndex(columnIndex).getFactIdentifier();
    // We have to keep the original List unmodified
    List<String> propertyNameElementsClone = new ArrayList<>();
    propertyNameElementsClone.add(factIdentifier.getClassNameWithoutPackage());
    propertyNameElementsClone.addAll(propertyNameElements.subList(1, propertyNameElements.size()));
    if (IntStream.range(instanceLimits.getMinRowIndex(), instanceLimits.getMaxRowIndex() + 1).filter(index -> index != columnIndex).mapToObj(simulationDescriptor::getFactMappingByIndex).anyMatch(factMapping -> {
        List<String> factMappingPropertyNameElements = factMapping.getExpressionElements().stream().map(ExpressionElement::getStep).collect(Collectors.toList());
        return Objects.equals(factMappingPropertyNameElements, propertyNameElementsClone);
    })) {
        throw new IllegalStateException(String.join(".", propertyNameElements) + " has already been used in the current instance.");
    }
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) ArrayList(java.util.ArrayList) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier)

Aggregations

ScesimModelDescriptor (org.drools.scenariosimulation.api.model.ScesimModelDescriptor)29 FactMapping (org.drools.scenariosimulation.api.model.FactMapping)18 ArrayList (java.util.ArrayList)11 ExpressionIdentifier (org.drools.scenariosimulation.api.model.ExpressionIdentifier)11 List (java.util.List)9 Map (java.util.Map)9 FactIdentifier (org.drools.scenariosimulation.api.model.FactIdentifier)9 Set (java.util.Set)8 Simulation (org.drools.scenariosimulation.api.model.Simulation)8 Objects (java.util.Objects)7 ExpressionElement (org.drools.scenariosimulation.api.model.ExpressionElement)7 FactMappingType (org.drools.scenariosimulation.api.model.FactMappingType)7 ScenarioSimulationModel (org.drools.scenariosimulation.api.model.ScenarioSimulationModel)7 ScenarioWithIndex (org.drools.scenariosimulation.api.model.ScenarioWithIndex)7 Collections (java.util.Collections)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 AbstractScesimData (org.drools.scenariosimulation.api.model.AbstractScesimData)6 FactMappingValue (org.drools.scenariosimulation.api.model.FactMappingValue)6 Scenario (org.drools.scenariosimulation.api.model.Scenario)6 ScenarioGridColumn (org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)5