use of org.kie.dmn.model.api.ItemDefinition in project drools by kiegroup.
the class ItemDefinitionConverter method writeChildren.
@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
super.writeChildren(writer, context, parent);
ItemDefinition id = (ItemDefinition) parent;
if (id.getTypeRef() != null)
writeChildrenNode(writer, context, id.getTypeRef(), TYPE_REF);
if (id.getAllowedValues() != null)
writeChildrenNode(writer, context, id.getAllowedValues(), ALLOWED_VALUES);
for (ItemDefinition ic : id.getItemComponent()) {
writeChildrenNode(writer, context, ic, ITEM_COMPONENT);
}
if (id.getFunctionItem() != null) {
writeChildrenNode(writer, context, id.getFunctionItem(), FUNCTION_ITEM);
}
}
use of org.kie.dmn.model.api.ItemDefinition in project drools by kiegroup.
the class ItemDefinitionConverter method writeAttributes.
@Override
protected void writeAttributes(HierarchicalStreamWriter writer, Object parent) {
super.writeAttributes(writer, parent);
ItemDefinition id = (ItemDefinition) parent;
if (id.getTypeLanguage() != null)
writer.addAttribute(TYPE_LANGUAGE, id.getTypeLanguage());
writer.addAttribute(IS_COLLECTION, Boolean.valueOf(id.isIsCollection()).toString());
}
use of org.kie.dmn.model.api.ItemDefinition in project drools by kiegroup.
the class DMNRuntimeTest method testAssignNullToAllowedValues.
@Test
public void testAssignNullToAllowedValues() {
// DROOLS-3132 DMN assign null to ItemDefinition with allowedValues
final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("assignNullToAllowedValues.dmn", this.getClass());
final DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_700a46e0-01ed-4361-9034-4afdb2537ea4", "Drawing 1");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
final DMNContext context = DMNFactory.newContext();
context.set("an input letter", null);
final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
LOG.debug("{}", dmnResult);
DMNRuntimeUtil.formatMessages(dmnResult.getMessages());
assertThat(dmnResult.hasErrors(), is(true));
assertThat(dmnResult.getMessages().stream().anyMatch(m -> m.getSourceId().equals("_24e8b31b-9505-4f52-93af-6dd9ef39c72a")), is(true));
assertThat(dmnResult.getMessages().stream().anyMatch(m -> m.getSourceId().equals("_09945fda-2b89-4148-8758-0bcb91a66e4a")), is(true));
}
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);
}
}
}
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);
}
}
}
Aggregations