-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[incubator-kie-issues#852] DMN - Allow importing into the default nam…
…espace (#5684) * [private-bamoe-issues#253] WIP - working only ItemDefNode import * [incubator-kie-issues#852] WIP * [incubator-kie-issues#852] WIP - experimenting different approach * [incubator-kie-issues#852] WIP - Experimenting model merge. * [incubator-kie-issues#852] WIP - Working Imported model test * [incubator-kie-issues#852] Working state * [incubator-kie-issues#852] Add tests. Minor fixes * [incubator-kie-issues#852] Fixing UnnamedImportUtilsTest - using a unique name for imported model --------- Co-authored-by: BAMOE CI <bamoe.ci@ibm.com> Co-authored-by: Gabriele-Cardosi <gabriele.cardosi@ibm.com>
- Loading branch information
1 parent
eb2f4f6
commit d55ce2d
Showing
19 changed files
with
672 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/UnnamedImportUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.kie.dmn.core.compiler; | ||
|
||
import java.util.Collection; | ||
import java.util.Objects; | ||
|
||
import org.kie.dmn.api.core.ast.DMNNode; | ||
import org.kie.dmn.core.impl.DMNModelImpl; | ||
import org.kie.dmn.model.api.Definitions; | ||
import org.kie.dmn.model.api.Import; | ||
import org.kie.dmn.model.api.NamedElement; | ||
|
||
/** | ||
* Class meant to provide helper methods to deal with unnamed model imports | ||
*/ | ||
public class UnnamedImportUtils { | ||
|
||
private UnnamedImportUtils() { | ||
} | ||
|
||
public static boolean isInUnnamedImport(DMNNode node, DMNModelImpl model) { | ||
for (Import imported : model.getDefinitions().getImport()) { | ||
String importedName = imported.getName(); | ||
if ((node.getModelNamespace().equals(imported.getNamespace()) && | ||
(importedName != null && importedName.isEmpty()))) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
public static void processMergedModel(DMNModelImpl parentModel, DMNModelImpl mergedModel) { | ||
// incubator-kie-issues#852: The idea is to not treat the anonymous models as import, but to "merge" them with original opne, | ||
// Here we try to put all the definitions from the "imported" model inside the parent one | ||
Definitions parentDefinitions = parentModel.getDefinitions(); | ||
Definitions mergedDefinitions = mergedModel.getDefinitions(); | ||
parentDefinitions.getArtifact().addAll(mergedDefinitions.getArtifact()); | ||
|
||
addIfNotPresent(parentDefinitions.getDecisionService(), mergedDefinitions.getDecisionService()); | ||
addIfNotPresent(parentDefinitions.getBusinessContextElement(), mergedDefinitions.getBusinessContextElement()); | ||
addIfNotPresent(parentDefinitions.getDrgElement(), mergedDefinitions.getDrgElement()); | ||
addIfNotPresent(parentDefinitions.getImport(), mergedDefinitions.getImport()); | ||
addIfNotPresent(parentDefinitions.getItemDefinition(), mergedDefinitions.getItemDefinition()); | ||
mergedDefinitions.getChildren().forEach(parentDefinitions::addChildren); | ||
mergedModel.getTypeRegistry().getTypes().forEach((s, stringDMNTypeMap) -> | ||
stringDMNTypeMap.values(). | ||
forEach(dmnType -> parentModel.getTypeRegistry().registerType(dmnType))); | ||
} | ||
|
||
static <T extends NamedElement> void addIfNotPresent(Collection<T> target, Collection<T> source) { | ||
source.forEach(sourceElement -> addIfNotPresent(target, sourceElement)); | ||
} | ||
|
||
static <T extends NamedElement> void addIfNotPresent(Collection<T> target, T source) { | ||
if (target.stream().noneMatch(namedElement -> Objects.equals(namedElement.getName(), source.getName()))) { | ||
target.add(source); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.