Skip to content

Commit

Permalink
[2211] Location inconsistencies on fragmented model or with libraries
Browse files Browse the repository at this point in the history
The main fix is located in ILocationHandler and traceability handlers
inconsistent implementations.

Location retrieval on Fragments and Update REC from RPL were wrongly
handled as we were looking for eResource from the initial selection, not
from the expected one.
ILocationHandler.isInvalidResourceLocation and
retrieveDefaultContainerFromRule have been clarified.

Traceability handlers were unclear and mostly unused. Only one
traceability handler is useful, to make retrieveDefaultContainerFromRule
work. MatchPolicy wasn't using them, AttachmentActivity neither

Bug: 2211
Change-Id: I61ff0402917e6e3e8a4a450329d7090b88987e43
Signed-off-by: Philippe DUL <philippe.dul@thalesgroup.com>
  • Loading branch information
pdulth committed Oct 2, 2018
1 parent 71c31d8 commit 99e1b32
Show file tree
Hide file tree
Showing 41 changed files with 700 additions and 972 deletions.
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2017 THALES GLOBAL SERVICES.
* Copyright (c) 2006, 2018 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 All @@ -20,6 +20,7 @@
import org.eclipse.core.runtime.Status;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider;
import org.eclipse.jface.util.LocalSelectionTransfer;
import org.eclipse.jface.viewers.CellEditor;
Expand Down Expand Up @@ -56,7 +57,6 @@
import org.polarsys.capella.common.re.handlers.replicable.ReplicableElementHandlerHelper;
import org.polarsys.capella.common.re.helpers.ReplicableElementExt;
import org.polarsys.capella.common.ui.toolkit.viewers.data.ListData;
import org.polarsys.capella.core.transition.common.constants.ITransitionConstants;
import org.polarsys.capella.core.transition.common.handlers.contextscope.ContextScopeHandlerHelper;
import org.polarsys.kitalpha.transposer.rules.handler.rules.api.IContext;

Expand Down Expand Up @@ -383,18 +383,9 @@ protected Object createInput(IProperty property, IRendererContext context) {
return Collections.emptyList();
}

Collection<Object> selection =
(Collection<Object>) ((IContext) (context.getPropertyContext().getSource())).get(ITransitionConstants.TRANSITION_SOURCES);
if ((selection != null) && (selection.size() > 0)) {
for (Object item : selection) {
if (item instanceof EObject) {
return ((EObject) item).eResource();
}
}
}

return ((CatalogElementLink) scopeElements.iterator().next()).getTarget().eResource();

IProperty rplProperty = context.getPropertyContext().getProperties().getProperty(IReConstants.PROPERTY__REPLICABLE_ELEMENT__INITIAL_TARGET);
EObject replica = (EObject) context.getPropertyContext().getCurrentValue(rplProperty);
return EcoreUtil.getRootContainer(replica).eResource();
}
return new ListData(Collections.emptyList(), context.getPropertyContext());
}
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2017 THALES GLOBAL SERVICES.
* Copyright (c) 2006, 2018 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 @@ -28,15 +28,12 @@
import org.polarsys.capella.common.re.handlers.attributes.AttributesHandlerHelper;
import org.polarsys.capella.common.re.handlers.location.LocationHandlerHelper;
import org.polarsys.capella.common.re.handlers.replicable.ReplicableElementHandlerHelper;
import org.polarsys.capella.common.re.handlers.traceability.MatchConfiguration;
import org.polarsys.capella.core.transition.common.activities.AbstractActivity;
import org.polarsys.capella.core.transition.common.constants.ITransitionConstants;
import org.polarsys.capella.core.transition.common.constants.Messages;
import org.polarsys.capella.core.transition.common.handlers.IHandler;
import org.polarsys.capella.core.transition.common.handlers.attachment.AttachmentHelper;
import org.polarsys.capella.core.transition.common.handlers.contextscope.ContextScopeHandlerHelper;
import org.polarsys.capella.core.transition.common.handlers.log.LogHelper;
import org.polarsys.capella.core.transition.common.handlers.traceability.CompoundTraceabilityHandler;
import org.polarsys.capella.core.transition.common.merge.ExtendedComparison;
import org.polarsys.kitalpha.cadence.core.api.parameter.ActivityParameters;
import org.polarsys.kitalpha.transposer.rules.handler.rules.api.IContext;
Expand All @@ -56,44 +53,53 @@ protected IStatus _run(ActivityParameters activityParams) {

IContext context = getContext(activityParams);

initializeTraceabilityAttachmentHandler(context, activityParams);

CatalogElement sourceElement = ReplicableElementHandlerHelper.getInstance(context).getSource(context);
CatalogElement targetElement = ReplicableElementHandlerHelper.getInstance(context).getTarget(context);

Collection<EObject> sourceAddedElements = ContextScopeHandlerHelper.getInstance(context).getCollection(IReConstants.SOURCE__ADDED_ELEMENTS, context);
Collection<EObject> sourceAddedElements = ContextScopeHandlerHelper.getInstance(context)
.getCollection(IReConstants.SOURCE__ADDED_ELEMENTS, context);
for (EObject object : sourceAddedElements) {
attachContainment(context, object, true, sourceElement);
if (object instanceof CatalogElementLink) {
attachContainment(context, (CatalogElementLink) object, true, sourceElement);
}
}

Collection<EObject> targetAddedElements = ContextScopeHandlerHelper.getInstance(context).getCollection(IReConstants.TARGET__ADDED_ELEMENTS, context);
Collection<EObject> targetAddedElements = ContextScopeHandlerHelper.getInstance(context)
.getCollection(IReConstants.TARGET__ADDED_ELEMENTS, context);
for (EObject object : targetAddedElements) {
attachContainment(context, object, false, targetElement);
updateElement(context, object, false, targetElement);
if (object instanceof CatalogElementLink) {
attachContainment(context, (CatalogElementLink) object, false, targetElement);
updateElement(context, (CatalogElementLink) object, targetElement);
}
}

String value = (String) context.get(IReConstants.COMMAND__CURRENT_VALUE);
if (IReConstants.COMMAND__UPDATE_DEFINITION_REPLICA_FROM_REPLICA.equals(value) || IReConstants.COMMAND__UPDATE_CURRENT_REPLICA_FROM_REPLICA.equals(value)
if (IReConstants.COMMAND__UPDATE_DEFINITION_REPLICA_FROM_REPLICA.equals(value)
|| IReConstants.COMMAND__UPDATE_CURRENT_REPLICA_FROM_REPLICA.equals(value)
|| IReConstants.COMMAND__CREATE_REPLICABLE_ELEMENT.equals(value)) {

// We set unsynchronize features from values set in the wizard by the user
for (CatalogElementLink link : ReplicableElementHandlerHelper.getInstance(context).getElementsLinks(targetElement)) {
for (CatalogElementLink link : ReplicableElementHandlerHelper.getInstance(context)
.getElementsLinks(targetElement)) {
storeUnsynchronizedFeatures(context, link, link, targetElement);
}

if (IReConstants.COMMAND__UPDATE_DEFINITION_REPLICA_FROM_REPLICA.equals(value)) {

// For all links of the replica, add a unsynchronizable on parent
for (CatalogElementLink link : ReplicableElementHandlerHelper.getInstance(context).getElementsLinks(sourceElement)) {
for (CatalogElementLink link : ReplicableElementHandlerHelper.getInstance(context)
.getElementsLinks(sourceElement)) {
storeUnsynchronizedFeatures(context, link.getOrigin(), link, targetElement);
}

}

} else if (IReConstants.COMMAND__CREATE_A_REPLICA_FROM_REPLICABLE.equals(value) || IReConstants.COMMAND__UPDATE_A_REPLICA_FROM_REPLICABLE.equals(value)) {
} else if (IReConstants.COMMAND__CREATE_A_REPLICA_FROM_REPLICABLE.equals(value)
|| IReConstants.COMMAND__UPDATE_A_REPLICA_FROM_REPLICABLE.equals(value)) {

// We copy unsychronizedFeatures into RPL from its REC
for (CatalogElementLink link : ReplicableElementHandlerHelper.getInstance(context).getElementsLinks(targetElement)) {
for (CatalogElementLink link : ReplicableElementHandlerHelper.getInstance(context)
.getElementsLinks(targetElement)) {
storeUnsynchronizedFeatures(context, link, link.getOrigin(), targetElement);
}

Expand All @@ -119,18 +125,15 @@ protected IStatus _run(ActivityParameters activityParams) {
* @param b
* @param targetElement
*/
protected void updateElement(IContext context, EObject object, boolean b, CatalogElement targetElement) {
if (object instanceof CatalogElementLink) {
CatalogElementLink link = (CatalogElementLink) object;
EObject target = link.getTarget();
if ((target != null) && (target instanceof CatalogElement)) {
CatalogElement element = (CatalogElement) target;
if (link.getSource().getKind() != CatalogElementKind.RPL) {
if (element.getKind() == CatalogElementKind.RPL) {
element.setKind(CatalogElementKind.REC_RPL);
}
// maybe we should set also the kind for all element.subrpls
protected void updateElement(IContext context, CatalogElementLink link, CatalogElement targetElement) {
EObject target = link.getTarget();
if ((target != null) && (target instanceof CatalogElement)) {
CatalogElement element = (CatalogElement) target;
if (link.getSource().getKind() != CatalogElementKind.RPL) {
if (element.getKind() == CatalogElementKind.RPL) {
element.setKind(CatalogElementKind.REC_RPL);
}
// maybe we should set also the kind for all element.subrpls
}
}
}
Expand All @@ -141,7 +144,8 @@ protected void updateElement(IContext context, EObject object, boolean b, Catalo
* @param linkSuffixable
* @param target1
*/
protected void storeUnsynchronizedFeatures(IContext context, EObject link1, EObject linkSuffixable, CatalogElement target1) {
protected void storeUnsynchronizedFeatures(IContext context, EObject link1, EObject linkSuffixable,
CatalogElement target1) {
if (link1 instanceof CatalogElementLink) {
CatalogElementLink link = (CatalogElementLink) link1;

Expand Down Expand Up @@ -180,41 +184,15 @@ protected void storeUnsynchronizedFeatures(IContext context, EObject link1, EObj
}
}

/**
* Initialize the transformation traceability handler and set it into context via TRANSFORMATION_HANDLER
* @param context
* @param activityParams
* @return
*/
protected IStatus initializeTraceabilityAttachmentHandler(IContext context, ActivityParameters activityParams) {
IHandler handler = loadHandlerFromParameters(IReConstants.TRACEABILITY_ATTACHMENT_HANDLER, activityParams);
if (handler == null) {
handler = createDefaultTraceabilityTransformationHandler();
}
context.put(IReConstants.TRACEABILITY_ATTACHMENT_HANDLER, handler);
context.put(ITransitionConstants.TRACEABILITY_HANDLER, handler);
handler.init(context);
return Status.OK_STATUS;
}

/**
* Create default transformation traceability handler for common transition
* @return
*/
protected IHandler createDefaultTraceabilityTransformationHandler() {
return new CompoundTraceabilityHandler(new MatchConfiguration());
}

public void attachContainment(IContext context, EObject source1, boolean isSource, CatalogElement element) {

CatalogElementLink link = (CatalogElementLink) source1;
public void attachContainment(IContext context, CatalogElementLink link, boolean isSource, CatalogElement element) {

// Don't attach an invalid link
if ((link == null) || (link.getTarget() == null)) {
return;
}
// Don't move such element, element must not be copied, and so on, not moved from its original location
if (ContextScopeHandlerHelper.getInstance(context).contains(IReConstants.UNMERGEABLE_ELEMENTS, link.getTarget(), context)) {
if (ContextScopeHandlerHelper.getInstance(context).contains(IReConstants.UNMERGEABLE_ELEMENTS, link.getTarget(),
context)) {
return;
}
// If the target is already attached somewhere, we don't wan't to move it!
Expand All @@ -226,7 +204,7 @@ public void attachContainment(IContext context, EObject source1, boolean isSourc
Role oppositeRole = !isSource ? Role.REFERENCE : Role.TARGET;
ExtendedComparison comparison = (ExtendedComparison) context.get(ITransitionConstants.MERGE_COMPARISON);

EObject targetElement = ((CatalogElementLink) source1).getTarget();
EObject targetElement = link.getTarget();
IMatch match = comparison.getMapping().getMatchFor(targetElement, destinationRole);

if (match == null) {
Expand All @@ -235,9 +213,11 @@ public void attachContainment(IContext context, EObject source1, boolean isSourc
EObject source = match.get(oppositeRole);
EObject target = match.get(destinationRole);

CatalogElementLink oppositeLink = ReplicableElementHandlerHelper.getInstance(context).getOppositeLink(link, context);
CatalogElementLink oppositeLink = ReplicableElementHandlerHelper.getInstance(context).getOppositeLink(link,
context);

// For a REC to RPL, all location have been set as current after the first wizard. location should not be null for these modes.
// For a REC to RPL, all location have been set as current after the first wizard. location should not be null for
// these modes.
EObject location = LocationHandlerHelper.getInstance(context).getCurrentLocation(link, context);
if (location == null) {
// For a RPL to REC, we can go in that case.
Expand All @@ -260,16 +240,18 @@ public void attachContainment(IContext context, EObject source1, boolean isSourc
} else {
// No match, location is not in the scope of the diffmerge.
// This can occurs when instanciating sub replicas: a sub replica's element can be located inside
// a super replica's element which is not present in the scope at the time where instanciating the sub replica.
// a super replica's element which is not present in the scope at the time where instanciating the sub
// replica.
// It will be stored when re-updating the super-replica.
}
}
}

if (location != null) {
EStructuralFeature feature = LocationHandlerHelper.getInstance(context).getFeature(source, target, location, context);
EStructuralFeature feature = LocationHandlerHelper.getInstance(context).getFeature(source, target, location,
context);
attachElement(context, target, location, feature);

} else {
LogHelper.getInstance().debug(
NLS.bind("Element ''{0}'' has not been attached.", LogHelper.getInstance().getText(target)),
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2016 THALES GLOBAL SERVICES.
* Copyright (c) 2006, 2018 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 All @@ -11,24 +11,24 @@

package org.polarsys.capella.common.re.activities;

import java.util.Collection;
import java.util.HashSet;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.emf.ecore.EObject;
import org.polarsys.capella.common.re.constants.IReConstants;
import org.polarsys.capella.common.re.handlers.replicable.ReplicableElementHandlerHelper;
import org.polarsys.capella.common.re.handlers.traceability.MatchConfiguration;
import org.polarsys.capella.core.transition.common.activities.AbstractActivity;
import org.polarsys.capella.core.transition.common.constants.ITransitionConstants;
import org.polarsys.capella.core.transition.common.handlers.IHandler;
import org.polarsys.capella.core.transition.common.handlers.contextscope.ContextScopeHandlerHelper;
import org.polarsys.capella.core.transition.common.handlers.contextscope.IContextScopeHandler;
import org.polarsys.capella.core.transition.common.handlers.scope.ScopeHandlerHelper;
import org.polarsys.capella.core.transition.common.handlers.traceability.CompoundTraceabilityHandler;
import org.polarsys.kitalpha.cadence.core.api.parameter.ActivityParameters;
import org.polarsys.kitalpha.transposer.api.ITransposerWorkflow;
import java.util.Collection;
import java.util.HashSet;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.emf.ecore.EObject;
import org.polarsys.capella.common.re.constants.IReConstants;
import org.polarsys.capella.common.re.handlers.replicable.ReplicableElementHandlerHelper;
import org.polarsys.capella.common.re.handlers.traceability.LocationTraceabilityConfiguration;
import org.polarsys.capella.core.transition.common.activities.AbstractActivity;
import org.polarsys.capella.core.transition.common.constants.ITransitionConstants;
import org.polarsys.capella.core.transition.common.handlers.IHandler;
import org.polarsys.capella.core.transition.common.handlers.contextscope.ContextScopeHandlerHelper;
import org.polarsys.capella.core.transition.common.handlers.contextscope.IContextScopeHandler;
import org.polarsys.capella.core.transition.common.handlers.scope.ScopeHandlerHelper;
import org.polarsys.capella.core.transition.common.handlers.traceability.CompoundTraceabilityHandler;
import org.polarsys.kitalpha.cadence.core.api.parameter.ActivityParameters;
import org.polarsys.kitalpha.transposer.api.ITransposerWorkflow;
import org.polarsys.kitalpha.transposer.rules.handler.rules.api.IContext;

/**
Expand All @@ -53,7 +53,7 @@ protected IStatus _run(ActivityParameters activityParams) {
return status;
}

initializeTraceabilityAttachmentHandler(context, activityParams);
initializeTraceabilityLocationHandler(context, activityParams);

//Compute scope and additional elements
IContextScopeHandler scopeHandler = ContextScopeHandlerHelper.getInstance(context);
Expand All @@ -75,30 +75,31 @@ protected IStatus _run(ActivityParameters activityParams) {
}

/**
* Initialize the transformation traceability handler and set it into context via TRANSFORMATION_HANDLER
* Initialize the traceability handler used for location and set it into context via TRANSFORMATION_HANDLER
* @param context
* @param activityParams
* @return
*/
protected IStatus initializeTraceabilityAttachmentHandler(IContext context, ActivityParameters activityParams) {
IHandler handler = loadHandlerFromParameters(IReConstants.TRACEABILITY_ATTACHMENT_HANDLER, activityParams);
protected IStatus initializeTraceabilityLocationHandler(IContext context, ActivityParameters activityParams) {
IHandler handler = loadHandlerFromParameters(IReConstants.TRACEABILITY_LOCATION_HANDLER, activityParams);
if (handler == null) {
handler = createDefaultTraceabilityTransformationHandler();
handler = createDefaultTraceabilityLocationHandler();
}
context.put(IReConstants.TRACEABILITY_ATTACHMENT_HANDLER, handler);
context.put(IReConstants.TRACEABILITY_LOCATION_HANDLER, handler);
context.put(ITransitionConstants.TRACEABILITY_HANDLER, handler);
handler.init(context);
handler.init(context);

return Status.OK_STATUS;
}

/**
* Create default transformation traceability handler for common transition
* @return
*/
protected IHandler createDefaultTraceabilityTransformationHandler() {
return new CompoundTraceabilityHandler(new MatchConfiguration());
}

protected IHandler createDefaultTraceabilityLocationHandler() {
return new CompoundTraceabilityHandler(new LocationTraceabilityConfiguration());
}
/**
* Should compute scope
* ScopeHandlerHelper.getInstance(context).getScope should not be null
Expand Down

0 comments on commit 99e1b32

Please sign in to comment.