Search in sources :

Example 46 with FactModelTree

use of org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree in project drools-wb by kiegroup.

the class SetHeaderCellValueCommand method recursivelyFindIsPropertyType.

protected boolean recursivelyFindIsPropertyType(ScenarioSimulationContext context, FactModelTree factModelTree, List<String> propertyNameElements) {
    boolean toReturn = propertyNameElements.size() == 1 && (factModelTree.getSimpleProperties().containsKey(propertyNameElements.get(0)) || factModelTree.getExpandableProperties().containsKey(propertyNameElements.get(0)));
    if (!toReturn && propertyNameElements.size() > 1) {
        String propertyParent = propertyNameElements.get(0);
        if (factModelTree.getExpandableProperties().containsKey(propertyParent)) {
            List<String> nestedPropertyNameElements = propertyNameElements.subList(1, propertyNameElements.size());
            String className = factModelTree.getExpandableProperties().get(propertyParent);
            final FactModelTree nestedFactModelTree = context.getDataObjectFieldsMap().get(className);
            toReturn = recursivelyFindIsPropertyType(context, nestedFactModelTree, nestedPropertyNameElements);
        }
    }
    return toReturn;
}
Also used : FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree)

Example 47 with FactModelTree

use of org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree in project drools-wb by kiegroup.

the class AbstractDMODataManagementStrategy method getFactModelTree.

/**
 * Create a <code>FactModelTree</code> for a given <b>factName</b> populating it with the given
 * <code>ModelField[]</code>
 * @param factName
 * @param superTypeMap
 * @param modelFields
 * @return
 * @implNote For the moment being, due to current implementation of <b>DMO</b>, it it not possible to retrieve <b>all</b>
 * the generic types of a class with more then one, but only the last one. So, for <code>Map</code>, the <b>key</b>
 * will always be a <code>java.lang.String</code>
 */
public FactModelTree getFactModelTree(String factName, Map<String, String> superTypeMap, ModelField[] modelFields) {
    Map<String, FactModelTree.PropertyTypeName> simpleProperties = new HashMap<>();
    Map<String, List<String>> genericTypesMap = new HashMap<>();
    String fullFactClassName = getFQCNByFactName(factName);
    String factPackageName = packageName;
    String factClassName = fullFactClassName;
    if (fullFactClassName != null && fullFactClassName.contains(".")) {
        factPackageName = fullFactClassName.substring(0, fullFactClassName.lastIndexOf('.'));
        factClassName = fullFactClassName.substring(fullFactClassName.lastIndexOf('.') + 1);
    }
    if (ScenarioSimulationSharedUtils.isEnumCanonicalName(superTypeMap.get(factName))) {
        simpleProperties.put(ConstantsHolder.VALUE, new FactModelTree.PropertyTypeName(fullFactClassName));
        return getSimpleClassFactModelTree(factName, fullFactClassName);
    }
    for (ModelField modelField : modelFields) {
        if (!modelField.getName().equals("this")) {
            String className = defineClassNameField(modelField.getClassName(), superTypeMap);
            simpleProperties.put(modelField.getName(), new FactModelTree.PropertyTypeName(className));
            if (ScenarioSimulationSharedUtils.isCollectionOrMap(className)) {
                populateGenericTypeMap(genericTypesMap, factName, modelField.getName(), ScenarioSimulationSharedUtils.isList(className));
            }
        }
    }
    return FactModelTree.ofDMO(factName, factPackageName, simpleProperties, genericTypesMap, factClassName);
}
Also used : ModelField(org.kie.soup.project.datamodel.oracle.ModelField) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree)

Aggregations

FactModelTree (org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree)47 Test (org.junit.Test)19 TreeMap (java.util.TreeMap)16 Matchers.anyString (org.mockito.Matchers.anyString)14 HashMap (java.util.HashMap)10 DMNType (org.kie.dmn.api.core.DMNType)10 ArrayList (java.util.ArrayList)9 AbstractScenarioSimulationEditorTest (org.drools.workbench.screens.scenariosimulation.client.editor.AbstractScenarioSimulationEditorTest)8 FactModelTuple (org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple)7 List (java.util.List)6 Map (java.util.Map)6 SortedMap (java.util.SortedMap)6 FactMapping (org.drools.scenariosimulation.api.model.FactMapping)6 ScenarioSimulationModel (org.drools.scenariosimulation.api.model.ScenarioSimulationModel)4 Collections (java.util.Collections)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 AbstractScesimData (org.drools.scenariosimulation.api.model.AbstractScesimData)3 AbstractScesimModel (org.drools.scenariosimulation.api.model.AbstractScesimModel)3 FactMappingType (org.drools.scenariosimulation.api.model.FactMappingType)3