Search in sources :

Example 11 with FactModelTree

use of org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree in project drools-wb by kiegroup.

the class DMNSimulationSettingsCreationStrategyTest method getFactModelTuple.

private FactModelTuple getFactModelTuple(boolean hasInput, boolean hasOutput) throws IOException {
    SortedMap<String, FactModelTree> visibleFacts = new TreeMap<>();
    SortedMap<String, FactModelTree> hiddenFacts = new TreeMap<>();
    if (hasInput) {
        for (InputDataNode input : dmnModelLocal.getInputs()) {
            DMNType type = input.getType();
            visibleFacts.put(input.getName(), createFactModelTree(input.getName(), input.getName(), type, hiddenFacts, FactModelTree.Type.INPUT));
        }
    }
    if (hasOutput) {
        for (DecisionNode decision : dmnModelLocal.getDecisions()) {
            DMNType type = decision.getResultType();
            visibleFacts.put(decision.getName(), createFactModelTree(decision.getName(), decision.getName(), type, hiddenFacts, DECISION));
        }
    }
    return new FactModelTuple(visibleFacts, hiddenFacts);
}
Also used : FactModelTuple(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple) Matchers.anyString(org.mockito.Matchers.anyString) InputDataNode(org.kie.dmn.api.core.ast.InputDataNode) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) TreeMap(java.util.TreeMap) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree) DMNType(org.kie.dmn.api.core.DMNType)

Example 12 with FactModelTree

use of org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree in project drools-wb by kiegroup.

the class DMNSimulationSettingsCreationStrategyTest method addToScenarioRecursive.

@Test
public void addToScenarioRecursive() {
    FactMapping factMappingMock = mock(FactMapping.class);
    DMNSimulationSettingsCreationStrategy.FactMappingExtractor factMappingExtractorMock = mock(DMNSimulationSettingsCreationStrategy.FactMappingExtractor.class);
    when(factMappingExtractorMock.getFactMapping(any(), anyString(), any(), anyString())).thenReturn(factMappingMock);
    Map<String, FactModelTree> hiddenFacts = new HashMap<>();
    FactModelTree factModelTree = new FactModelTree("myFact", "", new HashMap<>(), Collections.emptyMap());
    factModelTree.addExpandableProperty("recursiveProperty", "recursive");
    String propertyType = String.class.getCanonicalName();
    String propertyName = "simpleProperty";
    factModelTree.addSimpleProperty(propertyName, new FactModelTree.PropertyTypeName(propertyType));
    hiddenFacts.put("recursive", factModelTree);
    dmnSimulationCreationStrategy.addFactMapping(factMappingExtractorMock, factModelTree, new ArrayList<>(), hiddenFacts);
    verify(factMappingExtractorMock, times(1)).getFactMapping(eq(factModelTree), eq(propertyName), eq(Arrays.asList("myFact", "recursiveProperty")), eq(propertyType));
    verify(factMappingExtractorMock, times(2)).getFactMapping(any(), any(), any(), any());
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree) AbstractDMNTest(org.drools.workbench.screens.scenariosimulation.backend.server.AbstractDMNTest) Test(org.junit.Test)

Example 13 with FactModelTree

use of org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree in project drools-wb by kiegroup.

the class DMNSimulationSettingsCreationStrategyTest method createFactModelTree.

private FactModelTree createFactModelTree(String name, String path, DMNType type, SortedMap<String, FactModelTree> hiddenFacts, FactModelTree.Type fmType) {
    Map<String, FactModelTree.PropertyTypeName> simpleFields = new HashMap<>();
    if (!type.isComposite()) {
        simpleFields.put(VALUE, new FactModelTree.PropertyTypeName(type.getName()));
        FactModelTree simpleFactModelTree = new FactModelTree(name, "", simpleFields, new HashMap<>(), fmType);
        simpleFactModelTree.setSimple(true);
        return simpleFactModelTree;
    }
    FactModelTree factModelTree = new FactModelTree(name, "", simpleFields, new HashMap<>(), fmType);
    for (Map.Entry<String, DMNType> entry : type.getFields().entrySet()) {
        if (!entry.getValue().isComposite()) {
            FactModelTree.PropertyTypeName propertyTypeName = entry.getValue().getBaseType() != null ? new FactModelTree.PropertyTypeName(entry.getValue().getName(), entry.getValue().getBaseType().getName()) : new FactModelTree.PropertyTypeName(entry.getValue().getName());
            simpleFields.put(entry.getKey(), propertyTypeName);
        } else {
            String expandableId = path + "." + entry.getKey();
            factModelTree.addExpandableProperty(entry.getKey(), expandableId);
            hiddenFacts.put(expandableId, createFactModelTree(entry.getKey(), expandableId, entry.getValue(), hiddenFacts, FactModelTree.Type.UNDEFINED));
        }
    }
    return factModelTree;
}
Also used : HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree) Map(java.util.Map) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) DMNType(org.kie.dmn.api.core.DMNType)

Example 14 with FactModelTree

use of org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree in project drools-wb by kiegroup.

the class BusinessCentralDMODataManagementStrategy method fieldCompletionsCallbackMethod.

/**
 * Actual code of the <b>fieldCompletionsCallback</b>; isolated for testing
 * @param factName
 * @param superTypeMap
 * @param result
 * @param aggregatorCallback
 */
protected void fieldCompletionsCallbackMethod(String factName, Map<String, String> superTypeMap, ModelField[] result, Callback<FactModelTree> aggregatorCallback) {
    FactModelTree toSend = getFactModelTree(factName, superTypeMap, result);
    aggregatorCallback.callback(toSend);
}
Also used : FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree)

Example 15 with FactModelTree

use of org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree in project drools-wb by kiegroup.

the class AbstractTestToolsTest method getDataObjectFactTreeMap.

protected SortedMap<String, FactModelTree> getDataObjectFactTreeMap() {
    SortedMap<String, FactModelTree> toReturn = new TreeMap<>();
    IntStream.range(0, 3).forEach(id -> {
        String key = getRandomString();
        FactModelTree value = new FactModelTree(key, FACT_PACKAGE, getMockSimpleProperties(), new HashMap<>());
        toReturn.put(key, value);
        if (id == 1) {
            value.addSimpleProperty(getRandomString(), getRandomType());
        }
        if (id == 2) {
            value.addSimpleProperty(getRandomString(), getRandomType());
            // Recursion
            value.addSimpleProperty(getRandomString(), getRandomType());
        }
    });
    return toReturn;
}
Also used : TreeMap(java.util.TreeMap) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree)

Aggregations

FactModelTree (org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree)47 Test (org.junit.Test)19 TreeMap (java.util.TreeMap)16 Matchers.anyString (org.mockito.Matchers.anyString)14 HashMap (java.util.HashMap)10 DMNType (org.kie.dmn.api.core.DMNType)10 ArrayList (java.util.ArrayList)9 AbstractScenarioSimulationEditorTest (org.drools.workbench.screens.scenariosimulation.client.editor.AbstractScenarioSimulationEditorTest)8 FactModelTuple (org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple)7 List (java.util.List)6 Map (java.util.Map)6 SortedMap (java.util.SortedMap)6 FactMapping (org.drools.scenariosimulation.api.model.FactMapping)6 ScenarioSimulationModel (org.drools.scenariosimulation.api.model.ScenarioSimulationModel)4 Collections (java.util.Collections)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 AbstractScesimData (org.drools.scenariosimulation.api.model.AbstractScesimData)3 AbstractScesimModel (org.drools.scenariosimulation.api.model.AbstractScesimModel)3 FactMappingType (org.drools.scenariosimulation.api.model.FactMappingType)3