Hello all,
I am trying to create a Profile property that will list all DC Worksheet where the particular Safety mechanism is used. I searched through forum but did not find the answer to the problem i have been facing.
I am currently using Medini Analyze 22R1.1
I have started with JavaScript and also with OCL.
General strategy was to utilize mediniGetOpposites twice
- first navigate from safetyMechanims to a failureMode
- Second to navigate from a failure mode to a DCComponentEntry
--OCL - simplified approachusing null instead of 'spfSafetyMechanisms', 'mpfSafetyMechanisms'
-- Collects any medini object , filter only failure modes
-- collect opposites for every failure modes using 'element' ( FM included in DCFailureModeEntry)
self.mediniGetOpposites(null)->select(entry|entry.oclIsKindOf(safety::FailureMode))->collect(entry|entry.oclAsType(safety::FailureMode).mediniGetOpposites('element'))->asSet()->select(entry|entry.oclIsKindOf(dc::DCFailureModeEntry))->asSet()
->collect(entry|entry.oclAsType(dc::DCFailureModeEntry).component.worksheet)->asSet()
So far everything works the derived profile property will correctly display list of worksheet where this particular SM is used and it is also possible to use Select Elements using right mouse button context menu
Here comes the tricky/confusing part.
I would like to "write" this result into a SM Reference profile property with multiple DC Worksheet as element Type

To do so I was not able to find a working solution through Profile property as OCL/JavaScript.
Javascript
The only current working solution was to actually use designated JS script and then use "Execute" script on particular SM to use add/addAll List method.
Example of JS inside Derived profile property:
//JavaScript insideDerived Profile property user_dcsheets
var elements = self.mediniGetOpposites("spfSafetyMechanisms")
//add mpf safety mechanisms
elements.addAll(self.mediniGetOpposites("lmpfSafetyMechanisms"))
//crate a result list variable
var covered = elements.clone()
//cleanup of variable
covered.clear()
covered.shrink()
// 1st loop through medini elements
elements.toArray().forEach(function (covele,id){
if (covele.component == undefined) {
// test if current component is not a DCFailureModeEntry
// get opoosites 'element' and add any DCFailureModeEntry to current list
covele.mediniGetOpposites("element").toArray().forEach(function scanop(ele) {
test = getDCfromFMs(ele)
if (ele && ele instanceof Metamodel.dc.DCFailureModeEntry)) elements.add(ele)
}); // internal forech opposites of nnon DCFailureEnry mediniObjects
elements.remove(covele) //remove from original list
}
});
// 2nd lopping though modified list, scan for DC workshetts , get only unique records
elements.toArray().forEach(function (covele,id){
//check Metamodel type, and if he worksheet is not already added
if (covele instanceof Metamodel.dc.DCFailureModeEntry && covered.indexOf(covele.component.worksheet) == -1) {
covered.add(covele.component.worksheet)
}
});
elements
// add resutls into Refence profiel Property user_dcpick
if (covered.size()) self.user_dcpick.addAll(covered)
//dipslae the results in the current Derived profile property user_dcsheets
Outcome of previous JS is always getting a Java error :
java.lang.IllegalStateException: Cannot modify resource set without a write transaction
I could not post the OCL source as with my limited OCL knowledge I was not able to do what I wanted
I have got a lot of various OCL complaints regarding the target operations
(set/sequence/union/append ) and also the Meta-class was not matching expected dcWorksheet ( FMEA worksheet in result from interactive OCL).
In the end i did not now how to properly "convert" it to dc Worksheet or why this type mismatch was an issue
Excerpt from interactive OCL console
Evaluating:
self.user_dcpick.addAll(self.mediniGetOpposites(null)->select(entry|entry.oclIsKindOf(safety::FailureMode))->collect(entry|entry.oclAsType(safety::FailureMode).mediniGetOpposites('element'))->asSet()->select(entry|entry.oclIsKindOf(dc::DCFailureModeEntry))->asSet()->collect(entry|entry.oclAsType(dc::DCFailureModeEntry).component.worksheet) ->asSet())
Results:
Cannot find operation (addAll(Set(FMEAWorksheet))) for the type (DCWorksheet)
--------
--another trial trying with union,Bag
Evaluating:
self.user_dcpick.oclAsSet() ->asBag()->union(self.mediniGetOpposites(null)->select(entry|entry.oclIsKindOf(safety::FailureMode))
->collect(entry|entry.oclAsType(safety::FailureMode).mediniGetOpposites('element'))->asSet()->select(entry|entry.oclIsKindOf(dc::DCFailureModeEntry))->asSet()
->collect(entry|entry.oclAsType(dc::DCFailureModeEntry).component.worksheet))
Results:
Cannot find operation (union(Bag(FMEAWorksheet))) for the type (Bag(DCWorksheet))
----------------------------------------------
--abnother trial using set,union
Evaluating:
self.user_dcpick.oclAsSet() ->asSet()->union(self.mediniGetOpposites(null)->select(entry|entry.oclIsKindOf(safety::FailureMode))
->collect(entry|entry.oclAsType(safety::FailureMode).mediniGetOpposites('element'))->asSet()->select(entry|entry.oclIsKindOf(dc::DCFailureModeEntry))->asSet()
->collect(entry|entry.oclAsType(dc::DCFailureModeEntry).component.worksheet)->asSet())
Results:
Cannot find operation (union(Set(FMEAWorksheet))) for the type (Set(DCWorksheet))
The only working solution through external *.js file using Execute on selected SM element:
//designated *.js file , only working solution to write to a Reference proifle property
//selction[0] SafetyMechanism as selection object -> Execute
// write DC sheets ( user_dcsheets) into the Reference property (user_dcpick)
var sm=selection[0];
if (sm.user_dcsheets && sm].user_dccpick && sm.user_dcsheets.size()) {
sm.user_dcpick.addAll(sm.user_dcsheets)
} // property exists, some objects inside of the source property
Could please guide me and point to the things what I may be doing wrong ?
I have impression taht the OCL is simply more strict in terms of class type FMEAWorksheet vs. DCWorksheet. Or I am not using proper methods , i do know about add()*/addAll() OCL equivalent.
Is there a way how to get DC worksheet class object form DCComponentEntry? If not then the only solution would be in fact to set the Reference profile property to an FMEAWorksheet type.
Thanks & Regards,
Marian