Search in sources :

Example 1 with ExpressionElement

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

the class ScenarioGridTest method isPropertyAssigned.

@Test
public void isPropertyAssigned() {
    factMappingDescription.getExpressionElements().clear();
    assertTrue(scenarioGridSpy.isPropertyAssigned(false, factMappingDescription));
    assertTrue(scenarioGridSpy.isPropertyAssigned(true, factMappingDescription));
    factMappingDescription.getExpressionElements().add(new ExpressionElement(TEST));
    assertTrue(scenarioGridSpy.isPropertyAssigned(false, factMappingDescription));
    assertTrue(scenarioGridSpy.isPropertyAssigned(true, factMappingDescription));
    factMappingGiven.getExpressionElements().clear();
    assertFalse(scenarioGridSpy.isPropertyAssigned(false, factMappingGiven));
    assertFalse(scenarioGridSpy.isPropertyAssigned(true, factMappingGiven));
    factMappingGiven.getExpressionElements().add(new ExpressionElement("test"));
    assertFalse(scenarioGridSpy.isPropertyAssigned(false, factMappingGiven));
    assertTrue(scenarioGridSpy.isPropertyAssigned(true, factMappingGiven));
    factMappingInteger.getExpressionElements().clear();
    assertFalse(scenarioGridSpy.isPropertyAssigned(false, factMappingInteger));
    assertTrue(scenarioGridSpy.isPropertyAssigned(true, factMappingInteger));
}
Also used : ExpressionElement(org.drools.scenariosimulation.api.model.ExpressionElement) Test(org.junit.Test)

Example 2 with ExpressionElement

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

the class AbstractDataManagementStrategy method getPropertiesToHide.

/**
 * This method returns a <code>List</code> with the properties of a given <b>Type</b> (Fact, class, other dmn defined) instance,
 * to be hidden from the right panel for the selected column.
 * <p>
 * If click happen on an already assigned property, <b>all</b> all the properties of given type should be shown;
 * if, instead, click is on an unassigned property, the already assigned properties must be hidden.
 * (e.g. inside GIVEN there is an "Author" group; if clicking on "books" property header, this method returns  an <b>empty</b> <code>List</code>;
 * if click is on an unassigned property column, this method returns a <code>List</code>.
 * with all the <b>already assigned</b> Author's properties)
 * @param selectedColumn
 * @param abstractScesimGridModel
 * @return
 */
protected <T extends AbstractScesimModel<E>, E extends AbstractScesimData> List<List<String>> getPropertiesToHide(ScenarioGridColumn selectedColumn, AbstractScesimGridModel<T, E> abstractScesimGridModel) {
    List<List<String>> toReturn = new ArrayList<>();
    if (!selectedColumn.isPropertyAssigned()) {
        abstractScesimGridModel.getAbstractScesimModel().ifPresent(simulation -> {
            final ScesimModelDescriptor simulationDescriptor = simulation.getScesimModelDescriptor();
            List<ScenarioGridColumn> instanceColumns = abstractScesimGridModel.getInstanceScenarioGridColumns(selectedColumn);
            toReturn.addAll(instanceColumns.stream().filter(ScenarioGridColumn::isPropertyAssigned).map(instanceColumn -> abstractScesimGridModel.getColumns().indexOf(instanceColumn)).map(columnIndex -> {
                List<String> propertyNameElements = simulationDescriptor.getFactMappingByIndex(columnIndex).getExpressionElementsWithoutClass().stream().map(ExpressionElement::getStep).collect(Collectors.toList());
                if (propertyNameElements.isEmpty()) {
                    propertyNameElements.add(VALUE);
                }
                return Collections.unmodifiableList(propertyNameElements);
            }).collect(Collectors.toList()));
        });
    }
    return toReturn;
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree) FactModelTuple(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple) GridWidget(org.drools.workbench.screens.scenariosimulation.client.enums.GridWidget) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ExpressionElement(org.drools.scenariosimulation.api.model.ExpressionElement) ScenarioSimulationContext(org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext) AbstractScesimModel(org.drools.scenariosimulation.api.model.AbstractScesimModel) VALUE(org.drools.scenariosimulation.api.utils.ConstantsHolder.VALUE) Map(java.util.Map) AbstractScesimGridModel(org.drools.workbench.screens.scenariosimulation.client.models.AbstractScesimGridModel) ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) TestToolsPresenterData(org.drools.workbench.screens.scenariosimulation.client.rightpanel.TestToolsPresenterData) Set(java.util.Set) FactMappingType(org.drools.scenariosimulation.api.model.FactMappingType) Collectors(java.util.stream.Collectors) TestToolsView(org.drools.workbench.screens.scenariosimulation.client.rightpanel.TestToolsView) Objects(java.util.Objects) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) List(java.util.List) TreeMap(java.util.TreeMap) Collections(java.util.Collections) SortedMap(java.util.SortedMap) AbstractScesimData(org.drools.scenariosimulation.api.model.AbstractScesimData) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)

Example 3 with ExpressionElement

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

the class AbstractRunnerHelper method throwScenarioException.

private void throwScenarioException(FactMappingValue factMappingValue, ScesimModelDescriptor scesimModelDescriptor) {
    FactMapping factMapping = scesimModelDescriptor.getFactMapping(factMappingValue.getFactIdentifier(), factMappingValue.getExpressionIdentifier()).orElseThrow(() -> new IllegalStateException("Wrong expression, this should not happen"));
    String factName = String.join(".", factMapping.getExpressionElements().stream().map(ExpressionElement::getStep).collect(Collectors.toList()));
    if (FactMappingValueStatus.FAILED_WITH_ERROR == factMappingValue.getStatus()) {
        throw new ScenarioException(determineExceptionMessage(factMappingValue, factName), true);
    } else if (FactMappingValueStatus.FAILED_WITH_EXCEPTION == factMappingValue.getStatus()) {
        throw new ScenarioException(ScenarioSimulationServerMessages.getGenericScenarioExceptionMessage(factMappingValue.getExceptionMessage()));
    } else {
        throw new IllegalStateException("Illegal FactMappingValue status");
    }
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) ExpressionElement(org.drools.scenariosimulation.api.model.ExpressionElement)

Example 4 with ExpressionElement

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

the class DMNScenarioRunnerHelper method getSingleFactValueResult.

@SuppressWarnings("unchecked")
protected ValueWrapper getSingleFactValueResult(FactMapping factMapping, FactMappingValue expectedResult, DMNDecisionResult decisionResult, List<DMNMessage> failureMessages, ExpressionEvaluator expressionEvaluator) {
    Object resultRaw = decisionResult.getResult();
    final DMNDecisionResult.DecisionEvaluationStatus evaluationStatus = decisionResult.getEvaluationStatus();
    if (!SUCCEEDED.equals(evaluationStatus)) {
        String failureReason = determineFailureMessage(evaluationStatus, failureMessages);
        return errorWithMessage("The decision \"" + decisionResult.getDecisionName() + "\" has not been successfully evaluated: " + failureReason);
    }
    List<ExpressionElement> elementsWithoutClass = factMapping.getExpressionElementsWithoutClass();
    // DMN engine doesn't generate the whole object when no entry of the decision table match
    if (resultRaw != null) {
        for (ExpressionElement expressionElement : elementsWithoutClass) {
            if (!(resultRaw instanceof Map)) {
                throw new ScenarioException("Wrong resultRaw structure because it is not a complex type as expected");
            }
            Map<String, Object> result = (Map<String, Object>) resultRaw;
            resultRaw = result.get(expressionElement.getStep());
        }
    }
    Class<?> resultClass = resultRaw != null ? resultRaw.getClass() : null;
    Object expectedResultRaw = expectedResult.getRawValue();
    return getResultWrapper(factMapping.getClassName(), expectedResult, expressionEvaluator, expectedResultRaw, resultRaw, resultClass);
}
Also used : DMNDecisionResult(org.kie.dmn.api.core.DMNDecisionResult) ExpressionElement(org.drools.scenariosimulation.api.model.ExpressionElement) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with ExpressionElement

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

the class AbstractScesimGridModelTest method isSameSelectedColumnProperty.

@Test
public void isSameSelectedColumnProperty() {
    List<ExpressionElement> expressionList = Arrays.asList(new ExpressionElement("Fact"), new ExpressionElement("property"));
    when(factMappingMock.getExpressionElements()).thenReturn(expressionList);
    when(factMappingMock.getFactMappingValueType()).thenReturn(FactMappingValueType.NOT_EXPRESSION);
    assertTrue(abstractScesimGridModelSpy.isSameSelectedColumnProperty(1, Arrays.asList("Fact", "property"), FactMappingValueType.NOT_EXPRESSION));
    assertFalse(abstractScesimGridModelSpy.isSameSelectedColumnProperty(1, Arrays.asList("Fact", "property2"), FactMappingValueType.NOT_EXPRESSION));
    assertFalse(abstractScesimGridModelSpy.isSameSelectedColumnProperty(1, Arrays.asList("property2"), FactMappingValueType.NOT_EXPRESSION));
    assertFalse(abstractScesimGridModelSpy.isSameSelectedColumnProperty(1, Arrays.asList("Fact", "property"), FactMappingValueType.EXPRESSION));
    assertFalse(abstractScesimGridModelSpy.isSameSelectedColumnProperty(1, Arrays.asList("Fact", "property2"), FactMappingValueType.EXPRESSION));
    assertFalse(abstractScesimGridModelSpy.isSameSelectedColumnProperty(1, Arrays.asList("property2"), FactMappingValueType.EXPRESSION));
    when(factMappingMock.getFactMappingValueType()).thenReturn(FactMappingValueType.EXPRESSION);
    assertFalse(abstractScesimGridModelSpy.isSameSelectedColumnProperty(1, Arrays.asList("Fact", "property"), FactMappingValueType.NOT_EXPRESSION));
    assertFalse(abstractScesimGridModelSpy.isSameSelectedColumnProperty(1, Arrays.asList("Fact", "property2"), FactMappingValueType.NOT_EXPRESSION));
    assertFalse(abstractScesimGridModelSpy.isSameSelectedColumnProperty(1, Arrays.asList("property2"), FactMappingValueType.NOT_EXPRESSION));
    assertTrue(abstractScesimGridModelSpy.isSameSelectedColumnProperty(1, Arrays.asList("Fact", "property"), FactMappingValueType.EXPRESSION));
    assertFalse(abstractScesimGridModelSpy.isSameSelectedColumnProperty(1, Arrays.asList("Fact", "property2"), FactMappingValueType.EXPRESSION));
    assertFalse(abstractScesimGridModelSpy.isSameSelectedColumnProperty(1, Arrays.asList("property2"), FactMappingValueType.EXPRESSION));
}
Also used : ExpressionElement(org.drools.scenariosimulation.api.model.ExpressionElement) AbstractScenarioSimulationTest(org.drools.workbench.screens.scenariosimulation.client.AbstractScenarioSimulationTest) Test(org.junit.Test)

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