isomorfeus-data 1.0.0.zeta12 → 1.0.0.zeta13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -0
- data/lib/isomorfeus-data.rb +2 -0
- data/lib/isomorfeus/data/attribute_support.rb +2 -2
- data/lib/isomorfeus/data/config.rb +1 -1
- data/lib/isomorfeus/data/element_validator.rb +16 -16
- data/lib/isomorfeus/data/generic_class_api.rb +34 -52
- data/lib/isomorfeus/data/generic_instance_api.rb +35 -8
- data/lib/isomorfeus/data/handler/arango.rb +2 -3
- data/lib/isomorfeus/data/handler/generic.rb +44 -55
- data/lib/isomorfeus/data/handler/object_call.rb +2 -3
- data/lib/isomorfeus/data/handler/object_store.rb +2 -3
- data/lib/isomorfeus/data/version.rb +1 -1
- data/lib/isomorfeus_data/lucid_data/array/base.rb +0 -2
- data/lib/isomorfeus_data/lucid_data/array/mixin.rb +18 -22
- data/lib/isomorfeus_data/lucid_data/collection/base.rb +0 -2
- data/lib/isomorfeus_data/lucid_data/collection/mixin.rb +33 -36
- data/lib/isomorfeus_data/lucid_data/composition/base.rb +0 -2
- data/lib/isomorfeus_data/lucid_data/composition/mixin.rb +35 -29
- data/lib/isomorfeus_data/lucid_data/document/base.rb +0 -2
- data/lib/isomorfeus_data/lucid_data/edge/base.rb +0 -2
- data/lib/isomorfeus_data/lucid_data/edge/mixin.rb +39 -31
- data/lib/isomorfeus_data/lucid_data/edge_collection/base.rb +0 -2
- data/lib/isomorfeus_data/lucid_data/edge_collection/mixin.rb +33 -29
- data/lib/isomorfeus_data/lucid_data/graph/base.rb +0 -2
- data/lib/isomorfeus_data/lucid_data/graph/mixin.rb +41 -40
- data/lib/isomorfeus_data/lucid_data/hash/base.rb +0 -2
- data/lib/isomorfeus_data/lucid_data/hash/mixin.rb +20 -25
- data/lib/isomorfeus_data/lucid_data/link/base.rb +0 -2
- data/lib/isomorfeus_data/lucid_data/link_collection/base.rb +0 -2
- data/lib/isomorfeus_data/lucid_data/node/base.rb +0 -2
- data/lib/isomorfeus_data/lucid_data/node/mixin.rb +18 -23
- data/lib/isomorfeus_data/lucid_data/query/base.rb +13 -0
- data/lib/isomorfeus_data/lucid_data/query/mixin.rb +88 -0
- data/lib/isomorfeus_data/lucid_data/query_result.rb +12 -10
- data/lib/isomorfeus_data/lucid_data/vertex/base.rb +0 -2
- data/lib/lucid_arango/collection/base.rb +0 -2
- data/lib/lucid_arango/collection/mixin.rb +0 -2
- data/lib/lucid_arango/document/base.rb +0 -2
- data/lib/lucid_arango/edge/base.rb +0 -3
- data/lib/lucid_arango/edge/mixin.rb +0 -2
- data/lib/lucid_arango/edge_collection/base.rb +0 -2
- data/lib/lucid_arango/edge_collection/mixin.rb +0 -2
- data/lib/lucid_arango/graph/base.rb +0 -2
- data/lib/lucid_arango/graph/mixin.rb +0 -2
- data/lib/lucid_arango/node/base.rb +0 -3
- data/lib/lucid_arango/node/mixin.rb +0 -2
- data/lib/lucid_arango/object/base.rb +0 -2
- data/lib/lucid_arango/object/mixin.rb +1 -3
- data/lib/lucid_arango/remote_object/base.rb +0 -2
- data/lib/lucid_arango/remote_object/mixin.rb +0 -2
- data/lib/lucid_arango/vertex/base.rb +0 -2
- metadata +10 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5cee3d71649477f132cee03fd570b5fc5c4ef9430ccad0d40daab90e05525eff
|
4
|
+
data.tar.gz: 6839dfeb7ceebc8f7311073c31d69f11d73265ab0689d798d2c60754f4e65b72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 189425d916a46bda087d17a9d49afe58bf6334446605a0d631032aff08b44f0b651acad2dea727ca6499e170d602bfe6cc1dccd31eaf5172ad3b9e737bf6399f
|
7
|
+
data.tar.gz: bb087ac1acdf8887b28bea4b5c997c2fac9263c500c7e88d18a3ef66115bde41a93bdf2955ac1546bc85e947405720f4e22d36d19abf26dd9388c3956e518dbf
|
data/README.md
CHANGED
@@ -36,4 +36,10 @@ All classes follow the common principles and the common API above.
|
|
36
36
|
- [LucidData::Graph](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-data/docs/data_graph.md) - A graph, which can be build from several LucidData::Collection objects and LucidData::EdgeCollection objects
|
37
37
|
- [LucidData::Hash](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-data/docs/data_hash.md) - A hash, easily accessible on client and server
|
38
38
|
|
39
|
+
For convenience the following generic classes are provided. They can be used when creating a separate class wouldn't be useful:
|
40
|
+
- LucidData::GenericCollection
|
41
|
+
- LucidData::GenericEdgeCollection
|
42
|
+
- LucidData::GenericNode
|
43
|
+
- LucidData::GenericEdge
|
44
|
+
|
39
45
|
(more to come soon)
|
data/lib/isomorfeus-data.rb
CHANGED
@@ -44,6 +44,8 @@ else
|
|
44
44
|
require 'isomorfeus_data/lucid_data/graph/base'
|
45
45
|
require 'isomorfeus_data/lucid_data/composition/mixin'
|
46
46
|
require 'isomorfeus_data/lucid_data/composition/base'
|
47
|
+
require 'isomorfeus_data/lucid_data/query/mixin'
|
48
|
+
require 'isomorfeus_data/lucid_data/query/base'
|
47
49
|
|
48
50
|
require 'isomorfeus_data/lucid_data/generic_collection'
|
49
51
|
require 'isomorfeus_data/lucid_data/generic_edge'
|
@@ -18,14 +18,14 @@ module Isomorfeus
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def _validate_attribute(attr_name, attr_val)
|
21
|
-
|
21
|
+
Isomorfeus.raise_error(message: "#{self.name}: No such attribute declared: '#{attr_name}'!") unless attribute_conditions.key?(attr_name)
|
22
22
|
Isomorfeus::Props::Validator.new(self.name, attr_name, attr_val, attribute_conditions[attr_name]).validate!
|
23
23
|
end
|
24
24
|
|
25
25
|
def _validate_attributes(attrs)
|
26
26
|
attribute_conditions.each_key do |attr|
|
27
27
|
if attribute_conditions[attr].key?(:required) && attribute_conditions[attr][:required] && !attrs.key?(attr)
|
28
|
-
|
28
|
+
Isomorfeus.raise_error(message: "Required attribute #{attr} not given!")
|
29
29
|
end
|
30
30
|
end
|
31
31
|
attrs.each { |attr, val| _validate_attribute(attr, val) }
|
@@ -50,7 +50,7 @@ module Isomorfeus
|
|
50
50
|
begin
|
51
51
|
Arango.current_server.get_database(database)
|
52
52
|
rescue Exception => e
|
53
|
-
|
53
|
+
Isomorfeus.raise_error(message: "Can't connect to database '#{database}' (#{e.message}).")
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
@@ -33,7 +33,7 @@ module Isomorfeus
|
|
33
33
|
end
|
34
34
|
@e = !!@e if @o[:type] == :boolean
|
35
35
|
rescue
|
36
|
-
|
36
|
+
Isomorfeus.raise_error(message: "#{@c}: #{@p} cast failed") unless @e.class == @o[:class]
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
@@ -53,13 +53,13 @@ module Isomorfeus
|
|
53
53
|
def type!
|
54
54
|
return if @o[:allow_nil] && @e.nil?
|
55
55
|
if @o.key?(:class)
|
56
|
-
|
56
|
+
Isomorfeus.raise_error(message: "#{@c}: #{@p} class not #{@o[:class]}") unless @e.class == @o[:class]
|
57
57
|
elsif @o.key?(:is_a)
|
58
|
-
|
58
|
+
Isomorfeus.raise_error(message: "#{@c}: #{@p} is not a #{@o[:is_a]}") unless @e.is_a?(@o[:is_a])
|
59
59
|
elsif @o.key?(:type)
|
60
60
|
case @o[:type]
|
61
61
|
when :boolean
|
62
|
-
|
62
|
+
Isomorfeus.raise_error(message: "#{@c}: #{@p} is not a boolean") unless @e.class == TrueClass || @e.class == FalseClass
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
@@ -76,48 +76,48 @@ module Isomorfeus
|
|
76
76
|
|
77
77
|
# specific validations
|
78
78
|
def c_gt(v)
|
79
|
-
|
79
|
+
Isomorfeus.raise_error(message: "#{@c}: #{@p} not greater than #{v}!") unless @e > v
|
80
80
|
end
|
81
81
|
|
82
82
|
def c_lt(v)
|
83
|
-
|
83
|
+
Isomorfeus.raise_error(message: "#{@c}: #{@p} not less than #{v}!") unless @e < v
|
84
84
|
end
|
85
85
|
|
86
86
|
def c_keys(v)
|
87
|
-
|
87
|
+
Isomorfeus.raise_error(message: "#{@c}: #{@p} keys dont fit!") unless @e.keys.sort == v.sort
|
88
88
|
end
|
89
89
|
|
90
90
|
def c_size(v)
|
91
|
-
|
91
|
+
Isomorfeus.raise_error(message: "#{@c}: #{@p} length/size is not #{v}") unless @e.size == v
|
92
92
|
end
|
93
93
|
|
94
94
|
def c_matches(v)
|
95
|
-
|
95
|
+
Isomorfeus.raise_error(message: "#{@c}: #{@p} does not match #{v}") unless v.match?(@e)
|
96
96
|
end
|
97
97
|
|
98
98
|
def c_max(v)
|
99
|
-
|
99
|
+
Isomorfeus.raise_error(message: "#{@c}: #{@p} is larger than #{v}") unless @e <= v
|
100
100
|
end
|
101
101
|
|
102
102
|
def c_min(v)
|
103
|
-
|
103
|
+
Isomorfeus.raise_error(message: "#{@c}: #{@p} is smaller than #{v}") unless @e >= v
|
104
104
|
end
|
105
105
|
|
106
106
|
def c_max_size(v)
|
107
|
-
|
107
|
+
Isomorfeus.raise_error(message: "#{@c}: #{@p} is larger than #{v}") unless @e.size <= v
|
108
108
|
end
|
109
109
|
|
110
110
|
def c_min_size(v)
|
111
|
-
|
111
|
+
Isomorfeus.raise_error(message: "#{@c}: #{@p} is smaller than #{v}") unless @e.size >= v
|
112
112
|
end
|
113
113
|
|
114
114
|
def c_direction(v)
|
115
|
-
|
116
|
-
|
115
|
+
Isomorfeus.raise_error(message: "#{@c}: #{@p} is positive") if v == :negative && @e >= 0
|
116
|
+
Isomorfeus.raise_error(message: "#{@c}: #{@p} is negative") if v == :positive && @e < 0
|
117
117
|
end
|
118
118
|
|
119
119
|
def c_test
|
120
|
-
|
120
|
+
Isomorfeus.raise_error(message: "#{@c}: #{@p} test condition check failed") unless @o[:test].call(@e)
|
121
121
|
end
|
122
122
|
|
123
123
|
def c_sub_type(v)
|
@@ -25,9 +25,9 @@ module Isomorfeus
|
|
25
25
|
agent.processed = true
|
26
26
|
if agent.response.key?(:error)
|
27
27
|
`console.error(#{agent.response[:error].to_n})`
|
28
|
-
|
28
|
+
Isomorfeus.raise_error(message: agent.response[:error])
|
29
29
|
end
|
30
|
-
Isomorfeus.store.dispatch(type: 'DATA_DESTROY', data:
|
30
|
+
Isomorfeus.store.dispatch(type: 'DATA_DESTROY', data: [self.name, key])
|
31
31
|
agent.result = true
|
32
32
|
end
|
33
33
|
end
|
@@ -48,7 +48,7 @@ module Isomorfeus
|
|
48
48
|
agent.processed = true
|
49
49
|
if agent.response.key?(:error)
|
50
50
|
`console.error(#{agent.response[:error].to_n})`
|
51
|
-
|
51
|
+
Isomorfeus.raise_error(message: agent.response[:error])
|
52
52
|
end
|
53
53
|
instance._load_from_store!
|
54
54
|
Isomorfeus.store.dispatch(type: 'DATA_LOAD', data: agent.full_response[:data])
|
@@ -57,40 +57,18 @@ module Isomorfeus
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
def
|
61
|
-
|
62
|
-
|
63
|
-
query_result_instance
|
60
|
+
def save(instance:)
|
61
|
+
instance.promise_save
|
62
|
+
instance
|
64
63
|
end
|
65
64
|
|
66
|
-
def
|
67
|
-
|
68
|
-
props.each_key do |prop_name|
|
69
|
-
raise "#{self.to_s} No such query prop declared: '#{prop_name}'!" unless declared_props.key?(prop_name)
|
70
|
-
end
|
71
|
-
validate_props(props)
|
72
|
-
data_props = { props: props, query_result_instance_key: query_result_instance.key }
|
73
|
-
props_json = data_props.to_json
|
74
|
-
Isomorfeus::Transport.promise_send_path( 'Isomorfeus::Data::Handler::Generic', self.name, :query, props_json).then do |agent|
|
75
|
-
if agent.processed
|
76
|
-
agent.result
|
77
|
-
else
|
78
|
-
agent.processed = true
|
79
|
-
if agent.response.key?(:error)
|
80
|
-
`console.error(#{agent.response[:error].to_n})`
|
81
|
-
raise agent.response[:error]
|
82
|
-
end
|
83
|
-
query_result_instance._load_from_store!
|
84
|
-
Isomorfeus.store.dispatch(type: 'DATA_LOAD', data: agent.full_response[:data])
|
85
|
-
agent.result = query_result_instance
|
86
|
-
end
|
87
|
-
end
|
65
|
+
def promise_save(instance:)
|
66
|
+
instance.promise_save
|
88
67
|
end
|
89
68
|
|
90
69
|
# execute
|
91
70
|
def execute_destroy(_); end
|
92
71
|
def execute_load(_); end
|
93
|
-
def execute_query(_); end
|
94
72
|
def execute_save(_); end
|
95
73
|
else
|
96
74
|
def promise_create(key:, **things)
|
@@ -101,14 +79,14 @@ module Isomorfeus
|
|
101
79
|
end
|
102
80
|
|
103
81
|
def promise_destroy(key:)
|
104
|
-
|
82
|
+
result = self.destroy(key: key)
|
105
83
|
result_promise = Promise.new
|
106
|
-
result_promise.resolve(
|
84
|
+
result_promise.resolve(result)
|
107
85
|
result_promise
|
108
86
|
end
|
109
87
|
|
110
|
-
def destroy(key
|
111
|
-
instance_exec(key: key,
|
88
|
+
def destroy(key:)
|
89
|
+
!!instance_exec(key: key, &@_destroy_block)
|
112
90
|
end
|
113
91
|
|
114
92
|
def promise_load(key:)
|
@@ -118,22 +96,22 @@ module Isomorfeus
|
|
118
96
|
result_promise
|
119
97
|
end
|
120
98
|
|
121
|
-
def
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
99
|
+
def load(key:)
|
100
|
+
data = instance_exec(key: key, &@_load_block)
|
101
|
+
return nil unless data
|
102
|
+
return data if data.class == self
|
103
|
+
Isomorfeus.raise_error "#{self.to_s}: execute_load must return a instance of #{self.to_s} or nil. Returned was: #{data.class}." if data.class != self
|
104
|
+
data
|
126
105
|
end
|
127
106
|
|
128
|
-
def
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
query_result
|
107
|
+
def save(instance:)
|
108
|
+
previous_key = instance.key
|
109
|
+
data = instance_exec(instance: instance, &@_save_block)
|
110
|
+
return nil unless data
|
111
|
+
Isomorfeus.raise_error "#{self.to_s}: execute_save must return a instance of #{self.to_s} or nil. Returned was: #{data.class}." if data.class != self
|
112
|
+
data.instance_variable_set(:@previous_key, previous_key) if data.key != previous_key
|
113
|
+
data._unchange!
|
114
|
+
data
|
137
115
|
end
|
138
116
|
|
139
117
|
# execute
|
@@ -145,14 +123,18 @@ module Isomorfeus
|
|
145
123
|
@_load_block = block
|
146
124
|
end
|
147
125
|
|
148
|
-
def execute_query(&block)
|
149
|
-
@_query_block = block
|
150
|
-
end
|
151
|
-
|
152
126
|
def execute_save(&block)
|
153
127
|
@_save_block = block
|
154
128
|
end
|
155
129
|
end
|
130
|
+
|
131
|
+
def current_user
|
132
|
+
Isomorfeus.current_user
|
133
|
+
end
|
134
|
+
|
135
|
+
def pub_sub_client
|
136
|
+
Isomorfeus.pub_sub_client
|
137
|
+
end
|
156
138
|
end
|
157
139
|
end
|
158
140
|
end
|
@@ -47,30 +47,57 @@ module Isomorfeus
|
|
47
47
|
alias create save
|
48
48
|
|
49
49
|
def promise_save
|
50
|
-
data_hash = to_transport
|
51
|
-
if
|
52
|
-
|
53
|
-
|
54
|
-
Isomorfeus::Transport.promise_send_path( 'Isomorfeus::Data::Handler::Generic', self.name, 'save', data_hash).then do |agent|
|
50
|
+
data_hash = { instance: to_transport }
|
51
|
+
data_hash.deep_merge!(included_items: included_items_to_transport) if respond_to?(:included_items_to_transport)
|
52
|
+
class_name = self.class.name
|
53
|
+
Isomorfeus::Transport.promise_send_path( 'Isomorfeus::Data::Handler::Generic', class_name, :save, data_hash).then do |agent|
|
55
54
|
if agent.processed
|
56
55
|
agent.result
|
57
56
|
else
|
58
57
|
agent.processed = true
|
59
58
|
if agent.response.key?(:error)
|
60
59
|
`console.error(#{agent.response[:error].to_n})`
|
61
|
-
|
60
|
+
Isomorfeus.raise_error(message: agent.response[:error])
|
61
|
+
end
|
62
|
+
data = agent.full_response[:data]
|
63
|
+
if data.key?(class_name) && data[class_name].key?(@key) && data[class_name][@key].key?('new_key')
|
64
|
+
@key = data[class_name][@key]['new_key']
|
65
|
+
@revision = data[class_name][@key]['revision'] if data[class_name][@key].key?('revision')
|
66
|
+
_update_paths
|
62
67
|
end
|
63
|
-
|
64
|
-
|
68
|
+
_load_from_store!
|
69
|
+
Isomorfeus.store.dispatch(type: 'DATA_LOAD', data: data)
|
70
|
+
agent.result = self
|
65
71
|
end
|
66
72
|
end
|
67
73
|
end
|
68
74
|
alias promise_create promise_save
|
75
|
+
|
76
|
+
# TODO update -> only send partial change
|
77
|
+
# included_changed_items
|
69
78
|
else # RUBY_ENGINE
|
70
79
|
def loaded?
|
71
80
|
true
|
72
81
|
end
|
82
|
+
|
83
|
+
def save
|
84
|
+
self.class.save(instance: self)
|
85
|
+
self
|
86
|
+
end
|
87
|
+
|
88
|
+
def promise_save
|
89
|
+
promise = Promise.new
|
90
|
+
promise.resolve(save)
|
91
|
+
end
|
73
92
|
end # RUBY_ENGINE
|
93
|
+
|
94
|
+
def current_user
|
95
|
+
Isomorfeus.current_user
|
96
|
+
end
|
97
|
+
|
98
|
+
def pub_sub_client
|
99
|
+
Isomorfeus.pub_sub_client
|
100
|
+
end
|
74
101
|
end
|
75
102
|
end
|
76
103
|
end
|
@@ -4,7 +4,7 @@ module Isomorfeus
|
|
4
4
|
module Data
|
5
5
|
module Handler
|
6
6
|
class Arango < LucidHandler::Base
|
7
|
-
on_request do |
|
7
|
+
on_request do |response_agent|
|
8
8
|
# promise_send_path('Isomorfeus::Data::Handler::Generic', action, type, self.to_s, props_hash)
|
9
9
|
response_agent.request.each_key do |action|
|
10
10
|
if action == 'load'
|
@@ -17,11 +17,10 @@ module Isomorfeus
|
|
17
17
|
props_json = response_agent.request[type_class_name]
|
18
18
|
begin
|
19
19
|
props = Oj.load(props_json, mode: :strict)
|
20
|
-
props.merge!({pub_sub_client: pub_sub_client, current_user: current_user})
|
21
20
|
if current_user.authorized?(type_class, :load, *props)
|
22
21
|
loaded_type = type_class.load(props)
|
23
22
|
loaded_type.instance_exec do
|
24
|
-
type_class.on_load_block.call(
|
23
|
+
type_class.on_load_block.call() if type_class.on_load_block
|
25
24
|
end
|
26
25
|
response_agent.outer_result = { data: loaded_type.to_transport }
|
27
26
|
if %w[collection graph].include?(type)
|
@@ -14,7 +14,7 @@ module Isomorfeus
|
|
14
14
|
# LucidData::Graph
|
15
15
|
# LucidData::Composition
|
16
16
|
|
17
|
-
def process_request(
|
17
|
+
def process_request(response_agent)
|
18
18
|
# promise_send_path('Isomorfeus::Data::Handler::Generic', self.to_s, action, props_hash)
|
19
19
|
response_agent.request.each_key do |type_class_name|
|
20
20
|
if Isomorfeus.valid_data_class_name?(type_class_name)
|
@@ -22,103 +22,92 @@ module Isomorfeus
|
|
22
22
|
if type_class
|
23
23
|
response_agent.request[type_class_name].each_key do |action|
|
24
24
|
case action
|
25
|
-
when 'load' then process_load(
|
26
|
-
when '
|
27
|
-
when 'save' then process_save(
|
28
|
-
when 'destroy' then process_destroy(
|
25
|
+
when 'load' then process_load(response_agent, type_class, type_class_name)
|
26
|
+
when 'execute' then process_execute(response_agent, type_class, type_class_name)
|
27
|
+
when 'save' then process_save(response_agent, type_class, type_class_name)
|
28
|
+
when 'destroy' then process_destroy(response_agent, type_class, type_class_name)
|
29
29
|
else response_agent.error = { error: { action => 'No such thing!' }}
|
30
30
|
end
|
31
31
|
end
|
32
|
-
else response_agent.error = { error: { type_class_name => 'No such
|
32
|
+
else response_agent.error = { error: { type_class_name => 'No such class!' }}
|
33
33
|
end
|
34
|
-
else response_agent.error = { error: { type_class_name => '
|
34
|
+
else response_agent.error = { error: { type_class_name => 'Not a valid LucidData class!' }}
|
35
35
|
end
|
36
36
|
end
|
37
37
|
rescue Exception => e
|
38
38
|
response_agent.error = { error: "Isomorfeus::Data::Handler::Generic: #{e.message}\n#{e.backtrace.join("\n")}" }
|
39
39
|
end
|
40
40
|
|
41
|
-
def process_load(
|
41
|
+
def process_load(response_agent, type_class, type_class_name)
|
42
|
+
# 'Isomorfeus::Data::Handler::Generic', self.name, :load, key: key
|
42
43
|
props = response_agent.request[type_class_name]['load']
|
43
44
|
props.transform_keys!(&:to_sym)
|
44
|
-
|
45
|
-
if current_user.authorized?(type_class, :load, props)
|
45
|
+
if Isomorfeus.current_user.authorized?(type_class, :load, props)
|
46
46
|
loaded_type = type_class.load(**props)
|
47
47
|
if loaded_type
|
48
|
-
response_agent.outer_result = {
|
48
|
+
response_agent.outer_result = {} unless response_agent.outer_result
|
49
|
+
response_agent.outer_result.deep_merge!(data: loaded_type.to_transport)
|
49
50
|
if loaded_type.respond_to?(:included_items_to_transport)
|
50
51
|
response_agent.outer_result.deep_merge!(data: loaded_type.included_items_to_transport)
|
51
52
|
end
|
52
53
|
response_agent.agent_result = { success: 'ok' }
|
53
|
-
else response_agent.error = { error: { type_class_name => '
|
54
|
+
else response_agent.error = { error: { type_class_name => 'Load returned nothing!' }}
|
54
55
|
end
|
55
56
|
else response_agent.error = { error: 'Access denied!' }
|
56
57
|
end
|
57
58
|
end
|
58
59
|
|
59
|
-
def
|
60
|
-
|
60
|
+
def process_execute(response_agent, type_class, type_class_name)
|
61
|
+
# 'Isomorfeus::Data::Handler::Generic', self.name, :execute, props_json
|
62
|
+
props_json = response_agent.request[type_class_name]['execute']
|
61
63
|
props = Oj.load(props_json, mode: :strict)
|
62
64
|
props.transform_keys!(&:to_sym)
|
63
65
|
props[:props].transform_keys!(&:to_sym)
|
64
|
-
|
65
|
-
|
66
|
-
queried_type = type_class.query(**props)
|
66
|
+
if Isomorfeus.current_user.authorized?(type_class, :execute, props[:props])
|
67
|
+
queried_type = type_class.execute(**props)
|
67
68
|
if queried_type
|
68
|
-
response_agent.outer_result = {
|
69
|
+
response_agent.outer_result = {} unless response_agent.outer_result
|
70
|
+
response_agent.outer_result.deep_merge!(data: queried_type.to_transport)
|
69
71
|
if queried_type.respond_to?(:included_items_to_transport)
|
70
72
|
response_agent.outer_result.deep_merge!(data: queried_type.included_items_to_transport)
|
71
73
|
end
|
72
74
|
response_agent.agent_result = { success: 'ok' }
|
73
|
-
else response_agent.error = { error: { type_class_name => '
|
75
|
+
else response_agent.error = { error: { type_class_name => 'Query returned nothing!' }}
|
74
76
|
end
|
75
77
|
else response_agent.error = { error: 'Access denied!' }
|
76
78
|
end
|
77
79
|
end
|
78
80
|
|
79
|
-
def process_save(
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
saved_type = data_class.save(**item_data_hash)
|
93
|
-
if saved_type
|
94
|
-
response_agent.outer_result.deep_merge!({ data: saved_type.to_transport })
|
95
|
-
end
|
96
|
-
else
|
97
|
-
response_agent.error = { error: 'Access denied!' }
|
98
|
-
break
|
99
|
-
end
|
100
|
-
else
|
101
|
-
response_agent.error = { error: 'Access denied!' }
|
102
|
-
break
|
103
|
-
end
|
104
|
-
end
|
81
|
+
def process_save(response_agent, type_class, type_class_name)
|
82
|
+
# 'Isomorfeus::Data::Handler::Generic', self.name, :save, data_hash
|
83
|
+
data = response_agent.request[type_class_name]['save']
|
84
|
+
instance_data = data['instance']
|
85
|
+
included_items_data = data.key?('included_items') ? data['included_items'] : nil
|
86
|
+
if Isomorfeus.current_user.authorized?(type_class, :save, data)
|
87
|
+
instance = type_class.instance_from_transport(instance_data, included_items_data)
|
88
|
+
saved_type = type_class.save(instance: instance)
|
89
|
+
if saved_type
|
90
|
+
response_agent.outer_result = {} unless response_agent.outer_result
|
91
|
+
response_agent.outer_result.deep_merge!(data: saved_type.to_transport)
|
92
|
+
if saved_type.respond_to?(:included_items_to_transport)
|
93
|
+
response_agent.outer_result.deep_merge!(data: saved_type.included_items_to_transport)
|
105
94
|
end
|
95
|
+
response_agent.agent_result = { success: 'ok' }
|
96
|
+
else response_agent.error = { error: { type_class_name => 'Save returned nothing!' }}
|
106
97
|
end
|
107
|
-
response_agent.agent_result = { success: 'ok' }
|
108
98
|
else response_agent.error = { error: 'Access denied!' }
|
109
99
|
end
|
110
100
|
end
|
111
101
|
|
112
|
-
def process_destroy(
|
113
|
-
|
114
|
-
props
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
if destroyed_type
|
119
|
-
response_agent.outer_result = { data: destroyed_type }
|
102
|
+
def process_destroy(response_agent, type_class, type_class_name)
|
103
|
+
props = response_agent.request[type_class_name]['destroy']
|
104
|
+
props.transform_keys!(&:to_sym)
|
105
|
+
if Isomorfeus.current_user.authorized?(type_class, :destroy, props)
|
106
|
+
result = type_class.destroy(**props)
|
107
|
+
if result
|
120
108
|
response_agent.agent_result = { success: 'ok' }
|
121
|
-
else
|
109
|
+
else
|
110
|
+
response_agent.error = { error: { type_class_name => 'Destroy failed!' }}
|
122
111
|
end
|
123
112
|
else response_agent.error = { error: 'Access denied!' }
|
124
113
|
end
|