Search in sources :

Example 11 with Import

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;
}
Also used : Import(org.kie.dmn.model.v1_1.Import) QName(javax.xml.namespace.QName) DMNModelImpl(org.kie.dmn.core.impl.DMNModelImpl) DMNModel(org.kie.dmn.api.core.DMNModel)

Example 12 with Import

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());
}
Also used : Import(org.kie.dmn.model.v1_1.Import) QName(javax.xml.namespace.QName) Test(org.junit.Test)

Example 13 with Import

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());
}
Also used : Import(org.kie.dmn.model.v1_1.Import) QName(javax.xml.namespace.QName) Test(org.junit.Test)

Example 14 with Import

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));
}
Also used : Import(org.kie.dmn.model.v1_1.Import) QName(javax.xml.namespace.QName) Test(org.junit.Test)

Example 15 with Import

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;
}
Also used : Import(org.kie.dmn.model.v1_1.Import) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName)

Aggregations

Import (org.kie.dmn.model.v1_1.Import)17 QName (javax.xml.namespace.QName)15 Test (org.junit.Test)12 DMNModel (org.kie.dmn.api.core.DMNModel)2 Definitions (org.kie.dmn.model.v1_1.Definitions)2 XStream (com.thoughtworks.xstream.XStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)1 Auditing (org.eclipse.bpmn2.Auditing)1 ExtensionAttributeValue (org.eclipse.bpmn2.ExtensionAttributeValue)1 Import (org.eclipse.bpmn2.Import)1 Monitoring (org.eclipse.bpmn2.Monitoring)1 Internal (org.eclipse.emf.ecore.EStructuralFeature.Internal)1 EAttributeImpl (org.eclipse.emf.ecore.impl.EAttributeImpl)1 SimpleFeatureMapEntry (org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry)1 ExtendedMetaData (org.eclipse.emf.ecore.util.ExtendedMetaData)1 FeatureMap (org.eclipse.emf.ecore.util.FeatureMap)1 GlobalType (org.jboss.drools.GlobalType)1