Search in sources :

Example 1 with WrongDMNTypeException

use of org.drools.workbench.screens.scenariosimulation.backend.server.exceptions.WrongDMNTypeException 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;
}
Also used : FactModelTuple(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) TreeMap(java.util.TreeMap) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree) WrongDMNTypeException(org.drools.workbench.screens.scenariosimulation.backend.server.exceptions.WrongDMNTypeException) InputDataNode(org.kie.dmn.api.core.ast.InputDataNode) DMNModel(org.kie.dmn.api.core.DMNModel) DMNType(org.kie.dmn.api.core.DMNType)

Example 2 with WrongDMNTypeException

use of org.drools.workbench.screens.scenariosimulation.backend.server.exceptions.WrongDMNTypeException in project drools-wb by kiegroup.

the class DMNTypeServiceImpl method createFactModelTreeForCollection.

/**
 * Creates a <code>FactModelTree</code> for <code>DMNType</code> where <code>DMNType.isCollection()</code> == <code>true</code>
 * @param factName
 * @param type
 * @param hiddenFacts
 * @param fmType
 * @return
 * @throws WrongDMNTypeException if <code>DMNType.isCollection()</code> != <code>true</code>
 */
protected FactModelTree createFactModelTreeForCollection(Map<String, List<String>> genericTypeInfoMap, String factName, String importPrefix, DMNType type, SortedMap<String, FactModelTree> hiddenFacts, FactModelTree.Type fmType, List<String> alreadyVisited) throws WrongDMNTypeException {
    if (!type.isCollection() && !isToBeManagedAsCollection(type)) {
        throw new WrongDMNTypeException();
    }
    String typeName = type.getName();
    populateGeneric(genericTypeInfoMap, VALUE, typeName);
    FactModelTree toReturn = createFactModelTreeForSimple(factName, importPrefix, typeName, List.class.getCanonicalName(), genericTypeInfoMap, fmType);
    if (!hiddenFacts.containsKey(typeName) && !alreadyVisited.contains(typeName)) {
        alreadyVisited.add(typeName);
        FactModelTree genericFactModelTree = createFactModelTreeForGenericType(new HashMap<>(), typeName, importPrefix, typeName, typeName, type, hiddenFacts, fmType, alreadyVisited);
        hiddenFacts.put(typeName, genericFactModelTree);
    }
    return toReturn;
}
Also used : WrongDMNTypeException(org.drools.workbench.screens.scenariosimulation.backend.server.exceptions.WrongDMNTypeException) ArrayList(java.util.ArrayList) List(java.util.List) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree)

Example 3 with WrongDMNTypeException

use of org.drools.workbench.screens.scenariosimulation.backend.server.exceptions.WrongDMNTypeException 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)

Aggregations

WrongDMNTypeException (org.drools.workbench.screens.scenariosimulation.backend.server.exceptions.WrongDMNTypeException)3 FactModelTree (org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree)3 TreeMap (java.util.TreeMap)2 DMNType (org.kie.dmn.api.core.DMNType)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 FactModelTuple (org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple)1 DMNModel (org.kie.dmn.api.core.DMNModel)1 DecisionNode (org.kie.dmn.api.core.ast.DecisionNode)1 InputDataNode (org.kie.dmn.api.core.ast.InputDataNode)1