use of org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree in project drools-wb by kiegroup.
the class DMNTypeServiceImplTest method verifyFactModelTree.
/**
* Verify the <code>FactModelTree</code> generated for a <b>given</b> <code>DMNNode</code> (<code>InputDataNode</code> or <code>DecisionNode</code>)
* @param factModelTuple
* @param dmnNode
* @param hiddenFacts
*/
private void verifyFactModelTree(FactModelTuple factModelTuple, DMNNode dmnNode, SortedMap<String, FactModelTree> hiddenFacts, Map<String, String> importedModelsMap) {
final String name = importedModelsMap.containsKey(dmnNode.getModelNamespace()) ? importedModelsMap.get(dmnNode.getModelNamespace()) + "." + dmnNode.getName() : dmnNode.getName();
// Check the FactModelTree has been mapped between visible facts
assertTrue(factModelTuple.getVisibleFacts().containsKey(name));
final FactModelTree mappedFactModelTree = factModelTuple.getVisibleFacts().get(name);
// Check the FactModelTree is not null
assertNotNull(mappedFactModelTree);
DMNType originalType;
// Retrieving DMNType mapped by original DMNNode
if (dmnNode instanceof InputDataNode) {
originalType = ((InputDataNode) dmnNode).getType();
} else if (dmnNode instanceof DecisionNode) {
originalType = ((DecisionNode) dmnNode).getResultType();
} else {
fail("Unrecognized node type " + name + " -> " + dmnNode.getClass().getCanonicalName());
return;
}
if (originalType.isCollection()) {
// if original type is a collection
verifyCollectionDMNType(mappedFactModelTree, originalType, hiddenFacts);
} else {
// Otherwise look inside for specific cases
if (originalType.isComposite()) {
verifyCompositeDMNType(mappedFactModelTree, originalType, hiddenFacts);
} else {
verifySimpleDMNType(mappedFactModelTree, originalType);
}
}
}
use of org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree in project drools-wb by kiegroup.
the class DMNTypeServiceImplTest method createTopLevelFactModelTreeCompositeNoCollectionBaseType.
@Test
public void createTopLevelFactModelTreeCompositeNoCollectionBaseType() throws WrongDMNTypeException {
// Single property retrieve
DMNType composite = getSingleCompositeWithBaseTypeField();
FactModelTree retrieved = dmnTypeServiceImpl.createTopLevelFactModelTree("testPath", IMPORTED_PREFIX, composite, new TreeMap<>(), FactModelTree.Type.INPUT);
assertNotNull(retrieved);
assertEquals("testPath", retrieved.getFactName());
assertEquals(2, retrieved.getSimpleProperties().size());
assertTrue(retrieved.getSimpleProperties().containsKey("name"));
assertEquals(SIMPLE_TYPE_NAME, retrieved.getSimpleProperties().get("name").getTypeName());
assertFalse(retrieved.getSimpleProperties().get("name").getBaseTypeName().isPresent());
assertEquals(SIMPLE_TYPE_NAME, retrieved.getSimpleProperties().get("name").getPropertyTypeNameToVisualize());
//
assertTrue(retrieved.getSimpleProperties().containsKey("gender"));
assertEquals("simpleType", retrieved.getSimpleProperties().get("gender").getTypeName());
assertEquals(SIMPLE_TYPE_NAME, retrieved.getSimpleProperties().get("gender").getBaseTypeName().get());
assertEquals(SIMPLE_TYPE_NAME, retrieved.getSimpleProperties().get("gender").getPropertyTypeNameToVisualize());
assertTrue(retrieved.getExpandableProperties().isEmpty());
assertTrue(retrieved.getGenericTypesMap().isEmpty());
assertEquals(IMPORTED_PREFIX, retrieved.getImportPrefix());
}
use of org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree in project drools-wb by kiegroup.
the class DMNSimulationSettingsCreationStrategy method createSimulation.
@Override
public Simulation createSimulation(Path context, String dmnFilePath) {
final FactModelTuple factModelTuple = getFactModelTuple(context, dmnFilePath);
Simulation toReturn = new Simulation();
ScesimModelDescriptor simulationDescriptor = toReturn.getScesimModelDescriptor();
simulationDescriptor.addFactMapping(FactIdentifier.INDEX.getName(), FactIdentifier.INDEX, ExpressionIdentifier.INDEX);
simulationDescriptor.addFactMapping(FactIdentifier.DESCRIPTION.getName(), FactIdentifier.DESCRIPTION, ExpressionIdentifier.DESCRIPTION);
ScenarioWithIndex scenarioWithIndex = createScesimDataWithIndex(toReturn, simulationDescriptor, ScenarioWithIndex::new);
AtomicInteger id = new AtomicInteger(1);
final Collection<FactModelTree> visibleFactTrees = factModelTuple.getVisibleFacts().values();
final Map<String, FactModelTree> hiddenValues = factModelTuple.getHiddenFacts();
visibleFactTrees.stream().sorted((a, b) -> {
Type aType = a.getType();
Type bType = b.getType();
int inputFirstOrder = Type.INPUT.equals(aType) ? -1 : 1;
return aType.equals(bType) ? 0 : inputFirstOrder;
}).forEach(factModelTree -> {
FactIdentifier factIdentifier = FactIdentifier.create(factModelTree.getFactName(), factModelTree.getFactName(), factModelTree.getImportPrefix());
FactMappingExtractor factMappingExtractor = new FactMappingExtractor(factIdentifier, scenarioWithIndex.getIndex(), id, convert(factModelTree.getType()), simulationDescriptor, scenarioWithIndex.getScesimData());
addFactMapping(factMappingExtractor, factModelTree, new ArrayList<>(), hiddenValues);
});
addEmptyColumnsIfNeeded(toReturn, scenarioWithIndex);
return toReturn;
}
use of org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree in project drools-wb by kiegroup.
the class BusinessCentralDMODataManagementStrategyTest method getRandomMap.
private SortedMap<String, FactModelTree> getRandomMap() {
SortedMap<String, FactModelTree> toReturn = new TreeMap<>();
String[] dataObjects = getRandomStringArray();
for (String factName : dataObjects) {
toReturn.put(factName, getFactModelTreeInner(factName));
}
return toReturn;
}
use of org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree in project drools-wb by kiegroup.
the class AbstractSelectedColumnCommand method manageCollectionProperty.
/**
* @param context
* @param selectedColumn
* @param factName The name of the class to be used to retrieve the corresponding <code>FactModelTree</code>, i.e. without the <b>package</b>
* @param columnIndex
* @param fullPropertyPathElements This is the <code>List</code> of all the elements pointing to the final property (ex. Book.author.books)
*/
protected void manageCollectionProperty(ScenarioSimulationContext context, ScenarioGridColumn selectedColumn, String factName, int columnIndex, List<String> fullPropertyPathElements) {
final SortedMap<String, FactModelTree> dataObjectFieldsMap = context.getDataObjectFieldsMap();
final FactModelTree factModelTree = dataObjectFieldsMap.get(factName);
final Optional<AbstractScesimModel> selectedScenarioGridModel = context.getAbstractScesimGridModelByGridWidget(gridWidget).getAbstractScesimModel();
if (!selectedScenarioGridModel.isPresent()) {
throw new IllegalArgumentException("SelectedGrid not found");
}
final FactMapping factMapping = selectedScenarioGridModel.get().getScesimModelDescriptor().getFactMappingByIndex(columnIndex);
selectedColumn.setFactory(context.getCollectionEditorSingletonDOMElementFactory(gridWidget));
if (factModelTree.isSimple()) {
factMapping.setGenericTypes(factModelTree.getGenericTypeInfo(VALUE));
} else {
final FactModelTree nestedFactModelTree = navigateComplexObject(factModelTree, fullPropertyPathElements, dataObjectFieldsMap);
factMapping.setGenericTypes(nestedFactModelTree.getGenericTypeInfo(fullPropertyPathElements.get(fullPropertyPathElements.size() - 1)));
}
}
Aggregations