Using Regex for Property Mapping
As mentioned in Using Regular Expressions for Class Mapping, the source data is in json format. The tables used for the examples are just a different kind of representation. The json object may be formatted like this:
Data
{ "items": [ { "id": "2", "name": null, "graphicalId": null, "properties": [ { "key": "UserLabel", "value": "P1.M1.T1-V109" }, { "key": "Class", "value": "2 way valve" }, { "key": "Dry Weight", "value": "42" } ] }, { "id": "3", "name": null, "graphicalId": null, "properties": [ { "key": "UserLabel", "value": "P20.H1.T3-V101" }, { "key": "Class", "value": "gate valve" }, { "key": "Empty weight", "value": "30" }, ] }, { "id": "4", "name": null, "graphicalId": null, "properties": [ { "key": "UserLabel", "value": "P20.H1.T3-V001" }, { "key": "Class", "value": "Ball valve" }, { "key": "Weight", "value": "19" }, ] } ], "maxPropertyCount": 3, "totalCount": 3, "totalErrorCount": 0, "totalMappedCount": 0, "totalSearchedCount": 0 }
Configuration
{ "id": 7, "name": "mapping 7", "importType": "smartExcel", "classKey": "Class", "columnHeaderIsPropertyName": true, "data": [ { selector": { "path": "$.items[*].properties[?(@.key==\"Class\")]", "regex": "^.*valve$" }, "ecClass": { "name": "BALL_VALVE", "fullName": "ProcessFunctional:BALL_VALVE" }, "mapping": [ { "path": "$.items[*].properties[*].key", "regex": "^.*(W|w)eight$", "target": "DRY_WEIGHT", } ] } ], }
This mapping configuration will map all entries with a "Class" property having a value ending with "valve" to EC class elements of class "BALL_VALVE". It will map the "UserLabel" property as it is named the same as the EC class property. It will also map every property ending with "weight" to the "DRY_WEIGHT" property of the EC class.