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;
}
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;
}
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;
}
Aggregations