Search in sources :

Example 1 with ItemDefinition

use of org.kie.dmn.model.api.ItemDefinition in project drools by kiegroup.

the class ItemDefinitionDependenciesGeneratedTest method assertOrdering.

private void assertOrdering(final ItemDefinition itemDefinition, final List<ItemDefinition> orderedList) {
    for (final 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 : TItemDefinition(org.kie.dmn.model.v1_1.TItemDefinition) ItemDefinition(org.kie.dmn.model.api.ItemDefinition)

Example 2 with ItemDefinition

use of org.kie.dmn.model.api.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 (final 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) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) TItemDefinition(org.kie.dmn.model.v1_1.TItemDefinition) HashSet(java.util.HashSet) List(java.util.List) ItemDefinition(org.kie.dmn.model.api.ItemDefinition) QName(javax.xml.namespace.QName) Parameterized(org.junit.runners.Parameterized) TItemDefinition(org.kie.dmn.model.v1_1.TItemDefinition) ItemDefinition(org.kie.dmn.model.api.ItemDefinition) ArrayList(java.util.ArrayList)

Example 3 with ItemDefinition

use of org.kie.dmn.model.api.ItemDefinition in project drools by kiegroup.

the class ItemDefinitionDependenciesGeneratedTest method testOrdering.

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

Example 4 with ItemDefinition

use of org.kie.dmn.model.api.ItemDefinition in project drools by kiegroup.

the class ItemDefinitionDependenciesGeneratedTest method createAndAddDependency.

private static void createAndAddDependency(final ItemDefinition itemDefinition, final ItemDefinition dependency) {
    final ItemDefinition newDependency = new TItemDefinition();
    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) TItemDefinition(org.kie.dmn.model.v1_1.TItemDefinition) TItemDefinition(org.kie.dmn.model.v1_1.TItemDefinition) ItemDefinition(org.kie.dmn.model.api.ItemDefinition)

Example 5 with ItemDefinition

use of org.kie.dmn.model.api.ItemDefinition in project drools by kiegroup.

the class ItemDefinitionDependenciesGeneratedTest method getBaseListOfItemDefinitions.

private static List<ItemDefinition> getBaseListOfItemDefinitions(final int nameIndexFrom) {
    final List<ItemDefinition> itemDefinitions = new ArrayList<>();
    for (int i = nameIndexFrom; i < NUMBER_OF_BASE_ITEM_DEFINITIONS + nameIndexFrom; i++) {
        final ItemDefinition it = new TItemDefinition();
        it.setName(ITEM_DEFINITION_NAME_BASE + i);
        itemDefinitions.add(it);
    }
    return itemDefinitions;
}
Also used : TItemDefinition(org.kie.dmn.model.v1_1.TItemDefinition) TItemDefinition(org.kie.dmn.model.v1_1.TItemDefinition) ItemDefinition(org.kie.dmn.model.api.ItemDefinition) ArrayList(java.util.ArrayList)

Aggregations

ItemDefinition (org.kie.dmn.model.api.ItemDefinition)50 TItemDefinition (org.kie.dmn.model.v1_1.TItemDefinition)19 Test (org.junit.Test)15 QName (javax.xml.namespace.QName)13 Definitions (org.kie.dmn.model.api.Definitions)13 ArrayList (java.util.ArrayList)10 DRGElement (org.kie.dmn.model.api.DRGElement)9 List (java.util.List)7 Collectors (java.util.stream.Collectors)7 Artifact (org.kie.dmn.model.api.Artifact)7 BusinessContextElement (org.kie.dmn.model.api.BusinessContextElement)7 Decision (org.kie.dmn.model.api.Decision)7 Import (org.kie.dmn.model.api.Import)7 Collection (java.util.Collection)6 TItemDefinition (org.kie.dmn.model.v1_2.TItemDefinition)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 DecisionService (org.kie.dmn.model.api.DecisionService)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4