use of org.kie.dmn.model.api.ItemDefinition in project drools by kiegroup.
the class ItemDefinitionDependenciesTest method build.
private ItemDefinition build(final String name, final ItemDefinition... components) {
final ItemDefinition res = new TItemDefinition();
res.setName(name);
for (final ItemDefinition ic : components) {
addComponent(res, ic.getName());
}
return res;
}
use of org.kie.dmn.model.api.ItemDefinition in project drools by kiegroup.
the class ItemDefinitionDependenciesTest method testOrdering1.
@Test
public void testOrdering1() {
final ItemDefinition tCollateralRiskCategory = build("tCollateralRiskCategory");
final ItemDefinition tCreditRiskCategory = build("tCreditRiskCategory");
final ItemDefinition tAffordabilityCategory = build("tAffordabilityCategory");
final ItemDefinition tLoanRecommendation = build("tLoanRecommendation");
final ItemDefinition tLoan = build("tLoan");
final ItemDefinition tAge = build("tAge");
final ItemDefinition temploementStatus = build("temploementStatus");
final ItemDefinition tCreditScore = build("tCreditScore");
final ItemDefinition tRiskCategory = build("tRiskCategory");
final ItemDefinition tIncomeRisk = build("tIncomeRisk");
final ItemDefinition tBorrowe = build("tBorrowe", tAge, temploementStatus);
final ItemDefinition tPrequalification = build("tPrequalification");
final List<ItemDefinition> originalList = Arrays.asList(tCollateralRiskCategory, tCreditRiskCategory, tAffordabilityCategory, tLoanRecommendation, tLoan, tAge, temploementStatus, tCreditScore, tRiskCategory, tIncomeRisk, tBorrowe, tPrequalification);
final List<ItemDefinition> orderedList = orderingStrategy(originalList);
assertTrue("Index of tAge < tBorrowe", orderedList.indexOf(tAge) < orderedList.indexOf(tBorrowe));
assertTrue("Index of temploementStatus < tBorrowe", orderedList.indexOf(temploementStatus) < orderedList.indexOf(tBorrowe));
}
use of org.kie.dmn.model.api.ItemDefinition in project drools by kiegroup.
the class ItemDefinitionDependenciesTest method testOrdering2.
@Test
public void testOrdering2() {
final ItemDefinition tMortgageType = build("tMortgageType");
final ItemDefinition tObjective = build("tObjective");
final ItemDefinition tRequested = build("tRequested", tMortgageType, tObjective);
final ItemDefinition tProduct = build("tProduct");
final ItemDefinition tProductCollection = build("tProductCollection", tProduct);
final ItemDefinition tConformanceType = build("tConformanceType");
final ItemDefinition tLoanTypes = build("tLoanTypes", tMortgageType, tConformanceType);
final List<ItemDefinition> originalList = Arrays.asList(tRequested, tProduct, tProductCollection, tMortgageType, tObjective, tConformanceType, tLoanTypes);
final List<ItemDefinition> orderedList = orderingStrategy(originalList);
assertTrue("Index of tMortgageType < tRequested", orderedList.indexOf(tMortgageType) < orderedList.indexOf(tRequested));
assertTrue("Index of tObjective < tRequested", orderedList.indexOf(tObjective) < orderedList.indexOf(tRequested));
assertTrue("Index of tProduct < tProductCollection", orderedList.indexOf(tProduct) < orderedList.indexOf(tProductCollection));
assertTrue("Index of tMortgageType < tLoanTypes", orderedList.indexOf(tMortgageType) < orderedList.indexOf(tLoanTypes));
assertTrue("Index of tConformanceType < tLoanTypes", orderedList.indexOf(tConformanceType) < orderedList.indexOf(tLoanTypes));
}
use of org.kie.dmn.model.api.ItemDefinition in project drools by kiegroup.
the class ItemDefinitionDependenciesTest method testOrdering3.
@Test
public void testOrdering3() {
final ItemDefinition tNumberList = build("tNumberList");
final ItemDefinition tTax = build("tTax");
final ItemDefinition tStateModel = build("tStateModel");
final ItemDefinition tTaxList = build("tTaxList", tTax);
final ItemDefinition tCategory = build("tCategory");
final ItemDefinition tItem = build("tItem", tCategory);
final ItemDefinition tItemList = build("tItemList", tItem);
final ItemDefinition tOrder = build("tOrder", tItemList);
final List<ItemDefinition> originalList = Arrays.asList(tOrder, tItem, tCategory, tNumberList, tItemList, tTax, tStateModel, tTaxList);
final List<ItemDefinition> orderedList = orderingStrategy(originalList);
assertTrue("Index of tCategory < tItem", orderedList.indexOf(tCategory) < orderedList.indexOf(tItem));
assertTrue("Index of tItem < tItemList", orderedList.indexOf(tItem) < orderedList.indexOf(tItemList));
assertTrue("Index of tItemList < tOrder", orderedList.indexOf(tItemList) < orderedList.indexOf(tOrder));
assertTrue("Index of tTax < tTaxList", orderedList.indexOf(tTax) < orderedList.indexOf(tTaxList));
}
use of org.kie.dmn.model.api.ItemDefinition in project drools by kiegroup.
the class DMNCompilerImpl method buildTypeDef.
/**
* @param topLevel null if it is a top level ItemDefinition
*/
private DMNType buildTypeDef(DMNCompilerContext ctx, DMNModelImpl dmnModel, DMNNode node, ItemDefinition itemDef, DMNType topLevel) {
BaseDMNTypeImpl type = null;
if (itemDef.getTypeRef() != null) {
// this is a reference to an existing type, so resolve the reference
type = (BaseDMNTypeImpl) resolveTypeRef(dmnModel, itemDef, itemDef, itemDef.getTypeRef());
if (type != null) {
UnaryTests allowedValuesStr = itemDef.getAllowedValues();
// or if it changes the metadata for the base type
if (topLevel == null || allowedValuesStr != null || itemDef.isIsCollection() != type.isCollection()) {
// we have to clone this type definition into a new one
String name = itemDef.getName();
String namespace = dmnModel.getNamespace();
String id = itemDef.getId();
BaseDMNTypeImpl baseType = type;
Type baseFEELType = type.getFeelType();
if (baseFEELType instanceof BuiltInType) {
// Then it is an ItemDefinition in place for "aliasing" a base FEEL type, for having type(itemDefname) I need to define its SimpleType.
baseFEELType = new AliasFEELType(itemDef.getName(), (BuiltInType) baseFEELType);
}
List<UnaryTest> av = null;
if (allowedValuesStr != null) {
av = ctx.getFeelHelper().evaluateUnaryTests(ctx, allowedValuesStr.getText(), dmnModel, itemDef, Msg.ERR_COMPILING_ALLOWED_VALUES_LIST_ON_ITEM_DEF, allowedValuesStr.getText(), node.getName());
}
boolean isCollection = itemDef.isIsCollection();
if (isCollection) {
baseFEELType = new GenListType(baseFEELType);
}
if (type instanceof CompositeTypeImpl) {
CompositeTypeImpl compositeTypeImpl = (CompositeTypeImpl) type;
type = new CompositeTypeImpl(namespace, name, id, isCollection, compositeTypeImpl.getFields(), baseType, baseFEELType);
} else if (type instanceof SimpleTypeImpl) {
type = new SimpleTypeImpl(namespace, name, id, isCollection, av, baseType, baseFEELType);
}
if (topLevel != null) {
((BaseDMNTypeImpl) type).setBelongingType(topLevel);
}
}
if (topLevel == null) {
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 if (itemDef.getItemComponent() != null && itemDef.getItemComponent().size() > 0) {
// first, locate preregistered or create anonymous inner composite
if (topLevel == null) {
type = (CompositeTypeImpl) dmnModel.getTypeRegistry().resolveType(dmnModel.getNamespace(), itemDef.getName());
} else {
DMNCompilerHelper.checkVariableName(dmnModel, itemDef, itemDef.getName());
type = new CompositeTypeImpl(dmnModel.getNamespace(), itemDef.getName(), itemDef.getId(), itemDef.isIsCollection());
((BaseDMNTypeImpl) type).setBelongingType(topLevel);
}
// second, add fields to located composite
for (ItemDefinition fieldDef : itemDef.getItemComponent()) {
DMNCompilerHelper.checkVariableName(dmnModel, fieldDef, fieldDef.getName());
DMNType fieldType = buildTypeDef(ctx, dmnModel, node, fieldDef, type);
fieldType = fieldType != null ? fieldType : dmnModel.getTypeRegistry().unknown();
((CompositeTypeImpl) type).addField(fieldDef.getName(), fieldType);
}
} else if (isFunctionItem(itemDef)) {
FunctionItem fi = itemDef.getFunctionItem();
String name = itemDef.getName();
String namespace = dmnModel.getNamespace();
String id = itemDef.getId();
Map<String, DMNType> params = new HashMap<>();
for (InformationItem p : fi.getParameters()) {
DMNType resolveTypeRef = resolveTypeRef(dmnModel, itemDef, itemDef, p.getTypeRef());
params.put(p.getName(), resolveTypeRef);
}
DMNType returnType = resolveTypeRef(dmnModel, itemDef, itemDef, fi.getOutputTypeRef());
List<Type> feelPs = fi.getParameters().stream().map(InformationItem::getName).map(n -> ((BaseDMNTypeImpl) params.get(n)).getFeelType()).collect(Collectors.toList());
GenFnType feeltype = new GenFnType(feelPs, ((BaseDMNTypeImpl) returnType).getFeelType());
type = new SimpleFnTypeImpl(namespace, name, id, feeltype, params, returnType, fi);
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 {
DMNType unknown = (BaseDMNTypeImpl) resolveTypeRef(dmnModel, itemDef, itemDef, null);
type = new SimpleTypeImpl(dmnModel.getNamespace(), itemDef.getName(), itemDef.getId(), itemDef.isIsCollection(), null, unknown, ((BaseDMNTypeImpl) unknown).getFeelType());
if (topLevel == null) {
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 {
((BaseDMNTypeImpl) type).setBelongingType(topLevel);
}
}
return type;
}
Aggregations