Transformation XText to Papyrus and vice versa [message #1835623] |
Wed, 09 December 2020 01:56 |
John Henbergs Messages: 239 Registered: October 2020 |
Senior Member |
|
|
Hi all,
I am trying to write transformation rules on ETL between a graphical UML model created with Papyrus using UML Profiles, and a textual model created through the grammar that I have defined on XText.
I first used a different approach. I created the UML Profile and XText grammar, and then I created an EMF model for these two. I created two different .etl files, for the following two transformations: graphical2textual and textual2graphical. These transformations were working fine and whenever I opened the coronagraphical.model or coronatextual. model (the two EMF models I created), I could see the changes after the transformation.
However, what I want to do is something different. After creating the UML Profile and writing the XText grammar, I dont want to create EMF models, but I want to create a UML model and an xtext model, and then run the transformations. So that is what I did. These are the steps I followed:
1. Write the DSML
2. Run a second Eclipse instance, and create the XText model.
3. Create a UML profile and a UML model.
4. Write the transformations.
5. Create the run configurations for both .etl files. Add the UML model as UML model and name it coronagraphical and add the XText model as EMF model and name it coronatextual.
6. Run the transformations.
Note: Steps 2-6 take place on the second instance on Eclipse.
Now the issue is that if I run the textual2graphical transformation, when I open the UML model I get the following window. It looks like the transformation is working but there are errors somehow.
If I run the graphical2textual transformation I get nothing. I wanted to check if I could see the changes from the transformation on ecore, so I opened the XText model using Sample Ecore Model Editor, but nothing happens there after I run the transformation.
Attached I am also providing the zip files of this project.
First instance - The files of the DSML I have written on the first instance
coronaepsilon - The files I have on the second instance that include the UML Profile, UML model, Xtext model and the transformation files.
Please let me know if you need further information.
Thank you
[Updated on: Wed, 09 December 2020 10:30] by Moderator Report message to a moderator
|
|
|
|
|
|
|
Re: Transformation XText to Papyrus and vice versa [message #1835639 is a reply to message #1835637] |
Wed, 09 December 2020 10:29 |
|
Hi Malvina,
The problem seems to be the input UML model (corona.uml). If you open it with the built-in tree-based editor, right-click on its root and select "Validate", EMF validation should report several errors (see attached). Once you have fixed these, please try to run the transformation again and let me know if the problem persists.
Thanks,
Dimitris
|
|
|
Re: Transformation XText to Papyrus and vice versa [message #1835650 is a reply to message #1835639] |
Wed, 09 December 2020 13:32 |
John Henbergs Messages: 239 Registered: October 2020 |
Senior Member |
|
|
Hi Dimitris,
I made a few changes and I am uploading the zip files once again. When I run the model validation now, I get no errors.
I believe that transformation does happen, but I do not know where to check that. Whenever I tried the graphical2textual transformation with the first approach, I could see the changes reflected on my EMF model, because I did not write the DSL model on Xtext but I created an EMF model. However, now I cannot see any changes.
The reason why I say that I believe that the transformation does take place is because if i run the other transformation, textual2graphical, I get this error.
So that means that four stereotypes are created on the graphical model because I have four of them on the textual one (one world map and three countries).
So my first question is, how can I fix this? Do I need to change the transformation rules and hardcode the profile definition for each of these stereotypes? If so, do you have any idea on how that can be done?
Second thing is regarding the graphical2textual transformation.
I understand that this transformation also takes place because after running the textual2graphical transformation mentioned above and getting 4 dangling stereotypes, I try to run the graphical2textual transformation and then once again textual2graphical.
Now I get 8 dangling stereotypes, which means that the graphical2textual transformation also works. However, I do not know where to see the ones that have been added. When I open the XText file with sample ecore model editor, I only get the ones that I have written myself on XText, not the ones added by the transformation.
Any idea about this?
|
|
|
Re: Transformation XText to Papyrus and vice versa [message #1835653 is a reply to message #1835650] |
Wed, 09 December 2020 14:14 |
|
The issue with the graphical2textual transformation seems to be that world maps do not get connected to countries in the target model (and therefore Xtext refuses to serialise them). Updating your graphical2textual.etl transformation as follows seems to be doing the trick. If you open your UML model with a text editor you will notice three instances of WorldMap and several copies of the same countries - which should be cleaned up and then you shouldn't need the guard of the first rule. Please note that in the configurations of your transformations, only the "Read on load" option should be selected for the source model, and only the "Store on disposal" option should be selected for the target model.
rule WorldMap2Worldmap
transform g: coronagraphical!WorldMap
to t: coronatextual!WorldMap {
guard: g.base_Package != null
t.name = g.name;
t.country ::= g.getCountries();
}
// transformation rule for object country
rule Country2Country
transform g: coronagraphical!Country
to t: coronatextual!Country {
t.name = g.name;
t.population = g.population;
t.zone = g.zone.getzone();
}
//operation for enumeration zonelabel
operation Any getzone() {
if (self == coronagraphical!zonelabel#green) {
return coronatextual!zonelabelcolour#green;
}
else if (self = coronagraphical!zonelabel#red) {
return coronatextual!zonelabelcolour#red;
}
else {
return coronatextual!zonelabelcolour#yellow;
}
}
operation coronagraphical!WorldMap getCountries() {
return coronagraphical!Country.all.select(c|self.base_Package.
packagedElement.includes(c.base_Component));
}
Thanks,
Dimitris
[Updated on: Wed, 09 December 2020 14:20] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Transformation XText to Papyrus and vice versa [message #1835820 is a reply to message #1835817] |
Mon, 14 December 2020 09:34 |
|
The solution I suggested was for the profiled UML model (coronagraphical). Adding the following pre-block to your textual2graphical.etl transformation prints the expected result, which indicates that your textual model is loaded and processed without issues.
pre {
coronatextual!WorldMap.all.first().println();
}
Given that we may need to go back and forth a few more times on this, could you please put your minimal example in a public GitHub repo so that I can fetch your updates without needing to delete/re-import the projects in every iteration?
Thanks,
Dimitris
|
|
|
|
|
|
Re: Transformation XText to Papyrus and vice versa [message #1835871 is a reply to message #1835846] |
Tue, 15 December 2020 14:56 |
|
In the first rule of your textual2graphical.etl transformation you should create a UML package (or model) instead of a WorldMap and in the body you should apply the WorldMap stereotype to it as follows (the 2nd rule should be updated accordingly). You also need to add another CoronaProfile model to your run configuration, which points at your corona.profile.uml profile.
rule WorldMapT2WorldMapG
transform s: Coronatextual!WorldMap
to t: Coronagraphical!Model {
//get hold of the profile
var profile = CoronaProfile!Profile.all.first();
//get hold of the model
t.applyProfile(profile);
//get hold of the stereotype WorldMap
var worldMapStereotype = profile.getPackagedElement("WorldMap");
//apply the stereotype to the model
var worldMap = t.applyStereotype(worldMapStereotype);
worldMap.name=s.name;
}
If you could grant me write access to your repo (my GitHub id is @kolovos) I can push the changes directly.
Thanks,
Dimitris
|
|
|
|
Re: Transformation XText to Papyrus and vice versa [message #1835873 is a reply to message #1835871] |
Tue, 15 December 2020 15:14 |
|
Fixed in https://github.com/TRworkspace/EpsilonTransformation/commit/2dfb5c036c0f13d314c3ff44f41868ce0efb1469. The complete transformation is below for anyone else to whom this might be useful in the future.
rule WorldMapT2WorldMapG
transform s: Coronatextual!WorldMap
to t: Coronagraphical!Model {
//get hold of the profile
var profile = CoronaProfile!Profile.all.first();
//get hold of the model
t.applyProfile(profile);
//get hold of the stereotype WorldMap
var worldMapStereotype = profile.getPackagedElement("WorldMap");
//apply the stereotype to the model
var worldMap = t.applyStereotype(worldMapStereotype);
worldMap.name=s.name;
// Get hold of the EPackage representation of the profile
var profileEPackage = t.profileApplications.first().appliedDefinition;
// ... and add it to the package registry of our UML model
Coronagraphical.resource.resourceSet.packageRegistry.
put(profileEPackage.nsURI, profileEPackage);
}
rule Country2CountryComponent
transform s: Coronatextual!Country
to t: Coronagraphical!Component {
// Add the component as a child of the model
// produced by its world map
s.eContainer().equivalent().packagedElement.add(t);
//get hold of the profile
var profile = CoronaProfile!Profile.all.first();
//get hold of the stereotype Country
var countryStereotype = profile.getPackagedElement("Country");
//apply the stereotype to the Component
var country= t.applyStereotype(countryStereotype);
country.name=s.name;
country.population=s.population;
country.zone = s.zone.getZone();
}
//operation for enumeration zonelabel
operation Any getZone() {
if (self == Coronatextual!zonelabelcolour#green) {
return Coronagraphical!zonelabelcolour#green;
}
else if (self = Coronatextual!zonelabelcolour#red) {
return Coronagraphical!zonelabelcolour#red;
}
else {
return Coronagraphical!zonelabelcolour#yellow;
}
}
Thanks,
Dimitris
|
|
|
Re: Transformation XText to Papyrus and vice versa [message #1835874 is a reply to message #1835873] |
Tue, 15 December 2020 15:16 |
|
> Is there a specific reason for that? On why should I create another model, when also my former graphical model points to the same profile?
As the "Read on load" option of your target UML model is (rightly) not ticked in the run configuration of textual2graphical, its existing contents are ignored.
Thanks,
Dimitris
|
|
|
|
|
|
|
|