use of org.eclipse.bpmn2.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;
}
use of org.eclipse.bpmn2.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);
}
use of org.eclipse.bpmn2.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);
}
}
}
use of org.eclipse.bpmn2.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);
}
}
}
use of org.eclipse.bpmn2.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);
}
}
Aggregations