Class: Krikri::Mapper::Agent

Inherits:
Object
  • Object
show all
Includes:
EntityConsumer, SoftwareAgent
Defined in:
lib/krikri/mapper.rb

Overview

A SoftwareAgent to run mapping processes.

@see: Krikri::SoftwareAgent, Krikri::Activity

Examples:

to map the records harvested by the harvest activity with ID 1:

Krikri::Mapper::Agent.enqueue(name: :scdl_qdc,
  generator_uri: 'http://ldp.local.dp.la/ldp/activity/1')

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from EntityConsumer

#assign_generator_activity!, #entities, #entity_source, #set_entity_source!

Methods included from SoftwareAgent

#agent_name

Constructor Details

#initialize(opts = {}) ⇒ Agent

Returns a new instance of Agent.

Parameters:

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • name (#to_sym)

    the symbol naming the mapping to use



110
111
112
113
114
# File 'lib/krikri/mapper.rb', line 110

def initialize(opts = {})
  @name = opts.fetch(:name).to_sym
  @entity_behavior = self.class.entity_behavior
  assign_generator_activity!(opts)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



91
92
93
# File 'lib/krikri/mapper.rb', line 91

def name
  @name
end

Class Method Details

.queue_nameSymbol

Returns the default queue for jobs using this agent.

Returns:

  • (Symbol)

    the default queue for jobs using this agent



95
96
97
# File 'lib/krikri/mapper.rb', line 95

def self.queue_name
  :mapping
end

Instance Method Details

#entity_behaviorObject



103
104
105
# File 'lib/krikri/mapper.rb', line 103

def entity_behavior
  @entity_behavior ||= Krikri::AggregationEntityBehavior
end

#run(activity_uri = nil) ⇒ Object

Parameters:

  • activity_uri (RDF::URI) (defaults to: nil)

    the uri of the activity to attribute for provenance purposes (default: nil)

See Also:



120
121
122
123
124
125
126
127
128
129
130
# File 'lib/krikri/mapper.rb', line 120

def run(activity_uri = nil)
  Krikri::Mapper.map(name, entities).each do |rec|
    begin
      rec.mint_id! if rec.node?
      activity_uri ? rec.save_with_provenance(activity_uri) : rec.save
    rescue => e
      Rails.logger.error("Error saving record: #{rec.try(:rdf_subject)}\n" \
                         "#{e.message}\n#{e.backtrace}")
    end
  end
end