solis 0.74.0 → 0.76.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 166805286e332f8a5a9f572fa6ab7841f2f234223384b298139fa25d8339cf91
4
- data.tar.gz: e43b4f5b33c911c8759e96012165cd9203b6941113e511442d169b0acd61bfe3
3
+ metadata.gz: 14e23fd1f3bfd75d6c0349299ec95fd1b298224be106532bd0af5e85ea7eeef2
4
+ data.tar.gz: 73e6ccc7ca60e80c6afe349c0384b416b00a9de7661509995ac7cffe7b35aa2e
5
5
  SHA512:
6
- metadata.gz: 7a091ee239234b0a71cfde2cbebb19905af07af63bf2e58dedb6c0178a7f2c4ac9d3f875df509cecf689857c4dcfac2cc76fa0f4b8dc4ef2d7b1df566af4edc8
7
- data.tar.gz: 96dc87a0b2b208f6f56adcae71b391a7cbd18b22ac2ba4ea6d936d87d39bd98d88a2c74bed54d12c6a73fa00896ec23dbd60bf4b52474cc5d7f11f4048188961
6
+ metadata.gz: 6994d3c3a89e1456c71b3e09bd846c20a93076d4b3d1a179fa129ba313066ba2534b1eb3288b71c06eb5e0ea90d9a0c7d7c31270e7972e832fb7212b9b6373eb
7
+ data.tar.gz: b382ce56230855d7a6716b90e43f97734bd9b82335f0cdeac14708787a551cab2c573c61d60c2b4c6df691249d1abea7a04c1da24e30097750da41e4af6b9bd1
data/lib/solis/graph.rb CHANGED
@@ -309,7 +309,8 @@ module Solis
309
309
  remote_resource.id =~ /^http/ ? remote_resource.id.split('/').last : remote_resource.id
310
310
  end
311
311
  end
312
- "#{resource.class.graph_name.gsub(/\/$/,'')}/#{belongs_to_resource.name.tableize}?filter[id]=#{resource_ids.join(',')}" unless remote_resources.nil? || resource_ids.empty?
312
+ #"#{resource.class.graph_name.gsub(/\/$/,'')}/#{belongs_to_resource.name.tableize}?filter[id]=#{resource_ids.join(',')}" unless remote_resources.nil? || resource_ids.empty?
313
+ "#{resource.class.graph_name.gsub(/\/$/,'')}/#{remote_resources.first.name.tableize}?filter[id]=#{resource_ids.join(',')}" unless remote_resources.nil? || resource_ids.empty?
313
314
  end
314
315
  end
315
316
  #
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
- if embedded.exists?(sparql)
183
- embedded_data = properties_to_hash(embedded)
184
- embedded.update(embedded_data)
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.save
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
- id = SecureRandom.uuid
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
@@ -456,6 +394,10 @@ values ?s {<#{self.graph_id}>}
456
394
  m
457
395
  end
458
396
 
397
+ def self.construct(level = 0)
398
+ raise 'to bo implemented'
399
+ end
400
+
459
401
  def self.model_before_read(&blk)
460
402
  self.before_read_proc = blk
461
403
  end
data/lib/solis/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Solis
2
- VERSION = "0.74.0"
2
+ VERSION = "0.76.0"
3
3
  end
data/solis.gemspec CHANGED
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
29
29
 
30
30
  spec.add_runtime_dependency 'activesupport', '~> 7.0'
31
31
  spec.add_runtime_dependency 'http', '~> 5.1'
32
- spec.add_runtime_dependency 'graphiti', '~> 1.3'
32
+ spec.add_runtime_dependency 'graphiti', '~> 1.7'
33
33
  spec.add_runtime_dependency 'moneta', '~> 1.6'
34
34
  spec.add_runtime_dependency 'linkeddata', '~> 3.3'
35
35
  spec.add_runtime_dependency 'google_drive', '~> 3.0'
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.74.0
4
+ version: 0.76.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-22 00:00:00.000000000 Z
11
+ date: 2024-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.3'
47
+ version: '1.7'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.3'
54
+ version: '1.7'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: moneta
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -295,7 +295,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
295
295
  - !ruby/object:Gem::Version
296
296
  version: '0'
297
297
  requirements: []
298
- rubygems_version: 3.5.6
298
+ rubygems_version: 3.5.10
299
299
  signing_key:
300
300
  specification_version: 4
301
301
  summary: Turn any SHACL file into an API, ORM, documentation, ...