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));
}
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;
}
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");
}
}
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);
}
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));
}
Aggregations