Skip to content

Correct serialization so that reserialize Library works #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 7, 2023

Conversation

ftomassetti
Copy link
Contributor

I applied some changes to the serialization logic, some to the LionCore self definition and some to library-metamodel.json to ensure that reserializing this unserialized metamodel produce a JSON equivalent to the original JSON.

To verify the JSON is equivalent, even if not identical, I implemented some logic to compare the JSON and ignore irrelevant differences.

@@ -152,7 +152,7 @@ public static Metamodel getInstance() {
namespacedEntity.addFeature(Property.createRequired("qualifiedName", LionCoreBuiltins.getString(),
"LIonCore_M3_NamespacedEntity_qualifiedName").setDerived(true));

namespaceProvider.addFeature(Property.createRequired("namespaceQualifier", LionCoreBuiltins.getString(), "LIonCore_M3_NamespaceProvider_namespaceQualifier"));
namespaceProvider.addFeature(Property.createRequired("namespaceQualifier", LionCoreBuiltins.getString(), "LIonCore_M3_NamespaceProvider_namespaceQualifier").setDerived(true));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now aligned to the TS implementation

@@ -100,7 +101,7 @@ private JsonObject serializeThisNode(Node node) {
jsonObject.addProperty(ID_LABEL, node.getID());

JsonObject properties = new JsonObject();
node.getConcept().allProperties().forEach(property -> {
node.getConcept().allProperties().stream().filter(p -> !p.isDerived()).forEach(property -> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not serialize the derived features now.
I think we should actually serialize derived features, as the receiving part could not have the logic to calculate the values, so it is beneficial to send the derived value. I will disk this with @dslmeinte during the next meeting on serialization

@@ -16,13 +16,23 @@
"nNUEzZ7it7d2HoHPAtk5rGO4SsqVA3hAlBwkK1KP8QU",
"RDa_L8gbU8XgW9z46oMysBi1Hb7vjcS8O8LUgXlFpeU"
]
}
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I modified the JSON file always to include all the keys (containment, references, parent, etc.) based on LionWeb-io/specification#59. I assumed the same logic applied also to parent

"parent": "OcDK2GESljInG-ApIqtkXUoA2UeviB97u0UuiZzM0Hs"
},
{
"concept": "LIonCore_M3_Concept",
"id": "Pk1NRJfHMt4eSja2kpXia7x8vj6Vzc6WQCUzT3aVeYY",
"properties": {
"LIonCore_M3_NamespacedEntity_simpleName": "Library",
"LIonCore_M3_Concept_abstract": false
"LIonCore_M3_Concept_abstract": "false"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made sure that all property values are strings (see LionWeb-io/lionweb-typescript#38)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now _un_aligned with the TS-implementation, but we'll discuss this on Wednesday as well.

@ftomassetti ftomassetti requested a review from enikao February 6, 2023 14:26
@enikao
Copy link
Contributor

enikao commented Feb 6, 2023

I'm unsure about the experimental parts. They are not supported in the current MPS implementation, let's see if that breaks something.

Copy link
Contributor

@dslmeinte dslmeinte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had some questions/comments/suggestions, but don't have to be processed in this PR, necessarily.

"parent": "OcDK2GESljInG-ApIqtkXUoA2UeviB97u0UuiZzM0Hs"
},
{
"concept": "LIonCore_M3_Concept",
"id": "Pk1NRJfHMt4eSja2kpXia7x8vj6Vzc6WQCUzT3aVeYY",
"properties": {
"LIonCore_M3_NamespacedEntity_simpleName": "Library",
"LIonCore_M3_Concept_abstract": false
"LIonCore_M3_Concept_abstract": "false"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now _un_aligned with the TS-implementation, but we'll discuss this on Wednesday as well.

} else if (key.equals("properties")) {
assertEquivalentObjects(expected.getAsJsonObject("properties"), actual.getAsJsonObject("properties"), "Properties of " + context);
} else {
throw new UnsupportedOperationException(key);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think an AssertionError (or even just a RuntimeException) with a meaningful description along the line of pair ("${key}", ...) found in object but don't know what to assert about it would be helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I will fix it

private void assertEquivalentLionWebJson(JsonArray expected, JsonArray actual) {
Map<String, JsonObject> expectedElements = new HashMap<>();
Map<String, JsonObject> actualElements = new HashMap<>();
expected.forEach(e -> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that some FP-style DRY could happen here: lines 79&81-84 are really very similar to lines 80&85-88.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@ftomassetti ftomassetti merged commit 2ce908e into master Feb 7, 2023
@ftomassetti ftomassetti deleted the serializeLibrary branch March 14, 2023 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants