Search in sources :

Example 6 with Import

use of org.kie.dmn.model.v1_1.Import in project drools by kiegroup.

the class ImportDMNResolverUtilTest method testLocateInNSAliased.

@Test
public void testLocateInNSAliased() {
    Import i = makeImport("nsA", "aliased", "m1");
    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.isRight());
    assertEquals(new QName("nsA", "m1"), result.getOrElse(null));
}
Also used : Import(org.kie.dmn.model.v1_1.Import) QName(javax.xml.namespace.QName) Test(org.junit.Test)

Example 7 with Import

use of org.kie.dmn.model.v1_1.Import in project drools by kiegroup.

the class ImportDMNResolverUtilTest method testLocateInNSAliasedBadScenario.

@Test
public void testLocateInNSAliasedBadScenario() {
    Import i = makeImport("nsA", "aliased", "mA");
    List<QName> available = Arrays.asList(new QName("nsA", "mA"), new QName("nsA", "mA"), 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 8 with Import

use of org.kie.dmn.model.v1_1.Import in project drools by kiegroup.

the class ImportDMNResolverUtilTest method testLocateInNSdefaultwithAlias.

@Test
public void testLocateInNSdefaultwithAlias() {
    Import i = makeImport("nsA", "m1", null);
    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.isRight());
    assertEquals(new QName("nsA", "m1"), result.getOrElse(null));
}
Also used : Import(org.kie.dmn.model.v1_1.Import) QName(javax.xml.namespace.QName) Test(org.junit.Test)

Example 9 with Import

use of org.kie.dmn.model.v1_1.Import in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method applyProcessProperties.

protected void applyProcessProperties(Process process, Map<String, String> properties) {
    if (properties.get("processn") != null) {
        process.setName(StringEscapeUtils.escapeXml(properties.get("processn")));
    } else {
        process.setName("");
    }
    if (properties.get("auditing") != null && !"".equals(properties.get("auditing"))) {
        Auditing audit = Bpmn2Factory.eINSTANCE.createAuditing();
        audit.getDocumentation().add(createDocumentation(properties.get("auditing")));
        process.setAuditing(audit);
    }
    process.setProcessType(ProcessType.getByName(properties.get("processtype")));
    process.setIsClosed(Boolean.parseBoolean(properties.get("isclosed")));
    process.setIsExecutable(Boolean.parseBoolean(properties.get("executable")));
    // get the drools-specific extension packageName attribute to Process if defined
    if (properties.get("package") != null && properties.get("package").length() > 0) {
        ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
        EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "packageName", false, false);
        SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("package"));
        process.getAnyAttribute().add(extensionEntry);
    }
    // add version attrbute to process
    if (properties.get("version") != null && properties.get("version").length() > 0) {
        ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
        EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "version", false, false);
        SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("version"));
        process.getAnyAttribute().add(extensionEntry);
    }
    if (properties.get("monitoring") != null && !"".equals(properties.get("monitoring"))) {
        Monitoring monitoring = Bpmn2Factory.eINSTANCE.createMonitoring();
        monitoring.getDocumentation().add(createDocumentation(properties.get("monitoring")));
        process.setMonitoring(monitoring);
    }
    // import extension elements
    if (properties.get("imports") != null && properties.get("imports").length() > 0) {
        String[] allImports = properties.get("imports").split(",\\s*");
        for (String importStr : allImports) {
            String[] importParts = importStr.split("\\|\\s*");
            // sample 'com.sample.Myclass|default,location|namespace|wsdl
            if (importParts.length == 2 || importParts.length == 3) {
                if (importParts[1] != null && importParts[1].equals("default")) {
                    ImportType importType = DroolsFactory.eINSTANCE.createImportType();
                    importType.setName(importParts[0]);
                    if (process.getExtensionValues() == null || process.getExtensionValues().size() < 1) {
                        ExtensionAttributeValue extensionElement = Bpmn2Factory.eINSTANCE.createExtensionAttributeValue();
                        process.getExtensionValues().add(extensionElement);
                    }
                    FeatureMap.Entry extensionElementEntry = new SimpleFeatureMapEntry((Internal) DroolsPackage.Literals.DOCUMENT_ROOT__IMPORT, importType);
                    process.getExtensionValues().get(0).getValue().add(extensionElementEntry);
                } else {
                    Import imp = Bpmn2Factory.eINSTANCE.createImport();
                    imp.setImportType("http://schemas.xmlsoap.org/wsdl/");
                    imp.setLocation(importParts[0]);
                    imp.setNamespace(importParts[1]);
                    _wsdlImports.add(imp);
                }
            } else {
                // just default (support legacy)
                ImportType importType = DroolsFactory.eINSTANCE.createImportType();
                importType.setName(importStr);
                if (process.getExtensionValues() == null || process.getExtensionValues().size() < 1) {
                    ExtensionAttributeValue extensionElement = Bpmn2Factory.eINSTANCE.createExtensionAttributeValue();
                    process.getExtensionValues().add(extensionElement);
                }
                FeatureMap.Entry extensionElementEntry = new SimpleFeatureMapEntry((Internal) DroolsPackage.Literals.DOCUMENT_ROOT__IMPORT, importType);
                process.getExtensionValues().get(0).getValue().add(extensionElementEntry);
            }
        }
    }
    // globals extension elements
    if (properties.get("globals") != null && properties.get("globals").length() > 0) {
        String[] allGlobals = properties.get("globals").split(",\\s*");
        for (String globalStr : allGlobals) {
            // identifier:type
            String[] globalParts = globalStr.split(":\\s*");
            if (globalParts.length == 2) {
                GlobalType globalType = DroolsFactory.eINSTANCE.createGlobalType();
                globalType.setIdentifier(globalParts[0]);
                globalType.setType(globalParts[1]);
                if (process.getExtensionValues() == null || process.getExtensionValues().size() < 1) {
                    ExtensionAttributeValue extensionElement = Bpmn2Factory.eINSTANCE.createExtensionAttributeValue();
                    process.getExtensionValues().add(extensionElement);
                }
                FeatureMap.Entry extensionElementEntry = new SimpleFeatureMapEntry((Internal) DroolsPackage.Literals.DOCUMENT_ROOT__GLOBAL, globalType);
                process.getExtensionValues().get(0).getValue().add(extensionElementEntry);
            } else if (globalParts.length == 1) {
                GlobalType globalType = DroolsFactory.eINSTANCE.createGlobalType();
                globalType.setIdentifier(globalParts[0]);
                globalType.setType("Object");
                if (process.getExtensionValues() == null || process.getExtensionValues().size() < 1) {
                    ExtensionAttributeValue extensionElement = Bpmn2Factory.eINSTANCE.createExtensionAttributeValue();
                    process.getExtensionValues().add(extensionElement);
                }
                FeatureMap.Entry extensionElementEntry = new SimpleFeatureMapEntry((Internal) DroolsPackage.Literals.DOCUMENT_ROOT__GLOBAL, globalType);
                process.getExtensionValues().get(0).getValue().add(extensionElementEntry);
            }
        }
    }
    // simulation properties
    if (properties.get("timeunit") != null && properties.get("timeunit").length() > 0) {
        _simulationScenarioParameters.setBaseTimeUnit(TimeUnit.getByName(properties.get("timeunit")));
    }
    if (properties.get("currency") != null && properties.get("currency").length() > 0) {
        _simulationScenarioParameters.setBaseCurrencyUnit(properties.get("currency"));
    }
}
Also used : ImportType(org.jboss.drools.ImportType) Import(org.eclipse.bpmn2.Import) Internal(org.eclipse.emf.ecore.EStructuralFeature.Internal) ExtensionAttributeValue(org.eclipse.bpmn2.ExtensionAttributeValue) Auditing(org.eclipse.bpmn2.Auditing) FeatureMap(org.eclipse.emf.ecore.util.FeatureMap) Entry(java.util.Map.Entry) SimpleFeatureMapEntry(org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry) EAttributeImpl(org.eclipse.emf.ecore.impl.EAttributeImpl) SimpleFeatureMapEntry(org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry) ExtendedMetaData(org.eclipse.emf.ecore.util.ExtendedMetaData) Monitoring(org.eclipse.bpmn2.Monitoring) GlobalType(org.jboss.drools.GlobalType)

Example 10 with Import

use of org.kie.dmn.model.v1_1.Import in project drools by kiegroup.

the class DMNAssemblerService method addResources.

@Override
public void addResources(Object kbuilder, Collection<ResourceWithConfiguration> resources, ResourceType type) throws Exception {
    KnowledgeBuilderImpl kbuilderImpl = (KnowledgeBuilderImpl) kbuilder;
    DMNCompilerImpl dmnCompiler = (DMNCompilerImpl) kbuilderImpl.getCachedOrCreate(DMN_COMPILER_CACHE_KEY, () -> getCompiler(kbuilderImpl));
    DMNMarshaller dmnMarshaller = dmnCompiler.getMarshaller();
    if (resources.size() == 1) {
        // quick path:
        internalAddResource(kbuilderImpl, dmnCompiler, resources.iterator().next(), Collections.emptyList());
        return;
    }
    List<DMNResource> dmnResources = new ArrayList<>();
    for (ResourceWithConfiguration r : resources) {
        Definitions definitions = dmnMarshaller.unmarshal(r.getResource().getReader());
        QName modelID = new QName(definitions.getNamespace(), definitions.getName());
        DMNResource dmnResource = new DMNResource(modelID, r, definitions);
        dmnResources.add(dmnResource);
    }
    // enrich with imports
    for (DMNResource r : dmnResources) {
        for (Import i : r.getDefinitions().getImport()) {
            if (ImportDMNResolverUtil.whichImportType(i) == ImportType.DMN) {
                Either<String, DMNResource> resolvedResult = ImportDMNResolverUtil.resolveImportDMN(i, dmnResources, DMNResource::getModelID);
                DMNResource located = resolvedResult.getOrElseThrow(RuntimeException::new);
                r.addDependency(located.getModelID());
            }
        }
    }
    List<DMNResource> sortedDmnResources = DMNResourceDependenciesSorter.sort(dmnResources);
    Collection<DMNModel> dmnModels = new ArrayList<>();
    for (DMNResource dmnRes : sortedDmnResources) {
        DMNModel dmnModel = internalAddResource(kbuilderImpl, dmnCompiler, dmnRes.getResAndConfig(), dmnModels);
        dmnModels.add(dmnModel);
    }
}
Also used : DMNCompilerImpl(org.kie.dmn.core.compiler.DMNCompilerImpl) Import(org.kie.dmn.model.v1_1.Import) DMNMarshaller(org.kie.dmn.api.marshalling.v1_1.DMNMarshaller) QName(javax.xml.namespace.QName) Definitions(org.kie.dmn.model.v1_1.Definitions) ArrayList(java.util.ArrayList) ResourceWithConfiguration(org.kie.api.io.ResourceWithConfiguration) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) DMNModel(org.kie.dmn.api.core.DMNModel)

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