This repository has been archived by the owner on May 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
technical.ex
84 lines (74 loc) · 2.43 KB
/
technical.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
defmodule SmartCity.Dataset.Technical do
@moduledoc """
A struct defining technical metadata on a registry event message.
"""
alias SmartCity.Helpers
@type not_required(type) :: type | nil
@type t() :: %SmartCity.Dataset.Technical{
dataName: String.t(),
orgName: String.t(),
systemName: String.t(),
sourceUrl: String.t(),
authUrl: String.t(),
sourceFormat: String.t(),
schema: not_required(list(map())),
orgId: not_required(String.t()),
sourceType: not_required(String.t()),
cadence: not_required(String.t()),
sourceQueryParams: not_required(map()),
transformations: not_required(list()),
validations: not_required(list()),
sourceHeaders: not_required(map()),
authHeaders: not_required(map()),
protocol: not_required(list(String.t())),
partitioner: not_required(%{type: String.t(), query: String.t()}),
private: not_required(boolean())
}
@derive Jason.Encoder
defstruct cadence: "never",
credentials: false,
dataName: nil,
sourceHeaders: %{},
authHeaders: %{},
orgId: nil,
orgName: nil,
partitioner: %{type: nil, query: nil},
private: true,
sourceQueryParams: %{},
schema: [],
sourceFormat: nil,
sourceType: "remote",
sourceUrl: nil,
authUrl: nil,
systemName: nil,
protocol: nil,
transformations: [],
validations: []
@doc """
Returns a new `SmartCity.Dataset.Technical`.
Can be created from `Map` with string or atom keys.
Raises an `ArgumentError` when passed invalid input
## Parameters
- msg: Map with string or atom keys that defines the dataset's technical metadata
_Required Keys_
- dataName
- orgName
- systemName
- sourceUrl
- sourceFormat
- sourceType will default to "remote"
- cadence will default to "never"
"""
@spec new(map()) :: SmartCity.Dataset.Technical.t()
def new(%{"dataName" => _} = msg) do
msg
|> Helpers.to_atom_keys()
|> new()
end
def new(%{dataName: _, orgName: _, systemName: _, sourceUrl: _, sourceFormat: _} = msg) do
struct(%__MODULE__{}, msg)
end
def new(msg) do
raise ArgumentError, "Invalid technical metadata: #{inspect(msg)}"
end
end