Skip to content

Bug fix: In RDF update, delete all old triples #29

@demery

Description

@demery

The change to not send empty values to RDF when objects are updated has meant that old triples are not getting deleted.

In order to prevent triples without objects being added to the store, a change was made to only send to the interface those values that a present on objects. Thus:

  def to_rdf
    map = {
      model_class: "names",
      id: id,
      fields: {}
    }

    map[:fields][:name]       = "'''#{name.to_s.gsub("'", "")}'''"       if name.present?
    map[:fields][:viaf_id]    = "'''#{viaf_id}'''"                       if viaf_id.present?
    map[:fields][:subtype]    = "'''#{subtype}'''"                       if subtype.present?
    map[:fields][:startdate]  = "'''#{startdate}'''"                     if startdate.present?
    map[:fields][:enddate]    = "'''#{enddate}'''"                       if enddate.present?
    map[:fields][:other_info] = "'''#{other_info.to_s.gsub("'", "")}'''" if other_info.present?
    map[:fields][:deleted]    = "'#{deleted}'^^xsd:boolean"              unless deleted.nil?

    map
  end

However, the RDF update process deletes each triple before inserting the updated one. interface.rb deletes only those triples given in the message hash:

      message['fields'].each do |field, new_value|
        query += %Q(
          DELETE { ?subject #{predicate} ?object }
          INSERT { ?subject #{predicate} #{new_value} }
          WHERE {
            BIND (<https://sdbm.library.upenn.edu/#{message['model_class']}/#{message['id']}> as ?subject) .
            OPTIONAL { ?subject #{predicate} ?object }
          };
        )
      # etc.
      end

Since empty values are not sent in the message hash, the delete clause isn't created. To fix this, the empty fields should be sent in the message hash, and -- in the update code in interface.rb -- added to the DELETE clause, but no INSERT clause should be created.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions