Search in sources :

Example 6 with ExpressionElement

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

the class DuplicateInstanceCommand method executeIfSelectedColumn.

@Override
protected void executeIfSelectedColumn(ScenarioSimulationContext context, ScenarioGridColumn selectedColumn) {
    final AbstractScesimGridModel<? extends AbstractScesimModel, ? extends AbstractScesimData> selectedScenarioGridModel = context.getAbstractScesimGridModelByGridWidget(gridWidget);
    /* Generating the new instance alias with following schema: <original instance name> + '_copy_' + <number of existing instances> */
    int instancesCount = selectedScenarioGridModel.getInstancesCount(selectedColumn.getFactIdentifier().getClassName());
    String alias = selectedColumn.getInformationHeaderMetaData().getTitle().split(COPY_LABEL)[0] + COPY_LABEL + instancesCount;
    /* For every columns which belongs to the selected instance, it creates a new column and assign it the duplicated instance
         * and the duplicated property, if are assigned */
    int columnPosition = selectedScenarioGridModel.getInstanceLimits(selectedScenarioGridModel.getColumns().indexOf(selectedColumn)).getMaxRowIndex() + 1;
    AtomicInteger nextColumnPosition = new AtomicInteger(columnPosition);
    selectedScenarioGridModel.getInstanceScenarioGridColumns(selectedColumn).forEach(originalColumn -> {
        ScenarioGridColumn createdColumn = insertNewColumn(context, originalColumn, nextColumnPosition.getAndIncrement(), false);
        if (originalColumn.isInstanceAssigned()) {
            setInstanceHeader(context, createdColumn, alias, originalColumn.getFactIdentifier().getClassName());
            if (originalColumn.isPropertyAssigned()) {
                int originalColumnIndex = selectedScenarioGridModel.getColumns().indexOf(originalColumn);
                final FactMapping originalFactMapping = selectedScenarioGridModel.getAbstractScesimModel().get().getScesimModelDescriptor().getFactMappingByIndex(originalColumnIndex);
                factMappingValueType = originalFactMapping.getFactMappingValueType();
                /*  Rebuilt propertyNameElements, which is composed by: factName.property . The property MUST be the original property name */
                List<String> propertyNameElements = new ArrayList<>();
                propertyNameElements.add(alias);
                propertyNameElements.addAll(originalFactMapping.getExpressionElementsWithoutClass().stream().map(ExpressionElement::getStep).collect(Collectors.toList()));
                setPropertyHeader(context, createdColumn, originalColumn.getFactIdentifier().getClassName(), propertyNameElements, originalFactMapping.getClassName(), originalColumn.getPropertyHeaderMetaData().getTitle());
                /* It copies the properties values */
                int createdColumnIndex = selectedScenarioGridModel.getColumns().indexOf(createdColumn);
                selectedScenarioGridModel.duplicateColumnValues(originalColumnIndex, createdColumnIndex);
            }
        }
    });
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) ExpressionElement(org.drools.scenariosimulation.api.model.ExpressionElement) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)

Example 7 with ExpressionElement

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

the class AbstractScenarioSimulationTest method addNewColumn.

/**
 * Common method to add a new column in the model
 */
protected void addNewColumn(ScenarioGridColumn gridColumn, List<GridColumn.HeaderMetaData> metaData, ScenarioHeaderMetaData informationHeaderMetaData, ScenarioHeaderMetaData propertyHeaderMetaData, FactIdentifier factIdentifier, FactMapping factMapping, FactMappingValue factMappingValue, int factStartingRange, int factEndingRange, int columnIndex, String value, String propertyTitle, String columnId, String factAlias, String valueClassName, String propertyAlias, String fullClassName, String factIdentfierName) {
    when(gridColumn.getHeaderMetaData()).thenReturn(metaData);
    when(gridColumn.getInformationHeaderMetaData()).thenReturn(informationHeaderMetaData);
    when(gridColumn.getPropertyHeaderMetaData()).thenReturn(propertyHeaderMetaData);
    when(gridColumn.getFactIdentifier()).thenReturn(factIdentifier);
    when(gridColumn.isInstanceAssigned()).thenReturn(Boolean.TRUE);
    when(gridColumn.isPropertyAssigned()).thenReturn(Boolean.TRUE);
    when(scenarioGridModelMock.getInstanceLimits(columnIndex)).thenReturn(new GridData.Range(factStartingRange, factEndingRange));
    when(metaData.get(columnIndex)).thenReturn(informationHeaderMetaDataMock);
    when(informationHeaderMetaData.getTitle()).thenReturn(value);
    when(informationHeaderMetaData.getColumnGroup()).thenReturn(COLUMN_GROUP);
    when(propertyHeaderMetaData.getMetadataType()).thenReturn(ScenarioHeaderMetaData.MetadataType.PROPERTY);
    when(propertyHeaderMetaData.getTitle()).thenReturn(propertyTitle);
    when(propertyHeaderMetaData.getColumnGroup()).thenReturn(COLUMN_GROUP);
    when(propertyHeaderMetaData.getColumnId()).thenReturn(columnId);
    when(factMapping.getFactIdentifier()).thenReturn(factIdentifier);
    when(factMapping.getFactAlias()).thenReturn(factAlias);
    when(factMapping.getClassName()).thenReturn(valueClassName);
    final ExpressionElement factAliasExpressionElement = new ExpressionElement(factAlias);
    final ExpressionElement propertyAliasExpressionElement = new ExpressionElement(propertyAlias);
    List<ExpressionElement> expressionElements = new ArrayList<>();
    expressionElements.add(factAliasExpressionElement);
    expressionElements.add(propertyAliasExpressionElement);
    when(factMapping.getExpressionElements()).thenReturn(expressionElements);
    when(factMapping.getExpressionElementsWithoutClass()).thenReturn(Collections.singletonList(propertyAliasExpressionElement));
    when(factIdentifier.getClassName()).thenReturn(fullClassName);
    when(factIdentifier.getClassNameWithoutPackage()).thenReturn(fullClassName.substring(fullClassName.lastIndexOf(".") + 1));
    when(factIdentifier.getPackageWithoutClassName()).thenReturn(fullClassName.substring(0, fullClassName.lastIndexOf(".")));
    when(factIdentifier.getName()).thenReturn(factIdentfierName);
    gridColumns.add(gridColumn);
    factMappingValuesLocal.add(factMappingValue);
    factIdentifierSet.add(factIdentifier);
    factMappingLocal.add(factMapping);
    when(simulationDescriptorMock.getFactMappingByIndex(columnIndex)).thenReturn(factMapping);
    when(scenarioGridModelMock.nextColumnCount()).thenReturn(factMappingValuesLocal.size());
}
Also used : GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) ArrayList(java.util.ArrayList) ExpressionElement(org.drools.scenariosimulation.api.model.ExpressionElement)

Example 8 with ExpressionElement

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

the class AbstractSelectedColumnCommandTest method getMatchingExpressionAlias.

/* This test is usable ONLY by <code>SetPropertyCommandTest</code> subclass */
protected void getMatchingExpressionAlias() {
    Optional<String> retrieved = ((AbstractSelectedColumnCommand) commandSpy).getMatchingExpressionAlias(scenarioSimulationContextLocal, MULTIPART_VALUE_ELEMENTS, factIdentifierMock);
    verify(simulationDescriptorMock, times(1)).getFactMappingsByFactName(eq(factIdentifierMock.getName()));
    assertEquals(Optional.empty(), retrieved);
    List<FactMapping> factMappingList = new ArrayList<>();
    factMappingList.add(factMappingMock);
    when(simulationDescriptorMock.getFactMappingsByFactName(FACT_IDENTIFIER_NAME)).thenReturn(factMappingList.stream());
    String EXPRESSION_ALIAS = "EXPRESSION_ALIAS";
    when(factMappingMock.getExpressionAlias()).thenReturn(EXPRESSION_ALIAS);
    retrieved = ((AbstractSelectedColumnCommand) commandSpy).getMatchingExpressionAlias(scenarioSimulationContextLocal, FULL_PROPERTY_NAME_ELEMENTS, factIdentifierMock);
    assertEquals(Optional.empty(), retrieved);
    List<ExpressionElement> expressionElements = FULL_PROPERTY_NAME_ELEMENTS.stream().map(ExpressionElement::new).collect(Collectors.toList());
    when(factMappingMock.getExpressionElements()).thenReturn(expressionElements);
    when(simulationDescriptorMock.getFactMappingsByFactName(FACT_IDENTIFIER_NAME)).thenReturn(factMappingList.stream());
    retrieved = ((AbstractSelectedColumnCommand) commandSpy).getMatchingExpressionAlias(scenarioSimulationContextLocal, FULL_PROPERTY_NAME_ELEMENTS, factIdentifierMock);
    assertEquals(Optional.of(EXPRESSION_ALIAS), retrieved);
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) ArrayList(java.util.ArrayList) ExpressionElement(org.drools.scenariosimulation.api.model.ExpressionElement) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString)

Aggregations

ExpressionElement (org.drools.scenariosimulation.api.model.ExpressionElement)8 ArrayList (java.util.ArrayList)4 FactMapping (org.drools.scenariosimulation.api.model.FactMapping)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ScenarioGridColumn (org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)2 Test (org.junit.Test)2 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Objects (java.util.Objects)1 Set (java.util.Set)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Collectors (java.util.stream.Collectors)1 AbstractScesimData (org.drools.scenariosimulation.api.model.AbstractScesimData)1 AbstractScesimModel (org.drools.scenariosimulation.api.model.AbstractScesimModel)1 FactMappingType (org.drools.scenariosimulation.api.model.FactMappingType)1 ScenarioSimulationModel (org.drools.scenariosimulation.api.model.ScenarioSimulationModel)1