[Edapt] Can't get values in Custom Migration [message #1780999] |
Wed, 31 January 2018 07:41 |
Felix Buehler Messages: 15 Registered: July 2017 |
Junior Member |
|
|
Hi there!
I'm stuck at a custom migration and hope to find help here. These are the steps I took so far:
- Attach a Custom Migration to 2 Delete-Operations
- implement the migrateBefore and migrateAfter-Methods as shown in the library example (https://www.eclipse.org/edapt/libraryexample.php#custom)
- call the unset() on our model instance
- try to set the obtained value in a new model instance
My migrateBefore():
public void migrateBefore(Model model, Metamodel metamodel) throws MigrationException {
value = metamodel.getEAttribute("forms.Vertex.value");
orderNumber = metamodel.getEAttribute("forms.Vertex.orderNumber");
}
My migrateAfter():
public void migrateAfter(Model model, Metamodel metamodel) throws MigrationException {
for (Instance vertex : model.getAllInstances("forms.Vertex")) {
String oldValue = vertex.unset(value);
Integer oldOrderNumber = vertex.unset(orderNumber);
Instance dimensionPoint = model.newInstance("forms.DimensionPoint");
dimensionPoint.set("value", oldValue);
dimensionPoint.set("orderNumber", oldOrderNumber);
vertex.set("dimensionPoint", dimensionPoint);
}
}
What I'm trying to do is move the "value"- and "orderNumber"-Attributes from the "Vertex" to a new instance named "DimensionPoint" which is a reference of the Vertex. The code runs fine but the "oldValue" and "oldOrderNumber" are null so that the migration doesn't work in the end.
I have attached the model which is saved temporarily during migration.
Another question would be how to migrate the graphiti elements that are contained in our model. As far as I understand I would have to specify the necessary migrations in the migrateAfter, too. Any suggestions on this?
Thank you so much in advance!
Cheers,
Felix
[Updated on: Wed, 31 January 2018 07:45] Report message to a moderator
|
|
|
Re: [Edapt] Can't get values in Custom Migration [message #1781171 is a reply to message #1780999] |
Fri, 02 February 2018 09:34 |
|
Hi Felix,
First of all, have a look at the "Fold Class" Operation, because as far as I understood, it provides what you want and so removes the need for the custom migration:
https://www.eclipse.org/edapt/org.eclipse.emf.edapt.declaration.delegation.DelegationOperations.php#extractExistingClass
Regarding your migration code. I can't tell what is going on without the ecore and history, because I don't know to which changes the custom migration is attached. I assume that it is attached to the removal of the value and orderNumber features. So when migrateAfter is called the metamodel was changed already and this could explain that oldValue and oldOrderNumber are null. So you could try to read those attributes in the migrateBefore method and store them in a map from vertex-Instance to value and in migrate after use the values from the map.
Regarding Graphiti, all I can say here is that migrateBefore is called before the Ecore changes have been made and migrateAfter is called after the Ecore changes have been made. So reading values from the old model usually has to be done in migrateBefore and changing the model with the new metamodel has to be done in migrateAfter.
I hope this helps!
Cheers,
Johannes
Johannes Faltermeier
Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04379 seconds