Search in sources :

Example 36 with FactModelTree

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

the class DMNTypeServiceImplTest method verifyFactModelTree.

/**
 * Verify the <code>FactModelTree</code> generated for a <b>given</b> <code>DMNNode</code> (<code>InputDataNode</code> or <code>DecisionNode</code>)
 * @param factModelTuple
 * @param dmnNode
 * @param hiddenFacts
 */
private void verifyFactModelTree(FactModelTuple factModelTuple, DMNNode dmnNode, SortedMap<String, FactModelTree> hiddenFacts, Map<String, String> importedModelsMap) {
    final String name = importedModelsMap.containsKey(dmnNode.getModelNamespace()) ? importedModelsMap.get(dmnNode.getModelNamespace()) + "." + dmnNode.getName() : dmnNode.getName();
    // Check the FactModelTree has been mapped between visible facts
    assertTrue(factModelTuple.getVisibleFacts().containsKey(name));
    final FactModelTree mappedFactModelTree = factModelTuple.getVisibleFacts().get(name);
    // Check the FactModelTree is not null
    assertNotNull(mappedFactModelTree);
    DMNType originalType;
    // Retrieving DMNType mapped by original DMNNode
    if (dmnNode instanceof InputDataNode) {
        originalType = ((InputDataNode) dmnNode).getType();
    } else if (dmnNode instanceof DecisionNode) {
        originalType = ((DecisionNode) dmnNode).getResultType();
    } else {
        fail("Unrecognized node type " + name + " -> " + dmnNode.getClass().getCanonicalName());
        return;
    }
    if (originalType.isCollection()) {
        // if original type is a collection
        verifyCollectionDMNType(mappedFactModelTree, originalType, hiddenFacts);
    } else {
        // Otherwise look inside for specific cases
        if (originalType.isComposite()) {
            verifyCompositeDMNType(mappedFactModelTree, originalType, hiddenFacts);
        } else {
            verifySimpleDMNType(mappedFactModelTree, originalType);
        }
    }
}
Also used : InputDataNode(org.kie.dmn.api.core.ast.InputDataNode) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree) DMNType(org.kie.dmn.api.core.DMNType)

Example 37 with FactModelTree

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

the class DMNTypeServiceImplTest method createTopLevelFactModelTreeCompositeNoCollectionBaseType.

@Test
public void createTopLevelFactModelTreeCompositeNoCollectionBaseType() throws WrongDMNTypeException {
    // Single property retrieve
    DMNType composite = getSingleCompositeWithBaseTypeField();
    FactModelTree retrieved = dmnTypeServiceImpl.createTopLevelFactModelTree("testPath", IMPORTED_PREFIX, composite, new TreeMap<>(), FactModelTree.Type.INPUT);
    assertNotNull(retrieved);
    assertEquals("testPath", retrieved.getFactName());
    assertEquals(2, retrieved.getSimpleProperties().size());
    assertTrue(retrieved.getSimpleProperties().containsKey("name"));
    assertEquals(SIMPLE_TYPE_NAME, retrieved.getSimpleProperties().get("name").getTypeName());
    assertFalse(retrieved.getSimpleProperties().get("name").getBaseTypeName().isPresent());
    assertEquals(SIMPLE_TYPE_NAME, retrieved.getSimpleProperties().get("name").getPropertyTypeNameToVisualize());
    // 
    assertTrue(retrieved.getSimpleProperties().containsKey("gender"));
    assertEquals("simpleType", retrieved.getSimpleProperties().get("gender").getTypeName());
    assertEquals(SIMPLE_TYPE_NAME, retrieved.getSimpleProperties().get("gender").getBaseTypeName().get());
    assertEquals(SIMPLE_TYPE_NAME, retrieved.getSimpleProperties().get("gender").getPropertyTypeNameToVisualize());
    assertTrue(retrieved.getExpandableProperties().isEmpty());
    assertTrue(retrieved.getGenericTypesMap().isEmpty());
    assertEquals(IMPORTED_PREFIX, retrieved.getImportPrefix());
}
Also used : FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree) DMNType(org.kie.dmn.api.core.DMNType) Test(org.junit.Test)

Example 38 with FactModelTree

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

the class DMNSimulationSettingsCreationStrategy method createSimulation.

@Override
public Simulation createSimulation(Path context, String dmnFilePath) {
    final FactModelTuple factModelTuple = getFactModelTuple(context, dmnFilePath);
    Simulation toReturn = new Simulation();
    ScesimModelDescriptor simulationDescriptor = toReturn.getScesimModelDescriptor();
    simulationDescriptor.addFactMapping(FactIdentifier.INDEX.getName(), FactIdentifier.INDEX, ExpressionIdentifier.INDEX);
    simulationDescriptor.addFactMapping(FactIdentifier.DESCRIPTION.getName(), FactIdentifier.DESCRIPTION, ExpressionIdentifier.DESCRIPTION);
    ScenarioWithIndex scenarioWithIndex = createScesimDataWithIndex(toReturn, simulationDescriptor, ScenarioWithIndex::new);
    AtomicInteger id = new AtomicInteger(1);
    final Collection<FactModelTree> visibleFactTrees = factModelTuple.getVisibleFacts().values();
    final Map<String, FactModelTree> hiddenValues = factModelTuple.getHiddenFacts();
    visibleFactTrees.stream().sorted((a, b) -> {
        Type aType = a.getType();
        Type bType = b.getType();
        int inputFirstOrder = Type.INPUT.equals(aType) ? -1 : 1;
        return aType.equals(bType) ? 0 : inputFirstOrder;
    }).forEach(factModelTree -> {
        FactIdentifier factIdentifier = FactIdentifier.create(factModelTree.getFactName(), factModelTree.getFactName(), factModelTree.getImportPrefix());
        FactMappingExtractor factMappingExtractor = new FactMappingExtractor(factIdentifier, scenarioWithIndex.getIndex(), id, convert(factModelTree.getType()), simulationDescriptor, scenarioWithIndex.getScesimData());
        addFactMapping(factMappingExtractor, factModelTree, new ArrayList<>(), hiddenValues);
    });
    addEmptyColumnsIfNeeded(toReturn, scenarioWithIndex);
    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) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) GIVEN(org.drools.scenariosimulation.api.model.FactMappingType.GIVEN) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) Type(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree.Type) VALUE(org.drools.scenariosimulation.api.utils.ConstantsHolder.VALUE) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ScenarioSimulationSharedUtils(org.drools.scenariosimulation.api.utils.ScenarioSimulationSharedUtils) DMNTypeService(org.drools.workbench.screens.scenariosimulation.service.DMNTypeService) Map(java.util.Map) ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) Path(org.uberfire.backend.vfs.Path) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) Collection(java.util.Collection) Settings(org.drools.scenariosimulation.api.model.Settings) Set(java.util.Set) FactMappingType(org.drools.scenariosimulation.api.model.FactMappingType) List(java.util.List) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) Simulation(org.drools.scenariosimulation.api.model.Simulation) ApplicationScoped(javax.enterprise.context.ApplicationScoped) EXPECT(org.drools.scenariosimulation.api.model.FactMappingType.EXPECT) AbstractScesimData(org.drools.scenariosimulation.api.model.AbstractScesimData) FactModelTuple(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree) Type(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree.Type) FactMappingType(org.drools.scenariosimulation.api.model.FactMappingType) Simulation(org.drools.scenariosimulation.api.model.Simulation) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex)

Example 39 with FactModelTree

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

the class BusinessCentralDMODataManagementStrategyTest method getRandomMap.

private SortedMap<String, FactModelTree> getRandomMap() {
    SortedMap<String, FactModelTree> toReturn = new TreeMap<>();
    String[] dataObjects = getRandomStringArray();
    for (String factName : dataObjects) {
        toReturn.put(factName, getFactModelTreeInner(factName));
    }
    return toReturn;
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) TreeMap(java.util.TreeMap) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree)

Example 40 with FactModelTree

use of org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree 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)

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