Archi Forum

Archi Plug-ins => jArchi => Topic started by: Manj75 on October 28, 2019, 13:32:20 PM

Title: Get the number of elements per ArchiMate layer in JArchi
Post by: Manj75 on October 28, 2019, 13:32:20 PM
Hi,

This may be a simple question but I could not find in the wiki how in JArchi to get the number of elements in each ArchiMate layer.

I am using the example Statistics.ajs are reference and there is a 'business-object' and I can use the following, but there is no equivalent for the other layers:

msg += "Number of ArchiMate business objects: " + $("business-object").size() + "\n";

I want to do the same for each of the layers, but I cannot find what I would expect to be equivalent to 'business-object'

application-object
motivation-object
strategy-object
technology-object
physical-object
implementation&migration-object
other-object

Can you please advise how I can achieve and element count without having to iterate through each specific element type of each layer.

Thanks,
Manjit
Title: Re: Get the number of elements per ArchiMate layer in JArchi
Post by: Jean-Baptiste Sarrodie on October 28, 2019, 13:59:03 PM
Hi,

The easiest way is to get the folder matching the layer and count its descendants.

Shoud be something like: model.children('folder.Business').find('element').size()

Regards,

JB
Title: Re: Get the number of elements per ArchiMate layer in JArchi
Post by: Phil Beauvoir on October 28, 2019, 14:00:58 PM
"business-object" is an ArchiMate element not a layer, and "application-object" etc are neither layers nor objects.

There is no jArchi API to ascertain the ArchiMate layer as the underlying Java object is (purposefully) not exposed in jArchi. One could write a JS method to map all the type names ("business-actor", etc) to layer constants.
Title: Re: Get the number of elements per ArchiMate layer in JArchi
Post by: Manj75 on October 29, 2019, 09:50:43 AM
My apologies; of course 'business-object' is an ArchiMate concept - I made a quick presumption that it was all business layer objects and was a type instead of an actual element.  I will try the solution suggested by JB.

Thanks
Title: Re: Get the number of elements per ArchiMate layer in JArchi
Post by: Manj75 on October 29, 2019, 14:07:55 PM
Hi JB,

I was getting a TypeError with your suggestion stating as follows:

model.children('folder.Business').find('element').size()

Script Error at: javax.script.ScriptException, javax.script.ScriptException: TypeError: model.children is not a function

So having played around I got it working with the following:

$("folder.Business").find('element').size()

Thanks for your help
Title: Re: Get the number of elements per ArchiMate layer in JArchi
Post by: Jean-Baptiste Sarrodie on October 29, 2019, 20:19:42 PM
Hi,

I've tested it. The right way to do it is:

$(model).children('folder.Business').find('element').size()


using
$("folder.Business")

can match any folder named " Business", so this might go wrong.

Regards,

JB
Title: Re: Get the number of elements per ArchiMate layer in JArchi
Post by: Manj75 on October 30, 2019, 07:31:04 AM
So, just to confirm the $(model).children will look for the specified Named Selector directly under the model, whereas my approach could result in folders with the Named Selector at any level in the hierarchy, e.g. a folder nested 5 levels in Views with the name given.

I appreciate your corrective suggestion.