Skip to content

Commit 56bc977

Browse files
committed
access only on diffo 040
1 parent c0023a2 commit 56bc977

76 files changed

Lines changed: 1958 additions & 958 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

lib/nbn/nbn.ex renamed to _aside/nbn/nbn.ex

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ defmodule DiffoExample.Nbn do
1414
"""
1515
use Ash.Domain,
1616
otp_app: :diffo,
17+
fragments: [Diffo.Provider.DomainFragment],
1718
extensions: [AshJsonApi.Domain]
1819

1920
alias DiffoExample.Nbn.NbnEthernet
@@ -24,6 +25,13 @@ defmodule DiffoExample.Nbn do
2425
alias DiffoExample.Nbn.NniGroup
2526
alias DiffoExample.Nbn.Nni
2627
alias DiffoExample.Nbn.Rsp
28+
alias DiffoExample.Nbn.AvcCharacteristic
29+
alias DiffoExample.Nbn.CvcCharacteristic
30+
alias DiffoExample.Nbn.NniGroupCharacteristic
31+
alias DiffoExample.Nbn.NniCharacteristic
32+
alias DiffoExample.Nbn.NtdCharacteristic
33+
alias DiffoExample.Nbn.UniCharacteristic
34+
alias DiffoExample.Nbn.PriCharacteristic
2735

2836
domain do
2937
description "An example showing how TMF Resources for a fictional NBN domain can be extended from the Provider domain"
@@ -37,7 +45,6 @@ defmodule DiffoExample.Nbn do
3745
post :build
3846
patch :define
3947
patch :relate, route: "/:id/relate"
40-
patch :mine, route: "/:id/mine"
4148
delete :destroy
4249
end
4350

@@ -47,7 +54,6 @@ defmodule DiffoExample.Nbn do
4754
post :build
4855
patch :define
4956
patch :relate, route: "/:id/relate"
50-
patch :mine, route: "/:id/mine"
5157
delete :destroy
5258
end
5359

@@ -57,7 +63,6 @@ defmodule DiffoExample.Nbn do
5763
post :build
5864
patch :define
5965
patch :relate, route: "/:id/relate"
60-
patch :mine, route: "/:id/mine"
6166
delete :destroy
6267
end
6368

@@ -76,7 +81,6 @@ defmodule DiffoExample.Nbn do
7681
post :build
7782
patch :define
7883
patch :relate, route: "/:id/relate"
79-
patch :mine, route: "/:id/mine"
8084
delete :destroy
8185
end
8286

@@ -110,23 +114,20 @@ defmodule DiffoExample.Nbn do
110114
define :build_nbn_ethernet, action: :build
111115
define :define_nbn_ethernet, action: :define
112116
define :relate_nbn_ethernet, action: :relate
113-
define :mine_nbn_ethernet, action: :mine
114117
end
115118

116119
resource Uni do
117120
define :get_uni_by_id, action: :read, get_by: :id
118121
define :build_uni, action: :build
119122
define :define_uni, action: :define
120123
define :relate_uni, action: :relate
121-
define :mine_uni, action: :mine
122124
end
123125

124126
resource Avc do
125127
define :get_avc_by_id, action: :read, get_by: :id
126128
define :build_avc, action: :build
127129
define :define_avc, action: :define
128130
define :relate_avc, action: :relate
129-
define :mine_avc, action: :mine
130131
end
131132

132133
resource Ntd do
@@ -143,7 +144,6 @@ defmodule DiffoExample.Nbn do
143144
define :define_cvc, action: :define
144145
define :assign_cvlan, action: :assign_cvlan
145146
define :relate_cvc, action: :relate
146-
define :mine_cvc, action: :mine
147147
end
148148

149149
resource NniGroup do
@@ -170,5 +170,13 @@ defmodule DiffoExample.Nbn do
170170
define :suspend_rsp, action: :suspend
171171
define :deactivate_rsp, action: :deactivate
172172
end
173+
174+
resource AvcCharacteristic
175+
resource CvcCharacteristic
176+
resource NniGroupCharacteristic
177+
resource NniCharacteristic
178+
resource NtdCharacteristic
179+
resource UniCharacteristic
180+
resource PriCharacteristic
173181
end
174182
end
Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ defmodule DiffoExample.Nbn.Avc do
1414

1515
alias Diffo.Provider.BaseInstance
1616
alias Diffo.Provider.Instance.Relationship
17-
alias Diffo.Provider.Instance.Characteristic
17+
alias Diffo.Provider.Extension.Characteristic
1818

1919
alias DiffoExample.Nbn
2020

@@ -33,7 +33,7 @@ defmodule DiffoExample.Nbn.Avc do
3333
type "avc"
3434
end
3535

36-
structure do
36+
provider do
3737
specification do
3838
id "b2c3d4e5-6f7a-4b8c-9d0e-1f2a3b4c5d6e"
3939
name "avc"
@@ -43,14 +43,14 @@ defmodule DiffoExample.Nbn.Avc do
4343
end
4444

4545
characteristics do
46-
characteristic :avc, DiffoExample.Nbn.AvcValue
47-
characteristic :cvc, DiffoExample.Nbn.CvcValue
46+
characteristic :avc, DiffoExample.Nbn.AvcCharacteristic
47+
characteristic :cvc, DiffoExample.Nbn.CvcCharacteristic
4848
end
49-
end
5049

51-
behaviour do
52-
actions do
53-
create :build
50+
behaviour do
51+
actions do
52+
create :build
53+
end
5454
end
5555
end
5656

@@ -74,7 +74,7 @@ defmodule DiffoExample.Nbn.Avc do
7474
argument :characteristic_value_updates, {:array, :term}
7575

7676
change after_action(fn changeset, result, _context ->
77-
with {:ok, result} <- Characteristic.update_values(result, changeset),
77+
with {:ok, result} <- Characteristic.update_all(result, changeset, characteristics()),
7878
{:ok, result} <- Nbn.get_avc_by_id(result.id),
7979
do: {:ok, result}
8080
end)
@@ -90,21 +90,6 @@ defmodule DiffoExample.Nbn.Avc do
9090
do: {:ok, result}
9191
end)
9292
end
93-
94-
update :mine do
95-
description "updates the AVC with data mined from related instances"
96-
argument :characteristic_value_updates, {:array, :term}
97-
98-
change before_action(fn changeset, context ->
99-
DiffoExample.Nbn.Avc.mine_related(changeset, context)
100-
end)
101-
102-
change after_action(fn changeset, result, _context ->
103-
with {:ok, result} <- Characteristic.update_values(result, changeset),
104-
{:ok, result} <- Nbn.get_avc_by_id(result.id),
105-
do: {:ok, result}
106-
end)
107-
end
10893
end
10994

11095
attributes do
@@ -119,14 +104,5 @@ defmodule DiffoExample.Nbn.Avc do
119104
DiffoExample.Nbn.Util.identifier("AVC")
120105
end
121106

122-
# mines related resource to characteristics
123-
def mine_related(changeset, _context) when is_struct(changeset, Ash.Changeset) do
124-
avc = Ash.load!(changeset.data, reverse_relationships: [:characteristics])
125-
126-
cvlan = {:cvlan, Diffo.Unwrap.unwrap(hd(hd(avc.reverse_relationships).characteristics).value)}
127-
128-
Ash.Changeset.force_set_argument(changeset, :characteristic_value_updates, avc: [cvlan])
129-
end
130-
131107
use DiffoExample.Nbn.RspOwnership
132108
end
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# SPDX-FileCopyrightText: 2025 diffo_example contributors <https://github.com/diffo-dev/diffo_example/graphs.contributors>
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
defmodule DiffoExample.Nbn.AvcCharacteristic do
6+
@moduledoc "Typed characteristic for an AVC's circuit properties."
7+
use Ash.Resource,
8+
fragments: [Diffo.Provider.BaseCharacteristic],
9+
domain: DiffoExample.Nbn
10+
11+
resource do
12+
description "Typed characteristic carrying AVC circuit fields"
13+
plural_name :avc_characteristics
14+
end
15+
16+
attributes do
17+
attribute :cvlan, :integer, public?: true
18+
attribute :bandwidth_profile, DiffoExample.Nbn.BandwidthProfile, public?: true
19+
end
20+
21+
calculations do
22+
calculate :value, Diffo.Type.CharacteristicValue,
23+
Diffo.Provider.Calculations.CharacteristicValue do
24+
public? true
25+
end
26+
end
27+
28+
actions do
29+
create :create do
30+
accept [:name, :cvlan, :bandwidth_profile]
31+
argument :instance_id, :uuid
32+
argument :feature_id, :uuid
33+
change manage_relationship(:instance_id, :instance, type: :append)
34+
change manage_relationship(:feature_id, :feature, type: :append)
35+
end
36+
37+
update :update do
38+
accept [:cvlan, :bandwidth_profile]
39+
end
40+
end
41+
42+
preparations do
43+
prepare build(load: [:value])
44+
end
45+
46+
jason do
47+
pick [:name, :value]
48+
compact true
49+
end
50+
end
51+
52+
defmodule DiffoExample.Nbn.AvcCharacteristic.Value do
53+
@moduledoc false
54+
use Ash.TypedStruct, extensions: [AshJason.TypedStruct, AshOutstanding.TypedStruct]
55+
56+
alias DiffoExample.Nbn.BandwidthProfile
57+
58+
typed_struct do
59+
field :cvlan, :integer
60+
field :bandwidth_profile, BandwidthProfile
61+
end
62+
63+
outstanding do
64+
expect [:cvlan, :bandwidth_profile]
65+
end
66+
67+
jason do
68+
pick [:cvlan, :bandwidth_profile]
69+
compact true
70+
end
71+
end

lib/nbn/resources/characteristic_values/avc_value.ex renamed to _aside/nbn/resources/characteristic_values/avc_value.ex

File renamed without changes.

0 commit comments

Comments
 (0)