Skip to end of metadata
Go to start of metadata

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:

Preparing the target model

Start by creating a new arKItect project and setup the type diagram as below:

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.

Icon

Note that there are two different projects open in two arKItect applications : the first one "Target model" (see above) and in the second one "Rule model" (see below).

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 arKItect model.
  • 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 arKItect object.
  • 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.

Why some _contentType_ values end with a sharp # character ?

Icon

ContentType values ending with a sharp # character require the contentId attribute to be set. For other contentType values, contentId should remain empty.

On the Importance of the relations sense

Icon

The sense of the relations between the Rule Columns (like Parent Of, Producer Of, ...) indicate the Model Gateway the order in which it shall search for the corresponding items. In our current sample, the Model Gateway will start its search at the root, then will look for all children of type Country under the root, then for each found country it will look for children of type City.

This has an important impact on the export process (it also plays a lesser role in the import process as the import relies on export for its key identification mechanism). In our example it means that a Country object without any City child will be exported, but (supposing the type diagram did allow it) no City object which is not a child of a Country object will be exported. Also the Parent Of relation between Root and Country means that only Country object which are children of the Root will be exported.

Icon

The Rule model defines to import/export rules between the Target model and the Excel file. The table below shows the equivalence between Arki Objects in Rule model and Excel.

Sheet and Column in Rule model must have the same name as their counterpart in Excel ! Otherwise the Model Gateway won't find any match and no import nor export can be performed.

Importing

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):

Exporting

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.

Updating

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.

  • No labels