solis 0.74.0 → 0.75.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/solis/model.rb +45 -107
- data/lib/solis/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d927fa3a6e648f3d4359df7bc05f60d3ac2cdd62e36ae8a3c1bd7b9845c6c13c
|
4
|
+
data.tar.gz: 92475ada9028fa045fe7f8f5b07a9ccd8b03db2ecb81f67a978dbecdd6eef714
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb0e60d9e4d347e488bac8429e6c1481ad3344cdf1acc5170da37079d82cdc5a1e412ca28b648edaf4db642d6481a3fa07afb45bb176688cbef142b32c9d96b3
|
7
|
+
data.tar.gz: 8fab47cd98128888ed69e3c1af21df1a19bc2872dc05be70fd23a66fc25b2738b344353b28ebce4e7a7d26fb81647d1bc8b0e61ad5bd70fbfaa633fe7d45e57c
|
data/lib/solis/model.rb
CHANGED
@@ -131,7 +131,7 @@ values ?s {<#{self.graph_id}>}
|
|
131
131
|
result
|
132
132
|
end
|
133
133
|
|
134
|
-
def save(validate_dependencies = true)
|
134
|
+
def save(validate_dependencies = true, top_level = true)
|
135
135
|
raise "I need a SPARQL endpoint" if self.class.sparql_endpoint.nil?
|
136
136
|
sparql = SPARQL::Client.new(self.class.sparql_endpoint)
|
137
137
|
|
@@ -142,6 +142,29 @@ values ?s {<#{self.graph_id}>}
|
|
142
142
|
|
143
143
|
result = update(data)
|
144
144
|
else
|
145
|
+
data = properties_to_hash(self)
|
146
|
+
attributes = data.include?('attributes') ? data['attributes'] : data
|
147
|
+
attributes.each_pair do |key, value| # check each key. if it is an entity process it
|
148
|
+
unless self.class.metadata[:attributes][key][:node].nil? #is it an entity
|
149
|
+
value = [value] unless value.is_a?(Array)
|
150
|
+
value.each do |sub_value|
|
151
|
+
embedded = self.class.graph.shape_as_model(self.class.metadata[:attributes][key][:datatype].to_s).new(sub_value)
|
152
|
+
embedded_readonly_entities = Solis::Options.instance.get[:embedded_readonly].map{|s| s.to_s} || []
|
153
|
+
|
154
|
+
if (embedded.class.ancestors.map{|s| s.to_s} & embedded_readonly_entities).empty? || top_level
|
155
|
+
if embedded.exists?(sparql)
|
156
|
+
embedded_data = properties_to_hash(embedded)
|
157
|
+
embedded.update(embedded_data, validate_dependencies, false)
|
158
|
+
else
|
159
|
+
embedded.save(validate_dependencies, false)
|
160
|
+
end
|
161
|
+
else
|
162
|
+
Solis::LOGGER.info("#{embedded.class.name} is embedded not allowed to change. Skipping")
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
145
168
|
graph = as_graph(self, validate_dependencies)
|
146
169
|
|
147
170
|
# File.open('/Users/mehmetc/Dropbox/AllSources/LP/graphiti-api/save.ttl', 'wb') do |file|
|
@@ -160,7 +183,7 @@ values ?s {<#{self.graph_id}>}
|
|
160
183
|
raise e
|
161
184
|
end
|
162
185
|
|
163
|
-
def update(data, validate_dependencies = true)
|
186
|
+
def update(data, validate_dependencies = true, top_level = true)
|
164
187
|
raise Solis::Error::GeneralError, "I need a SPARQL endpoint" if self.class.sparql_endpoint.nil?
|
165
188
|
|
166
189
|
attributes = data.include?('attributes') ? data['attributes'] : data
|
@@ -179,11 +202,18 @@ values ?s {<#{self.graph_id}>}
|
|
179
202
|
value = [value] unless value.is_a?(Array)
|
180
203
|
value.each do |sub_value|
|
181
204
|
embedded = self.class.graph.shape_as_model(original_klass.class.metadata[:attributes][key][:datatype].to_s).new(sub_value)
|
182
|
-
|
183
|
-
|
184
|
-
|
205
|
+
|
206
|
+
embedded_readonly_entities = Solis::Options.instance.get[:embedded_readonly].map{|s| s.to_s} || []
|
207
|
+
|
208
|
+
if (embedded.class.ancestors.map{|s| s.to_s} & embedded_readonly_entities).empty? || top_level
|
209
|
+
if embedded.exists?(sparql)
|
210
|
+
embedded_data = properties_to_hash(embedded)
|
211
|
+
embedded.update(embedded_data, validate_dependencies, false)
|
212
|
+
else
|
213
|
+
embedded.save(validate_dependencies, false)
|
214
|
+
end
|
185
215
|
else
|
186
|
-
embedded.
|
216
|
+
Solis::LOGGER.info("#{embedded.class.name} is embedded not allowed to change. Skipping")
|
187
217
|
end
|
188
218
|
end
|
189
219
|
end
|
@@ -191,106 +221,6 @@ values ?s {<#{self.graph_id}>}
|
|
191
221
|
updated_klass.instance_variable_set("@#{key}", value)
|
192
222
|
end
|
193
223
|
|
194
|
-
|
195
|
-
# attributes.each_pair do |key, value|
|
196
|
-
# if value.is_a?(Hash)
|
197
|
-
# embedded = self.class.graph.shape_as_model(original_klass.class.metadata[:attributes][key][:datatype].to_s).new(value)
|
198
|
-
# if embedded.exists?(sparql)
|
199
|
-
# embedded_data = properties_to_hash(embedded)
|
200
|
-
# embedded.update(embedded_data)
|
201
|
-
# else
|
202
|
-
# embedded.save
|
203
|
-
# end
|
204
|
-
# elsif value.is_a?(Array)
|
205
|
-
# value.each do |sub_value|
|
206
|
-
# if sub_value.is_a?(Hash)
|
207
|
-
# if embedded.exists?(sparql)
|
208
|
-
# embedded_data = properties_to_hash(embedded)
|
209
|
-
# embedded.update(embedded_data)
|
210
|
-
# else
|
211
|
-
# embedded.save
|
212
|
-
# end
|
213
|
-
# end
|
214
|
-
# end
|
215
|
-
# end
|
216
|
-
#
|
217
|
-
# updated_klass.instance_variable_set("@#{key}", value)
|
218
|
-
# end
|
219
|
-
|
220
|
-
# attributes.each_pair do |key, value|
|
221
|
-
# updated_klass.instance_variable_set("@#{key}", value)
|
222
|
-
# end
|
223
|
-
# properties_original_klass=Model.properties_to_hash(original_klass)
|
224
|
-
# properties_updated_klass = Model.properties_to_hash(updated_klass)
|
225
|
-
# changes = Hashdiff.diff(properties_original_klass, properties_updated_klass)
|
226
|
-
# pp changes
|
227
|
-
#
|
228
|
-
# #a=self.class.graph.shape_as_model('Identificatienummer').new
|
229
|
-
# changes.each do |change|
|
230
|
-
# change_type = change[0]
|
231
|
-
# original_change_entity = change[1]
|
232
|
-
# change_entity = original_change_entity.split('.').last
|
233
|
-
# change[1] = change_object
|
234
|
-
# data = change[2]
|
235
|
-
#
|
236
|
-
# case change_type
|
237
|
-
# when '+' # new
|
238
|
-
# new_entity_hash = {} #self.class.graph.shape_as_model(change_object.classify).new
|
239
|
-
# Hashdiff.patch!(new_entity_hash, [change])
|
240
|
-
#
|
241
|
-
# new_entity = self.class.graph.shape_as_model(change_entity.classify).new(new_entity_hash[change_entity])
|
242
|
-
# new_entity.save
|
243
|
-
# when '-' # delete
|
244
|
-
# when '~' # change
|
245
|
-
# else
|
246
|
-
# raise RuntimeError, "Unknown change type(#{change_type}) for #{change[1]}"
|
247
|
-
# end
|
248
|
-
#
|
249
|
-
# end
|
250
|
-
|
251
|
-
# attributes.each_pair do |key, value|
|
252
|
-
# updated_klass.instance_variable_set("@#{key}", value)
|
253
|
-
# unless original_klass.class.metadata[:attributes][key][:node_kind].nil?
|
254
|
-
# inner_model = self.class.graph.shape_as_model(original_klass.class.metadata[:attributes][key][:datatype].to_s)
|
255
|
-
# if value.is_a?(Hash)
|
256
|
-
# value.each_pair do |inner_key, inner_value|
|
257
|
-
# next unless inner_model.metadata[:attributes][inner_key][:node_kind].is_a?(RDF::URI)
|
258
|
-
# inner_inner_model = self.class.graph.shape_as_model(inner_model.metadata[:attributes][inner_key][:datatype].to_s)
|
259
|
-
# # if inner_inner_model.class.ancestors.include?(Codetabel) && inner_value.key?('id')
|
260
|
-
# # inner_data = inner_inner_model.query.filter({ language: nil, filters: { id: [inner_value['id']] } }).find_all.map { |m| m }&.first
|
261
|
-
# # else
|
262
|
-
# inner_value = inner_value.first if inner_value.is_a?(Array)
|
263
|
-
# inner_data = inner_inner_model.new(inner_value)
|
264
|
-
# inner_data.save
|
265
|
-
# # end
|
266
|
-
# end
|
267
|
-
# elsif value.is_a?(Array)
|
268
|
-
# data = value.map do |m|
|
269
|
-
# if m.is_a?(Hash)
|
270
|
-
# m.each do |inner_key, inner_value|
|
271
|
-
# #next if inner_model.metadata[:attributes][inner_key][:class].nil?
|
272
|
-
# next unless inner_model.metadata[:attributes][inner_key][:node_kind].is_a?(RDF::URI)
|
273
|
-
# inner_inner_model = self.class.graph.shape_as_model(inner_model.class.metadata[:attributes][inner_key][:datatype].to_s)
|
274
|
-
# # if inner_inner_model.class.ancestors.include?(Codetabel) && inner_value.key?('id')
|
275
|
-
# # inner_data = inner_inner_model.query.filter({ language: nil, filters: { id: [inner_value['id']] } }).find_all.map { |m| m }&.first
|
276
|
-
# # else
|
277
|
-
# inner_value = inner_value.first if inner_value.is_a?(Array)
|
278
|
-
# inner_data = inner_inner_model.new(inner_value)
|
279
|
-
# inner_data.save
|
280
|
-
# # end
|
281
|
-
#
|
282
|
-
# inner_data
|
283
|
-
# end
|
284
|
-
# else
|
285
|
-
# m
|
286
|
-
# end
|
287
|
-
# end
|
288
|
-
# elsif value.is_a?(Object)
|
289
|
-
# value.save
|
290
|
-
# end
|
291
|
-
# end
|
292
|
-
# end
|
293
|
-
|
294
224
|
before_update_proc&.call(original_klass, updated_klass)
|
295
225
|
|
296
226
|
properties_orignal_klass = properties_to_hash(original_klass)
|
@@ -360,9 +290,17 @@ values ?s {<#{self.graph_id}>}
|
|
360
290
|
end
|
361
291
|
|
362
292
|
def self.make_id_for(model)
|
293
|
+
raise "I need a SPARQL endpoint" if self.sparql_endpoint.nil?
|
294
|
+
sparql = SPARQL::Client.new(self.sparql_endpoint)
|
363
295
|
id = model.instance_variable_get("@id")
|
364
296
|
if id.nil? || (id.is_a?(String) && id&.empty?)
|
365
|
-
|
297
|
+
id_retries = 0
|
298
|
+
|
299
|
+
while id.nil? || sparql.query("ASK WHERE { ?s <#{self.graph_name}/id> \"#{id}\" }")
|
300
|
+
id = SecureRandom.uuid
|
301
|
+
id_retries+=1
|
302
|
+
end
|
303
|
+
LOGGER.info("ID(#{id}) generated for #{self.name} in #{id_retries} retries") if ConfigFile[:debug]
|
366
304
|
model.instance_variable_set("@id", id)
|
367
305
|
end
|
368
306
|
model
|
data/lib/solis/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.75.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mehmet Celik
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-03-
|
11
|
+
date: 2024-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|