Skip to content

Commit

Permalink
[2244] Impossible to migrate models due to corrupted aird/airdfragment
Browse files Browse the repository at this point in the history
models

in this commit we check if Drepresentation and DrepresentationDescriptor
are different of null and do the treatment.

Bug: 2244

Change-Id: If027be6f224aa68e77b452262af51b376d81c1f9
Signed-off-by: Joacquim Esabe <joacquim.esabe@laposte.net>
  • Loading branch information
Joacquim Esabe committed Oct 24, 2018
1 parent 267e4ca commit 2b9b637
Showing 1 changed file with 31 additions and 29 deletions.
Expand Up @@ -12,7 +12,6 @@

import java.util.HashMap;
import java.util.Map.Entry;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.emf.ecore.EObject;
Expand All @@ -34,30 +33,30 @@
*/
public class UidFromXmiIdContribution extends AbstractMigrationContribution {

HashMap<DRepresentation, String> representationToOriginalUidMap = new HashMap<>();
HashMap<String, DRepresentationDescriptor> originalRepPathToDescriptorMap = new HashMap<>();
HashMap<DRepresentation, String> representationToOriginalUidMap = new HashMap<>();
HashMap<String, DRepresentationDescriptor> originalRepPathToDescriptorMap = new HashMap<>();

@Override
public void dispose(MigrationContext context) {
super.dispose(context);
representationToOriginalUidMap.clear();
originalRepPathToDescriptorMap.clear();
}

@Override
public void updateElement(EObject peekObject, String typeName, EObject result, EStructuralFeature feature,
Resource resource, MigrationContext context) {
super.updateElement(peekObject, typeName, result, feature, resource, context);

// Store the original UID and representation of 1.2.x in a map in order to use later.
if (result instanceof DRepresentation ) {
if (result instanceof DRepresentation) {
DRepresentation representation = (DRepresentation) result;
String originalUid = representation.getUid();
if (originalUid != null) {
representationToOriginalUidMap.put(representation, originalUid);
}
}

// Store the original RepPath and descriptor of 1.2.x in a map in order to use later.
if (result instanceof DRepresentationDescriptor) {
DRepresentationDescriptor descriptor = (DRepresentationDescriptor) result;
Expand All @@ -68,19 +67,19 @@ public void updateElement(EObject peekObject, String typeName, EObject result, E
}
}
}

}

/**
* Migration from 1.2.x with x >= 1 only
* - In 1.2.0, it was still XMI:ID as a the reference for Representation. So there is no problem.
* Migration from 1.2.x with x >= 1 only - In 1.2.0, it was still XMI:ID as a the reference for Representation. So
* there is no problem.
*
* - Since 1.2.x, it has been UID as the reference for Representation. However, in Sirius migration,
* it always considers XMI:ID as the reference for Representation, so UID of each representation created in 1.2.x
* will be totally replaced.
* - Since 1.2.x, it has been UID as the reference for Representation. However, in Sirius migration, it always
* considers XMI:ID as the reference for Representation, so UID of each representation created in 1.2.x will be
* totally replaced.
*
* => In order to avoid so, we will RESET the uid of each representation in 1.3.0 to its own
* value in 1.2.x after the migration of sirius is finished.
* => In order to avoid so, we will RESET the uid of each representation in 1.3.0 to its own value in 1.2.x after the
* migration of sirius is finished.
*/
protected boolean isCompatibleVersion(MigrationContext context) {
Version currentVersion = context.getCurrentVersion();
Expand All @@ -94,7 +93,6 @@ protected boolean isCompatibleVersion(MigrationContext context) {
return false;
}


@Override
public void postMigrationExecute(ExecutionManager executionManager, ResourceSet resourceSet,
MigrationContext context) {
Expand All @@ -107,20 +105,24 @@ public void postMigrationExecute(ExecutionManager executionManager, ResourceSet
String originalUid = entry.getValue();
// In 1.2.x, Representation.Uid == Descriptor.repPath
DRepresentationDescriptor descriptor = originalRepPathToDescriptorMap.get(originalUid);

representation.setUid(originalUid);
new DRepresentationDescriptorToDRepresentationLinkManager(descriptor).setRepresentation(representation);
// This method updates the sirius CUSMTOM data "GMF_DIAGRAMS", which need to be corresponding
// with Respresentation.UID and Descriptor.repPath
// TODO: It is magic, not really understand!!
// Is there any more comprehensible and clearer API method for doing so?
((XMIResource)representation.eResource()).setID(representation, originalUid);

i++;

if (descriptor != null && representation != null) {
representation.setUid(originalUid);
new DRepresentationDescriptorToDRepresentationLinkManager(descriptor).setRepresentation(representation);
// This method updates the sirius CUSMTOM data "GMF_DIAGRAMS", which need to be corresponding
// with Respresentation.UID and Descriptor.repPath
// TODO: It is magic, not really understand!!
// Is there any more comprehensible and clearer API method for doing so?
((XMIResource) representation.eResource()).setID(representation, originalUid);

i++;
}
}

if (i > 0) {
IStatus status = new Status(IStatus.INFO, Activator.PLUGIN_ID, NLS.bind(org.polarsys.capella.core.data.migration.contribution.Messages.MigrationAction_UidMigration, context.getName(), i));
IStatus status = new Status(IStatus.INFO, Activator.PLUGIN_ID,
NLS.bind(org.polarsys.capella.core.data.migration.contribution.Messages.MigrationAction_UidMigration,
context.getName(), i));
Activator.getDefault().getLog().log(status);
}
}
Expand Down

0 comments on commit 2b9b637

Please sign in to comment.