@@ -8,8 +8,8 @@ defmodule DiffoExample.Nbn.Cvc do
88
99 Cvc - Connectivity Virtual Circuit Resource Instance
1010
11- A CVC is the wholesale bandwidth product that aggregates one or more AVC
12- resources and terminates at an NNI Group resource. Each AVC has a related UNI .
11+ A CVC is the wholesale bandwidth product that supports AVC and terminates at an NNI Group.
12+ The CVC assigns cvlan to AVC.
1313 """
1414
1515 alias Diffo.Provider.BaseInstance
@@ -42,7 +42,7 @@ defmodule DiffoExample.Nbn.Cvc do
4242
4343 characteristics do
4444 characteristic :cvc , DiffoExample.Nbn.CvcValue
45- characteristic :cvlan_ids , Diffo.Provider.AssignableValue
45+ characteristic :cvlans , Diffo.Provider.AssignableValue
4646 end
4747
4848 actions do
@@ -86,7 +86,7 @@ defmodule DiffoExample.Nbn.Cvc do
8686 argument :assignment , :struct , constraints: [ instance_of: Assignment ]
8787
8888 change after_action ( fn changeset , result , _context ->
89- with { :ok , result } <- Assigner . assign ( result , changeset , :cvlan_ids , :cvlan_id ) ,
89+ with { :ok , result } <- Assigner . assign ( result , changeset , :cvlans , :cvlan ) ,
9090 { :ok , result } <- Nbn . get_cvc_by_id ( result . id ) ,
9191 do: { :ok , result }
9292 end )
@@ -102,15 +102,33 @@ defmodule DiffoExample.Nbn.Cvc do
102102 do: { :ok , result }
103103 end )
104104 end
105- end
106105
107- attributes do
108- attribute :cvcid , :string do
109- default & DiffoExample.Nbn.Cvc . identifier / 0
106+ update :mine do
107+ description "updates the CVC with data mined from related instances"
108+ argument :characteristic_value_updates , { :array , :term }
109+
110+ change before_action ( fn changeset , context ->
111+ DiffoExample.Nbn.Cvc . mine_related ( changeset , context )
112+ end )
113+
114+ change after_action ( fn changeset , result , _context ->
115+ with { :ok , result } <- Characteristic . update_values ( result , changeset ) ,
116+ { :ok , result } <- Nbn . get_cvc_by_id ( result . id ) ,
117+ do: { :ok , result }
118+ end )
110119 end
111120 end
112121
113122 def identifier ( ) do
114123 DiffoExample.Nbn.Util . identifier ( "CVC" )
115124 end
125+
126+ # mines related resource to characteristics
127+ def mine_related ( changeset , _context ) when is_struct ( changeset , Ash.Changeset ) do
128+ reverse_relationships = Ash.Changeset . get_attribute ( changeset , :reverse_relationships )
129+
130+ svlan = { :svlan , hd ( hd ( reverse_relationships ) . characteristics ) . value }
131+
132+ Ash.Changeset . force_set_argument ( changeset , :characteristic_value_updates , cvc: [ svlan ] )
133+ end
116134end
0 commit comments