Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [Edapt] Can't get values in Custom Migration
[Edapt] Can't get values in Custom Migration [message #1780999] Wed, 31 January 2018 07:41 Go to next message
Felix Buehler is currently offline Felix BuehlerFriend
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



  • Attachment: formmodel.xmi
    (Size: 11.31KB, Downloaded 314 times)

[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 Go to previous messageGo to next message
Johannes Faltermeier is currently offline Johannes FaltermeierFriend
Messages: 101
Registered: December 2013
Senior Member

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/
Re: [Edapt] Can't get values in Custom Migration [message #1781285 is a reply to message #1781171] Mon, 05 February 2018 14:36 Go to previous messageGo to next message
Felix Buehler is currently offline Felix BuehlerFriend
Messages: 15
Registered: July 2017
Junior Member
Hi Johannes,

your assumptions were right and thanks a lot for the hint! You hit the nail!
What I had to do was getting all the values (not only the reference to the EAttributes) in the migrateBefore() and applying them in the migrateAfter(). That was the missing part in the migrateBefore():

value = metamodel.getEAttribute("forms.Vertex.value");
orderNumber = metamodel.getEAttribute("forms.Vertex.orderNumber");

for (Instance vertex : model.getAllInstances("forms.Vertex")) {

			String oldValue = vertex.unset(value);
			String oldOrderNumber = String.valueOf(vertex.unset(orderNumber));

			vertices.put(vertex, new String[] {oldValue, oldOrderNumber});

		}


All that's left now is migrate the graphiti-model. I'll have to dig into that.
Thank you very much!

Do you think we should adjust the library example to show that unsetting the values should be done in the migrateBefore() not in the migrateAfter()?

Cheers,
Felix
Re: [Edapt] Can't get values in Custom Migration [message #1781370 is a reply to message #1781285] Tue, 06 February 2018 14:17 Go to previous messageGo to next message
Maximilian Koegel is currently offline Maximilian KoegelFriend
Messages: 11
Registered: January 2017
Junior Member
Hi Felix,

good to hear it works for you now!
Johannes will get back to you next week about the potential documentation update.

Best regards,
Maximilian


--
get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/
Re: [Edapt] Can't get values in Custom Migration [message #1781810 is a reply to message #1781285] Tue, 13 February 2018 12:37 Go to previous message
Johannes Faltermeier is currently offline Johannes FaltermeierFriend
Messages: 101
Registered: December 2013
Senior Member

Hi,
yes I agree. I opened Bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=531096 to track this.
Cheers


Johannes Faltermeier

Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/
Previous Topic:EMFStore produce deployable WAR-File with Tycho
Next Topic:Model Explorer view reload
Goto Forum:
  


Current Time: Thu Apr 25 04:06:59 GMT 2024

Powered by FUDForum. Page generated in 0.04982 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top