Skip to content

Commit

Permalink
Add model comparison example
Browse files Browse the repository at this point in the history
  • Loading branch information
MaksimAniskov committed Feb 12, 2024
1 parent df73b9a commit 596de71
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 0 deletions.
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,46 @@ Error!
Verification completed
~~~

## Compare two models

There is [an example](examples/model-federation) which demonstrates detecting discrepancies between two views in two different models.

*[System-A](examples/model-federation/enterprise.archimate)* model has *Default* view in it.
And *[Enterprise](examples/model-federation/enterprise.archimate)* model is supposed to have
its *System A* view equal to *System-A*'s *Default*.

Views equality means that those two views represent same elements and relations between the elements.

To detect if there any inequality between the views, let's run following command.
~~~sh
ARCHI_FOLDER=./examples/model-federation \
ARCHI_FILE=enterprise.archimate \
ARCHI_FILE2=system-a.archimate \
NEO4J_SCRIPTS_FOLDER=./examples/model-federation/verification_scripts_cql \
NEO4J_VERSION=4.4 \
COMPOSE_PROJECT_NAME=archi-powertools-verifier-44 \
docker compose run --rm neo4j
~~~

> Note: This example runs Neo4j version 4.4 which has support for [apoc.diff.graphs](https://neo4j.com/labs/apoc/4.4/comparing-graphs/graph-difference/) procedure.
This is the output we expect from the verification run:
~~~
Executing verification scripts...
import/verification_scripts/00-compare-views.cypher
difference, entityType, id, sourceLabel, destLabel, source, dest
"Destination Entity not found", "Node", 0, "Element", NULL, {}, NULL
"Destination Entity not found", "Node", 1, "Element", NULL, {}, NULL
difference, entityType, id, sourceLabel, destLabel, source, dest
"Destination Entity not found", "Node", 3, "Element", NULL, {}, NULL
"Destination Entity not found", "Node", 4, "Element", NULL, {}, NULL
Verification completed
~~~

Non-empty result of running the verification script means that there are model elements or relations
that represented differently in those two view of interest.
> TODO: Make output of the script human-friendly.
# Usage

This is summary of command line syntax:
Expand Down
27 changes: 27 additions & 0 deletions examples/model-federation/enterprise.archimate
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<archimate:model xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:archimate="http://www.archimatetool.com/archimate" name="Enterprise level" id="id-5fa9d86300124ae1883c110dc93c47c4" version="5.0.0">
<folder name="Strategy" id="id-87eea7826eac410faffe88d935e6445d" type="strategy"/>
<folder name="Business" id="id-af9d3530cea640eb8bdab30df4fd5768" type="business"/>
<folder name="Application" id="id-4930bf7ab0ac4b5e9d7a05a2c4558d8d" type="application">
<element xsi:type="archimate:ApplicationService" name="Application Service 1" id="id-fb465737152e4ab19e81f03a2986654d"/>
<element xsi:type="archimate:ApplicationService" name="Application Service 2" id="id-ee309840ed5e494f8cf03f5377129b79"/>
</folder>
<folder name="Technology &amp; Physical" id="id-699d3c4a4c6f4a9284ebd71c2e5527c8" type="technology"/>
<folder name="Motivation" id="id-5c163cad00a0410e9c2dd1a6030dbf14" type="motivation"/>
<folder name="Implementation &amp; Migration" id="id-f96c031f813a47fb8b05e3219811c76f" type="implementation_migration"/>
<folder name="Other" id="id-83dc94f0f5ba41f28cc07a2891b93e29" type="other"/>
<folder name="Relations" id="id-1629b3d36b94487e97f596b5b003a25c" type="relations">
<element xsi:type="archimate:TriggeringRelationship" id="id-9d59629f208d415c94417d475d2a15cb" source="id-fb465737152e4ab19e81f03a2986654d" target="id-ee309840ed5e494f8cf03f5377129b79"/>
</folder>
<folder name="Views" id="id-1776976201b14be7b60eae7440431cba" type="diagrams">
<element xsi:type="archimate:ArchimateDiagramModel" name="System A" id="id-3e374488c9e14522a93462f5617083ea">
<child xsi:type="archimate:DiagramObject" id="id-cda0d212494a44df91605ffc749a2db3" archimateElement="id-fb465737152e4ab19e81f03a2986654d">
<bounds x="120" y="122" width="120" height="55"/>
<sourceConnection xsi:type="archimate:Connection" id="id-da35346fe4a04b02b2b9b7ddd5deb519" source="id-cda0d212494a44df91605ffc749a2db3" target="id-32da0ea27b63480aa97c269e607c00b4" archimateRelationship="id-9d59629f208d415c94417d475d2a15cb"/>
</child>
<child xsi:type="archimate:DiagramObject" id="id-32da0ea27b63480aa97c269e607c00b4" targetConnections="id-da35346fe4a04b02b2b9b7ddd5deb519" archimateElement="id-ee309840ed5e494f8cf03f5377129b79">
<bounds x="408" y="122" width="120" height="55"/>
</child>
</element>
</folder>
</archimate:model>
27 changes: 27 additions & 0 deletions examples/model-federation/system-a.archimate
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<archimate:model xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:archimate="http://www.archimatetool.com/archimate" name="System A" id="id-5fa9d86300124ae1883c110dc93c47c4" version="5.0.0">
<folder name="Strategy" id="id-87eea7826eac410faffe88d935e6445d" type="strategy"/>
<folder name="Business" id="id-af9d3530cea640eb8bdab30df4fd5768" type="business"/>
<folder name="Application" id="id-4930bf7ab0ac4b5e9d7a05a2c4558d8d" type="application">
<element xsi:type="archimate:ApplicationService" name="Application Service 1" id="id-fb465737152e4ab19e81f03a2986654d"/>
<element xsi:type="archimate:ApplicationService" name="Application Service 2" id="id-ee309840ed5e494f8cf03f5377129b79"/>
</folder>
<folder name="Technology &amp; Physical" id="id-699d3c4a4c6f4a9284ebd71c2e5527c8" type="technology"/>
<folder name="Motivation" id="id-5c163cad00a0410e9c2dd1a6030dbf14" type="motivation"/>
<folder name="Implementation &amp; Migration" id="id-f96c031f813a47fb8b05e3219811c76f" type="implementation_migration"/>
<folder name="Other" id="id-83dc94f0f5ba41f28cc07a2891b93e29" type="other"/>
<folder name="Relations" id="id-1629b3d36b94487e97f596b5b003a25c" type="relations">
<element xsi:type="archimate:FlowRelationship" id="id-bd2e133bd8db40d6b33869af832870e8" source="id-fb465737152e4ab19e81f03a2986654d" target="id-ee309840ed5e494f8cf03f5377129b79"/>
</folder>
<folder name="Views" id="id-1776976201b14be7b60eae7440431cba" type="diagrams">
<element xsi:type="archimate:ArchimateDiagramModel" name="Default View" id="id-3e374488c9e14522a93462f5617083ea">
<child xsi:type="archimate:DiagramObject" id="id-cda0d212494a44df91605ffc749a2db3" archimateElement="id-fb465737152e4ab19e81f03a2986654d">
<bounds x="120" y="122" width="120" height="55"/>
<sourceConnection xsi:type="archimate:Connection" id="id-052fad72e6ea44b0a941273600f46a50" source="id-cda0d212494a44df91605ffc749a2db3" target="id-32da0ea27b63480aa97c269e607c00b4" archimateRelationship="id-bd2e133bd8db40d6b33869af832870e8"/>
</child>
<child xsi:type="archimate:DiagramObject" id="id-32da0ea27b63480aa97c269e607c00b4" targetConnections="id-052fad72e6ea44b0a941273600f46a50" archimateElement="id-ee309840ed5e494f8cf03f5377129b79">
<bounds x="408" y="122" width="120" height="55"/>
</child>
</element>
</folder>
</archimate:model>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CALL apoc.diff.graphs(
'match (n)-[Archi_PresentedIn]->(:Archi_View{name:"System A"}) return n',
'match (n{_archi_pwrt_verifier_model_n: 2})-[Archi_PresentedIn]->(:Archi_View{name:"Default View", _archi_pwrt_verifier_model_n: 2}) return n'
);

// It needs to call apoc.diff.graphs again switching those two match statements.
// This is because apoc.diff.graphs behaves asymmetrically in regard to its source and dest parameters.
// Check out the procedure's documentation https://neo4j.com/labs/apoc/4.4/comparing-graphs/graph-difference/
CALL apoc.diff.graphs(
'match (n{_archi_pwrt_verifier_model_n: 2})-[Archi_PresentedIn]->(:Archi_View{name:"Default View", _archi_pwrt_verifier_model_n: 2}) return n',
'match (n)-[Archi_PresentedIn]->(:Archi_View{name:"System A"}) return n'
);

0 comments on commit 596de71

Please sign in to comment.