Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/diffo/provider.ex
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ defmodule Diffo.Provider do
action: :list_place_refs_by_instance_id,
args: [:instance_id]

define :list_place_refs_by_party_id, action: :list_place_refs_by_party_id, args: [:party_id]

define :list_place_refs_by_source_place_id,
action: :list_place_refs_by_source_place_id,
args: [:source_place_id]

define :update_place_ref, action: :update
define :delete_place_ref, action: :destroy
end
Expand All @@ -141,6 +147,12 @@ defmodule Diffo.Provider do
action: :list_party_refs_by_instance_id,
args: [:instance_id]

define :list_party_refs_by_place_id, action: :list_party_refs_by_place_id, args: [:place_id]

define :list_party_refs_by_source_party_id,
action: :list_party_refs_by_source_party_id,
args: [:source_party_id]

define :update_party_ref, action: :update
define :delete_party_ref, action: :destroy
end
Expand Down
4 changes: 2 additions & 2 deletions lib/diffo/provider/components/base_instance.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ defmodule Diffo.Provider.BaseInstance do
{:entities, :RELATES, :outgoing, :EntityRef},
{:notes, :ANNOTATES, :incoming, :Note},
{:event, :FIRED, :outgoing, :Event},
{:places, :LOCATED_BY, :outgoing, :PlaceRef},
{:parties, :INVOLVED_WITH, :outgoing, :PartyRef}
{:places, :RELATES, :outgoing, :PlaceRef},
{:parties, :RELATES, :outgoing, :PartyRef}
]

label :Instance
Expand Down
2 changes: 1 addition & 1 deletion lib/diffo/provider/components/party.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ defmodule Diffo.Provider.Party do
translate id: :key

relate [
{:party_refs, :INVOLVED_WITH, :incoming, :PartyRef},
{:party_refs, :RELATES, :incoming, :PartyRef},
{:external_identifiers, :OWNS, :outgoing, :ExternalIdentifier},
{:notes, :AUTHORS, :outgoing, :Note}
]
Expand Down
56 changes: 51 additions & 5 deletions lib/diffo/provider/components/party_ref.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ defmodule Diffo.Provider.PartyRef do

neo4j do
relate [
{:instance, :INVOLVED_WITH, :incoming, :Instance},
{:party, :INVOLVED_WITH, :outgoing, :Party}
{:instance, :RELATES, :incoming, :Instance},
{:place, :RELATES, :incoming, :Place},
{:source_party, :RELATES, :incoming, :Party},
{:party, :RELATES, :outgoing, :Party}
]
end

Expand Down Expand Up @@ -50,13 +52,17 @@ defmodule Diffo.Provider.PartyRef do
defaults [:read, :destroy]

create :create do
description "creates a party ref, relating an instance and a party"
description "creates a party ref, relating an instance, place or source party to a party"
accept [:role]

argument :instance_id, :uuid
argument :place_id, :string
argument :source_party_id, :string
argument :party_id, :string

change manage_relationship(:instance_id, :instance, type: :append_and_remove)
change manage_relationship(:place_id, :place, type: :append_and_remove)
change manage_relationship(:source_party_id, :source_party, type: :append_and_remove)
change manage_relationship(:party_id, :party, type: :append_and_remove)
end

Expand All @@ -70,6 +76,18 @@ defmodule Diffo.Provider.PartyRef do
filter expr(instance_id == ^arg(:instance_id))
end

read :list_party_refs_by_place_id do
description "lists party refs by place id"
argument :place_id, :string
filter expr(place_id == ^arg(:place_id))
end

read :list_party_refs_by_source_party_id do
description "lists party refs by source_party id"
argument :source_party_id, :string
filter expr(source_party_id == ^arg(:source_party_id))
end

read :list_party_refs_by_party_id do
description "lists party refs by party id"
argument :party_id, :string
Expand Down Expand Up @@ -100,7 +118,7 @@ defmodule Diffo.Provider.PartyRef do
end

attribute :role, :atom do
description "the role of the party to the instance"
description "the role of the party to the instance, place or source party"
allow_nil? true
public? true
end
Expand All @@ -113,7 +131,21 @@ defmodule Diffo.Provider.PartyRef do
relationships do
belongs_to :instance, Diffo.Provider.Instance do
description "the instance which relates to a party via this party ref"
allow_nil? false
allow_nil? true
public? true
end

belongs_to :place, Diffo.Provider.Place do
description "the place which relates to a party via this party ref"
attribute_type :string
allow_nil? true
public? true
end

belongs_to :source_party, Diffo.Provider.Party do
description "the source party which relates to a party via this party ref"
attribute_type :string
allow_nil? true
public? true
end

Expand All @@ -129,6 +161,20 @@ defmodule Diffo.Provider.PartyRef do
identity :instance_party_uniqueness, [:instance_id, :party_id] do
message "another party ref exists"
end

identity :place_party_uniqueness, [:place_id, :party_id] do
message "another party ref exists"
end

identity :source_party_party_uniqueness, [:source_party_id, :party_id] do
message "another party ref exists"
end
end

validations do
validate present([:instance_id, :place_id, :source_party_id], exactly: 1) do
message "a party ref can relate either an instance, place or source party"
end
end

preparations do
Expand Down
2 changes: 1 addition & 1 deletion lib/diffo/provider/components/place.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ defmodule Diffo.Provider.Place do
translate id: :key

relate [
{:place_refs, :LOCATED_BY, :incoming, :PlaceRef}
{:place_refs, :RELATES, :incoming, :PlaceRef}
]
end

Expand Down
56 changes: 51 additions & 5 deletions lib/diffo/provider/components/place_ref.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ defmodule Diffo.Provider.PlaceRef do

neo4j do
relate [
{:instance, :LOCATED_BY, :incoming, :Instance},
{:place, :LOCATED_BY, :outgoing, :Place}
{:instance, :RELATES, :incoming, :Instance},
{:party, :RELATES, :incoming, :Party},
{:source_place, :RELATES, :incoming, :Place},
{:place, :RELATES, :outgoing, :Place}
]
end

Expand Down Expand Up @@ -50,12 +52,16 @@ defmodule Diffo.Provider.PlaceRef do
defaults [:read, :destroy]

create :create do
description "creates a place ref, relating an instance and a place"
description "creates a place ref, relating an instance, party or source place to a place"
accept [:role]
argument :instance_id, :uuid
argument :party_id, :string
argument :source_place_id, :string
argument :place_id, :string

change manage_relationship(:instance_id, :instance, type: :append_and_remove)
change manage_relationship(:party_id, :party, type: :append_and_remove)
change manage_relationship(:source_place_id, :source_place, type: :append_and_remove)
change manage_relationship(:place_id, :place, type: :append_and_remove)
end

Expand All @@ -69,6 +75,18 @@ defmodule Diffo.Provider.PlaceRef do
filter expr(instance_id == ^arg(:instance_id))
end

read :list_place_refs_by_party_id do
description "lists place refs by party id"
argument :party_id, :string
filter expr(party_id == ^arg(:party_id))
end

read :list_place_refs_by_source_place_id do
description "lists place refs by source_place id"
argument :source_place_id, :string
filter expr(source_place_id == ^arg(:source_place_id))
end

read :list_place_refs_by_place_id do
description "lists place refs by place id"
argument :place_id, :string
Expand All @@ -88,7 +106,7 @@ defmodule Diffo.Provider.PlaceRef do
end

attribute :role, :atom do
description "the role of the place to the instance"
description "the role of the place to the instance, party or source place"
allow_nil? true
public? true
end
Expand All @@ -101,7 +119,21 @@ defmodule Diffo.Provider.PlaceRef do
relationships do
belongs_to :instance, Diffo.Provider.Instance do
description "the instance which relates to a place via this place ref"
allow_nil? false
allow_nil? true
public? true
end

belongs_to :party, Diffo.Provider.Party do
description "the party which relates to a place via this place ref"
attribute_type :string
allow_nil? true
public? true
end

belongs_to :source_place, Diffo.Provider.Place do
description "the source place which relates to a place via this place ref"
attribute_type :string
allow_nil? true
public? true
end

Expand All @@ -117,6 +149,20 @@ defmodule Diffo.Provider.PlaceRef do
identity :instance_place_uniqueness, [:instance_id, :place_id] do
message "another place ref exists relating the same instance and place"
end

identity :party_place_uniqueness, [:party_id, :place_id] do
message "another place ref exists"
end

identity :source_place_place_uniqueness, [:source_place_id, :place_id] do
message "another place ref exists"
end
end

validations do
validate present([:instance_id, :party_id, :source_place_id], exactly: 1) do
message "a place ref can relate either an instance, party or source place"
end
end

preparations do
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ defmodule Diffo.MixProject do
{:ash_outstanding, "~> 0.2.3"},
{:ash_jason, "~> 3.0"},
{:ash_state_machine, "~> 0.2.12"},
{:ash_neo4j, ash_neo4j_version("~> 0.2.11")},
{:ash_neo4j, ash_neo4j_version("~> 0.2.12")},
{:boltx, "~> 0.0.6"},
{:ash, ash_version("~> 3.0 and >= 3.6.2")},
{:uuid, "~> 1.1"},
Expand Down
4 changes: 2 additions & 2 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%{
"ash": {:hex, :ash, "3.9.0", "004371ffb181a142cda09544342dad1ffedf360a5636219d71cb5431ccbe3ad6", [:mix], [{:crux, ">= 0.1.2 and < 1.0.0-0", [hex: :crux, repo: "hexpm", optional: false]}, {:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:ecto, "~> 3.7", [hex: :ecto, repo: "hexpm", optional: false]}, {:ets, "~> 0.8", [hex: :ets, repo: "hexpm", optional: false]}, {:igniter, ">= 0.6.29 and < 1.0.0-0", [hex: :igniter, repo: "hexpm", optional: true]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: false]}, {:picosat_elixir, "~> 0.2", [hex: :picosat_elixir, repo: "hexpm", optional: true]}, {:plug, ">= 0.0.0", [hex: :plug, repo: "hexpm", optional: true]}, {:reactor, "~> 0.11", [hex: :reactor, repo: "hexpm", optional: false]}, {:simple_sat, ">= 0.1.1 and < 1.0.0-0", [hex: :simple_sat, repo: "hexpm", optional: true]}, {:spark, ">= 2.3.3 and < 3.0.0-0", [hex: :spark, repo: "hexpm", optional: false]}, {:splode, ">= 0.2.6 and < 1.0.0-0", [hex: :splode, repo: "hexpm", optional: false]}, {:stream_data, "~> 1.0", [hex: :stream_data, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.1", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "e3e80a182c6e8b4d87f1caa4dba774da210f1f75f1420650ba012eb4388dc8c3"},
"ash_jason": {:hex, :ash_jason, "3.0.3", "05349fe257c958ce84bcfc35871da7647960fcbcb288025623d1eb19839dc5fd", [:mix], [{:ash, ">= 3.6.2 and < 4.0.0-0", [hex: :ash, repo: "hexpm", optional: false]}, {:ex_check, "~> 0.16.0", [hex: :ex_check, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:spark, ">= 2.1.21 and < 3.0.0", [hex: :spark, repo: "hexpm", optional: false]}], "hexpm", "1ef2cd24be16a46ee46a9e0de1f319acc6cc71ff31e0bc3e7bfd800955a4c550"},
"ash_neo4j": {:hex, :ash_neo4j, "0.2.11", "41433b79c8dfe1f371faf411757c03b44cb56f14870375e80b348819fb17ddf1", [:mix], [{:ash, ">= 3.6.2 and < 4.0.0-0", [hex: :ash, repo: "hexpm", optional: false]}, {:boltx, ">= 0.0.6", [hex: :boltx, repo: "hexpm", optional: false]}], "hexpm", "b26a165908af327d45e951794c0fc1eaf4002d23239c41d6c4c01b1203471293"},
"ash_neo4j": {:hex, :ash_neo4j, "0.2.12", "cc662833f3d4eb10ff36b217a1693c6deff3a878a9aea3baaf66090d987bb54a", [:mix], [{:ash, ">= 3.6.2 and < 4.0.0-0", [hex: :ash, repo: "hexpm", optional: false]}, {:boltx, ">= 0.0.6", [hex: :boltx, repo: "hexpm", optional: false]}], "hexpm", "fda719bfc002ce0840d62eabbf0502ab79dd1e249d852aa3eb0bee457bf96352"},
"ash_outstanding": {:hex, :ash_outstanding, "0.2.3", "dc8ec13028ea7bd1d74b46569b9db08f0d275d63700e2418d9e33fe4b21af2eb", [:mix], [{:ash, ">= 3.6.2 and < 4.0.0-0", [hex: :ash, repo: "hexpm", optional: false]}, {:outstanding, "~> 0.2.4", [hex: :outstanding, repo: "hexpm", optional: false]}], "hexpm", "05e2718b59937d9f7e77b7bc90f70e8f28c3f328de7cabf3ea55ca04a1abed52"},
"ash_state_machine": {:hex, :ash_state_machine, "0.2.12", "c0f7ebb8a176584f70c6ed196b7d0118c930d73e0590ade705d2dddc48aa7311", [:mix], [{:ash, ">= 3.4.66 and < 4.0.0-0", [hex: :ash, repo: "hexpm", optional: false]}], "hexpm", "394ce761ce82358e3c715e1cae6c5cf1390be27c03a8b661f2e5a2fda849873d"},
"boltx": {:hex, :boltx, "0.0.6", "c6a396b1538b258e4d5ee2a94aaf8fb2c7879240efffba94b9159dbdce963790", [:mix], [{:db_connection, "~> 2.6.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: true]}, {:poison, "~> 5.0", [hex: :poison, repo: "hexpm", optional: true]}], "hexpm", "576b8f21a2021674130d04cd1fc79a4829a23d2cdf50641b3d7a00ce31b98ead"},
Expand Down Expand Up @@ -31,7 +31,7 @@
"outstanding": {:hex, :outstanding, "0.2.5", "2f40416eb9617748cb1f8ae4c8ed94515d731f9c4fcee4f902355d30bc0792cc", [:mix], [], "hexpm", "bb47a210f0d2804ea6b8477fa6f4d15e8c58c18acee79d8e06c9296e6dd004cd"},
"owl": {:hex, :owl, "0.13.0", "26010e066d5992774268f3163506972ddac0a7e77bfe57fa42a250f24d6b876e", [:mix], [{:ucwidth, "~> 0.2", [hex: :ucwidth, repo: "hexpm", optional: true]}], "hexpm", "59bf9d11ce37a4db98f57cb68fbfd61593bf419ec4ed302852b6683d3d2f7475"},
"reactor": {:hex, :reactor, "0.17.0", "eb8bdb530dbae824e2d36a8538f8ec4f3aa7c2d1b61b04959fa787c634f88b49", [:mix], [{:igniter, "~> 0.4", [hex: :igniter, repo: "hexpm", optional: true]}, {:iterex, "~> 0.1", [hex: :iterex, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:libgraph, "~> 0.16", [hex: :libgraph, repo: "hexpm", optional: false]}, {:spark, ">= 2.3.3 and < 3.0.0-0", [hex: :spark, repo: "hexpm", optional: false]}, {:splode, "~> 0.2", [hex: :splode, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.2", [hex: :telemetry, repo: "hexpm", optional: false]}, {:yaml_elixir, "~> 2.11", [hex: :yaml_elixir, repo: "hexpm", optional: false]}, {:ymlr, "~> 5.0", [hex: :ymlr, repo: "hexpm", optional: false]}], "hexpm", "3c3bf71693adbad9117b11ec83cfed7d5851b916ade508ed9718de7ae165bf25"},
"req": {:hex, :req, "0.5.15", "662020efb6ea60b9f0e0fac9be88cd7558b53fe51155a2d9899de594f9906ba9", [:mix], [{:brotli, "~> 0.3.1", [hex: :brotli, repo: "hexpm", optional: true]}, {:ezstd, "~> 1.0", [hex: :ezstd, repo: "hexpm", optional: true]}, {:finch, "~> 0.17", [hex: :finch, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mime, "~> 2.0.6 or ~> 2.1", [hex: :mime, repo: "hexpm", optional: false]}, {:nimble_csv, "~> 1.0", [hex: :nimble_csv, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "a6513a35fad65467893ced9785457e91693352c70b58bbc045b47e5eb2ef0c53"},
"req": {:hex, :req, "0.5.16", "99ba6a36b014458e52a8b9a0543bfa752cb0344b2a9d756651db1281d4ba4450", [:mix], [{:brotli, "~> 0.3.1", [hex: :brotli, repo: "hexpm", optional: true]}, {:ezstd, "~> 1.0", [hex: :ezstd, repo: "hexpm", optional: true]}, {:finch, "~> 0.17", [hex: :finch, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mime, "~> 2.0.6 or ~> 2.1", [hex: :mime, repo: "hexpm", optional: false]}, {:nimble_csv, "~> 1.0", [hex: :nimble_csv, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "974a7a27982b9b791df84e8f6687d21483795882a7840e8309abdbe08bb06f09"},
"rewrite": {:hex, :rewrite, "1.2.0", "80220eb14010e175b67c939397e1a8cdaa2c32db6e2e0a9d5e23e45c0414ce21", [:mix], [{:glob_ex, "~> 0.1", [hex: :glob_ex, repo: "hexpm", optional: false]}, {:sourceror, "~> 1.0", [hex: :sourceror, repo: "hexpm", optional: false]}, {:text_diff, "~> 0.1", [hex: :text_diff, repo: "hexpm", optional: false]}], "hexpm", "a1cd702bbb9d51613ab21091f04a386d750fc6f4516b81900df082d78b2d8c50"},
"sourceror": {:hex, :sourceror, "1.10.0", "38397dedbbc286966ec48c7af13e228b171332be1ad731974438c77791945ce9", [:mix], [], "hexpm", "29dbdfc92e04569c9d8e6efdc422fc1d815f4bd0055dc7c51b8800fb75c4b3f1"},
"spark": {:hex, :spark, "2.3.14", "a08420d08e6e0e49d740aed3e160f1cb894ba8f6b3f5e6c63253e9df1995265c", [:mix], [{:igniter, ">= 0.3.64 and < 1.0.0-0", [hex: :igniter, repo: "hexpm", optional: true]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: true]}, {:sourceror, "~> 1.2", [hex: :sourceror, repo: "hexpm", optional: true]}], "hexpm", "af50c4ea5dd67eba822247f1c98e1d4e598cb7f6c28ccf5d002f0e0718096f4f"},
Expand Down
4 changes: 1 addition & 3 deletions test/provider/event_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ defmodule Diffo.Provider.EventTest do

setup do
on_exit(fn ->
# AshNeo4j.Neo4jHelper.delete_all()
:ok
AshNeo4j.Neo4jHelper.delete_all()
end)
end

Expand Down Expand Up @@ -149,7 +148,6 @@ defmodule Diffo.Provider.EventTest do
)
end

@tag debug: true
test "fired instance events are chained - success" do
specification = Diffo.Provider.create_specification!(%{name: "nbnAccess"})
instance = Diffo.Provider.create_instance!(%{specified_by: specification.id})
Expand Down
Loading