solis 0.73.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/graph.rb +1 -1
- data/lib/solis/model.rb +55 -87
- data/lib/solis/query.rb +2 -2
- 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/graph.rb
CHANGED
@@ -351,7 +351,7 @@ module Solis
|
|
351
351
|
|
352
352
|
@sparql_client = SPARQL::Client.new(@sparql_endpoint)
|
353
353
|
result = @sparql_client.query("with <#{graph_name}> delete {?s ?p ?o} where{?s ?p ?o}")
|
354
|
-
LOGGER.info(result
|
354
|
+
LOGGER.info(result)
|
355
355
|
true
|
356
356
|
end
|
357
357
|
|
data/lib/solis/model.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'securerandom'
|
2
2
|
require 'iso8601'
|
3
|
+
require 'hashdiff'
|
3
4
|
require_relative 'query'
|
4
5
|
|
5
6
|
module Solis
|
@@ -130,7 +131,7 @@ values ?s {<#{self.graph_id}>}
|
|
130
131
|
result
|
131
132
|
end
|
132
133
|
|
133
|
-
def save(validate_dependencies = true)
|
134
|
+
def save(validate_dependencies = true, top_level = true)
|
134
135
|
raise "I need a SPARQL endpoint" if self.class.sparql_endpoint.nil?
|
135
136
|
sparql = SPARQL::Client.new(self.class.sparql_endpoint)
|
136
137
|
|
@@ -141,6 +142,29 @@ values ?s {<#{self.graph_id}>}
|
|
141
142
|
|
142
143
|
result = update(data)
|
143
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
|
+
|
144
168
|
graph = as_graph(self, validate_dependencies)
|
145
169
|
|
146
170
|
# File.open('/Users/mehmetc/Dropbox/AllSources/LP/graphiti-api/save.ttl', 'wb') do |file|
|
@@ -159,7 +183,7 @@ values ?s {<#{self.graph_id}>}
|
|
159
183
|
raise e
|
160
184
|
end
|
161
185
|
|
162
|
-
def update(data, validate_dependencies = true)
|
186
|
+
def update(data, validate_dependencies = true, top_level = true)
|
163
187
|
raise Solis::Error::GeneralError, "I need a SPARQL endpoint" if self.class.sparql_endpoint.nil?
|
164
188
|
|
165
189
|
attributes = data.include?('attributes') ? data['attributes'] : data
|
@@ -173,100 +197,36 @@ values ?s {<#{self.graph_id}>}
|
|
173
197
|
raise Solis::Error::NotFoundError if original_klass.nil?
|
174
198
|
updated_klass = original_klass.deep_dup
|
175
199
|
|
176
|
-
attributes.each_pair do |key, value|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
200
|
+
attributes.each_pair do |key, value| # check each key. if it is an entity process it
|
201
|
+
unless original_klass.class.metadata[:attributes][key][:node].nil? #it is an entity
|
202
|
+
value = [value] unless value.is_a?(Array)
|
203
|
+
value.each do |sub_value|
|
204
|
+
embedded = self.class.graph.shape_as_model(original_klass.class.metadata[:attributes][key][:datatype].to_s).new(sub_value)
|
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
|
215
|
+
else
|
216
|
+
Solis::LOGGER.info("#{embedded.class.name} is embedded not allowed to change. Skipping")
|
217
|
+
end
|
184
218
|
end
|
185
219
|
end
|
186
220
|
|
187
221
|
updated_klass.instance_variable_set("@#{key}", value)
|
188
222
|
end
|
189
223
|
|
190
|
-
# attributes.each_pair do |key, value|
|
191
|
-
# updated_klass.instance_variable_set("@#{key}", value)
|
192
|
-
# end
|
193
|
-
# properties_original_klass=Model.properties_to_hash(original_klass)
|
194
|
-
# properties_updated_klass = Model.properties_to_hash(updated_klass)
|
195
|
-
# changes = Hashdiff.diff(properties_original_klass, properties_updated_klass)
|
196
|
-
# pp changes
|
197
|
-
#
|
198
|
-
# #a=self.class.graph.shape_as_model('Identificatienummer').new
|
199
|
-
# changes.each do |change|
|
200
|
-
# change_type = change[0]
|
201
|
-
# original_change_entity = change[1]
|
202
|
-
# change_entity = original_change_entity.split('.').last
|
203
|
-
# change[1] = change_object
|
204
|
-
# data = change[2]
|
205
|
-
#
|
206
|
-
# case change_type
|
207
|
-
# when '+' # new
|
208
|
-
# new_entity_hash = {} #self.class.graph.shape_as_model(change_object.classify).new
|
209
|
-
# Hashdiff.patch!(new_entity_hash, [change])
|
210
|
-
#
|
211
|
-
# new_entity = self.class.graph.shape_as_model(change_entity.classify).new(new_entity_hash[change_entity])
|
212
|
-
# new_entity.save
|
213
|
-
# when '-' # delete
|
214
|
-
# when '~' # change
|
215
|
-
# else
|
216
|
-
# raise RuntimeError, "Unknown change type(#{change_type}) for #{change[1]}"
|
217
|
-
# end
|
218
|
-
#
|
219
|
-
# end
|
220
|
-
|
221
|
-
# attributes.each_pair do |key, value|
|
222
|
-
# updated_klass.instance_variable_set("@#{key}", value)
|
223
|
-
# unless original_klass.class.metadata[:attributes][key][:node_kind].nil?
|
224
|
-
# inner_model = self.class.graph.shape_as_model(original_klass.class.metadata[:attributes][key][:datatype].to_s)
|
225
|
-
# if value.is_a?(Hash)
|
226
|
-
# value.each_pair do |inner_key, inner_value|
|
227
|
-
# next unless inner_model.metadata[:attributes][inner_key][:node_kind].is_a?(RDF::URI)
|
228
|
-
# inner_inner_model = self.class.graph.shape_as_model(inner_model.metadata[:attributes][inner_key][:datatype].to_s)
|
229
|
-
# # if inner_inner_model.class.ancestors.include?(Codetabel) && inner_value.key?('id')
|
230
|
-
# # inner_data = inner_inner_model.query.filter({ language: nil, filters: { id: [inner_value['id']] } }).find_all.map { |m| m }&.first
|
231
|
-
# # else
|
232
|
-
# inner_value = inner_value.first if inner_value.is_a?(Array)
|
233
|
-
# inner_data = inner_inner_model.new(inner_value)
|
234
|
-
# inner_data.save
|
235
|
-
# # end
|
236
|
-
# end
|
237
|
-
# elsif value.is_a?(Array)
|
238
|
-
# data = value.map do |m|
|
239
|
-
# if m.is_a?(Hash)
|
240
|
-
# m.each do |inner_key, inner_value|
|
241
|
-
# #next if inner_model.metadata[:attributes][inner_key][:class].nil?
|
242
|
-
# next unless inner_model.metadata[:attributes][inner_key][:node_kind].is_a?(RDF::URI)
|
243
|
-
# inner_inner_model = self.class.graph.shape_as_model(inner_model.class.metadata[:attributes][inner_key][:datatype].to_s)
|
244
|
-
# # if inner_inner_model.class.ancestors.include?(Codetabel) && inner_value.key?('id')
|
245
|
-
# # inner_data = inner_inner_model.query.filter({ language: nil, filters: { id: [inner_value['id']] } }).find_all.map { |m| m }&.first
|
246
|
-
# # else
|
247
|
-
# inner_value = inner_value.first if inner_value.is_a?(Array)
|
248
|
-
# inner_data = inner_inner_model.new(inner_value)
|
249
|
-
# inner_data.save
|
250
|
-
# # end
|
251
|
-
#
|
252
|
-
# inner_data
|
253
|
-
# end
|
254
|
-
# else
|
255
|
-
# m
|
256
|
-
# end
|
257
|
-
# end
|
258
|
-
# elsif value.is_a?(Object)
|
259
|
-
# value.save
|
260
|
-
# end
|
261
|
-
# end
|
262
|
-
# end
|
263
|
-
|
264
224
|
before_update_proc&.call(original_klass, updated_klass)
|
265
225
|
|
266
226
|
properties_orignal_klass = properties_to_hash(original_klass)
|
267
|
-
|
227
|
+
properties_updated_klass = properties_to_hash(updated_klass)
|
268
228
|
|
269
|
-
if Hashdiff.best_diff(properties_orignal_klass,
|
229
|
+
if Hashdiff.best_diff(properties_orignal_klass, properties_updated_klass).empty?
|
270
230
|
Solis::LOGGER.info("#{original_klass.class.name} unchanged, skipping")
|
271
231
|
data = self.query.filter({ filters: { id: [id] } }).find_all.map { |m| m }&.first
|
272
232
|
else
|
@@ -330,9 +290,17 @@ values ?s {<#{self.graph_id}>}
|
|
330
290
|
end
|
331
291
|
|
332
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)
|
333
295
|
id = model.instance_variable_get("@id")
|
334
296
|
if id.nil? || (id.is_a?(String) && id&.empty?)
|
335
|
-
|
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]
|
336
304
|
model.instance_variable_set("@id", id)
|
337
305
|
end
|
338
306
|
model
|
data/lib/solis/query.rb
CHANGED
@@ -191,11 +191,11 @@ order by ?s
|
|
191
191
|
from_cache = Graphiti.context[:object]&.from_cache || '0'
|
192
192
|
if @query_cache.key?(query_key) && from_cache.eql?('1')
|
193
193
|
result = @query_cache[query_key]
|
194
|
-
Solis::LOGGER.info("CACHE: from #{query_key}")
|
194
|
+
Solis::LOGGER.info("CACHE: from #{query_key}") if ConfigFile[:debug]
|
195
195
|
else
|
196
196
|
result = graph_to_object(sparql_client.query(query))
|
197
197
|
@query_cache[query_key] = result unless result.nil? || result.empty?
|
198
|
-
Solis::LOGGER.info("CACHE: to #{query_key}")
|
198
|
+
Solis::LOGGER.info("CACHE: to #{query_key}") if ConfigFile[:debug]
|
199
199
|
end
|
200
200
|
|
201
201
|
result
|
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
|