Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamille Letavernier2015-02-17 08:20:10 -0500
committerCamille Letavernier2015-02-17 08:20:10 -0500
commit471ad410fcaa6b541dca7496602d6b5f55d5de87 (patch)
tree6d4e7b914a7d09d27688833485d2814e0aa0cbbd
parent75d5c7f94022fa3005e0ab70e9a4a9daf69749de (diff)
downloadorg.eclipse.papyrus-471ad410fcaa6b541dca7496602d6b5f55d5de87.tar.gz
org.eclipse.papyrus-471ad410fcaa6b541dca7496602d6b5f55d5de87.tar.xz
org.eclipse.papyrus-471ad410fcaa6b541dca7496602d6b5f55d5de87.zip
458515: [Model Import] Importing RSA model does no longer migrate
applied profiles https://bugs.eclipse.org/bugs/show_bug.cgi?id=458515 - Move some mandatory code from the Optional URI Mapping Dialog to the Transformation Launcher, to ensure it is always executed
-rw-r--r--extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/transformation/DependencyAnalysisHelper.java81
-rw-r--r--extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/transformation/ImportTransformationLauncher.java5
-rw-r--r--extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/transformation/ui/URIMappingDialog.java82
3 files changed, 93 insertions, 75 deletions
diff --git a/extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/transformation/DependencyAnalysisHelper.java b/extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/transformation/DependencyAnalysisHelper.java
index aefbde7628d..033ab051ba1 100644
--- a/extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/transformation/DependencyAnalysisHelper.java
+++ b/extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/transformation/DependencyAnalysisHelper.java
@@ -14,6 +14,8 @@ package org.eclipse.papyrus.migration.rsa.transformation;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
@@ -31,6 +33,7 @@ import org.eclipse.emf.ecore.xmi.XMLResource;
import org.eclipse.emf.ecore.xml.type.AnyType;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.papyrus.migration.rsa.RSAToPapyrusParameters.Config;
+import org.eclipse.papyrus.migration.rsa.RSAToPapyrusParameters.MappingParameters;
import org.eclipse.papyrus.migration.rsa.RSAToPapyrusParameters.RSAToPapyrusParametersFactory;
import org.eclipse.papyrus.migration.rsa.RSAToPapyrusParameters.URIMapping;
import org.eclipse.papyrus.migration.rsa.concurrent.ThreadSafeResourceSet;
@@ -390,4 +393,82 @@ public class DependencyAnalysisHelper {
URI proxyURI = EcoreUtil.getURI(proxy);
return findExistingMapping(proxyURI, resourceSet);
}
+
+ /** Propagates the URI Mappings to all duplicates */
+ public void propagateURIMappings(List<URIMapping> allMappings, MappingParameters result) {
+ for (URIMapping mapping : allMappings) {
+ for (URIMapping uriMapping : result.getUriMappings()) {
+ if (uriMapping.getSourceURI().equals(mapping.getSourceURI())) {
+ uriMapping.setTargetURI(mapping.getTargetURI());
+ }
+ }
+
+ for (URIMapping profileURIMapping : result.getProfileUriMappings()) {
+ if (profileURIMapping.getSourceURI().equals(mapping.getSourceURI())) {
+ profileURIMapping.setTargetURI(mapping.getTargetURI());
+ }
+ }
+ }
+ }
+
+ public List<URIMapping> flattenURIMappings(MappingParameters result) {
+ List<URIMapping> allMappings = new LinkedList<URIMapping>();
+ allMappings.addAll(result.getUriMappings());
+ allMappings.addAll(result.getProfileUriMappings());
+
+ removeDuplicates(allMappings);
+
+ return allMappings;
+ }
+
+ /**
+ * Remove duplicate mappings. Mappings are duplicate if they have the same SourceURI.
+ * Less specific mappings will be discarded (Usually, the ones with the same Source and Target URI)
+ */
+ protected void removeDuplicates(List<URIMapping> allMappings) {
+ List<URIMapping> mappingsCopy = new LinkedList<URIMapping>(allMappings);
+
+ for (URIMapping mapping : mappingsCopy) {
+ for (URIMapping m : allMappings) {
+ if (m == mapping) {
+ continue;
+ }
+
+ // This is a duplicate
+ if (mapping.getSourceURI().equals(m.getSourceURI())) {
+ // If both mappings are still present, remove one of them
+ if (allMappings.contains(mapping) && allMappings.contains(m)) {
+ URIMapping mappingToRemove = findLessSpecificMapping(mapping, m);
+
+ allMappings.remove(mappingToRemove);
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * If 2 mappings have the same sourceURI but different targetURI, returns the less pertinent one
+ * (Usually, the one with the same Source and Target)
+ *
+ * @param mapping1
+ * @param mapping2
+ * @return
+ */
+ protected URIMapping findLessSpecificMapping(URIMapping mapping1, URIMapping mapping2) {
+ if (!isUsefulMapping(mapping1)) {
+ return mapping1;
+ }
+
+ return mapping2;
+ }
+
+ protected boolean isUsefulMapping(URIMapping mapping) {
+ if (mapping.getTargetURI() == null || "".equals(mapping.getTargetURI()) || mapping.getTargetURI().equals(mapping.getSourceURI())) {
+ return false;
+ }
+
+ return true;
+ }
}
diff --git a/extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/transformation/ImportTransformationLauncher.java b/extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/transformation/ImportTransformationLauncher.java
index 25f6ac781f5..fe9df8ca7c1 100644
--- a/extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/transformation/ImportTransformationLauncher.java
+++ b/extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/transformation/ImportTransformationLauncher.java
@@ -655,6 +655,9 @@ public class ImportTransformationLauncher {
}
protected MappingParameters confirmURIMappings(final MappingParameters mappingParameters) {
+ List<URIMapping> flatMappings = analysisHelper.flattenURIMappings(mappingParameters);
+ analysisHelper.propagateURIMappings(flatMappings, mappingParameters);
+
if (config.isAlwaysAcceptSuggestedMappings()) {
return mappingParameters;
}
@@ -676,7 +679,7 @@ public class ImportTransformationLauncher {
protected MappingParameters openMappingsDialog(final MappingParameters mappingParameters) {
final Shell shell = baseControl.getShell();
- SelectionDialog dialog = new URIMappingDialog(shell, mappingParameters);
+ SelectionDialog dialog = new URIMappingDialog(shell, mappingParameters, analysisHelper);
dialog.open();
return (MappingParameters) dialog.getResult()[0];
diff --git a/extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/transformation/ui/URIMappingDialog.java b/extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/transformation/ui/URIMappingDialog.java
index 687c0296aca..cef8939a647 100644
--- a/extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/transformation/ui/URIMappingDialog.java
+++ b/extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/transformation/ui/URIMappingDialog.java
@@ -47,6 +47,7 @@ import org.eclipse.papyrus.infra.widgets.providers.WorkspaceContentProvider;
import org.eclipse.papyrus.migration.rsa.Activator;
import org.eclipse.papyrus.migration.rsa.RSAToPapyrusParameters.MappingParameters;
import org.eclipse.papyrus.migration.rsa.RSAToPapyrusParameters.URIMapping;
+import org.eclipse.papyrus.migration.rsa.transformation.DependencyAnalysisHelper;
import org.eclipse.papyrus.uml.extensionpoints.IRegisteredItem;
import org.eclipse.papyrus.uml.extensionpoints.Registry;
import org.eclipse.swt.SWT;
@@ -83,9 +84,12 @@ public class URIMappingDialog extends SelectionDialog {
private static final int BROWSE_PROFILES_ID = IDialogConstants.CLIENT_ID + 3;
List<URIMapping> allMappings;
+
+ final DependencyAnalysisHelper dependencyHelper;
- public URIMappingDialog(Shell shell, MappingParameters mappingParameters) {
+ public URIMappingDialog(Shell shell, MappingParameters mappingParameters, DependencyAnalysisHelper dependencyHelper) {
super(shell);
+ this.dependencyHelper = dependencyHelper;
this.mappingParameters = mappingParameters;
}
@@ -170,11 +174,7 @@ public class URIMappingDialog extends SelectionDialog {
}
});
- allMappings = new LinkedList<URIMapping>();
- allMappings.addAll(result.getUriMappings());
- allMappings.addAll(result.getProfileUriMappings());
-
- removeDuplicates(allMappings);
+ allMappings = dependencyHelper.flattenURIMappings(result);
viewer.setInput(allMappings);
@@ -191,57 +191,6 @@ public class URIMappingDialog extends SelectionDialog {
return self;
}
- /**
- * Remove duplicate mappings. Mappings are duplicate if they have the same SourceURI.
- * Less specific mappings will be discarded (Usually, the ones with the same Source and Target URI)
- */
- protected void removeDuplicates(List<URIMapping> allMappings) {
- List<URIMapping> mappingsCopy = new LinkedList<URIMapping>(allMappings);
-
- for (URIMapping mapping : mappingsCopy) {
- for (URIMapping m : allMappings) {
- if (m == mapping) {
- continue;
- }
-
- // This is a duplicate
- if (mapping.getSourceURI().equals(m.getSourceURI())) {
- // If both mappings are still present, remove one of them
- if (allMappings.contains(mapping) && allMappings.contains(m)) {
- URIMapping mappingToRemove = findLessSpecificMapping(mapping, m);
-
- allMappings.remove(mappingToRemove);
- break;
- }
- }
- }
- }
- }
-
- /**
- * If 2 mappings have the same sourceURI but different targetURI, returns the less pertinent one
- * (Usually, the one with the same Source and Target)
- *
- * @param mapping1
- * @param mapping2
- * @return
- */
- protected URIMapping findLessSpecificMapping(URIMapping mapping1, URIMapping mapping2) {
- if (!isUsefulMapping(mapping1)) {
- return mapping1;
- }
-
- return mapping2;
- }
-
- protected boolean isUsefulMapping(URIMapping mapping) {
- if (mapping.getTargetURI() == null || "".equals(mapping.getTargetURI()) || mapping.getTargetURI().equals(mapping.getSourceURI())) {
- return false;
- }
-
- return true;
- }
-
@Override
public boolean close() {
try {
@@ -369,27 +318,12 @@ public class URIMappingDialog extends SelectionDialog {
@Override
protected void okPressed() {
- propagateURIMappings();
+ dependencyHelper.propagateURIMappings(allMappings, result);
setResult(Collections.singletonList(result)); // Set the new result
super.okPressed();
}
- /** Propagates the URI Mappings to all duplicates */
- protected void propagateURIMappings() {
- for (URIMapping mapping : allMappings) {
- for (URIMapping uriMapping : result.getUriMappings()) {
- if (uriMapping.getSourceURI().equals(mapping.getSourceURI())) {
- uriMapping.setTargetURI(mapping.getTargetURI());
- }
- }
-
- for (URIMapping profileURIMapping : result.getProfileUriMappings()) {
- if (profileURIMapping.getSourceURI().equals(mapping.getSourceURI())) {
- profileURIMapping.setTargetURI(mapping.getTargetURI());
- }
- }
- }
- }
+
private class URIColumnsLabelProvider extends ColumnLabelProvider {

Back to the top