use of org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree in project drools-wb by kiegroup.
the class DMNTypeServiceImplTest method createTopLevelFactModelTreeCompositeCollection.
@Test
public void createTopLevelFactModelTreeCompositeCollection() throws WrongDMNTypeException {
// Single property collection retrieve
DMNType compositePerson = getCompositeCollection();
TreeMap<String, FactModelTree> hiddenFactSimpleCollection = new TreeMap<>();
FactModelTree retrieved = dmnTypeServiceImpl.createTopLevelFactModelTree("testPath", IMPORTED_PREFIX, compositePerson, hiddenFactSimpleCollection, FactModelTree.Type.INPUT);
assertNotNull(retrieved);
assertEquals("testPath", retrieved.getFactName());
assertEquals(1, retrieved.getSimpleProperties().size());
assertTrue(retrieved.getSimpleProperties().containsKey(VALUE));
assertEquals("java.util.List", retrieved.getSimpleProperties().get(VALUE).getTypeName());
assertFalse(retrieved.getSimpleProperties().get(VALUE).getBaseTypeName().isPresent());
assertEquals("java.util.List", retrieved.getSimpleProperties().get(VALUE).getPropertyTypeNameToVisualize());
assertTrue(retrieved.getExpandableProperties().isEmpty());
assertEquals(1, retrieved.getGenericTypesMap().size());
assertTrue(retrieved.getGenericTypesMap().containsKey(VALUE));
assertNotNull(retrieved.getGenericTypesMap().get(VALUE));
assertEquals(1, retrieved.getGenericTypesMap().get(VALUE).size());
assertEquals(compositePerson.getName(), retrieved.getGenericTypesMap().get(VALUE).get(0));
assertEquals(IMPORTED_PREFIX, retrieved.getImportPrefix());
}
use of org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree 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.model.typedescriptor.FactModelTree 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.model.typedescriptor.FactModelTree in project drools-wb by kiegroup.
the class DMNSimulationSettingsCreationStrategy method internalAddToScenario.
protected void internalAddToScenario(FactMappingExtractor factMappingExtractor, FactModelTree factModelTree, List<String> readOnlyPreviousSteps, Map<String, FactModelTree> hiddenValues, Set<String> alreadyVisited) {
List<String> previousSteps = new ArrayList<>(readOnlyPreviousSteps);
// if is a simple type it generates a single column
if (factModelTree.isSimple()) {
FactModelTree.PropertyTypeName factType = factModelTree.getSimpleProperties().get(VALUE);
factMappingExtractor.getFactMapping(factModelTree, VALUE, previousSteps, factType.getTypeName());
} else // otherwise it adds a column for each simple properties direct or nested
{
factModelTree.getSimpleProperties().entrySet().stream().sorted(Map.Entry.comparingByKey()).forEach(entry -> {
String factName = entry.getKey();
String factTypeName = entry.getValue().getTypeName();
FactMapping factMapping = factMappingExtractor.getFactMapping(factModelTree, factName, previousSteps, factTypeName);
if (ScenarioSimulationSharedUtils.isList(factTypeName)) {
factMapping.setGenericTypes(factModelTree.getGenericTypeInfo(factName));
}
factMapping.addExpressionElement(factName, factTypeName);
});
factModelTree.getExpandableProperties().entrySet().stream().sorted(Map.Entry.comparingByValue()).forEach(entry -> {
String factType = entry.getValue();
FactModelTree nestedModelTree = hiddenValues.get(factType);
if (previousSteps.isEmpty()) {
previousSteps.add(factModelTree.getFactName());
}
ArrayList<String> currentSteps = new ArrayList<>(previousSteps);
currentSteps.add(entry.getKey());
if (!alreadyVisited.contains(nestedModelTree.getFactName())) {
alreadyVisited.add(factModelTree.getFactName());
internalAddToScenario(factMappingExtractor, nestedModelTree, currentSteps, hiddenValues, alreadyVisited);
}
});
}
}
use of org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree in project drools-wb by kiegroup.
the class AbstractDataManagementStrategy method getInstanceMap.
/**
* Returns a <code>Map</code> of the <b>instances</b> as defined in the grid and the mapped <code>FactModelTree</code>
* @param sourceMap
* @return
*/
public SortedMap<String, FactModelTree> getInstanceMap(SortedMap<String, FactModelTree> sourceMap) {
SortedMap<String, FactModelTree> toReturn = new TreeMap<>();
// map instance name to base class
if (model != null) {
final ScesimModelDescriptor simulationDescriptor = model.getSimulation().getScesimModelDescriptor();
final ScenarioSimulationModel.Type type = model.getSettings().getType();
simulationDescriptor.getUnmodifiableFactMappings().stream().filter(factMapping -> !Objects.equals(FactMappingType.OTHER, factMapping.getExpressionIdentifier().getType())).forEach(factMapping -> {
String dataObjectName = ScenarioSimulationModel.Type.DMN.equals(type) ? factMapping.getFactIdentifier().getClassName() : factMapping.getFactIdentifier().getClassNameWithoutPackage().replace("$", ".");
final String instanceName = factMapping.getFactAlias();
if (!instanceName.equals(dataObjectName)) {
final FactModelTree factModelTree = sourceMap.get(dataObjectName);
if (factModelTree != null) {
toReturn.put(instanceName, factModelTree);
}
}
});
}
return toReturn;
}
Aggregations