The collect expression is designed to filter the attribute values for a collection of elements. Is the parameter expected for the function collect that applies to collection or model. The function returns a collection with the values for the attribute specified in the Collect expression.
Syntax::
[collection, model].collect ( [ ElementType ] elementIterator : elementIterator.ATTRIBUTE_NAME );
ElementType defines the elements for which the expression will be evaluated, is optional and can be any element contained in the collection.
There is an short form to call the function collect:
[collection, model].collect ( 'ATTRIBUTE_NAME' );
This returns the value for the attribute's name for all elements in the collection or model. If the element does not have an attribute with that name, then is ignored.
Examples:
//gets all the application components from the model Collection appCom = model.filter( Entity a : a.type == 'ApplicationComponent' ); //gets the name attribute of the applications Collection names = appCom.collect( a : a.name );
//the one-line version of the previous example Collection names = model.filter( Entity a : a.type == 'ApplicationComponent' ).collect('name');
This expression is the parameter for the filter function applied to a collection or a model. The filter expression evaluates every element and returns only the ones that match.
Syntax:
[collection | model].filter ( ElementType | [ ElementType ] elementIterator1 [, ... [ ElementType ] elementIteratorN : [ CONDITION ] );
CONDITION must be a logical or relational expression involving the element iterators declared.
Examples:
//gets all the software systems Collection ss = model.filter( Entity e : e.type == 'SystemSoftware' );
//gets all the nodes of infrastructure that realise more than one infrastructure service Collection nodes = model.filter ( Entity e : e.type == 'Node' && e.R().from().filter( Relationship r : r.type == 'Realise' ).size() > 1 );
//gets only the entity elements from the model Collection entities = model.filter( Entity ); //gets only the entities that have an association with a DataObject entities.filter( Entity e : e.E().exists( Entity e2 : e2.type == 'DataObject' ) );
This kind of expression only applies to Path. It extends the filter expression to add filters over the path elements.
Syntax:
path.filter ( [ ElementType ] elementIterator1 [, ... [ ElementType ] elementIteratorN ] : [ CONDITION ] : [ PATH_RESTRICTIONS ] );
Either CONDITION or PATH_RESTRICTION or both must be specified. CONDITION must be a logical or relational expression involving the element iterators declared. PATH_RESTRICTIONS must have the element iterators as parameters.
Path restrictions are:
Restricts the structure of the path, this way the first entity passed must be before the second.
Example:
//gets the paths between the Register business process and all the software systems Entity bpRegister = model.filter(Entity e : e.type == 'BusinessProcess' && e.name == 'Register'); //gets the collection paths Collection paths = bpRegister.pathsTo( model.filter( Entity e : e.type == 'SystemSoftware' ) ); //filters the paths to assure that there is a path that follows the structure: //[ BusinessProcess -> ApplicationService -> ApplicationComponent -> InfrastructureService -> Node -> SystemSoftware ] Collection pathsFiltered = paths.filter( Path p : p.exists ( Entity e1, Entity e2, Entity e3, Entity e4, Entity e5, Entity e6 : e1.type == 'BusinessProcess' && e2.type == 'ApplicationService' && e3.type == 'ApplicationComponent' && e4.type == 'InfrastructureService' && e5.type == 'Node' && e6.type == 'SystemSoftware' : ordered(e1, e2) && ordered(e2, e3) && ordered(e3, e4) && ordered(e5, e6) ) ); //the only paths that match are: //1. [ 'Register' -> 'insurance application service' -> 'CRM' -> 'Database service' -> 'Mainframe' -> 'Transaction server' ] //2. [ 'Register' -> 'insurance application service' -> 'CRM' -> 'Database service' -> 'Mainframe' -> 'MessageQueing' ] //3. [ 'Register' -> 'insurance application service' -> 'CRM' -> 'Database service' -> 'Mainframe' -> 'DBMS' ]
Restricts the distance (associations between them) between entities. The distance_expression must be one of the following (D is an Integer):
Expression | Description |
---|---|
<D | The entities can have N1 associations between them, but N1 < D |
<=D | The entities can have N2 associations between them, but N2 <= D |
>D | The entities can have N3 associations between them, but N3 > D |
>=D | The entities can have N4 associations between them, but N4 >= D |
==D | The entities must have exactly D associations between them |
!= | The entities can have any number of associations between them, but the number of them must be different of D |
Example:
//gets all the paths between application components and nodes Collection allPaths = new Collection(); model.forEach({ Entity e : if ( e.type == 'ApplicationComponent') ) { Collection paths = e.pathsTo( model.filter( Entity e2 : e2.type == 'Node' ) ); paths.forEach({ Path p : allPaths.add( p ) }); } });
//filters the paths that have only 2 associations between the application component and the node allPaths.filter( Entity ac, Entity n : ac.type == 'ApplicationComponent' && n.type == 'Node' : distance(ac, n, 2) ); //the path filtered are: //1. [ CRM -> Database service -> Mainframe ] //2. [ Policy data management -> Claim file service -> Mainframe ]