Skip to content

Commit

Permalink
eclipse-capella#2062 fix part management in port-conservation functio…
Browse files Browse the repository at this point in the history
…nality.
  • Loading branch information
ebausson-obeo authored and SteveMonnier committed Apr 9, 2024
1 parent 410ce27 commit 45de484
Showing 1 changed file with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -3110,18 +3112,36 @@ private Collection<Allocation> 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<AbstractFunctionalBlock> 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<Allocation> retrievePortAllocations(Port port, boolean includeFunctionalRealization, boolean includeComponentRealization) {
Collection<Allocation> elements = new HashSet<>();

Expand Down

0 comments on commit 45de484

Please sign in to comment.