use of org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple in project drools-wb by kiegroup.
the class DMNSimulationSettingsCreationStrategyTest method verifySimulationCreated.
private void verifySimulationCreated(boolean hasInput, boolean hasOutput) throws Exception {
final Path pathMock = mock(Path.class);
final String dmnFilePath = "test";
FactModelTuple factModelTuple = getFactModelTuple(hasInput, hasOutput);
doReturn(factModelTuple).when(dmnSimulationCreationStrategy).getFactModelTuple(any(), any());
Simulation simulation = dmnSimulationCreationStrategy.createSimulation(pathMock, dmnFilePath);
assertNotNull(simulation);
List<FactMapping> factMappings = simulation.getScesimModelDescriptor().getFactMappings();
if (hasInput) {
assertTrue(factMappings.stream().anyMatch(elem -> GIVEN.equals(elem.getExpressionIdentifier().getType())));
} else {
assertEquals(1, factMappings.stream().filter(elem -> GIVEN.equals(elem.getExpressionIdentifier().getType())).count());
}
if (hasOutput) {
assertTrue(factMappings.stream().anyMatch(elem -> EXPECT.equals(elem.getExpressionIdentifier().getType())));
} else {
assertEquals(1, factMappings.stream().filter(elem -> EXPECT.equals(elem.getExpressionIdentifier().getType())).count());
}
}
use of org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple in project drools-wb by kiegroup.
the class AbstractDataManagementStrategyTest method storeDataSimulation.
@Test
public void storeDataSimulation() {
ScenarioSimulationContext scenarioSimulationContextSpy = spy(scenarioSimulationContextLocal);
doReturn(simulationMock).when(scenarioSimulationContextSpy).getAbstractScesimModelByGridWidget(GridWidget.SIMULATION);
final FactModelTuple factModelTuple = getFactTuple();
abstractDataManagementStrategySpy.storeData(factModelTuple, testToolsPresenterMock, scenarioSimulationContextSpy, GridWidget.SIMULATION);
verify(testToolsPresenterMock, times(1)).populateTestTools(testToolsPresenterDataArgumentCaptor.capture());
assertNotNull(testToolsPresenterDataArgumentCaptor.getValue());
assertNotNull(testToolsPresenterDataArgumentCaptor.getValue().getDataObjectFieldsMap());
assertNotNull(testToolsPresenterDataArgumentCaptor.getValue().getHiddenFieldsMap());
assertNotNull(testToolsPresenterDataArgumentCaptor.getValue().getInstanceFieldsMap());
assertNotNull(testToolsPresenterDataArgumentCaptor.getValue().getPropertiesToHide());
assertNotNull(testToolsPresenterDataArgumentCaptor.getValue().getSimpleJavaInstanceFieldsMap());
assertNotNull(testToolsPresenterDataArgumentCaptor.getValue().getSimpleJavaTypeFieldsMap());
assertEquals(GridWidget.SIMULATION, testToolsPresenterDataArgumentCaptor.getValue().getGridWidget());
verify(scenarioSimulationContextSpy, times(1)).setDataObjectFieldsMap(isA(SortedMap.class));
verify(scenarioSimulationContextSpy, times(1)).setDataObjectsInstancesName(isA(Set.class));
verify(scenarioGridModelMock, times(1)).setSimpleJavaTypeInstancesName(isA(Set.class));
}
use of org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple in project drools-wb by kiegroup.
the class DMNTypeServiceImpl method retrieveFactModelTuple.
@Override
public FactModelTuple retrieveFactModelTuple(Path path, String dmnPath) {
DMNModel dmnModel = getDMNModel(path, dmnPath);
SortedMap<String, FactModelTree> visibleFacts = new TreeMap<>();
SortedMap<String, FactModelTree> hiddenFacts = new TreeMap<>();
ErrorHolder errorHolder = new ErrorHolder();
Map<String, String> importedModelsMap = dmnModel.getDefinitions().getImport().stream().collect(Collectors.toMap(Import::getNamespace, Import::getName));
for (InputDataNode input : dmnModel.getInputs()) {
final DMNType type = input.getType();
final String importPrefix = importedModelsMap.getOrDefault(input.getModelNamespace(), null);
final String name = importedModelsMap.containsKey(input.getModelNamespace()) ? importedModelsMap.get(input.getModelNamespace()) + "." + input.getName() : input.getName();
checkTypeSupport(type, errorHolder, name);
try {
visibleFacts.put(name, createTopLevelFactModelTree(name, importPrefix, type, hiddenFacts, FactModelTree.Type.INPUT));
} catch (WrongDMNTypeException e) {
throw ExceptionUtilities.handleException(e);
}
}
for (DecisionNode decision : dmnModel.getDecisions()) {
DMNType type = decision.getResultType();
final String importPrefix = importedModelsMap.getOrDefault(decision.getModelNamespace(), null);
final String name = importedModelsMap.containsKey(decision.getModelNamespace()) ? importedModelsMap.get(decision.getModelNamespace()) + "." + decision.getName() : decision.getName();
checkTypeSupport(type, errorHolder, name);
try {
visibleFacts.put(name, createTopLevelFactModelTree(name, importPrefix, type, hiddenFacts, FactModelTree.Type.DECISION));
} catch (WrongDMNTypeException e) {
throw ExceptionUtilities.handleException(e);
}
}
FactModelTuple factModelTuple = new FactModelTuple(visibleFacts, hiddenFacts);
errorHolder.getMultipleNestedCollection().forEach(factModelTuple::addMultipleNestedCollectionError);
errorHolder.getMultipleNestedObject().forEach(factModelTuple::addMultipleNestedObjectError);
return factModelTuple;
}
use of org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple in project drools-wb by kiegroup.
the class AbstractDMODataManagementStrategy method aggregatorCallbackMethod.
/**
* Actual code of the <b>aggregatorCallback</b>; isolated for testing
* @param testToolsPresenter
* @param expectedElements
* @param factTypeFieldsMap
* @param context
* @param result pass <code>null</code> if there is not any <i>complex</i> data object but only simple ones
* @param simpleJavaTypes
*/
public void aggregatorCallbackMethod(final TestToolsView.Presenter testToolsPresenter, final int expectedElements, final SortedMap<String, FactModelTree> factTypeFieldsMap, final ScenarioSimulationContext context, final FactModelTree result, final List<String> simpleJavaTypes, final GridWidget gridWidget) {
if (result != null) {
factTypeFieldsMap.put(result.getFactName(), result);
}
if (factTypeFieldsMap.size() == expectedElements) {
// This is used to invoke this callback only once, when all the expected "complex" objects has been managed
factTypeFieldsMap.values().forEach(factModelTree -> populateFactModelTree(factModelTree, factTypeFieldsMap));
SortedMap<String, FactModelTree> simpleJavaTypeFieldsMap = new TreeMap<>(simpleJavaTypes.stream().collect(Collectors.toMap(factType -> factType, factType -> {
SimpleClassEntry classEntry = SIMPLE_CLASSES_MAP.get(factType);
return getSimpleClassFactModelTree(classEntry.getSimpleName(), classEntry.getCanonicalName());
})));
SortedMap<String, FactModelTree> visibleFacts = new TreeMap<>(factTypeFieldsMap);
visibleFacts.putAll(simpleJavaTypeFieldsMap);
FactModelTuple factModelTuple = new FactModelTuple(visibleFacts, new TreeMap<>());
factModelTreeHolder.setFactModelTuple(factModelTuple);
storeData(factModelTuple, testToolsPresenter, context, gridWidget);
}
}
use of org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple in project drools-wb by kiegroup.
the class DMNTypeServiceImplTest method retrieveFactModelTupleDmnList.
@Test
public void retrieveFactModelTupleDmnList() {
setDmnModelLocal("dmn-list.dmn", "https://github.com/kiegroup/drools/kie-dmn/_CC8924B0-D729-4D70-9588-039B5824FFE9", "dmn-list");
FactModelTuple factModelTuple = dmnTypeServiceImpl.retrieveFactModelTuple(mock(Path.class), null);
// VisibleFacts should match inputs and decisions on given model
int expectedVisibleFacts = dmnModelLocal.getInputs().size() + dmnModelLocal.getDecisions().size();
assertEquals(expectedVisibleFacts, factModelTuple.getVisibleFacts().size());
Map<String, String> importedModelsMap = dmnModelLocal.getDefinitions().getImport().stream().collect(Collectors.toMap(Import::getNamespace, Import::getName));
// Verify each inputDataNode has been correctly mapped
dmnModelLocal.getInputs().forEach(inputDataNode -> verifyFactModelTree(factModelTuple, inputDataNode, factModelTuple.getHiddenFacts(), importedModelsMap));
// Verify each decisionNode has been correctly mapped
dmnModelLocal.getDecisions().forEach(decisionNode -> verifyFactModelTree(factModelTuple, decisionNode, factModelTuple.getHiddenFacts(), importedModelsMap));
}
Aggregations