Elements related outside of a given View

Started by malcolm_t_evans, June 05, 2020, 05:32:51 AM

Previous topic - Next topic

malcolm_t_evans

I'm trying to write a script which steps though all the elements in a given view to determine the number of specific elements that are related but not contained within a given view.

For example, I have a business capability reference model (a view)which simply contains a number of capabilities (and composition relationships up to a composition level of three).  So for every capability in the view I want to determine the number of related say work packages which are resulting in a change to a given capability (think of this as a capability increment).

From a jArchi script I can get easily get a collection of capabilities, however because this is from a view, I can only get the related composition relationships for each capability.  Do I need to step back from the view to the model and then filter on the capability name (or id) and the given element type or is there a simpler approach?

Thanks,

Malcolm


Phil Beauvoir

The general gist of what you're trying to do is:

- iterate over each element in the view
- get the element's relationships
- and then, from that get the source/target elements from these relationships.

Once you have those you can call .viewRefs() on the collection (https://github.com/archimatetool/archi-scripting-plugin/wiki/jArchi-Collection#viewrefs) and compare each view with the given view.

That's off the top of my head...
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

Phil Beauvoir

#2
Here's some code that will log each related concept not in the selected concepts' current view:


var selectedConcept = selection.first().concept;
var currentView = selection.first().view;

$(selectedConcept).rels().ends().each(function(concept) {
    if(!selectedConcept.equals(concept)) {
        var views = $(concept).viewRefs();
        if(!views.contains(currentView)) {
            console.log(concept);
        }
    }
});


There's probably a better way to do it.
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

Phil Beauvoir

#3
Or you could get fancy using a filter predicate:


var selectedConcept = selection.first().concept;
var currentView = selection.first().view;

$(selectedConcept).rels()
                  .ends()
                  .filter(function(concept) {
                        return !selectedConcept.equals(concept) && !$(concept).viewRefs().contains(currentView);
                  })
                  .each(function(concept) { console.log(concept); }
);
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.