Since 2019 R2 there is another, yet unknown area where scripting becomes interesting. In that version the integration support for ALM/PLM and RM systems was improved in the way, that the rather static mapping between RM system and medini can be enriched with dynamic parts and these dynamic parts are small java script snippets.
Mappings
As you may know, a so called "mapping definition" is used when importing or exporting from a requirement management system as DOORS, PTC or Jama. The mapping definition consist of type, attribute and relation mappings in order to cope with the diversity of configurations in those systems. Each mapping typically maps a remote concept (type, attribute or relation) to a medini concept (type/metaclass, attribute or relation). The mapping is defined in an XML file:
<typeMappings
mediniType="SafetyRequirementsModel"
mappedType="Requirement Document">
<attributeMappings
mediniAttribute="name"
mappedAttribute="Document Short Title"/>
</typeMappings>
Selectors
The mappings are fine but lack some dynamic decisions, like "ignore all requirements with ASIL < D" or "only import elements with a certain tag/term". To support that the mappings where enriched with what we call "selectors", basically an expression that has to evaluate to "true" to "select the mapping". Consequently, it is now possible to define multiple mappings, even for the same type. The connector will iterate through the mappings in order of appearance in the file and will use the first mapping that either has no selector defined or that has a selector returning "true".
<typeMappings
mediniType="SafetyRequirementsModel"
mappedType="Goal Document">
<attributeMappings
mediniAttribute="name"
mappedAttribute="Document Short Title"
mappedSelector="false" />
</typeMappings>
<typeMappings
mediniType="SafetyRequirementsModel"
mappedType="Requirement Document">
<attributeMappings
mediniAttribute="name"
mappedAttribute="Document Short Title"
mappedSelector="true" />
</typeMappings>
The selector expression is a Java Script snippet that is evaluated against the imported element or the exported element. In both cases the snippet may investigate the element or navigate through the model and - depending on that investigation - return true or false.
Connector Specific Selectors
Now its time to have a closer look to the selector snippets. The engine will pass the element as "element" into the snippet, so the script cod may access the attributes and relations of the object to import (a DNG or Jama item) or the exported element (a medini object). For export its easy because the API is the same as for any other script. However, for import the API depends heavily on the connector. In this article I will give some more details on the PTC Integrity connector and post some helper code and snippet. In further articles or if there is some interest, I can also post snippets for DNG and Jama
PTC Integrity
The medini integration for PTC Integrity is based on software from Sodius, a company hat is specialized in connecting tools, especially ALM/PLM tools. As a result the API is defined by Sodius in alignment with the way how PTC Integrity is build. All artifacts in PTC are basically "Items" having attribute values. The complete API is based on EMF, same as medini so the behavior is pretty much the same when it comes to access to attributes and prototypes. I prepared an initial file that can be included and used in a snippet. It provides a single function "hasAnyValue" that checks for a particular attribute in the element, and verifies that the current value is one of a given set of values. The mentioned file is attached to this article, same for the example mapping. It may evolve into a kind of library in the future.
The selector example could look like this:
<typeMappings
mediniType="SafetyRequirement"
mappedType="Requirement"
mappedSelector="load('integrity.js'); hasAnyValue(element, 'ASIL', [ 'D', 'C' ] );">
...
This selector ensures that only ASIL D and C requirements are imported, assuming that in PTC there is an attribute name "ASIL". Note the usage of ' instead of " - because the snippet itself is enclosed in " characters in the XML. Note also the "load" function call at the beginning to load the library script in front.
Last note is that the library file has to be located near the mapping file and not in the default scripting location.
Any comment is welcome!
Happy Scripting
Jan