commit 909eab4307773dc5c3a09065cd7fb66481f90d4f
parent 9ea6eff658c340b878efa77e37ed425483a5cdfa
Author: sir fish <dev@srf.sh>
Date: Tue, 13 Sep 2022 16:52:39 +0200
Merge pull request #13 from dyne/srfsh/meta
Add data ingestion fields
Diffstat:
8 files changed, 168 insertions(+), 0 deletions(-)
diff --git a/priv/repo/migrations/20211113071804_fill_vf_economic_resource.exs b/priv/repo/migrations/20211113071804_fill_vf_economic_resource.exs
@@ -37,6 +37,12 @@ def change() do
add :lot_id, references("vf_product_batch")
add :contained_in_id, references("vf_economic_resource")
add :unit_of_effort_id, references("vf_unit")
+ add :okhv, :text
+ add :repo, :text
+ add :version, :text
+ add :licensor, :text
+ add :license, :text
+ add :metadata, :jsonb
timestamps()
end
end
diff --git a/src/zenflows/gql/type.ex b/src/zenflows/gql/type.ex
@@ -41,6 +41,12 @@ scalar :url64, name: "Url64" do
serialize & &1
end
+@desc "A JSON document encoded as string."
+scalar :json, name: "JSON" do
+ parse &Jason.decode/1
+ serialize & &1
+end
+
@desc "Cursors for pagination"
object :page_info do
@desc """
diff --git a/src/zenflows/vf/economic_resource.ex b/src/zenflows/vf/economic_resource.ex
@@ -56,6 +56,12 @@ alias Zenflows.VF.{
current_location: SpatialThing.t() | nil,
unit_of_effort: Unit.t() | nil,
contained_in: EconomicResource.t() | nil,
+ okhv: String.t() | nil,
+ repo: String.t() | nil,
+ version: String.t() | nil,
+ licensor: String.t() | nil,
+ license: String.t() | nil,
+ metadata: map() | nil,
}
schema "vf_economic_resource" do
@@ -80,6 +86,12 @@ schema "vf_economic_resource" do
belongs_to :lot, ProductBatch
belongs_to :contained_in, EconomicResource
belongs_to :unit_of_effort, Unit
+ field :okhv, :string
+ field :repo, :string
+ field :version, :string
+ field :licensor, :string
+ field :license, :string
+ field :metadata, :map
timestamps()
end
@@ -95,6 +107,7 @@ end
classified_as
stage_id state_id current_location_id
lot_id contained_in_id unit_of_effort_id
+ okhv repo version licensor license metadata
]a
@doc false
@@ -106,6 +119,11 @@ def chgset(schema \\ %__MODULE__{}, params) do
|> Validate.name(:name)
|> Validate.note(:note)
|> Validate.class(:classified_as)
+ |> Validate.name(:okhv)
+ |> Validate.uri(:repo)
+ |> Validate.name(:version)
+ |> Validate.name(:licensor)
+ |> Validate.name(:license)
|> require_quantity_units_same()
|> Changeset.cast_assoc(:images, with: &File.chgset/2)
|> Changeset.assoc_constraint(:conforms_to)
diff --git a/src/zenflows/vf/economic_resource/type.ex b/src/zenflows/vf/economic_resource/type.ex
@@ -94,6 +94,12 @@ economic resources.
@unit_of_effort """
The unit used for use or work or cite actions for this resource.
"""
+@okhv "The okh version of the standard of the manifest."
+@licensor "States who is licensing the project."
+@license "States the licenses under which the project is made available."
+@repo "A URL to the repository of the project."
+@version "The version of the project."
+@metadata "Metadata of the project."
@desc "A resource which is useful to people or the ecosystem."
object :economic_resource do
@@ -153,6 +159,24 @@ object :economic_resource do
@desc @unit_of_effort
field :unit_of_effort, :unit, resolve: &Resolv.unit_of_effort/3
+
+ @desc @okhv
+ field :okhv, :string
+
+ @desc @repo
+ field :repo, :string
+
+ @desc @version
+ field :version, :string
+
+ @desc @licensor
+ field :licensor, :string
+
+ @desc @license
+ field :license, :string
+
+ @desc @metadata
+ field :metadata, :json
end
input_object :economic_resource_create_params do
@@ -170,6 +194,24 @@ input_object :economic_resource_create_params do
@desc @lot_id
field :lot_id, :id, name: "lot"
+
+ @desc @okhv
+ field :okhv, :string
+
+ @desc @repo
+ field :repo, :string
+
+ @desc @version
+ field :version, :string
+
+ @desc @licensor
+ field :licensor, :string
+
+ @desc @license
+ field :license, :string
+
+ @desc @metadata
+ field :metadata, :json
end
input_object :economic_resource_update_params do
diff --git a/test/help/factory.ex b/test/help/factory.ex
@@ -382,6 +382,12 @@ def build(:economic_resource) do
lot: build(:product_batch),
contained_in: if(recurse?, do: build(:economic_resource)),
unit_of_effort: build(:unit),
+ okhv: str("okhv"),
+ repo: uri(),
+ version: str("version"),
+ licensor: str("licensor"),
+ license: str("license"),
+ metadata: %{str("key") => str("val")},
}
end
diff --git a/test/vf/economic_event/domain.test.exs b/test/vf/economic_event/domain.test.exs
@@ -122,6 +122,12 @@ describe "`create/2` with raise:" do
#image: Factory.img(),
tracking_identifier: Factory.str("tracking identifier"),
lot_id: Factory.insert!(:product_batch).id,
+ okhv: Factory.str("okhv"),
+ repo: Factory.uri(),
+ version: Factory.str("version"),
+ licensor: Factory.str("licensor"),
+ license: Factory.str("license"),
+ metadata: %{Factory.str("key") => Factory.str("val")},
}
assert {:ok, %EconomicEvent{}, %EconomicResource{} = res, _} =
Domain.create(evt_params, res_params)
@@ -131,6 +137,12 @@ describe "`create/2` with raise:" do
#assert res.image == res_params.image
assert res.tracking_identifier == res_params.tracking_identifier
assert res.lot_id == res_params.lot_id
+ assert res.okhv == res_params.okhv
+ assert res.repo == res_params.repo
+ assert res.version == res_params.version
+ assert res.licensor == res_params.licensor
+ assert res.license == res_params.license
+ assert res.metadata == res_params.metadata
assert res.primary_accountable_id == evt_params.receiver_id
assert res.custodian_id == evt_params.receiver_id
@@ -222,6 +234,12 @@ describe "`create/2` with produce:" do
#image: Factory.img(),
tracking_identifier: Factory.str("tracking identifier"),
lot_id: Factory.insert!(:product_batch).id,
+ okhv: Factory.str("okhv"),
+ repo: Factory.uri(),
+ version: Factory.str("version"),
+ licensor: Factory.str("licensor"),
+ license: Factory.str("license"),
+ metadata: %{Factory.str("key") => Factory.str("val")},
}
assert {:ok, %EconomicEvent{}, %EconomicResource{} = res, _} =
Domain.create(evt_params, res_params)
@@ -231,6 +249,12 @@ describe "`create/2` with produce:" do
#assert res.image == res_params.image
assert res.tracking_identifier == res_params.tracking_identifier
assert res.lot_id == res_params.lot_id
+ assert res.okhv == res_params.okhv
+ assert res.repo == res_params.repo
+ assert res.version == res_params.version
+ assert res.licensor == res_params.licensor
+ assert res.license == res_params.license
+ assert res.metadata == res_params.metadata
assert res.primary_accountable_id == evt_params.receiver_id
assert res.custodian_id == evt_params.receiver_id
@@ -786,6 +810,12 @@ describe "`create/2` with transferCustody:" do
#image: Factory.img(),
tracking_identifier: Factory.str("tracking identifier"),
lot_id: Factory.insert!(:product_batch).id,
+ okhv: Factory.str("okhv"),
+ repo: Factory.uri(),
+ version: Factory.str("version"),
+ licensor: Factory.str("licensor"),
+ license: Factory.str("license"),
+ metadata: %{Factory.str("key") => Factory.str("val")},
}
assert {:ok, %EconomicEvent{} = evt, _, %EconomicResource{} = to_res} = Domain.create(params, res_params)
{:ok, res_after} = EconomicResource.Domain.one(params.resource_inventoried_as_id)
@@ -800,6 +830,12 @@ describe "`create/2` with transferCustody:" do
#assert to_res.image == res_params.image
assert to_res.tracking_identifier == res_params.tracking_identifier
assert to_res.lot_id == res_params.lot_id
+ assert to_res.okhv == res_params.okhv
+ assert to_res.repo == res_params.repo
+ assert to_res.version == res_params.version
+ assert to_res.licensor == res_params.licensor
+ assert to_res.license == res_params.license
+ assert to_res.metadata == res_params.metadata
assert to_res.primary_accountable_id == params.receiver_id
assert to_res.custodian_id == params.receiver_id
@@ -1034,6 +1070,12 @@ describe "`create/2` with transferAllRights:" do
#image: Factory.img(),
tracking_identifier: Factory.str("tracking identifier"),
lot_id: Factory.insert!(:product_batch).id,
+ okhv: Factory.str("okhv"),
+ repo: Factory.uri(),
+ version: Factory.str("version"),
+ licensor: Factory.str("licensor"),
+ license: Factory.str("license"),
+ metadata: %{Factory.str("key") => Factory.str("val")},
}
assert {:ok, %EconomicEvent{} = evt, _, %EconomicResource{} = to_res} = Domain.create(params, res_params)
{:ok, res_after} = EconomicResource.Domain.one(params.resource_inventoried_as_id)
@@ -1048,6 +1090,12 @@ describe "`create/2` with transferAllRights:" do
#assert to_res.image == res_params.image
assert to_res.tracking_identifier == res_params.tracking_identifier
assert to_res.lot_id == res_params.lot_id
+ assert to_res.okhv == res_params.okhv
+ assert to_res.repo == res_params.repo
+ assert to_res.version == res_params.version
+ assert to_res.licensor == res_params.licensor
+ assert to_res.license == res_params.license
+ assert to_res.metadata == res_params.metadata
assert to_res.primary_accountable_id == params.receiver_id
assert to_res.custodian_id == params.receiver_id
@@ -1281,6 +1329,12 @@ describe "`create/2` with transfer:" do
#image: Factory.img(),
tracking_identifier: Factory.str("tracking identifier"),
lot_id: Factory.insert!(:product_batch).id,
+ okhv: Factory.str("okhv"),
+ repo: Factory.uri(),
+ version: Factory.str("version"),
+ licensor: Factory.str("licensor"),
+ license: Factory.str("license"),
+ metadata: %{Factory.str("key") => Factory.str("val")},
}
assert {:ok, %EconomicEvent{} = evt, _, %EconomicResource{} = to_res} = Domain.create(params, res_params)
{:ok, res_after} = EconomicResource.Domain.one(params.resource_inventoried_as_id)
@@ -1295,6 +1349,12 @@ describe "`create/2` with transfer:" do
#assert to_res.image == res_params.image
assert to_res.tracking_identifier == res_params.tracking_identifier
assert to_res.lot_id == res_params.lot_id
+ assert to_res.okhv == res_params.okhv
+ assert to_res.repo == res_params.repo
+ assert to_res.version == res_params.version
+ assert to_res.licensor == res_params.licensor
+ assert to_res.license == res_params.license
+ assert to_res.metadata == res_params.metadata
assert to_res.primary_accountable_id == params.receiver_id
assert to_res.custodian_id == params.receiver_id
@@ -1565,6 +1625,12 @@ describe "`create/2` with move:" do
#image: Factory.img(),
tracking_identifier: Factory.str("tracking identifier"),
lot_id: Factory.insert!(:product_batch).id,
+ okhv: Factory.str("okhv"),
+ repo: Factory.uri(),
+ version: Factory.str("version"),
+ licensor: Factory.str("licensor"),
+ license: Factory.str("license"),
+ metadata: %{Factory.str("key") => Factory.str("val")},
}
assert {:ok, %EconomicEvent{} = evt, _, %EconomicResource{} = to_res} = Domain.create(params, res_params)
{:ok, res_after} = EconomicResource.Domain.one(params.resource_inventoried_as_id)
@@ -1579,6 +1645,12 @@ describe "`create/2` with move:" do
#assert to_res.image == res_params.image
assert to_res.tracking_identifier == res_params.tracking_identifier
assert to_res.lot_id == res_params.lot_id
+ assert to_res.okhv == res_params.okhv
+ assert to_res.repo == res_params.repo
+ assert to_res.version == res_params.version
+ assert to_res.licensor == res_params.licensor
+ assert to_res.license == res_params.license
+ assert to_res.metadata == res_params.metadata
assert to_res.primary_accountable_id == params.receiver_id
assert to_res.custodian_id == params.receiver_id
diff --git a/test/vf/economic_resource/domain.test.exs b/test/vf/economic_resource/domain.test.exs
@@ -57,6 +57,12 @@ setup ctx do
lot_id: Factory.insert!(:product_batch).id,
contained_in_id: Factory.insert!(:economic_resource).id,
unit_of_effort_id: Factory.insert!(:unit).id,
+ okhv: Factory.str("okhv"),
+ repo: Factory.uri(),
+ version: Factory.str("version"),
+ licensor: Factory.str("licensor"),
+ license: Factory.str("license"),
+ metadata: %{"something" => "something"},
}
if ctx[:no_insert] do
diff --git a/test/vf/economic_resource/type.test.exs b/test/vf/economic_resource/type.test.exs
@@ -54,6 +54,12 @@ fragment economicResource on EconomicResource {
lot {id}
containedIn {id}
unitOfEffort {id}
+ okhv
+ repo
+ version
+ licensor
+ license
+ metadata
}
"""
@@ -86,6 +92,12 @@ describe "Query" do
assert data["lot"]["id"] == new.lot_id
assert data["containedIn"]["id"] == new.contained_in_id
assert data["unitOfEffort"]["id"] == new.unit_of_effort_id
+ assert data["okhv"] == new.okhv
+ assert data["repo"] == new.repo
+ assert data["version"] == new.version
+ assert data["licensor"] == new.licensor
+ assert data["license"] == new.license
+ assert data["metadata"] == new.metadata
end
end