This first example covers the following features:
- Creation of a Rule Model
- Relations Parent Of and Child Of
- Generation of the Rule File
- Import/export with the Model Gateway
- Update of the target model using the Model Gateway
The inputs for this example are:
- An empty target model with a specific type diagram
- The Excel file which you can see below
- The Rule Maker template : Model Gateway RuleMaker V10.arkz
Preparing the target model
Start by creating a new
Note that the ActionPanel and Action types are only here to facilitate the execution of import and export scripts. After setting up the the type diagram, create an 'all' treeview (i.e. a treeview where all elements are checked). In this treeview create an ActionPanel object with two Action objects named Import and Export.
Copy the following program to the script attribute of Import:
Finally copy this second program to the script attribute of Export:
Our target model is now ready.
Preparing the Rule Model and Rule File
Create a copy of the Rule Model template (also known as the Rule Maker Model).
The Rule Model contains three views:
- The 'all' view which contains all Rule Model definitions using for export and import
- The 'Perform Export' view contains Rule Model definitions allowed for exporting
- The 'Perform Import' view contains Rule Model definitions allowed for importing
In the view above you can create an object of type WorkBook which will contains the objects of type Sheet. This WorkBook object has four attributes:
- 'Create Rule File': generates the Rule File from the Rule Model
- 'Description' : allows to specify a description of the WorkBook
- 'Init Rule Model from Excel File': create the skeleton of the Rule Model from an Excel file
- 'Init Rule Model from XSD File': create the skeleton of the Rule Model from an XSD file
First create a new WorkBook object in one the view above depending whether you want to perform an Import or an Export. From the WorkBook object attributes launch the 'Init Rule Model from Excel File' script selecting the sample Excel file when requested. Then go into the WorkBook object just created where the script should have created a Sheet object named countries (like the Excel sheet) and four Column objects below it. The script sets the columnName attribute of each of the Column with the title of the columns in the Excel file (note that the name of the Column objects is not important but columnName must be correctly set). In the view 'all' and 'Perform Export' the script also generates Display Before links between the column to represent their order in the Excel file.
In the next steps we will configure the Column objects and add relations between them. The screenshot below shows the final resulting Rule Model inside the Sheet Countries.
Rule Model configuration steps:
- Add a Root object in the Countries Sheet object, this object represents the root of the
- Add new ArkType objects Country and City respectively to the columns 'country' and 'city'. The ArkType objects represents the types of the target model type diagram. Columns which contain ArkType objects are referred as Rule Columns, those without ArkType objects are always Attribute Columns.
- Create the relation flows between the objects as pictured in the screenshot above (note that even though some flows appear to have the same name, those are actually different objects). Those relations are the same as the ones in the target model type diagram, indeed root is the parent of Country which itself is a parent of City, and both is capital and population are attributes of City.
- Ensure that 'country' and 'city' columns both have their contentType attribute set to Name. This tells the Model Gateway to consider that the column content is the name of the
- Set the contentType of both is capital and population columns to Attribute# and set their contentId attribute respectively to 'is capital' and 'population'. This tells the Model Gateway that the content of those two columns will be respectively the value of attribute 'is capital' and 'population' of the City objects.
Finally run the 'Create Rule File' script from the WorkBook object in order to generate the Rule File from the model.
The import and the export take place in the target model where we have already created the Import and Export scripts.
Execute the Import script:
- at the first Open File dialog, select the Rule File you have generated
- at the second Open File dialog select the Excel File to be imported.
You should get the following result (the Country objects have been expanded except China which does not have any children):
To export the model data in the same file format, run the Export script and select the Rule File at the File Open dialog. The Model Gateway will open Excel and create a new workbook with the exported data. To actually save the data to an Excel file, you need to use the Save command in Excel.
To update the target model with new data, you simply need to perform an other import as described in the import section. The update creates new objects found in the Excel file and update modified attribute values. It cannot remove objects or relations between objects. For example this second Excel File will update the population of Marseilles and create the following new objects: Beijing, Korea, Seoul.