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