Dear,
You may encounter a situation when you though "I wish I could have an OLC/AQL" available in the JS.
In medini analyze the basic scripted execution handles every script file /profile property based on the configured extension ( js/ocl/aql).
Typical use case where you would like to have some debugg of an OCL/AQL:
- ocl snippets to be placed within a Constraint/ocl derived property
- aql statements in the m2doc or a AQL based derived profile property
- simpler code construct in ocl/aql to achieve the same goal in JS
Good news, with 26R1 you can now acces the ocl/aql scripting languaesd and evaluate any piece of code.
With experimental pragma you will find evaluate as a global function next to the others like load, bind
the evaluate function
The function signature is:
Object evaluate(String codeToEval, String language, Object context)
- codeToEvaluate - Mandatory, put your desired code snippet here
- language - Optional can be ocl, aql, or js [DEFAULT]
- context - Optional, can be any JS Object , or any EMF Object (medini object) or just nothing
Little bit on the context.
Its purpose is to provide a way to inject variables as an input to the evaluation.
If a simple JS Object is provided it will be accessible through self
evaluate("projectmodel::PJPackage","ocl") ;=>returns PJPackage EMF class
JS Object as a context
evaluate("self","ocl",Object.keys(this)) ;=>returns the array of keys
EMF Object as a context
evaluate("self","ocl",finder.project) ;=>returns the mediniProject of the finder
JS Scriptable as context
evaluate("Sequence{self.name,myNum,myString}","aql", {self:finder.project,myNum:1,myString:"hello"} ;=>returns the ArrayList of all variables
Note: the AQL language has some medini AQL services from m2doc, except of those handling image and documents, etc.
- Services present: List, Map, Date, Number, Checklist, Counter, Platform
IMPORTANT:If you want to use some cross-referencing/navigation functions to find traced, children, parent ,nested objects make sure you either have an EMF object , or the Scriptable object with self:EMFObject as a context argument.
Example:
find all direct children of a SysMLPart, a finder with level 1
evaluate("self.eContents(sysml::SysmlPart)","aql",myScopeObject)
find all children specific type , regular finder
evaluate("self.eAllContents(sysml::SysmlPart)","aql",myScopeObject)
get all parents
evaluate("self->closure(g|g.eContainer())","aql",myScopeObject)
Advanced examples & cases
Find all diagrams for a given EMF object, not easyily obtainable by a plain JS finder
evaluate("notation::Shape.allInstances()->select(sh|sh.element = self).diagram->asSet()", "aql",myEMFObj)
Find all medini project OCL dynamic Constraints
evaluate("OCLConstraints::Constraint","aql",myScopeObject)
More details will be posted under this topic
Marian