Skip to content

Instantly share code, notes, and snippets.

@adgerrits
Last active April 10, 2021 19:16
Show Gist options
  • Save adgerrits/32ae02b61c273ddaae0163b402d7c120 to your computer and use it in GitHub Desktop.
Save adgerrits/32ae02b61c273ddaae0163b402d7c120 to your computer and use it in GitHub Desktop.
#jArchi script to compare two views and show mutual missing Archimate elements
/*
* Comparison of two views to see which Archimate elements are missing
* 2018, Ad Gerrits
*/
console.clear();
function checkViews (v1, v2) {
var v2elements = [];
$(v2).find('element').each(function (e) {
v2elements.push(e.concept.id);
})
var lastconceptid = -1;
console.log('Present in view "' + v1.name + '" but missing in view "' + v2.name + '":');
$(v1).find('element').each(function (e) {
if (e.concept.id !== lastconceptid) {
if (v2elements.indexOf(e.concept.id) === -1) {
console.log(e.name + ' (' + e.type + ')');
}
lastconceptid = e.concept.id;
}
})
}
if (selection.size() === 2 && ($(selection.get(0)).is('archimate-diagram-model') && $(selection.get(1)).is('archimate-diagram-model'))) {
var v1 = selection.get(0);
var v2 = selection.get(1);
console.log('Compare views: "' + v1.name + '" and "' + v2.name + '"\n');
checkViews(v1, v2);
console.log('\n');
checkViews(v2, v1);
} else {
window.alert('Select 2 views to compare');
}
@jbsarrodie
Copy link

Good point !

So we have to create a collection of elements from a collection of visual objects:

var v1 = $("archimate-diagram-model.v1").first();
var v2 = $("archimate-diagram-model.v2").first();

getConcepts = function(c) {
    var out = $("empty");
    c.each(function(o) {
        out.add(o.concept);
    })
    return out;
}

var not_in_v1 = getConcepts($(v2).find('element')).not(getConcepts($(v1).find('element')));
var not_in_v2 = getConcepts($(v1).find('element')).not(getConcepts($(v2).find('element')));

console.log("Not in v1: ", not_in_v1);
console.log("Not in v2: ", not_in_v2);

Note that I used $("empty") to create an empty collection. This is a trick: $() operator will look for object of type "empty" but won't find one as this type does not exist. Thus it returns an empty collection.

In fact what we need is a map operator, but this is not implemented (yet) on collections (which are not JS arrays even if very similar).

@vnevzorov
Copy link

A stupid question, though... How one can select two views in Archi tool? I have tried doing that in the Model Tree view, but it always selects all views between those I need. Any advice?

@adgerrits
Copy link
Author

@vnevzorov: After the first selected view, press the Ctrl-key and select the second view. Just like when you want to select multiple elements in the model tree at other times.

@vnevzorov
Copy link

vnevzorov commented Mar 12, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment