How do you export generalized objects?

2
I’m performing A/B comparisons/validations between any two datasets (for example comparing csv to an excel). The user designs the validation via the ValidationConfig object. I have a need to move ValidationConfig objects between environments as well as duplicate them within the same environment. Being able to map the ValidationConfig with its DataSources and then export via a JSON document would solve both problems.   This is easy enough if I just want to export the ValidationConfig object. But I also want the associated DataSources. The difficulty is that the combination of data sources is unpredictable. For example I can’t know if the user is going to compare a CSV with a CSV, Excel with an Excel, or an Excel vs a CSV (this is a simplified version; there is also API and database datasources so there could be 4! combinations). Here you can see how I descend from ValidationConfig down to the DataSource using a message definition. This is where I’m concerned Mendix falls short. How can I map the potential generalizations to CSV or Excel? If I ascend back up starting from the CSV entity for example I only get the single one – and would somehow have to combine with another mapping.  Can anyone think of a way to leverage native Mendix functionality to dynamically export a ValidationConfig with the associated DataSources? Or do I just have to create a mapping for every possible eventuality.
asked
5 answers
1

Would the following work?

Create a new NPE called ExportedDataSource with the fields from all of the generalizations and specializations and an associated ExportedDataSources NPE.

Create the JSON structure below

{
    "Name": "",
    "ExportedDataSources": [
        {
            "Name": "",
            "Delimiter": "",
            "SheetName": ""
        }
    ]
}

Import mapping below

Mapping microflow and sub microflow below

Then you can set the fields on the ExportedDataSource based on the specialization. If the specialization is a CSV entity then set the ExportedDataSource.SheetName field to the CSV.SheetName field.

answered
1

It turns out Mendix can handle any number and combination of generalized, related objects. Unfortunately it doesn’t know how to do this via a message definition. So I created a JSON string like this (here you can see all 4 types (DB, API, CSV, and Excel)). Note that each data source expects a list. This allows for multiple for any data source but also is forgiving if there are none for any one data source (then it just generates an empty array [])

This allowed me to generate an export mapping pretty easily. I just had to add the generalized entities to each corresponding JSON object in the mapping (ignoring the empty objects it created). The import used the same JSON structure. Similarly (but slightly different) for the import I ignored the object name when selecting list elements.

answered
0

Not 4! but only 4^2 combinations. But still a problem.

What mapping does mendix studio pro generate when you create a message_definition, add entity DataSource to it and create a mapping via button Generate Mappings?

 

answered
0

Thanks for the feedback and correcting my math :) I did what you asked - certainly not what I expected - unfortunately I don't think this will help: 

I was also curious so I tried with CSV entity as well:

answered
0

If you’re not forced to use JSON, XML might be an option.

You can define an XML Schema with an xs:choice element. Then you can map the specialisations in an export mapping.

regards, Fabian

answered