Search in sources :

Example 51 with FactMapping

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

the class ScenarioCsvImportExport method generateHeader.

protected void generateHeader(List<FactMapping> factMappings, CSVPrinter printer) throws IOException {
    List<String> firstLineHeader = new ArrayList<>();
    List<String> secondLineHeader = new ArrayList<>();
    List<String> thirdLineHeader = new ArrayList<>();
    for (FactMapping factMapping : factMappings) {
        if (FactMappingType.OTHER.equals(factMapping.getExpressionIdentifier().getType())) {
            // OTHER
            String factAlias = factMapping.getFactAlias();
            firstLineHeader.add(factAlias);
            secondLineHeader.add(factAlias);
            thirdLineHeader.add(factAlias);
        } else {
            // GIVEN/EXPECT
            firstLineHeader.add(factMapping.getExpressionIdentifier().getType().name());
            // Instance
            secondLineHeader.add("#".equals(factMapping.getFactAlias()) ? "" : factMapping.getFactAlias());
            // Property
            thirdLineHeader.add(factMapping.getExpressionAlias());
        }
    }
    printer.printRecord(firstLineHeader.toArray());
    printer.printRecord(secondLineHeader.toArray());
    printer.printRecord(thirdLineHeader.toArray());
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) ArrayList(java.util.ArrayList)

Example 52 with FactMapping

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

Example 53 with FactMapping

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

the class AbstractSelectedColumnCommand method manageCollectionProperty.

/**
 * @param context
 * @param selectedColumn
 * @param factName The name of the class to be used to retrieve the corresponding <code>FactModelTree</code>, i.e. without the <b>package</b>
 * @param columnIndex
 * @param fullPropertyPathElements This is the <code>List</code> of all the elements pointing to the final property (ex. Book.author.books)
 */
protected void manageCollectionProperty(ScenarioSimulationContext context, ScenarioGridColumn selectedColumn, String factName, int columnIndex, List<String> fullPropertyPathElements) {
    final SortedMap<String, FactModelTree> dataObjectFieldsMap = context.getDataObjectFieldsMap();
    final FactModelTree factModelTree = dataObjectFieldsMap.get(factName);
    final Optional<AbstractScesimModel> selectedScenarioGridModel = context.getAbstractScesimGridModelByGridWidget(gridWidget).getAbstractScesimModel();
    if (!selectedScenarioGridModel.isPresent()) {
        throw new IllegalArgumentException("SelectedGrid not found");
    }
    final FactMapping factMapping = selectedScenarioGridModel.get().getScesimModelDescriptor().getFactMappingByIndex(columnIndex);
    selectedColumn.setFactory(context.getCollectionEditorSingletonDOMElementFactory(gridWidget));
    if (factModelTree.isSimple()) {
        factMapping.setGenericTypes(factModelTree.getGenericTypeInfo(VALUE));
    } else {
        final FactModelTree nestedFactModelTree = navigateComplexObject(factModelTree, fullPropertyPathElements, dataObjectFieldsMap);
        factMapping.setGenericTypes(nestedFactModelTree.getGenericTypeInfo(fullPropertyPathElements.get(fullPropertyPathElements.size() - 1)));
    }
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) AbstractScesimModel(org.drools.scenariosimulation.api.model.AbstractScesimModel) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree)

Example 54 with FactMapping

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

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

the class SetGridCellValueCommand method internalExecute.

@Override
protected void internalExecute(ScenarioSimulationContext context) {
    final ScenarioSimulationContext.Status status = context.getStatus();
    AbstractScesimModel<AbstractScesimData> abstractScesimModel = context.getAbstractScesimModelByGridWidget(gridWidget);
    int columnIndex = status.getColumnIndex();
    FactMapping factMapping = abstractScesimModel.getScesimModelDescriptor().getFactMappingByIndex(columnIndex);
    ScenarioGridColumn selectedColumn = (ScenarioGridColumn) context.getAbstractScesimGridModelByGridWidget(gridWidget).getColumns().get(columnIndex);
    String placeholder = ScenarioSimulationUtils.getPlaceHolder(selectedColumn.isInstanceAssigned(), selectedColumn.isPropertyAssigned(), factMapping.getFactMappingValueType(), factMapping.getClassName());
    context.getAbstractScesimGridModelByGridWidget(gridWidget).setCellValue(status.getRowIndex(), columnIndex, new ScenarioGridCellValue(status.getGridCellValue(), placeholder));
    context.getAbstractScesimGridModelByGridWidget(gridWidget).resetError(status.getRowIndex(), columnIndex);
}
Also used : ScenarioSimulationContext(org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) AbstractScesimData(org.drools.scenariosimulation.api.model.AbstractScesimData) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) ScenarioGridCellValue(org.drools.workbench.screens.scenariosimulation.client.values.ScenarioGridCellValue)

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