use of org.kie.dmn.model.v1_1.Import in project drools by kiegroup.
the class DMNCompilerImpl method compile.
@Override
public DMNModel compile(Definitions dmndefs, Collection<DMNModel> dmnModels) {
if (dmndefs == null) {
return null;
}
DMNModelImpl model = new DMNModelImpl(dmndefs);
model.setRuntimeTypeCheck(((DMNCompilerConfigurationImpl) dmnCompilerConfig).getOption(RuntimeTypeCheckOption.class).isRuntimeTypeCheck());
DMNCompilerContext ctx = new DMNCompilerContext();
if (!dmndefs.getImport().isEmpty()) {
for (Import i : dmndefs.getImport()) {
if (ImportDMNResolverUtil.whichImportType(i) == ImportType.DMN) {
Either<String, DMNModel> resolvedResult = ImportDMNResolverUtil.resolveImportDMN(i, dmnModels, (DMNModel m) -> new QName(m.getNamespace(), m.getName()));
DMNModel located = resolvedResult.cata(msg -> {
MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, i, model, null, null, Msg.IMPORT_NOT_FOUND_FOR_NODE, msg, i);
return null;
}, Function.identity());
if (located != null) {
String iAlias = Optional.ofNullable(i.getAdditionalAttributes().get(Import.NAME_QNAME)).orElse(located.getName());
model.setImportAliasForNS(iAlias, located.getNamespace(), located.getName());
importFromModel(model, located);
}
}
}
}
processItemDefinitions(ctx, feel, model, dmndefs);
processDrgElements(ctx, feel, model, dmndefs);
return model;
}
use of org.kie.dmn.model.v1_1.Import in project drools by kiegroup.
the class ImportDMNResolverUtilTest method testNSnoModelNameDefaultWithAliasButUnexistent.
@Test
public void testNSnoModelNameDefaultWithAliasButUnexistent() {
Import i = makeImport("ns1", "boh", null);
List<QName> available = Arrays.asList(new QName("ns1", "m1"), new QName("ns2", "m2"), new QName("ns3", "m3"));
Either<String, QName> result = ImportDMNResolverUtil.resolveImportDMN(i, available, Function.identity());
assertTrue(result.isLeft());
}
use of org.kie.dmn.model.v1_1.Import in project drools by kiegroup.
the class ImportDMNResolverUtilTest method testLocateInNSunexistent.
@Test
public void testLocateInNSunexistent() {
Import i = makeImport("nsA", null, "boh");
List<QName> available = Arrays.asList(new QName("nsA", "m1"), new QName("nsA", "m2"), new QName("nsB", "m3"));
Either<String, QName> result = ImportDMNResolverUtil.resolveImportDMN(i, available, Function.identity());
assertTrue(result.isLeft());
}
use of org.kie.dmn.model.v1_1.Import in project drools by kiegroup.
the class ImportDMNResolverUtilTest method testNSandModelName.
@Test
public void testNSandModelName() {
Import i = makeImport("ns1", null, "m1");
List<QName> available = Arrays.asList(new QName("ns1", "m1"), new QName("ns2", "m2"), new QName("ns3", "m3"));
Either<String, QName> result = ImportDMNResolverUtil.resolveImportDMN(i, available, Function.identity());
assertTrue(result.isRight());
assertEquals(new QName("ns1", "m1"), result.getOrElse(null));
}
use of org.kie.dmn.model.v1_1.Import in project drools by kiegroup.
the class ImportDMNResolverUtilTest method makeImport.
private Import makeImport(String namespace, String name, String modelName) {
Import i = new Import();
i.setNamespace(namespace);
Map<QName, String> addAttributes = new HashMap<>();
if (name != null) {
addAttributes.put(Import.NAME_QNAME, name);
}
if (modelName != null) {
addAttributes.put(Import.MODELNAME_QNAME, modelName);
}
i.setAdditionalAttributes(addAttributes);
return i;
}
Aggregations