From f15eaace215908f8cbf62bf3d4c5c30e3ba7c57d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Bausson?= Date: Thu, 7 Sep 2023 15:46:44 +0200 Subject: [PATCH] #2062 fix part management in port-conservation functionality. --- .../core/sirius/analysis/FaServices.java | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/core/plugins/org.polarsys.capella.core.sirius.analysis/src/org/polarsys/capella/core/sirius/analysis/FaServices.java b/core/plugins/org.polarsys.capella.core.sirius.analysis/src/org/polarsys/capella/core/sirius/analysis/FaServices.java index 4f5f50456d..aa374df12f 100644 --- a/core/plugins/org.polarsys.capella.core.sirius.analysis/src/org/polarsys/capella/core/sirius/analysis/FaServices.java +++ b/core/plugins/org.polarsys.capella.core.sirius.analysis/src/org/polarsys/capella/core/sirius/analysis/FaServices.java @@ -24,6 +24,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; @@ -92,6 +93,7 @@ import org.polarsys.capella.core.data.epbs.ConfigurationItem; import org.polarsys.capella.core.data.epbs.PhysicalArtifactRealization; import org.polarsys.capella.core.data.fa.AbstractFunction; +import org.polarsys.capella.core.data.fa.AbstractFunctionalBlock; import org.polarsys.capella.core.data.fa.ComponentExchange; import org.polarsys.capella.core.data.fa.ComponentExchangeEnd; import org.polarsys.capella.core.data.fa.ComponentExchangeFunctionalExchangeAllocation; @@ -3110,18 +3112,36 @@ private Collection retrieveObsoletePortAllocations(Port movingPort, * @return */ private boolean isEObjectInHierarchyOfContainer(EObject eObject, NamedElement container) { - if (eObject == container) { + if (eObject == null || container == null) { + return false; + } else if (eObject == container) { return true; } else if (eObject instanceof AbstractFunction) { - if (((AbstractFunction) eObject).getComponentFunctionalAllocations().stream().anyMatch(cfa -> isEObjectInHierarchyOfContainer(cfa, container))) { + AbstractFunction eFunction = (AbstractFunction) eObject; + if (eFunction.getComponentFunctionalAllocations().stream().anyMatch(cfa -> isEObjectInHierarchyOfContainer(cfa, container))) { return true; } - } else if (eObject instanceof ModelElement && eObject.eContainer() != null) { - return isEObjectInHierarchyOfContainer(eObject.eContainer(), container); + } + if (eObject instanceof ModelElement && eObject.eContainer() != null) { + return isEObjectInHierarchyOfContainer(getOwningComponent((ModelElement) eObject), container); } return false; } + private EObject getOwningComponent(ModelElement eObject) { + if (eObject instanceof AbstractFunction) { + AbstractFunction eFunction = (AbstractFunction) eObject; + Optional optional = eFunction.getAllocationBlocks().stream().filter(e -> ComponentExt.getAllSubUsedComponents((Component) e).contains(eObject)).findFirst(); + if (optional.isPresent()) { + return optional.get(); + } + } + if (eObject.eContainer() != null) { + return eObject.eContainer(); + } + return null; + } + private Collection retrievePortAllocations(Port port, boolean includeFunctionalRealization, boolean includeComponentRealization) { Collection elements = new HashSet<>();