Skip to content

Commit

Permalink
[1673] Fix function query to invalidate move of allocated function
Browse files Browse the repository at this point in the history
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
felixdo committed Mar 21, 2018
1 parent a931578 commit a1f194b
Show file tree
Hide file tree
Showing 14 changed files with 164 additions and 26 deletions.
@@ -1,10 +1,10 @@
/*******************************************************************************
* Copyright (c) 2006, 2016 THALES GLOBAL SERVICES.
* Copyright (c) 2006, 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
*******************************************************************************/
Expand Down Expand Up @@ -42,7 +42,7 @@ public EClass getEClass() {
*/
@Override
public List<EReference> getEStructuralFeatures() {
return Collections.singletonList(FaPackage.Literals.ABSTRACT_FUNCTIONAL_BLOCK__OWNED_FUNCTIONAL_ALLOCATION);
return Collections.singletonList(FaPackage.Literals.ABSTRACT_FUNCTIONAL_BLOCK__ALLOCATED_FUNCTIONS);
}

@Override
Expand Down
@@ -1,10 +1,10 @@
/*******************************************************************************
* Copyright (c) 2006, 2016 THALES GLOBAL SERVICES.
* Copyright (c) 2006, 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
*******************************************************************************/
Expand Down Expand Up @@ -36,7 +36,7 @@ public EClass getEClass() {

@Override
public List<EReference> getEStructuralFeatures() {
return Collections.singletonList(FaPackage.Literals.ABSTRACT_FUNCTIONAL_BLOCK__OWNED_FUNCTIONAL_ALLOCATION);
return Collections.singletonList(FaPackage.Literals.ABSTRACT_FUNCTIONAL_BLOCK__ALLOCATED_FUNCTIONS);
}

@Override
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2016 THALES GLOBAL SERVICES.
* Copyright (c) 2006, 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
Expand Down Expand Up @@ -35,7 +35,7 @@ public EClass getEClass() {

@Override
public List<EReference> getEStructuralFeatures() {
return Collections.singletonList(FaPackage.Literals.ABSTRACT_FUNCTIONAL_BLOCK__OWNED_FUNCTIONAL_ALLOCATION);
return Collections.singletonList(FaPackage.Literals.ABSTRACT_FUNCTIONAL_BLOCK__ALLOCATED_FUNCTIONS);
}

@Override
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2016 THALES GLOBAL SERVICES.
* Copyright (c) 2006, 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
Expand Down Expand Up @@ -35,7 +35,7 @@ public EClass getEClass() {

@Override
public List<EReference> getEStructuralFeatures() {
return Collections.singletonList(FaPackage.Literals.ABSTRACT_FUNCTIONAL_BLOCK__OWNED_FUNCTIONAL_ALLOCATION);
return Collections.singletonList(FaPackage.Literals.ABSTRACT_FUNCTIONAL_BLOCK__ALLOCATED_FUNCTIONS);
}

@Override
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2016 THALES GLOBAL SERVICES.
* Copyright (c) 2006, 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
Expand Down Expand Up @@ -41,7 +41,7 @@ public EClass getEClass() {
*/
@Override
public List<EReference> getEStructuralFeatures() {
return Collections.singletonList(FaPackage.Literals.ABSTRACT_FUNCTIONAL_BLOCK__OWNED_FUNCTIONAL_ALLOCATION);
return Collections.singletonList(FaPackage.Literals.ABSTRACT_FUNCTIONAL_BLOCK__ALLOCATED_FUNCTIONS);
}

@Override
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2016 THALES GLOBAL SERVICES.
* Copyright (c) 2006, 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
Expand Down Expand Up @@ -42,7 +42,7 @@ public EClass getEClass() {
*/
@Override
public List<EReference> getEStructuralFeatures() {
return Collections.singletonList(FaPackage.Literals.ABSTRACT_FUNCTIONAL_BLOCK__OWNED_FUNCTIONAL_ALLOCATION);
return Collections.singletonList(FaPackage.Literals.ABSTRACT_FUNCTIONAL_BLOCK__ALLOCATED_FUNCTIONS);
}

@Override
Expand All @@ -58,5 +58,5 @@ public List<EObject> getCurrentElements(EObject element, boolean onlyGenerated)
context.putValue(QueryConstants.ECLASS_PARAMETER, getEClass());
return QueryInterpretor.executeQuery(QueryConstants.GET_CURRENT__ENTITY__ALLOCATED_ACTIVITIES, element, context);
}

}
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2016 THALES GLOBAL SERVICES.
* Copyright (c) 2006, 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
Expand Down Expand Up @@ -35,7 +35,7 @@ public EClass getEClass() {

@Override
public List<EReference> getEStructuralFeatures() {
return Collections.singletonList(FaPackage.Literals.ABSTRACT_FUNCTIONAL_BLOCK__OWNED_FUNCTIONAL_ALLOCATION);
return Collections.singletonList(FaPackage.Literals.ABSTRACT_FUNCTIONAL_BLOCK__ALLOCATED_FUNCTIONS);
}

@Override
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2016 THALES GLOBAL SERVICES.
* Copyright (c) 2006, 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
Expand Down Expand Up @@ -35,7 +35,7 @@ public EClass getEClass() {

@Override
public List<EReference> getEStructuralFeatures() {
return Collections.singletonList(FaPackage.Literals.ABSTRACT_FUNCTIONAL_BLOCK__OWNED_FUNCTIONAL_ALLOCATION);
return Collections.singletonList(FaPackage.Literals.ABSTRACT_FUNCTIONAL_BLOCK__ALLOCATED_FUNCTIONS);
}

@Override
Expand Down
@@ -1,10 +1,10 @@
/*******************************************************************************
* Copyright (c) 2006, 2016 THALES GLOBAL SERVICES.
* Copyright (c) 2006, 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
*******************************************************************************/
Expand Down Expand Up @@ -32,7 +32,7 @@ public class AllocatedFunctionsController extends AbstractMultipleSemanticFieldC
*/
@Override
protected IBusinessQuery getReadOpenValuesQuery(EObject semanticElement) {
return BusinessQueriesProvider.getInstance().getContribution(semanticElement.eClass(), FaPackage.Literals.ABSTRACT_FUNCTIONAL_BLOCK__OWNED_FUNCTIONAL_ALLOCATION);
return BusinessQueriesProvider.getInstance().getContribution(semanticElement.eClass(), FaPackage.Literals.ABSTRACT_FUNCTIONAL_BLOCK__ALLOCATED_FUNCTIONS);
}

/**
Expand Down
@@ -1,10 +1,10 @@
/*******************************************************************************
* Copyright (c) 2006, 2016 THALES GLOBAL SERVICES.
* Copyright (c) 2006, 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
*******************************************************************************/
Expand Down Expand Up @@ -32,7 +32,7 @@ public class Entity_AllocatedActivitiesController extends AbstractMultipleSemant
*/
@Override
protected IBusinessQuery getReadOpenValuesQuery(EObject semanticElement) {
return BusinessQueriesProvider.getInstance().getContribution(semanticElement.eClass(), FaPackage.Literals.ABSTRACT_FUNCTIONAL_BLOCK__OWNED_FUNCTIONAL_ALLOCATION);
return BusinessQueriesProvider.getInstance().getContribution(semanticElement.eClass(), FaPackage.Literals.ABSTRACT_FUNCTIONAL_BLOCK__ALLOCATED_FUNCTIONS);
}

/**
Expand Down
@@ -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);
}

}
Expand Up @@ -1095,7 +1095,7 @@ public List<EObject> getAvailableExchangeItemElementToInsert(EObject context) {
public List<EObject> getAvailableFunctionalAllocation(CapellaElement capellaElement) {
List<EObject> returnedList = new ArrayList<EObject>();
IBusinessQuery query = BusinessQueriesProvider.getInstance().getContribution(capellaElement.eClass(),
FaPackage.Literals.ABSTRACT_FUNCTIONAL_BLOCK__OWNED_FUNCTIONAL_ALLOCATION);
FaPackage.Literals.ABSTRACT_FUNCTIONAL_BLOCK__ALLOCATED_FUNCTIONS);
if (query != null) {
returnedList.addAll(query.getAvailableElements(capellaElement));
}
Expand Down
Expand Up @@ -68,6 +68,7 @@ protected List<BasicTestArtefact> getTests() {
tests.add(new Rule_I_37_38_ComponentExchange());
tests.add(new Rule_I_37_38_FunctionalExchange());
tests.add(new Rule_I_37_38_PhysicalLink());
tests.add(new Rule_I_37_38_ComponentFunctionalAllocation());

return tests;
}
Expand Down
@@ -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);
// });

}


}

0 comments on commit a1f194b

Please sign in to comment.