Search in sources :

Example 31 with FactModelTree

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

the class SetHeaderCellValueCommand method validatePropertyHeader.

protected void validatePropertyHeader(ScenarioSimulationContext context, String headerCellValue, int columnIndex) {
    final ScenarioSimulationModel.Type simulationModelType = context.getScenarioSimulationModel().getSettings().getType();
    List<String> propertyNameElements = Collections.unmodifiableList(Arrays.asList(headerCellValue.split("\\.")));
    final FactMapping factMappingByIndex = context.getAbstractScesimModelByGridWidget(gridWidget).getScesimModelDescriptor().getFactMappingByIndex(columnIndex);
    String factName = simulationModelType.equals(ScenarioSimulationModel.Type.DMN) ? factMappingByIndex.getFactIdentifier().getName() : factMappingByIndex.getFactIdentifier().getClassNameWithoutPackage();
    final FactModelTree factModelTree = context.getDataObjectFieldsMap().get(factName);
    boolean isPropertyType = !headerCellValue.endsWith(".") && factModelTree != null && recursivelyFindIsPropertyType(context, factModelTree, propertyNameElements);
    context.getAbstractScesimGridModelByGridWidget(gridWidget).validatePropertyHeaderUpdate(headerCellValue, columnIndex, isPropertyType);
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree) ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel)

Example 32 with FactModelTree

use of org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree 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);
    }
}
Also used : FactModelTuple(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple) TreeMap(java.util.TreeMap) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree)

Example 33 with FactModelTree

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

the class SetHeaderCellValueCommandTest method recursivelyFindIsPropertyType.

@Test
public void recursivelyFindIsPropertyType() {
    Map<String, FactModelTree.PropertyTypeName> bookSimpleProperties = new HashMap<>();
    bookSimpleProperties.put("name", new FactModelTree.PropertyTypeName("String"));
    Map<String, String> bookExpandableProperties = new HashMap<>();
    bookExpandableProperties.put("author", "Author");
    Map<String, FactModelTree.PropertyTypeName> authorSimpleProperties = new HashMap<>();
    authorSimpleProperties.put("books", new FactModelTree.PropertyTypeName("List"));
    Map<String, String> authorExpandableProperties = new HashMap<>();
    FactModelTree bookFactModelTreeMock = getMockedFactModelTree(bookSimpleProperties, bookExpandableProperties);
    FactModelTree authorFactModelTreeMock = getMockedFactModelTree(authorSimpleProperties, authorExpandableProperties);
    when(dataObjectFieldsMapMock.get("Author")).thenReturn(authorFactModelTreeMock);
    when(dataObjectFieldsMapMock.get("Book")).thenReturn(bookFactModelTreeMock);
    assertFalse(((SetHeaderCellValueCommand) commandSpy).recursivelyFindIsPropertyType(scenarioSimulationContextLocal, bookFactModelTreeMock, Collections.singletonList("not-existing")));
    assertTrue(((SetHeaderCellValueCommand) commandSpy).recursivelyFindIsPropertyType(scenarioSimulationContextLocal, bookFactModelTreeMock, Collections.singletonList("name")));
    assertFalse(((SetHeaderCellValueCommand) commandSpy).recursivelyFindIsPropertyType(scenarioSimulationContextLocal, bookFactModelTreeMock, Arrays.asList("author", "not-existing")));
    assertTrue(((SetHeaderCellValueCommand) commandSpy).recursivelyFindIsPropertyType(scenarioSimulationContextLocal, bookFactModelTreeMock, Arrays.asList("author", "books")));
}
Also used : HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree) Test(org.junit.Test)

Example 34 with FactModelTree

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

the class DMNTypeServiceImpl method createFactModelTreeForComposite.

/**
 * Creates a <code>FactModelTree</code> for <code>DMNType</code> where <code>DMNType.isComposite()</code> == <code>true</code>
 * @param name
 * @param fullPropertyPath
 * @param type
 * @param hiddenFacts
 * @param fmType
 * @throws WrongDMNTypeException if <code>DMNType.isComposite()</code> != <code>true</code>
 */
protected FactModelTree createFactModelTreeForComposite(Map<String, List<String>> genericTypeInfoMap, String name, String importPrefix, String fullPropertyPath, DMNType type, SortedMap<String, FactModelTree> hiddenFacts, FactModelTree.Type fmType, List<String> alreadyVisited) throws WrongDMNTypeException {
    if (!type.isComposite() && !isToBeManagedAsComposite(type)) {
        throw new WrongDMNTypeException();
    }
    Map<String, FactModelTree.PropertyTypeName> simpleFields = new HashMap<>();
    FactModelTree toReturn = FactModelTree.ofDMN(name, importPrefix, simpleFields, genericTypeInfoMap, type.getName(), fmType);
    for (Map.Entry<String, DMNType> entry : type.getFields().entrySet()) {
        String expandablePropertyName = fullPropertyPath + "." + entry.getKey();
        if (isToBeManagedAsCollection(entry.getValue())) {
            // if it is a collection, generate the generic and add as hidden fact a simple or composite fact model tree
            FactModelTree fact = createFactModelTreeForCollection(new HashMap<>(), entry.getKey(), importPrefix, entry.getValue(), hiddenFacts, FactModelTree.Type.UNDEFINED, alreadyVisited);
            simpleFields.put(entry.getKey(), new FactModelTree.PropertyTypeName(List.class.getCanonicalName()));
            genericTypeInfoMap.put(entry.getKey(), fact.getGenericTypeInfo(VALUE));
        } else {
            String typeName = entry.getValue().getName();
            if (entry.getValue().isComposite()) {
                // a complex type needs the expandable property and then in the hidden map, its fact model tree
                if (!hiddenFacts.containsKey(typeName) && !alreadyVisited.contains(typeName)) {
                    alreadyVisited.add(typeName);
                    FactModelTree fact = createFactModelTreeForNoCollection(genericTypeInfoMap, entry.getKey(), importPrefix, VALUE, expandablePropertyName, entry.getValue(), hiddenFacts, FactModelTree.Type.UNDEFINED, alreadyVisited);
                    hiddenFacts.put(typeName, fact);
                }
                toReturn.addExpandableProperty(entry.getKey(), typeName);
            } else {
                FactModelTree.PropertyTypeName propertyTypeName = entry.getValue().getBaseType() != null ? new FactModelTree.PropertyTypeName(typeName, entry.getValue().getBaseType().getName()) : new FactModelTree.PropertyTypeName(typeName);
                simpleFields.put(entry.getKey(), propertyTypeName);
            }
        }
    }
    return toReturn;
}
Also used : HashMap(java.util.HashMap) WrongDMNTypeException(org.drools.workbench.screens.scenariosimulation.backend.server.exceptions.WrongDMNTypeException) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) DMNType(org.kie.dmn.api.core.DMNType)

Example 35 with FactModelTree

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

the class DMNTypeServiceImplTest method verifyCollectionDMNType.

/**
 * Verify the <code>FactModelTree</code> generated for a <b>collection</b> <code>DMNType</code>
 * @param mappedFactModelTree
 * @param originalType
 * @param hiddenFacts
 */
private void verifyCollectionDMNType(FactModelTree mappedFactModelTree, DMNType originalType, SortedMap<String, FactModelTree> hiddenFacts) {
    if (originalType.isComposite()) {
        // a composite collection is a collection of itself, the generic type is the DMNType itself
        if (!mappedFactModelTree.getGenericTypesMap().isEmpty()) {
            // with "value as key
            assertTrue(mappedFactModelTree.getGenericTypesMap().containsKey(VALUE));
            // since this is a list, it just have one generic
            final String genericType = mappedFactModelTree.getGenericTypesMap().get(VALUE).get(0);
            assertTrue(hiddenFacts.containsKey(genericType));
            final FactModelTree genericFactModelTree = hiddenFacts.get(genericType);
            assertNotNull(genericFactModelTree);
            verifyCompositeDMNType(genericFactModelTree, originalType, hiddenFacts);
        } else {
            verifyCompositeDMNType(mappedFactModelTree, originalType, hiddenFacts);
        }
    } else {
        // otherwise we have to check if it is a "direct" collection or a referenced one
        verifySimpleDMNType(mappedFactModelTree, originalType);
    }
}
Also used : 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