Search in sources :

Example 6 with ItemDefinition

use of org.kie.workbench.common.dmn.api.definition.v1_1.ItemDefinition in project drools by kiegroup.

the class DMNCompilerImpl method buildTypeDef.

private DMNType buildTypeDef(DMNCompilerContext ctx, DMNFEELHelper feel, DMNModelImpl dmnModel, DMNNode node, ItemDefinition itemDef, boolean topLevel) {
    BaseDMNTypeImpl type = null;
    if (itemDef.getTypeRef() != null) {
        // this is a reference to an existing type, so resolve the reference
        type = (BaseDMNTypeImpl) resolveTypeRef(dmnModel, node, itemDef, itemDef, itemDef.getTypeRef());
        if (type != null) {
            UnaryTests allowedValuesStr = itemDef.getAllowedValues();
            // or if it changes the metadata for the base type
            if (topLevel || allowedValuesStr != null || itemDef.isIsCollection() != type.isCollection()) {
                // we have to clone this type definition into a new one
                BaseDMNTypeImpl baseType = type;
                type = type.clone();
                type.setBaseType(baseType);
                type.setNamespace(dmnModel.getNamespace());
                type.setName(itemDef.getName());
                type.setAllowedValues(null);
                if (allowedValuesStr != null) {
                    List<UnaryTest> av = feel.evaluateUnaryTests(ctx, allowedValuesStr.getText(), dmnModel, itemDef, Msg.ERR_COMPILING_ALLOWED_VALUES_LIST_ON_ITEM_DEF, allowedValuesStr.getText(), node.getName());
                    type.setAllowedValues(av);
                }
                if (itemDef.isIsCollection()) {
                    type.setCollection(itemDef.isIsCollection());
                }
            }
            if (topLevel) {
                DMNType registered = dmnModel.getTypeRegistry().registerType(type);
                if (registered != type) {
                    MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, itemDef, dmnModel, null, null, Msg.DUPLICATED_ITEM_DEFINITION, itemDef.getName());
                }
            }
        }
    } else {
        // this is a composite type
        DMNCompilerHelper.checkVariableName(dmnModel, itemDef, itemDef.getName());
        CompositeTypeImpl compType = new CompositeTypeImpl(dmnModel.getNamespace(), itemDef.getName(), itemDef.getId(), itemDef.isIsCollection());
        for (ItemDefinition fieldDef : itemDef.getItemComponent()) {
            DMNCompilerHelper.checkVariableName(dmnModel, fieldDef, fieldDef.getName());
            DMNType fieldType = buildTypeDef(ctx, feel, dmnModel, node, fieldDef, false);
            fieldType = fieldType != null ? fieldType : DMNTypeRegistry.UNKNOWN;
            compType.addField(fieldDef.getName(), fieldType);
        }
        type = compType;
        if (topLevel) {
            DMNType registered = dmnModel.getTypeRegistry().registerType(type);
            if (registered != type) {
                MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, itemDef, dmnModel, null, null, Msg.DUPLICATED_ITEM_DEFINITION, itemDef.getName());
            }
        }
    }
    return type;
}
Also used : ItemDefinition(org.kie.dmn.model.v1_1.ItemDefinition) BaseDMNTypeImpl(org.kie.dmn.core.impl.BaseDMNTypeImpl) UnaryTests(org.kie.dmn.model.v1_1.UnaryTests) UnaryTest(org.kie.dmn.feel.runtime.UnaryTest) CompositeTypeImpl(org.kie.dmn.core.impl.CompositeTypeImpl) DMNType(org.kie.dmn.api.core.DMNType)

Example 7 with ItemDefinition

use of org.kie.workbench.common.dmn.api.definition.v1_1.ItemDefinition in project drools by kiegroup.

the class ItemDefinitionDependenciesGeneratedTest method createAndAddDependency.

private static void createAndAddDependency(final ItemDefinition itemDefinition, final ItemDefinition dependency) {
    ItemDefinition newDependency = new ItemDefinition();
    newDependency.setName("_" + itemDefinition.getName() + "-" + dependency.getName());
    newDependency.setTypeRef(new QName(TEST_NS, dependency.getName()));
    itemDefinition.getItemComponent().add(newDependency);
}
Also used : QName(javax.xml.namespace.QName) ItemDefinition(org.kie.dmn.model.v1_1.ItemDefinition)

Example 8 with ItemDefinition

use of org.kie.workbench.common.dmn.api.definition.v1_1.ItemDefinition in project drools by kiegroup.

the class ItemDefinitionDependenciesGeneratedTest method assertOrdering.

private void assertOrdering(final ItemDefinition itemDefinition, final List<ItemDefinition> orderedList) {
    for (ItemDefinition dependency : itemDefinition.getItemComponent()) {
        final String dependencyName = dependency.getTypeRef().getLocalPart();
        final int indexOfDependency = indexOfItemDefinitionByName(dependencyName, orderedList);
        assertTrue("Cannot find dependency " + dependencyName + " in the ordered list!", indexOfDependency > -1);
        assertTrue("Index of " + itemDefinition.getName() + " < " + dependency.getTypeRef().getLocalPart(), orderedList.indexOf(itemDefinition) > indexOfDependency);
        if (dependency.getItemComponent() != null && !dependency.getItemComponent().isEmpty()) {
            assertOrdering(dependency, orderedList);
        }
    }
}
Also used : ItemDefinition(org.kie.dmn.model.v1_1.ItemDefinition)

Example 9 with ItemDefinition

use of org.kie.workbench.common.dmn.api.definition.v1_1.ItemDefinition in project drools by kiegroup.

the class ItemDefinitionDependenciesGeneratedTest method getPermutations.

private static void getPermutations(final List<ItemDefinition> itemDefinitions, final List<ItemDefinition> head, final Collection<List<ItemDefinition>> result) {
    if (itemDefinitions.size() == 1) {
        final List<ItemDefinition> resultList = new ArrayList<>(head);
        resultList.addAll(itemDefinitions);
        result.add(resultList);
    } else {
        for (ItemDefinition itemDefinition : itemDefinitions) {
            final List<ItemDefinition> newHead = new ArrayList<>(head);
            newHead.add(itemDefinition);
            final List<ItemDefinition> possibleDependencies = itemDefinitions.stream().filter(item -> !newHead.contains(item)).collect(Collectors.toList());
            getPermutations(possibleDependencies, newHead, result);
        }
    }
}
Also used : Logger(org.slf4j.Logger) Collection(java.util.Collection) RunWith(org.junit.runner.RunWith) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ItemDefinition(org.kie.dmn.model.v1_1.ItemDefinition) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) QName(javax.xml.namespace.QName) Parameterized(org.junit.runners.Parameterized) ItemDefinition(org.kie.dmn.model.v1_1.ItemDefinition) ArrayList(java.util.ArrayList)

Example 10 with ItemDefinition

use of org.kie.workbench.common.dmn.api.definition.v1_1.ItemDefinition in project drools by kiegroup.

the class ItemDefinitionDependenciesGeneratedTest method testOrdering.

@Test
public void testOrdering() {
    logger.debug("Item definitions:");
    itemDefinitions.forEach(itemDefinition -> {
        logger.debug(itemDefinition.getName());
        itemDefinition.getItemComponent().forEach(dependency -> logger.debug(dependency.getName()));
    });
    List<ItemDefinition> orderedList = orderingStrategy(itemDefinitions);
    for (ItemDefinition itemDefinition : itemDefinitions) {
        assertOrdering(itemDefinition, orderedList);
    }
}
Also used : ItemDefinition(org.kie.dmn.model.v1_1.ItemDefinition) Test(org.junit.Test)

Aggregations

ItemDefinition (org.kie.dmn.model.v1_1.ItemDefinition)22 ItemDefinition (org.eclipse.bpmn2.ItemDefinition)21 ArrayList (java.util.ArrayList)17 RootElement (org.eclipse.bpmn2.RootElement)13 Message (org.eclipse.bpmn2.Message)10 AdHocSubProcess (org.eclipse.bpmn2.AdHocSubProcess)9 Process (org.eclipse.bpmn2.Process)9 SubProcess (org.eclipse.bpmn2.SubProcess)9 Test (org.junit.Test)9 List (java.util.List)7 Entry (java.util.Map.Entry)7 SimpleFeatureMapEntry (org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry)7 QName (javax.xml.namespace.QName)6 FlowElement (org.eclipse.bpmn2.FlowElement)6 FeatureMap (org.eclipse.emf.ecore.util.FeatureMap)6 ServiceTask (org.eclipse.bpmn2.ServiceTask)5 DataInput (org.eclipse.bpmn2.DataInput)4 DataOutput (org.eclipse.bpmn2.DataOutput)4 FlowElementsContainer (org.eclipse.bpmn2.FlowElementsContainer)4 Interface (org.eclipse.bpmn2.Interface)4