Skip to content

Commit

Permalink
\#2873 fix state query for activated elements
Browse files Browse the repository at this point in the history
Change-Id: I25f3b0e7bdc0a33f147a3b439aa2a3638f0b0b04
Signed-off-by: Anita Matei Gabriel <[email protected]>
  • Loading branch information
AnitaMateiGabriel authored and tguiu committed Jun 12, 2024
1 parent 3167b13 commit f268993
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature.Setting;
import org.polarsys.capella.core.data.capellacommon.AbstractState;
import org.polarsys.capella.core.data.capellacommon.CapellacommonFactory;
import org.polarsys.capella.core.data.capellacommon.FinalState;
import org.polarsys.capella.core.data.capellacommon.Mode;
import org.polarsys.capella.core.data.capellacommon.Pseudostate;
import org.polarsys.capella.core.data.capellacommon.Region;
import org.polarsys.capella.core.data.capellacommon.State;
import org.polarsys.capella.core.data.fa.AbstractFunction;
Expand Down Expand Up @@ -93,13 +95,15 @@ public static List<Object> getActiveElements(State state) {
return result;
}

public static List<Object> getRecursiveSubStates(State state) {
List<Object> result = new ArrayList<Object>();
for (Region region : state.getOwnedRegions()) {
List<AbstractState> rStates = region.getOwnedStates();
for(AbstractState s : rStates) {
public static List<State> getNonPseudoRecursiveSubStates(State state) {
List<State> result = new ArrayList<State>();

for (Region region : ((State) state).getOwnedRegions()) {
List<State> rStates = region.getOwnedStates().stream().filter(State.class::isInstance).map(State.class::cast)
.collect(Collectors.toList());
for (State s : rStates) {
result.add(s);
result.addAll(getRecursiveSubStates((State)s));
result.addAll(getNonPseudoRecursiveSubStates(s));
}
}
return result;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
/*******************************************************************************
* Copyright (c) 2019, 2020 THALES GLOBAL SERVICES.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Thales Global Services - initial API and implementation
*******************************************************************************/
package org.polarsys.capella.core.semantic.queries.basic.queries;

import java.util.ArrayList;
import java.util.List;

import org.polarsys.capella.common.helpers.query.IQuery;
import org.polarsys.capella.core.data.capellacommon.State;
import org.polarsys.capella.core.model.helpers.StateExt;

public class AbstractStateParentActiveElements implements IQuery {

/**
* Constructor.
*/
public AbstractStateParentActiveElements() {
}

@Override
public List<Object> compute(Object object) {
List<Object> result = new ArrayList<Object>();
if (object instanceof State) {
State state = (State) object;

List<Object> subStates = StateExt.getRecursiveSubStates(state);
for (Object obj : subStates) {
result.addAll(StateExt.getActiveElements((State) obj));
}
}

return result;
}
}
/*******************************************************************************
* Copyright (c) 2019, 2020 THALES GLOBAL SERVICES.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Thales Global Services - initial API and implementation
*******************************************************************************/
package org.polarsys.capella.core.semantic.queries.basic.queries;

import java.util.ArrayList;
import java.util.List;

import org.polarsys.capella.common.helpers.query.IQuery;
import org.polarsys.capella.core.data.capellacommon.State;
import org.polarsys.capella.core.model.helpers.StateExt;

public class AbstractStateParentActiveElements implements IQuery {

/**
* Constructor.
*/
public AbstractStateParentActiveElements() {
}

@Override
public List<Object> compute(Object object) {
List<Object> result = new ArrayList<Object>();
if (object instanceof State) {
State state = (State) object;

List<State> subStates = StateExt.getNonPseudoRecursiveSubStates(state);
for (Object obj : subStates) {
result.addAll(StateExt.getActiveElements((State) obj));
}
}

return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1685,20 +1685,24 @@
<ownedRegions xsi:type="org.polarsys.capella.core.data.capellacommon:Region"
id="3c0ec0d8-edec-4199-9cdc-5daf3ebb5bd3" name="Default Region" involvedStates="#384597dd-fdbc-4fc4-acae-68451e8f69e2">
<ownedStates xsi:type="org.polarsys.capella.core.data.capellacommon:State"
id="384597dd-fdbc-4fc4-acae-68451e8f69e2" name="State 1" referencedStates="#de7c3db9-d166-4445-b80d-a2d6a592b3c0">
id="384597dd-fdbc-4fc4-acae-68451e8f69e2" name="State 1" referencedStates="#de7c3db9-d166-4445-b80d-a2d6a592b3c0 #4c15290e-ac40-409e-b550-410bc766760b">
<ownedRegions xsi:type="org.polarsys.capella.core.data.capellacommon:Region"
id="a42786bc-6f51-4a8d-8b9c-900e20f2d6f3" name="region" involvedStates="#de7c3db9-d166-4445-b80d-a2d6a592b3c0">
id="a42786bc-6f51-4a8d-8b9c-900e20f2d6f3" name="region" involvedStates="#de7c3db9-d166-4445-b80d-a2d6a592b3c0 #4c15290e-ac40-409e-b550-410bc766760b">
<ownedStates xsi:type="org.polarsys.capella.core.data.capellacommon:State"
id="de7c3db9-d166-4445-b80d-a2d6a592b3c0" name="State 1_1" referencedStates="#7d1233e9-013f-4ae0-a692-f847f6502390">
id="de7c3db9-d166-4445-b80d-a2d6a592b3c0" name="State 1_1" referencedStates="#7d1233e9-013f-4ae0-a692-f847f6502390 #d482e9f6-6cb7-4e07-b791-d860983a9623">
<ownedRegions xsi:type="org.polarsys.capella.core.data.capellacommon:Region"
id="947aacb8-ab3a-4555-b6f6-0a2b3f826b92" name="region" involvedStates="#7d1233e9-013f-4ae0-a692-f847f6502390">
id="947aacb8-ab3a-4555-b6f6-0a2b3f826b92" name="region" involvedStates="#7d1233e9-013f-4ae0-a692-f847f6502390 #d482e9f6-6cb7-4e07-b791-d860983a9623">
<ownedStates xsi:type="org.polarsys.capella.core.data.capellacommon:State"
id="7d1233e9-013f-4ae0-a692-f847f6502390" name="State 1_1_1">
<ownedRegions xsi:type="org.polarsys.capella.core.data.capellacommon:Region"
id="5b1987ef-a1f4-4059-a149-87e2fd226414" name="region"/>
</ownedStates>
<ownedStates xsi:type="org.polarsys.capella.core.data.capellacommon:InitialPseudoState"
id="d482e9f6-6cb7-4e07-b791-d860983a9623" name="Initial 2"/>
</ownedRegions>
</ownedStates>
<ownedStates xsi:type="org.polarsys.capella.core.data.capellacommon:InitialPseudoState"
id="4c15290e-ac40-409e-b550-410bc766760b" name="Initial 2"/>
</ownedRegions>
</ownedStates>
</ownedRegions>
Expand All @@ -1708,20 +1712,24 @@
<ownedRegions xsi:type="org.polarsys.capella.core.data.capellacommon:Region"
id="0f91e0ae-b07d-4072-83b1-513e716b1276" name="Default Region" involvedStates="#69c99509-e445-46a7-93dc-ee9162790fa2">
<ownedStates xsi:type="org.polarsys.capella.core.data.capellacommon:Mode"
id="69c99509-e445-46a7-93dc-ee9162790fa2" name="Mode 1" referencedStates="#8f7ce582-1a8f-499b-a589-066235ca5dfe">
id="69c99509-e445-46a7-93dc-ee9162790fa2" name="Mode 1" referencedStates="#8f7ce582-1a8f-499b-a589-066235ca5dfe #d068f8d0-1020-4842-9d10-a4fea81aa997">
<ownedRegions xsi:type="org.polarsys.capella.core.data.capellacommon:Region"
id="a22ff7b4-b414-4459-a080-d21f04f16eec" name="region" involvedStates="#8f7ce582-1a8f-499b-a589-066235ca5dfe">
id="a22ff7b4-b414-4459-a080-d21f04f16eec" name="region" involvedStates="#8f7ce582-1a8f-499b-a589-066235ca5dfe #d068f8d0-1020-4842-9d10-a4fea81aa997">
<ownedStates xsi:type="org.polarsys.capella.core.data.capellacommon:Mode"
id="8f7ce582-1a8f-499b-a589-066235ca5dfe" name="Mode 1_1" referencedStates="#3bffa8df-2534-4669-8203-0ddb0f13422c">
id="8f7ce582-1a8f-499b-a589-066235ca5dfe" name="Mode 1_1" referencedStates="#3bffa8df-2534-4669-8203-0ddb0f13422c #528bf34a-77ee-4adb-845f-4056e7651c9e">
<ownedRegions xsi:type="org.polarsys.capella.core.data.capellacommon:Region"
id="6a6c1472-034e-487d-9961-ac4d1e5dca44" name="region" involvedStates="#3bffa8df-2534-4669-8203-0ddb0f13422c">
id="6a6c1472-034e-487d-9961-ac4d1e5dca44" name="region" involvedStates="#3bffa8df-2534-4669-8203-0ddb0f13422c #528bf34a-77ee-4adb-845f-4056e7651c9e">
<ownedStates xsi:type="org.polarsys.capella.core.data.capellacommon:Mode"
id="3bffa8df-2534-4669-8203-0ddb0f13422c" name="Mode 1_1_1">
<ownedRegions xsi:type="org.polarsys.capella.core.data.capellacommon:Region"
id="6133b46b-3c8f-4eff-b3df-c92ec04fd1d4" name="region"/>
</ownedStates>
<ownedStates xsi:type="org.polarsys.capella.core.data.capellacommon:InitialPseudoState"
id="528bf34a-77ee-4adb-845f-4056e7651c9e" name="Initial 2"/>
</ownedRegions>
</ownedStates>
<ownedStates xsi:type="org.polarsys.capella.core.data.capellacommon:InitialPseudoState"
id="d068f8d0-1020-4842-9d10-a4fea81aa997" name="Initial 2"/>
</ownedRegions>
</ownedStates>
</ownedRegions>
Expand Down

0 comments on commit f268993

Please sign in to comment.