zf

zenflows testing
git clone https://s.sonu.ch/~srfsh/zf.git
Log | Files | Refs | Submodules | README | LICENSE

type.ex (9642B)


      1 # Zenflows is designed to implement the Valueflows vocabulary,
      2 # written and maintained by srfsh <info@dyne.org>.
      3 # Copyright (C) 2021-2023 Dyne.org foundation <foundation@dyne.org>.
      4 #
      5 # This program is free software: you can redistribute it and/or modify
      6 # it under the terms of the GNU Affero General Public License as published by
      7 # the Free Software Foundation, either version 3 of the License, or
      8 # (at your option) any later version.
      9 #
     10 # This program is distributed in the hope that it will be useful,
     11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 # GNU Affero General Public License for more details.
     14 #
     15 # You should have received a copy of the GNU Affero General Public License
     16 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
     17 
     18 defmodule Zenflows.VF.EconomicEvent.Type do
     19 @moduledoc false
     20 
     21 use Absinthe.Schema.Notation
     22 
     23 alias Zenflows.VF.{
     24 	EconomicEvent,
     25 	EconomicEvent.Resolv,
     26 	EconomicResource,
     27 	Process,
     28 }
     29 
     30 @action """
     31 Relates an economic event to a verb, such as consume, produce, work,
     32 improve, etc.
     33 """
     34 @input_of "Defines the process to which this event is an input."
     35 @input_of_id "(`Process`) #{@input_of}"
     36 @output_of "Defines the process to which this event is an output."
     37 @output_of_id "(`Process`) #{@output_of}"
     38 @provider """
     39 The economic agent from whom the actual economic event is initiated.
     40 """
     41 @provider_id "(`Agent`) #{@provider}"
     42 @receiver "The economic agent whom the actual economic event is for."
     43 @receiver_id "(`Agent`) #{@receiver}"
     44 @resource_inventoried_as """
     45 Economic resource involved in the economic event.
     46 """
     47 @resource_inventoried_as_id """
     48 (`EconomicResource`) #{@resource_inventoried_as}
     49 """
     50 @to_resource_inventoried_as """
     51 Additional economic resource on the economic event when needed by the
     52 receiver.  Used when a transfer or move, or sometimes other actions,
     53 requires explicitly identifying an economic resource on the receiving
     54 side.
     55 """
     56 @to_resource_inventoried_as_id """
     57 (`EconomicResource`) #{@to_resource_inventoried_as}
     58 """
     59 @resource_classified_as """
     60 References a concept in a common taxonomy or other classification scheme
     61 for purposes of categorization or grouping.
     62 """
     63 @resource_conforms_to """
     64 The primary resource specification or definition of an existing or
     65 potential economic resource.  A resource will have only one, as this
     66 specifies exactly what the resource is.
     67 """
     68 @resource_conforms_to_id """
     69 (`ResourceSpecification`) #{@resource_conforms_to}
     70 """
     71 @resource_quantity """
     72 The amount and unit of the economic resource counted or inventoried.
     73 This is the quantity that could be used to increment or decrement a
     74 resource, depending on the type of resource and resource effect of action.
     75 """
     76 @effort_quantity """
     77 The amount and unit of the work or use or citation effort-based action.
     78 This is often a time duration, but also could be cycle counts or other
     79 measures of effort or usefulness.
     80 """
     81 @has_beginning "The beginning of the economic event."
     82 @has_end "The end of the economic event."
     83 @has_point_in_time """
     84 The date/time at which the economic event occurred.  Can be used instead of beginning and end."
     85 """
     86 @note "A textual description or comment."
     87 @to_location "The new location of the receiver resource."
     88 @to_location_id "(`SpatialThing`) #{@to_location}"
     89 @at_location "The place where an economic event occurs.  Usually mappable."
     90 @at_location_id "(`SpatialThing`) #{@at_location}"
     91 @realization_of "This economic event occurs as part of this agreement."
     92 @realization_of_id "(`Agreement`) #{@realization_of}"
     93 #@in_scope_of """
     94 #Grouping around something to create a boundary or context, used for
     95 #documenting, accounting, planning.
     96 #"""
     97 @agreed_in """
     98 Reference to an agreement between agents which specifies the rules or
     99 policies or calculations which govern this economic event.
    100 """
    101 @triggered_by "References another economic event that implied this economic event, often based on a prior agreement."
    102 @triggered_by_id "(`EconomicEvent`) #{@triggered_by}"
    103 
    104 union :production_flow_item do
    105 	types [:process, :economic_event, :economic_resource]
    106 	resolve_type fn
    107 		%Process{}, _ -> :process
    108 		%EconomicEvent{}, _ -> :economic_event
    109 		%EconomicResource{}, _ -> :economic_resource
    110 	end
    111 end
    112 
    113 union :track_trace_item do
    114 	types [:process, :economic_event, :economic_resource]
    115 	resolve_type fn
    116 		%Process{}, _ -> :process
    117 		%EconomicEvent{}, _ -> :economic_event
    118 		%EconomicResource{}, _ -> :economic_resource
    119 	end
    120 end
    121 
    122 @desc """
    123 An observed economic flow, as opposed to a flow planned to happen in
    124 the future.  This could reflect a change in the quantity of an economic
    125 resource.  It is also defined by its behavior in relation to the economic
    126 resource (see `Action`).
    127 """
    128 object :economic_event do
    129 	field :id, non_null(:id)
    130 
    131 	@desc @action
    132 	field :action, non_null(:action), resolve: &Resolv.action/3
    133 
    134 	@desc @input_of
    135 	field :input_of, :process, resolve: &Resolv.input_of/3
    136 
    137 	@desc @output_of
    138 	field :output_of, :process, resolve: &Resolv.output_of/3
    139 
    140 	@desc @provider
    141 	field :provider, non_null(:agent), resolve: &Resolv.provider/3
    142 
    143 	@desc @receiver
    144 	field :receiver, non_null(:agent), resolve: &Resolv.receiver/3
    145 
    146 	@desc @resource_inventoried_as
    147 	field :resource_inventoried_as, :economic_resource,
    148 		resolve: &Resolv.resource_inventoried_as/3
    149 
    150 	@desc @to_resource_inventoried_as
    151 	field :to_resource_inventoried_as, :economic_resource,
    152 		resolve: &Resolv.to_resource_inventoried_as/3
    153 
    154 	@desc @resource_classified_as
    155 	field :resource_classified_as, list_of(non_null(:uri))
    156 
    157 	@desc @resource_conforms_to
    158 	field :resource_conforms_to, :resource_specification,
    159 		resolve: &Resolv.resource_conforms_to/3
    160 
    161 	@desc @resource_quantity
    162 	field :resource_quantity, :measure,
    163 		resolve: &Resolv.resource_quantity/3
    164 
    165 	@desc @effort_quantity
    166 	field :effort_quantity, :measure,
    167 		resolve: &Resolv.effort_quantity/3
    168 
    169 	@desc @has_beginning
    170 	field :has_beginning, :datetime
    171 
    172 	@desc @has_end
    173 	field :has_end, :datetime
    174 
    175 	@desc @has_point_in_time
    176 	field :has_point_in_time, :datetime
    177 
    178 	@desc @note
    179 	field :note, :string
    180 
    181 	@desc @to_location
    182 	field :to_location, :spatial_thing, resolve: &Resolv.to_location/3
    183 
    184 	@desc @at_location
    185 	field :at_location, :spatial_thing, resolve: &Resolv.at_location/3
    186 
    187 	@desc @realization_of
    188 	field :realization_of, :agreement,
    189 		resolve: &Resolv.realization_of/3
    190 
    191 	@desc @agreed_in
    192 	field :agreed_in, :string
    193 
    194 	@desc @triggered_by
    195 	field :triggered_by, :economic_event,
    196 		resolve: &Resolv.triggered_by/3
    197 
    198 	field :previous_event, :economic_event,
    199 		resolve: &Resolv.previous_event/3
    200 
    201 	field :previous, :production_flow_item,
    202 		resolve: &Resolv.previous/3
    203 end
    204 
    205 input_object :economic_event_create_params do
    206 	@desc @action
    207 	field :action_id, non_null(:string), name: "action"
    208 
    209 	@desc @input_of_id
    210 	field :input_of_id, :id, name: "input_of"
    211 
    212 	@desc @output_of_id
    213 	field :output_of_id, :id, name: "output_of"
    214 
    215 	@desc @provider_id
    216 	field :provider_id, :id, name: "provider"
    217 
    218 	@desc @receiver_id
    219 	field :receiver_id, :id, name: "receiver"
    220 
    221 	@desc @resource_inventoried_as_id
    222 	field :resource_inventoried_as_id, :id, name: "resource_inventoried_as"
    223 
    224 	@desc @to_resource_inventoried_as_id
    225 	field :to_resource_inventoried_as_id, :id, name: "to_resource_inventoried_as"
    226 
    227 	@desc @resource_classified_as
    228 	field :resource_classified_as, list_of(non_null(:uri))
    229 
    230 	@desc @resource_conforms_to_id
    231 	field :resource_conforms_to_id, :id, name: "resource_conforms_to"
    232 
    233 	@desc @resource_quantity
    234 	field :resource_quantity, :imeasure
    235 
    236 	@desc @effort_quantity
    237 	field :effort_quantity, :imeasure
    238 
    239 	@desc @has_beginning
    240 	field :has_beginning, :datetime
    241 
    242 	@desc @has_end
    243 	field :has_end, :datetime
    244 
    245 	@desc @has_point_in_time
    246 	field :has_point_in_time, :datetime
    247 
    248 	@desc @note
    249 	field :note, :string
    250 
    251 	@desc @to_location_id
    252 	field :to_location_id, :id, name: "to_location"
    253 
    254 	@desc @at_location_id
    255 	field :at_location_id, :id, name: "at_location"
    256 
    257 	@desc @realization_of_id
    258 	field :realization_of_id, :id, name: "realization_of"
    259 
    260 	@desc @agreed_in
    261 	field :agreed_in, :string
    262 
    263 	@desc @triggered_by_id
    264 	field :triggered_by_id, :id, name: "triggered_by"
    265 end
    266 
    267 input_object :economic_event_update_params do
    268 	field :id, non_null(:id)
    269 
    270 	@desc @note
    271 	field :note, :string
    272 
    273 	@desc @realization_of_id
    274 	field :realization_of_id, :id, name: "realization_of"
    275 
    276 	@desc @agreed_in
    277 	field :agreed_in, :string
    278 
    279 	@desc @triggered_by_id
    280 	field :triggered_by_id, :id, name: "triggered_by"
    281 end
    282 
    283 object :economic_event_response do
    284 	@desc "Details of the newly created event."
    285 	field :economic_event, non_null(:economic_event)
    286 end
    287 
    288 object :economic_event_edge do
    289 	field :cursor, non_null(:id)
    290 	field :node, non_null(:economic_event)
    291 end
    292 
    293 object :economic_event_connection do
    294 	field :page_info, non_null(:page_info)
    295 	field :edges, non_null(list_of(non_null(:economic_event_edge)))
    296 end
    297 
    298 object :query_economic_event do
    299 	field :economic_event, :economic_event do
    300 		arg :id, non_null(:id)
    301 		resolve &Resolv.economic_event/2
    302 	end
    303 
    304 	field :economic_events, :economic_event_connection do
    305 		arg :first, :integer
    306 		arg :after, :id
    307 		arg :last, :integer
    308 		arg :before, :id
    309 		resolve &Resolv.economic_events/2
    310 	end
    311 
    312 	#recipeFlow(start: ID, limit: Int): [EconomicEvent!]
    313 end
    314 
    315 object :mutation_economic_event do
    316 	field :create_economic_event, non_null(:economic_event_response) do
    317 		arg :event, non_null(:economic_event_create_params)
    318 		arg :new_inventoried_resource, :economic_resource_create_params
    319 		resolve &Resolv.create_economic_event/2
    320 	end
    321 
    322 	field :update_economic_event, non_null(:economic_event_response) do
    323 		arg :event, non_null(:economic_event_update_params)
    324 		resolve &Resolv.update_economic_event/2
    325 	end
    326 end
    327 end