-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1673] Fix function query to invalidate move of allocated function
It shouldn't be possible to move an allocated function to a library without moving the allocator block too. Bug: 1673 Change-Id: I652ca20f05f0f7d23271a0fd61958a3efbad63a8 Signed-off-by: Felix Dorner <felix.dorner@gmail.com>
- Loading branch information
Showing
14 changed files
with
164 additions
and
26 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
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
70 changes: 70 additions & 0 deletions
70
...lla.core.model.helpers/src/org/polarsys/capella/core/model/helpers/FunctionAllocator.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,70 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2017 THALES GLOBAL SERVICES. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Thales - initial API and implementation | ||
*******************************************************************************/ | ||
package org.polarsys.capella.core.model.helpers; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
|
||
import org.polarsys.capella.core.data.cs.Component; | ||
import org.polarsys.capella.core.data.fa.AbstractFunction; | ||
import org.polarsys.capella.core.data.fa.ComponentFunctionalAllocation; | ||
import org.polarsys.capella.core.data.fa.FaFactory; | ||
|
||
/** | ||
* A helper to handle allocation of Functions to Components. | ||
* An allocator for one or several functions is obtained via the static factory | ||
* methods | ||
* <ul> | ||
* <li>{@link #allocate(Collection)} | ||
* <li>{@link #allocate(AbstractFunction)} | ||
* </ul> | ||
* Then, the items of the allocator are allocated via the 'on' method. | ||
* | ||
*<pre> | ||
* allocate(lf).on(lc) | ||
* </pre> | ||
* | ||
* Note that functions that are already allocated are ignored and no | ||
* other validation of compatibility between component and function | ||
* is performed, i.e. you can allocate a Logical Function on a System | ||
* if you want, but you don't want that. | ||
* | ||
* | ||
*/ | ||
public class FunctionAllocator { | ||
|
||
private final Collection<AbstractFunction> allocations; | ||
|
||
private FunctionAllocator(Collection<AbstractFunction> eia){ | ||
allocations = eia; | ||
} | ||
|
||
public FunctionAllocator on(Component c){ | ||
for (AbstractFunction f : allocations){ | ||
if (f.getAllocationBlocks().isEmpty()){ | ||
ComponentFunctionalAllocation cfa = FaFactory.eINSTANCE.createComponentFunctionalAllocation(); | ||
cfa.setSourceElement(c); | ||
cfa.setTargetElement(f); | ||
c.getOwnedFunctionalAllocation().add(cfa); | ||
} | ||
} | ||
return this; | ||
} | ||
|
||
public static FunctionAllocator allocate(AbstractFunction f){ | ||
return allocate(Collections.singleton(f)); | ||
} | ||
|
||
public static FunctionAllocator allocate(Collection<AbstractFunction> functions){ | ||
return new FunctionAllocator(functions); | ||
} | ||
|
||
} |
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
67 changes: 67 additions & 0 deletions
67
...ella/test/validation/rules/ju/testcases/i/Rule_I_37_38_ComponentFunctionalAllocation.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,67 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2017 THALES GLOBAL SERVICES. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Thales - initial API and implementation | ||
*******************************************************************************/ | ||
package org.polarsys.capella.test.validation.rules.ju.testcases.i; | ||
|
||
import static org.polarsys.capella.core.model.helpers.FunctionAllocator.allocate; | ||
|
||
import org.polarsys.capella.core.data.la.LaFactory; | ||
import org.polarsys.capella.core.data.la.LogicalComponent; | ||
import org.polarsys.capella.core.data.la.LogicalFunction; | ||
import org.polarsys.capella.core.model.helpers.BlockArchitectureExt; | ||
|
||
public class Rule_I_37_38_ComponentFunctionalAllocation extends Rule_I37_38{ | ||
|
||
LogicalFunction lf1; | ||
LogicalComponent lc; | ||
|
||
LogicalFunction libraryRootFunction; | ||
LogicalFunction projectRootFunction; | ||
|
||
@Override | ||
public void setUp() throws Exception { | ||
super.setUp(); | ||
|
||
executeCommand(() -> { | ||
|
||
projectRootFunction = (LogicalFunction) BlockArchitectureExt.getRootFunction(projectSkeleton.getLogicalArchitecture()); | ||
libraryRootFunction = (LogicalFunction) BlockArchitectureExt.getRootFunction(librarySkeleton.getLogicalArchitecture()); | ||
|
||
lf1 = LaFactory.eINSTANCE.createLogicalFunction(); | ||
projectRootFunction.getOwnedFunctions().add(lf1); | ||
|
||
lc = LaFactory.eINSTANCE.createLogicalComponent(); | ||
projectSkeleton.getLogicalArchitecture().getOwnedLogicalComponent().getOwnedLogicalComponents().add(lc); | ||
|
||
allocate(lf1).on(lc); | ||
|
||
}); | ||
|
||
} | ||
|
||
@SuppressWarnings("nls") | ||
@Override | ||
public void test() throws Exception { | ||
|
||
// can't move the function because a project component cannot allocate a function in a library | ||
expectRollback(() -> libraryRootFunction.getOwnedFunctions().add(lf1), | ||
"'[Logical Component]' cannot reference moved element '[Logical Function]' via 'allocatedFunctions'"); | ||
|
||
// can move both functions + component | ||
// FIXME broken by https://bugs.polarsys.org/show_bug.cgi?id=1878 | ||
// expectNoRollback(() -> { | ||
// libraryRootFunction.getOwnedFunctions().add(lf1); | ||
// librarySkeleton.getLogicalArchitecture().getOwnedLogicalComponent().getOwnedLogicalComponents().add(lc); | ||
// }); | ||
|
||
} | ||
|
||
|
||
} |