-
-
Save adgerrits/32ae02b61c273ddaae0163b402d7c120 to your computer and use it in GitHub Desktop.
/* | |
* 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'); | |
} |
API doc has been updated ;-)
Occam's razor: "the problem-solving principle that the simplest solution tends to be the right one". That's clear.
But... the statement is not working a 100% yet. It looks like it's comparing the visual element id's instead of the related Archimate concept. So it flags concepts that are present in both views as 'missing'...
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).
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?
@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.
Hi,
In fact there is a simplier solution: if you want to get the list of elements that are in v2 and not in v1 you can simply use
$(v2).find('element').not($(v1).find('element'))
...which makes me see that this is not mentionned in the API doc: I have to update it