solis 0.94.0 → 0.96.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 36a3cb8c2712803966b8da5b1fda51f0ecbdebc2d52fc11c91d5a6045ad395b8
4
- data.tar.gz: 56b2c6bc5e69977dddefa79a36bb6db2a759d8cdc9090fef97b0b751a571e315
3
+ metadata.gz: b8578caa34e99087db01bd4d8f2e3272be3c07e87a0fe55a97dc94a117b0eb49
4
+ data.tar.gz: 15e3ece865f8a09951ce5b8cfb36bcc4281e39cc0fe819b76450680a1e8fd770
5
5
  SHA512:
6
- metadata.gz: 6367fc29b396be4a11456d96bfa5b8d89dc260c466021cf2ee2539ab8f80a2e2a253ca7a742b4de857cacc83e22ea642c11f984731a430c1451e9fb04d1068ab
7
- data.tar.gz: ba2b061b4f30397c81153e87f01b24d6fd6e40c7f45f1a07158384117af924cdf391c9c4b3e9dc75aadf519c3691b875d87ce952ae1d74e9c5293393c754409a
6
+ metadata.gz: f61a2162a8da145017038c7928241112b308acaaae4c6fa7e9e7161b3417ee89fff816a4e65a398f280ee7744860171c25fdf1c9b8dd310586349ae229e4d2d8
7
+ data.tar.gz: fa67a9525a9aeb6b0080f3d91b380958f3142e18df867b99c5ce6e872bbafcb64a90765c9b695aea13eb54025a495c9ce282817fcf0328293a3bf6c398774c3e
data/lib/solis/model.rb CHANGED
@@ -52,16 +52,14 @@ module Solis
52
52
  end
53
53
 
54
54
  self.class.make_id_for(self)
55
- # id = instance_variable_get("@id")
56
- # if id.nil? || (id.is_a?(String) && id&.empty?)
57
- # instance_variable_set("@id", SecureRandom.uuid)
58
- # end
59
55
  rescue StandardError => e
60
56
  Solis::LOGGER.error(e.message)
61
57
  raise Solis::Error::GeneralError, "Unable to create entity #{@model_name}"
62
58
  end
63
59
 
64
- def name(plural = false)
60
+ # Removed the 'name' instance method to avoid conflicts with 'name' attributes
61
+ # Use model_class_name instead, or access @model_name directly
62
+ def model_class_name(plural = false)
65
63
  if plural
66
64
  @model_plural_name
67
65
  else
@@ -112,10 +110,8 @@ module Solis
112
110
  sparql = Solis::Store::Sparql::Client.new(self.class.sparql_endpoint)
113
111
 
114
112
  raise Solis::Error::QueryError, "#{self.id} is still referenced, refusing to delete" if is_referenced?(sparql)
115
- # sparql.query('delete{}')
113
+
116
114
  before_delete_proc&.call(self)
117
- # graph = as_graph(self, false)
118
- # Solis::LOGGER.info graph.dump(:ttl) if ConfigFile[:debug]
119
115
 
120
116
  query = %(
121
117
  with <#{self.class.graph_name}>
@@ -133,7 +129,7 @@ values ?s {<#{self.graph_id}>}
133
129
  after_delete_proc&.call(result)
134
130
  end
135
131
  end
136
- # result = sparql.delete_data(graph, graph: graph.name)
132
+
137
133
  result
138
134
  end
139
135
 
@@ -145,13 +141,12 @@ values ?s {<#{self.graph_id}>}
145
141
 
146
142
  if self.exists?(sparql)
147
143
  data = properties_to_hash(self)
148
-
149
144
  result = update(data)
150
145
  else
151
146
  data = properties_to_hash(self)
152
147
  attributes = data.include?('attributes') ? data['attributes'] : data
153
- attributes.each_pair do |key, value| # check each key. if it is an entity process it
154
- unless self.class.metadata[:attributes][key][:node].nil? #is it an entity
148
+ attributes.each_pair do |key, value|
149
+ unless self.class.metadata[:attributes][key][:node].nil?
155
150
  value = [value] unless value.is_a?(Array)
156
151
  value.each do |sub_value|
157
152
  embedded = self.class.graph.shape_as_model(self.class.metadata[:attributes][key][:datatype].to_s).new(sub_value)
@@ -173,9 +168,6 @@ values ?s {<#{self.graph_id}>}
173
168
 
174
169
  graph = as_graph(self, validate_dependencies)
175
170
 
176
- # File.open('/Users/mehmetc/Dropbox/AllSources/LP/graphiti-api/save.ttl', 'wb') do |file|
177
- # file.puts graph.dump(:ttl)
178
- # end
179
171
  Solis::LOGGER.info SPARQL::Client::Update::InsertData.new(graph, graph: graph.name).to_s if ConfigFile[:debug]
180
172
 
181
173
  result = sparql.insert_data(graph, graph: graph.name)
@@ -184,7 +176,6 @@ values ?s {<#{self.graph_id}>}
184
176
  after_create_proc&.call(self)
185
177
  self
186
178
  rescue StandardError => e
187
- Solis::LOGGER.error e.message
188
179
  Solis::LOGGER.error e.message
189
180
  raise e
190
181
  end
@@ -196,19 +187,34 @@ values ?s {<#{self.graph_id}>}
196
187
  raise "id is mandatory when updating" unless attributes.keys.include?('id')
197
188
 
198
189
  id = attributes.delete('id')
199
-
200
190
  sparql = SPARQL::Client.new(self.class.sparql_endpoint)
201
- #sparql = Solis::Store::Sparql::Client.new(self.class.sparql_endpoint, self.class.graph_name)
202
191
 
203
192
  original_klass = self.query.filter({ language: nil, filters: { id: [id] } }).find_all.map { |m| m }&.first
204
193
  raise Solis::Error::NotFoundError if original_klass.nil?
205
194
  updated_klass = original_klass.deep_dup
206
195
 
207
- attributes.each_pair do |key, value| # check each key. if it is an entity process it
208
- unless original_klass.class.metadata[:attributes][key][:node].nil? #it is an entity
196
+ # Track entities to potentially delete
197
+ entities_to_check_for_deletion = {}
198
+
199
+ attributes.each_pair do |key, value|
200
+ unless original_klass.class.metadata[:attributes][key][:node].nil?
209
201
  value = [value] unless value.is_a?(Array)
202
+
203
+ # Get original embedded entities for this attribute
204
+ original_embedded = original_klass.instance_variable_get("@#{key}")
205
+ original_embedded = [original_embedded] unless original_embedded.nil? || original_embedded.is_a?(Array)
206
+ original_embedded ||= []
207
+
208
+ # Track original IDs
209
+ original_ids = original_embedded.map { |e| solis_model?(e) ? e.id : nil }.compact
210
+
211
+ # Build new array of embedded entities
212
+ new_embedded_values = []
213
+ new_ids = []
214
+
210
215
  value.each do |sub_value|
211
216
  embedded = self.class.graph.shape_as_model(original_klass.class.metadata[:attributes][key][:datatype].to_s).new(sub_value)
217
+ new_ids << embedded.id if embedded.id
212
218
 
213
219
  embedded_readonly_entities = Solis::Options.instance.get[:embedded_readonly].map{|s| s.to_s} || []
214
220
 
@@ -216,87 +222,84 @@ values ?s {<#{self.graph_id}>}
216
222
  if embedded.exists?(sparql)
217
223
  embedded_data = properties_to_hash(embedded)
218
224
  embedded.update(embedded_data, validate_dependencies, false)
225
+ new_embedded_values << embedded
219
226
  else
220
227
  embedded_value = embedded.save(validate_dependencies, false)
221
- value = updated_klass.instance_variable_get("@#{key}").deep_dup
222
- if value.is_a?(Array)
223
- value << embedded_value
224
- else
225
- value = embedded_value
226
- end
228
+ new_embedded_values << embedded_value
227
229
  end
228
230
  else
229
231
  Solis::LOGGER.info("#{embedded.class.name} is embedded not allowed to change. Skipping")
232
+ new_embedded_values << embedded
230
233
  end
231
234
  end
232
- end
233
235
 
234
- maxcount = original_klass.class.metadata[:attributes][key][:maxcount]
235
- value = value.first if maxcount && maxcount == 1 && value.is_a?(Array)
236
+ # Identify orphaned entities (in original but not in new)
237
+ orphaned_ids = original_ids - new_ids
238
+ unless orphaned_ids.empty?
239
+ orphaned_entities = original_embedded.select { |e| solis_model?(e) && orphaned_ids.include?(e.id) }
240
+ entities_to_check_for_deletion[key] = orphaned_entities
241
+ end
242
+
243
+ # Replace entire array with new values
244
+ maxcount = original_klass.class.metadata[:attributes][key][:maxcount]
245
+ value = maxcount && maxcount == 1 ? new_embedded_values.first : new_embedded_values
246
+ end
236
247
 
237
248
  updated_klass.instance_variable_set("@#{key}", value)
238
249
  end
239
250
 
240
251
  before_update_proc&.call(original_klass, updated_klass)
241
252
 
242
- properties_orignal_klass = properties_to_hash(original_klass)
253
+ properties_original_klass = properties_to_hash(original_klass)
243
254
  properties_updated_klass = properties_to_hash(updated_klass)
244
255
 
245
- if Hashdiff.best_diff(properties_orignal_klass, properties_updated_klass).empty?
256
+ if Hashdiff.best_diff(properties_original_klass, properties_updated_klass).empty?
246
257
  Solis::LOGGER.info("#{original_klass.class.name} unchanged, skipping")
247
258
  data = self.query.filter({ filters: { id: [id] } }).find_all.map { |m| m }&.first
248
259
  else
249
-
250
260
  delete_graph = as_graph(original_klass, false)
251
-
252
- where_graph = RDF::Graph.new(graph_name: RDF::URI("#{self.class.graph_name}#{self.name.tableize}/#{id}"), data: RDF::Repository.new)
261
+ where_graph = RDF::Graph.new(graph_name: RDF::URI("#{self.class.graph_name}#{tableized_class_name(self)}/#{id}"), data: RDF::Repository.new)
253
262
 
254
263
  if id.is_a?(Array)
255
264
  id.each do |i|
256
- where_graph << [RDF::URI("#{self.class.graph_name}#{self.name.tableize}/#{i}"), :p, :o]
265
+ where_graph << [RDF::URI("#{self.class.graph_name}#{tableized_class_name(self)}/#{i}"), :p, :o]
257
266
  end
258
267
  else
259
- where_graph << [RDF::URI("#{self.class.graph_name}#{self.name.tableize}/#{id}"), :p, :o]
268
+ where_graph << [RDF::URI("#{self.class.graph_name}#{tableized_class_name(self)}/#{id}"), :p, :o]
260
269
  end
261
270
 
262
271
  insert_graph = as_graph(updated_klass, true)
263
272
 
264
- # puts delete_graph.dump(:ttl) if ConfigFile[:debug]
265
- # puts insert_graph.dump(:ttl) if ConfigFile[:debug]
266
- # puts where_graph.dump(:ttl) if ConfigFile[:debug]
267
-
268
- # if ConfigFile[:debug]
269
273
  delete_insert_query = SPARQL::Client::Update::DeleteInsert.new(delete_graph, insert_graph, where_graph, graph: insert_graph.name).to_s
270
274
  delete_insert_query.gsub!('_:p', '?p')
271
- # puts delete_insert_query
272
- data = sparql.query(delete_insert_query)
273
- # pp data
274
- # end
275
275
 
276
- # sparql.delete_insert(delete_graph, insert_graph, where_graph, graph: insert_graph.name)
276
+ data = sparql.query(delete_insert_query)
277
277
 
278
278
  data = self.query.filter({ filters: { id: [id] } }).find_all.map { |m| m }&.first
279
279
  if data.nil?
280
280
  sparql.insert_data(insert_graph, graph: insert_graph.name)
281
281
  data = self.query.filter({ filters: { id: [id] } }).find_all.map { |m| m }&.first
282
282
  end
283
+
284
+ # Delete orphaned entities after successful update
285
+ delete_orphaned_entities(entities_to_check_for_deletion, sparql)
283
286
  end
287
+
284
288
  after_update_proc&.call(updated_klass, data)
285
289
 
286
290
  data
287
- #rescue EOFError => e
288
291
  rescue StandardError => e
289
292
  original_graph = as_graph(original_klass, false)
290
293
  Solis::LOGGER.error(e.message)
291
294
  Solis::LOGGER.error original_graph.dump(:ttl)
292
- Solis::LOGGER.error delete_insert_query
295
+ Solis::LOGGER.error delete_insert_query if defined?(delete_insert_query)
293
296
  sparql.insert_data(original_graph, graph: original_graph.name)
294
297
 
295
298
  raise e
296
299
  end
297
300
 
298
301
  def graph_id
299
- "#{self.class.graph_name}#{self.name.tableize}/#{self.id}"
302
+ "#{self.class.graph_name}#{tableized_class_name(self)}/#{self.id}"
300
303
  end
301
304
 
302
305
  def is_referenced?(sparql)
@@ -316,7 +319,7 @@ values ?s {<#{self.graph_id}>}
316
319
 
317
320
  while id.nil? || sparql.query("ASK WHERE { ?s <#{self.graph_name}id> \"#{id}\" }")
318
321
  id = SecureRandom.uuid
319
- id_retries+=1
322
+ id_retries += 1
320
323
  end
321
324
  LOGGER.info("ID(#{id}) generated for #{self.name} in #{id_retries} retries") if ConfigFile[:debug]
322
325
  model.instance_variable_set("@id", id)
@@ -328,7 +331,7 @@ values ?s {<#{self.graph_id}>}
328
331
  model
329
332
  rescue StandardError => e
330
333
  Solis::LOGGER.error(e.message)
331
- raise Solis::Error::GeneralError, "Error generating id for #{@model_name}"
334
+ raise Solis::Error::GeneralError, "Error generating id for #{self.name}"
332
335
  end
333
336
 
334
337
  def self.metadata
@@ -390,14 +393,16 @@ values ?s {<#{self.graph_id}>}
390
393
  def self.model(level = 0)
391
394
  m = { type: self.name.tableize, attributes: {} }
392
395
  self.metadata[:attributes].each do |attribute, attribute_metadata|
393
-
396
+ is_array = ((attribute_metadata[:maxcount].nil? || (attribute_metadata[:maxcount].to_i > 1)) && !attribute_metadata[:datatype].eql?(:lang_string))
397
+ attribute_name = is_array ? "#{attribute}[]" : attribute
394
398
  if attribute_metadata.key?(:class) && !attribute_metadata[:class].nil? && attribute_metadata[:class].value =~ /#{self.graph_name}/ && level == 0
395
399
  cm = self.graph.shape_as_model(self.metadata[:attributes][attribute][:datatype].to_s).model(level + 1)
396
- m[:attributes][attribute.to_sym] = cm[:attributes]
400
+ m[:attributes][attribute_name.to_sym] = cm[:attributes]
397
401
  else
398
- m[:attributes][attribute.to_sym] = { description: attribute_metadata[:comment]&.value,
402
+ m[:attributes][attribute_name.to_sym] = { description: attribute_metadata[:comment]&.value,
399
403
  mandatory: (attribute_metadata[:mincount].to_i > 0),
400
404
  data_type: attribute_metadata[:datatype] }
405
+ m[:attributes][attribute_name.to_sym][:order] = attribute_metadata[:order]&.value.to_i if attribute_metadata.key?(:order) && !attribute_metadata[:order].nil?
401
406
  end
402
407
  end
403
408
 
@@ -420,7 +425,7 @@ values ?s {<#{self.graph_id}>}
420
425
  end
421
426
 
422
427
  def self.construct(level = 0)
423
- raise 'to bo implemented'
428
+ raise 'to be implemented'
424
429
  end
425
430
 
426
431
  def self.model_before_read(&blk)
@@ -457,16 +462,69 @@ values ?s {<#{self.graph_id}>}
457
462
 
458
463
  private
459
464
 
465
+ # Helper method to check if an object is a Solis model
466
+ def solis_model?(obj)
467
+ obj.class.ancestors.include?(Solis::Model)
468
+ end
469
+
470
+ # Helper method to get tableized class name
471
+ def tableized_class_name(obj)
472
+ obj.class.name.tableize
473
+ end
474
+
475
+ # Helper method to build entity URI
476
+ def build_entity_uri(entity_or_class, entity_id = nil)
477
+ if entity_or_class.is_a?(Class)
478
+ class_name = entity_or_class.name
479
+ id = entity_id
480
+ else
481
+ class_name = entity_or_class.class.name
482
+ id = entity_id || entity_or_class.id
483
+ end
484
+ RDF::URI("#{self.class.graph_name}#{class_name.tableize}/#{id}")
485
+ end
486
+
487
+ # Delete orphaned entities that are no longer referenced
488
+ def delete_orphaned_entities(entities_to_check, sparql)
489
+ embedded_readonly_entities = Solis::Options.instance.get[:embedded_readonly].map{|s| s.to_s} || []
490
+
491
+ entities_to_check.each do |key, orphaned_entities|
492
+ orphaned_entities.each do |orphaned_entity|
493
+ next unless solis_model?(orphaned_entity)
494
+
495
+ # Skip if it's a readonly entity (like code tables)
496
+ if (orphaned_entity.class.ancestors.map{|s| s.to_s} & embedded_readonly_entities).any?
497
+ Solis::LOGGER.info("#{orphaned_entity.class.name} (id: #{orphaned_entity.id}) is in embedded_readonly list. Skipping deletion.")
498
+ next
499
+ end
500
+
501
+ # Check if the entity is still referenced elsewhere
502
+ if orphaned_entity.is_referenced?(sparql)
503
+ Solis::LOGGER.info("#{orphaned_entity.class.name} (id: #{orphaned_entity.id}) is still referenced elsewhere. Skipping deletion.")
504
+ next
505
+ end
506
+
507
+ # Safe to delete the orphan
508
+ begin
509
+ Solis::LOGGER.info("Deleting orphaned entity: #{orphaned_entity.class.name} (id: #{orphaned_entity.id})")
510
+ orphaned_entity.destroy
511
+ rescue StandardError => e
512
+ Solis::LOGGER.error("Failed to delete orphaned entity #{orphaned_entity.class.name} (id: #{orphaned_entity.id}): #{e.message}")
513
+ end
514
+ end
515
+ end
516
+ end
517
+
460
518
  def as_graph(klass = self, resolve_all = true)
461
519
  graph = RDF::Graph.new
462
520
  graph.name = RDF::URI(self.class.graph_name)
463
- id = build_ttl_objekt2(graph, klass, [], resolve_all)
521
+ id = build_ttl_objekt(graph, klass, [], resolve_all)
464
522
 
465
523
  graph
466
524
  end
467
525
 
468
- def build_ttl_objekt2(graph, klass, hierarchy = [], resolve_all = true)
469
- hierarchy.push("#{klass.name}(#{klass.instance_variables.include?(:@id) ? klass.instance_variable_get("@id") : ''})")
526
+ def build_ttl_objekt(graph, klass, hierarchy = [], resolve_all = true)
527
+ hierarchy.push("#{klass.class.name}(#{klass.instance_variables.include?(:@id) ? klass.instance_variable_get("@id") : ''})")
470
528
 
471
529
  graph_name = self.class.graph_name
472
530
  klass_name = klass.class.name
@@ -484,10 +542,9 @@ values ?s {<#{self.graph_id}>}
484
542
  else
485
543
  resolve_all = false
486
544
  klass.instance_variables.map { |m| m.to_s.gsub(/^@/, '') }
487
- .select { |s| !["model_name", "model_plural_name"]
488
- .include?(s) }.each do |attribute, value|
545
+ .select { |s| !["model_name", "model_plural_name"].include?(s) }.each do |attribute|
489
546
  data = klass.instance_variable_get("@#{attribute}")
490
- original_data = original_klass.instance_variable_get("@#{attribute.to_s}")
547
+ original_data = original_klass.instance_variable_get("@#{attribute}")
491
548
  original_klass.instance_variable_set("@#{attribute}", data) unless original_data.eql?(data)
492
549
  end
493
550
  end
@@ -507,21 +564,21 @@ values ?s {<#{self.graph_id}>}
507
564
  klass_metadata[:attributes].each do |attribute, metadata|
508
565
  data = klass.instance_variable_get("@#{attribute}")
509
566
 
510
- if data.nil? && metadata.key?(:mincount) && ( metadata[:mincount].nil? || metadata[:mincount] > 0) && graph.query(RDF::Query.new({ attribute.to_sym => { RDF.type => metadata[:node] } })).size == 0
567
+ if data.nil? && metadata.key?(:mincount) && (metadata[:mincount].nil? || metadata[:mincount] > 0) && graph.query(RDF::Query.new({ attribute.to_sym => { RDF.type => metadata[:node] } })).size == 0
511
568
  if data.nil?
512
569
  uuid = id.value.split('/').last
513
- original_klass = klass.query.filter({ filters: { id: [ uuid ] } }).find_all { |f| f.id == uuid }.first || nil
570
+ original_klass = klass.query.filter({ filters: { id: [uuid] } }).find_all { |f| f.id == uuid }.first || nil
514
571
  unless original_klass.nil?
515
572
  klass = original_klass
516
573
  data = klass.instance_variable_get("@#{attribute}")
517
574
  end
518
575
  end
519
- #if data is still nil
520
- raise Solis::Error::InvalidAttributeError, "#{hierarchy.join('.')}~#{klass.name}.#{attribute} min=#{metadata[:mincount]} and max=#{metadata[:maxcount]}" if data.nil?
576
+ # if data is still nil
577
+ raise Solis::Error::InvalidAttributeError, "#{hierarchy.join('.')}~#{klass.class.name}.#{attribute} min=#{metadata[:mincount]} and max=#{metadata[:maxcount]}" if data.nil?
521
578
  end
522
579
 
523
- if data && metadata.key?(:maxcount) && ( metadata[:maxcount] && metadata[:maxcount] > 0) && graph.query(SPARQL.parse("select (count(?s) as ?max_subject) where { ?s #{self.class.graph_prefix}:#{attribute} ?p}")).first.max_subject > metadata[:maxcount].to_i
524
- raise Solis::Error::InvalidAttributeError, "#{hierarchy.join('.')}~#{klass.name}.#{attribute} min=#{metadata[:mincount]} and max=#{metadata[:maxcount]}" if data.nil?
580
+ if data && metadata.key?(:maxcount) && (metadata[:maxcount] && metadata[:maxcount] > 0) && graph.query(SPARQL.parse("select (count(?s) as ?max_subject) where { ?s #{self.class.graph_prefix}:#{attribute} ?p}")).first.max_subject > metadata[:maxcount].to_i
581
+ raise Solis::Error::InvalidAttributeError, "#{hierarchy.join('.')}~#{klass.class.name}.#{attribute} min=#{metadata[:mincount]} and max=#{metadata[:maxcount]}" if data.nil?
525
582
  end
526
583
 
527
584
  # skip if nil or an object that is empty
@@ -547,20 +604,19 @@ values ?s {<#{self.graph_id}>}
547
604
  data = [data] unless data.is_a?(Array)
548
605
 
549
606
  data.each do |d|
550
- if defined?(d.name) && self.class.graph.shape?(d.name) && resolve_all
551
- if self.class.graph.shape_as_model(d.name.to_s).metadata[:attributes].select { |_, v| v[:node_kind].is_a?(RDF::URI) }.size > 0 &&
552
- hierarchy.select { |s| s =~ /^#{d.name.to_s}/ }.size == 0
607
+ if solis_model?(d) && self.class.graph.shape?(d.class.name) && resolve_all
608
+ if self.class.graph.shape_as_model(d.class.name).metadata[:attributes].select { |_, v| v[:node_kind].is_a?(RDF::URI) }.size > 0 &&
609
+ hierarchy.select { |s| s =~ /^#{d.class.name}/ }.size == 0
553
610
  internal_resolve = false
554
- d = build_ttl_objekt2(graph, d, hierarchy, internal_resolve)
555
- elsif self.class.graph.shape_as_model(d.name.to_s) && hierarchy.select { |s| s =~ /^#{d.name.to_s}/ }.size == 0
611
+ d = build_ttl_objekt(graph, d, hierarchy, internal_resolve)
612
+ elsif self.class.graph.shape_as_model(d.class.name) && hierarchy.select { |s| s =~ /^#{d.class.name}/ }.size == 0
556
613
  internal_resolve = false
557
- d = build_ttl_objekt2(graph, d, hierarchy, internal_resolve)
614
+ d = build_ttl_objekt(graph, d, hierarchy, internal_resolve)
558
615
  else
559
- # d = "#{klass.class.graph_name}#{attribute.tableize}/#{d.id}"
560
- d = "#{klass.class.graph_name}#{d.name.tableize}/#{d.id}"
616
+ d = "#{klass.class.graph_name}#{d.class.name.tableize}/#{d.id}"
561
617
  end
562
- elsif defined?(d.name) && self.class.graph.shape?(d.name)
563
- d = "#{klass.class.graph_name}#{d.name.tableize}/#{d.id}"
618
+ elsif solis_model?(d) && self.class.graph.shape?(d.class.name)
619
+ d = "#{klass.class.graph_name}#{d.class.name.tableize}/#{d.id}"
564
620
  end
565
621
 
566
622
  if d.is_a?(Array) && d.length == 1
@@ -615,8 +671,8 @@ values ?s {<#{self.graph_id}>}
615
671
  raise e
616
672
  end
617
673
 
618
- def build_ttl_objekt(graph, klass, hierarchy = [], resolve_all = true)
619
- hierarchy.push("#{klass.name}(#{klass.instance_variables.include?(:@id) ? klass.instance_variable_get("@id") : ''})")
674
+ def build_ttl_objekt_old(graph, klass, hierarchy = [], resolve_all = true)
675
+ hierarchy.push("#{klass.class.name}(#{klass.instance_variables.include?(:@id) ? klass.instance_variable_get("@id") : ''})")
620
676
  sparql_endpoint = self.class.sparql_endpoint
621
677
  if klass.instance_variables.include?(:@id) && hierarchy.length > 1
622
678
  unless sparql_endpoint.nil?
@@ -661,14 +717,6 @@ values ?s {<#{self.graph_id}>}
661
717
  end
662
718
 
663
719
  if model && d.is_a?(Hash)
664
- # TODO: figure out in what use case we need the parent_model
665
- # model_instance = if parent_model
666
- # parent_model.new(d)
667
- # else
668
- # model.new(d)
669
- # end
670
-
671
- # model_instance = model.new(d)
672
720
  model_instance = model.descendants.map { |m| m&.new(d) rescue nil }.compact.first || nil
673
721
  model_instance = model.new(d) if model_instance.nil?
674
722
 
@@ -676,7 +724,7 @@ values ?s {<#{self.graph_id}>}
676
724
  d = build_ttl_objekt(graph, model_instance, hierarchy, false)
677
725
  else
678
726
  real_model = model_instance.query.filter({ filters: { id: model_instance.id } }).find_all { |f| f.id == model_instance.id }&.first
679
- d = RDF::URI("#{self.class.graph_name}#{real_model ? real_model.name.tableize : model_instance.name.tableize}/#{model_instance.id}")
727
+ d = RDF::URI("#{self.class.graph_name}#{real_model ? real_model.class.name.tableize : model_instance.class.name.tableize}/#{model_instance.id}")
680
728
  end
681
729
  elsif model && d.is_a?(model)
682
730
  if resolve_all
@@ -688,7 +736,7 @@ values ?s {<#{self.graph_id}>}
688
736
  end
689
737
  else
690
738
  real_model = model.new.query.filter({ filters: { id: d.id } }).find_all { |f| f.id == d.id }&.first
691
- d = RDF::URI("#{self.class.graph_name}#{real_model ? real_model.name.tableize : model.name.tableize}/#{d.id}")
739
+ d = RDF::URI("#{self.class.graph_name}#{real_model ? real_model.class.name.tableize : model.name.tableize}/#{d.id}")
692
740
  end
693
741
  else
694
742
  datatype = RDF::Vocabulary.find_term(metadata[:datatype_rdf] || metadata[:node])