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(
  :mapping,
  opts = {
    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!

Methods included from SoftwareAgent

#agent_name

Constructor Details

#initialize(opts = {}) ⇒ Agent

Returns a new instance of Agent.



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

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Class Method Details

.queue_nameObject



97
98
99
# File 'lib/krikri/mapper.rb', line 97

def self.queue_name
  :mapping
end

Instance Method Details

#entity_behaviorObject



105
106
107
# File 'lib/krikri/mapper.rb', line 105

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

#run(activity_uri = nil) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/krikri/mapper.rb', line 114

def run(activity_uri = nil)
  harvest_records = generator_activity.entities
  Krikri::Mapper.map(name, harvest_records).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