From 596de71a39d9ff3d9de754844c8755dc7e0c1f5f Mon Sep 17 00:00:00 2001 From: Maksim Aniskov Date: Mon, 12 Feb 2024 22:09:15 +0100 Subject: [PATCH] Add model comparison example --- README.md | 40 +++++++++++++++++++ .../model-federation/enterprise.archimate | 27 +++++++++++++ examples/model-federation/system-a.archimate | 27 +++++++++++++ .../00-compare-views.cypher | 12 ++++++ 4 files changed, 106 insertions(+) create mode 100644 examples/model-federation/enterprise.archimate create mode 100644 examples/model-federation/system-a.archimate create mode 100644 examples/model-federation/verification_scripts_cql/00-compare-views.cypher diff --git a/README.md b/README.md index 7ca1a61..e89d65e 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/examples/model-federation/enterprise.archimate b/examples/model-federation/enterprise.archimate new file mode 100644 index 0000000..83d9f97 --- /dev/null +++ b/examples/model-federation/enterprise.archimate @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/model-federation/system-a.archimate b/examples/model-federation/system-a.archimate new file mode 100644 index 0000000..3a953f8 --- /dev/null +++ b/examples/model-federation/system-a.archimate @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/model-federation/verification_scripts_cql/00-compare-views.cypher b/examples/model-federation/verification_scripts_cql/00-compare-views.cypher new file mode 100644 index 0000000..839a087 --- /dev/null +++ b/examples/model-federation/verification_scripts_cql/00-compare-views.cypher @@ -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' +);