Search in sources :

Example 21 with FactMapping

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

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

the class AbstractScesimGridModel method resetError.

/**
 * It resets the <code>FactMappingValue</code> status for a specific CELL
 * @param rowIndex
 * @param columnIndex
 */
public void resetError(int rowIndex, int columnIndex) {
    E scesimDataByIndex = abstractScesimModel.getDataByIndex(rowIndex);
    FactMapping factMapping = abstractScesimModel.getScesimModelDescriptor().getFactMappingByIndex(columnIndex);
    Optional<FactMappingValue> factMappingValue = scesimDataByIndex.getFactMappingValue(factMapping);
    factMappingValue.ifPresent(FactMappingValue::resetStatus);
    refreshErrors();
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue)

Example 23 with FactMapping

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

the class AbstractScesimGridModel method updateFactMapping.

/**
 * If the <code>FactIdentifier</code> of the given <code>FactMapping</code> equals the one at <b>index</b>, update the <code>FactMapping.FactAlias</code> at <b>index</b>
 * position with the provided <b>value</b>
 * @param simulationDescriptor
 * @param factMappingReference
 * @param index
 * @param value
 */
protected void updateFactMapping(ScesimModelDescriptor simulationDescriptor, FactMapping factMappingReference, int index, String value, ScenarioHeaderMetaData.MetadataType metadataType) {
    final FactIdentifier factIdentifierReference = factMappingReference.getFactIdentifier();
    FactMapping factMappingToCheck = simulationDescriptor.getFactMappingByIndex(index);
    final FactIdentifier factIdentifierToCheck = factMappingToCheck.getFactIdentifier();
    boolean toUpdate = (Objects.equals(FactIdentifier.EMPTY, factIdentifierReference) && (Objects.equals(factIdentifierToCheck, factIdentifierReference) && Objects.equals(factMappingReference.getFactAlias(), factMappingToCheck.getFactAlias()))) || (Objects.equals(factIdentifierToCheck, factIdentifierReference));
    if (toUpdate) {
        switch(metadataType) {
            case INSTANCE:
                ((ScenarioGridColumn) columns.get(index)).getInformationHeaderMetaData().setTitle(value);
                factMappingToCheck.setFactAlias(value);
                break;
            case PROPERTY:
                if (Objects.equals(factMappingToCheck.getFullExpression(), factMappingReference.getFullExpression())) {
                    ((ScenarioGridColumn) columns.get(index)).getPropertyHeaderMetaData().setTitle(value);
                    factMappingToCheck.setExpressionAlias(value);
                }
                break;
            default:
                break;
        }
    }
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier)

Example 24 with FactMapping

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

the class AbstractScesimGridModel method deleteCell.

@Override
public Range deleteCell(int rowIndex, int columnIndex) {
    FactMapping factMapping = abstractScesimModel.getScesimModelDescriptor().getFactMappingByIndex(columnIndex);
    abstractScesimModel.getDataByIndex(rowIndex).removeFactMappingValueByIdentifiers(factMapping.getFactIdentifier(), factMapping.getExpressionIdentifier());
    return super.deleteCell(rowIndex, columnIndex);
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping)

Example 25 with FactMapping

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

the class AbstractScesimGridModel method updateHeader.

public void updateHeader(int columnIndex, int headerRowIndex, String headerCellValue) {
    final ScenarioHeaderMetaData editedMetadata = (ScenarioHeaderMetaData) getColumns().get(columnIndex).getHeaderMetaData().get(headerRowIndex);
    // do not update if old and new value are the same
    if (Objects.equals(editedMetadata.getTitle(), headerCellValue)) {
        return;
    }
    ScesimModelDescriptor simulationDescriptor = abstractScesimModel.getScesimModelDescriptor();
    FactMapping factMappingToEdit = simulationDescriptor.getFactMappingByIndex(columnIndex);
    ScenarioHeaderMetaData.MetadataType metadataType = editedMetadata.getMetadataType();
    IntStream.range(0, getColumnCount()).forEach(index -> updateFactMapping(simulationDescriptor, factMappingToEdit, index, headerCellValue, metadataType));
    if (editedMetadata.getMetadataType().equals(ScenarioHeaderMetaData.MetadataType.INSTANCE)) {
        eventBus.fireEvent(new ReloadTestToolsEvent(false));
    }
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) ReloadTestToolsEvent(org.drools.workbench.screens.scenariosimulation.client.events.ReloadTestToolsEvent) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) ScenarioHeaderMetaData(org.drools.workbench.screens.scenariosimulation.client.metadata.ScenarioHeaderMetaData)

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