class UDAMUtils::GenericPublishMapProcessor

Attributes

object[RW]

Public Class Methods

new(params = {}) click to toggle source
# File lib/udam_utils/publish_map_processor.rb, line 534
def initialize(params = {})
  super(params)
  @full_file_path_field_name = params[:file_path_field_name]
end

Public Instance Methods

confirm(params = {}) click to toggle source
# File lib/udam_utils/publish_map_processor.rb, line 703
def confirm(params = {})

end
init_publish_params(params) click to toggle source
# File lib/udam_utils/publish_map_processor.rb, line 540
def init_publish_params(params)
  # We don't have events so the params are the params, there is not an 'event type' as a key in between
  @publish_params = params
  @publish_params
end
parse_object(object = @object, params = { }) click to toggle source
# File lib/udam_utils/publish_map_processor.rb, line 546
def parse_object(object = @object, params = { })
  logger.debug { "Parsing Object: #{PP.pp(object, '')}" }
  begin
    @full_file_path = object[@full_file_path_field_name]

    @metadata_sources = object.fetch(:metadata_sources, { })
    @exiftool = @metadata_sources[:exiftool] ||= { }
    @mediainfo = @metadata_sources[:mediainfo] ||= { }
    @ffmpeg = @metadata_sources[:ffmpeg] ||= { }
    @filemagic = @metadata_sources[:filemagic] ||= { }
    @media = @metadata_sources[:filemagic] ||= { }
    @common_media_info = @metadata_sources[:common] ||= { }

    #media = entity.fetch('media', { })
    @media_type = @media[:type] || @media['type']
    @media_subtype = @media[:subtype] || @media['subtype']
  rescue => e
    logger.error "Error parsing object.\n\tObject: #{object.inspect}\n\n\tException #{e.message}\n\tBacktrace #{e.backtrace}"
    raise
  end
end
process_object(params = { }) click to toggle source
# File lib/udam_utils/publish_map_processor.rb, line 583
def process_object(params = { })
  _object = params.has_key?(:object) ? params[:object] : nil
  return _object.map { |o| process_object(params.merge(:object => o)) } if _object.is_a?(Array)
  @object = _object

  logger.debug { "Processing Object: \n\n #{PP.pp(object, '')}" }
  parse_object
  ignore_publish_error = false

  #parse_event(event) #rescue return

  if match_found_in_publish_maps?

    # Determines if the event is to be published
    # Defaults to true so that that it doesn't have to be defined for every workflow map
    map_publish = @publish_params.fetch(:publish, true)

    # Determines if the event is to be confirmed
    # Defaults to true so that that it doesn't have to be defined for every workflow map
    map_confirm = @publish_params.fetch(:confirm, true)

    # Determines if the event will still get confirmed if there is an error during publishing
    ignore_publish_error = @publish_params.fetch(:ignore_publish_error, false)
  else
    map_publish = nil
    map_confirm = nil
  end

  to_publish = map_publish
  to_confirm = (map_confirm or @confirm_filtered_objects)

  if to_publish
    publish_response = publish
    publish_successful = publish_response[:success]
    confirm_response = confirm(@object_id) if (publish_successful or ignore_publish_error) and map_confirm
  elsif to_confirm
    logger.debug { "Confirming but not published. Map Publish Content: #{map_publish} Confirm Filtered: #{@confirm_filtered_events} Map Confirm Event: #{map_confirm} Object: #{object.inspect}"}
    confirm_response = confirm(@object_id)
  else
    publish_successful = publish_response = confirm_successful = confirm_response = nil
  end
  confirm_successful = confirm_response[:success] if confirm_response

  {
      :to_publish       => to_publish,
      :to_confirm       => to_confirm,
      :published        => (publish_successful or ignore_publish_error),
      :confirmed        => confirm_successful,
      :publish_response => publish_response,
      :confirm_response => confirm_response,
      :success          => (
        (!to_publish or (to_publish and publish_successful)) and
          (!to_confirm or (to_confirm and confirm_successful))
      )
  }
rescue StandardError, ScriptError => e
  logger.error "Error processing object.\n\tObject: #{object.inspect}\n\n\tException #{e.inspect}"
  { :success => false, :error => { :message => e.message }, :exception => { :message => e.message, :backtrace => e.backtrace }, :object => object }
end
process_objects(objects, params = {}) click to toggle source

@param [Array<Hash>] objects

# File lib/udam_utils/publish_map_processor.rb, line 570
def process_objects(objects, params = {})
  results = [ ]
  [*objects].each do |_object|
    begin
      results << process_object(params.merge(:object => _object))
    rescue StandardError, ScriptError => e
      logger.error "Error processing event.\n\tObject: #{_object.inspect}\n\n\tException #{e.inspect}"
      results << { :success => false, :error => { :message => e.message }, :exception => { :message => e.message, :backtrace => e.backtrace }, :object => _object }
    end
  end
  results
end
publish(object = @object, params = @publish_params) click to toggle source

@param [String|Integer] event_id @param [Hash] object @param [Hash] params @option params [String|nil] :publish_event_exec @option params [Boolean|nil] (false) :eval_publish_event_exec @option params [String|nil] :publish_event_arguments @option params [Boolean|nil] (true) :eval_publish_event_exec @return [Boolean]

# File lib/udam_utils/publish_map_processor.rb, line 677
def publish(object = @object, params = @publish_params)

  workflow = params.fetch(:workflow, false)
  return publish_to_workflow(:workflow => workflow) if workflow

  exec = search_hash(params, [:publish_executable, :publish_exec, :publish_event_exec])
  eval_publish_exec = search_hash(params, [:eval_publish_executable, :eval_publish_exec, :eval_publish_event_exec])

  arguments = search_hash(params, [:publish_arguments, :publish_event_arguments])
  eval_publish_arguments = search_hash(params, [:eval_publish_arguments, :eval_publish_event_arguments], :default => true)

  logger.debug { "Evaluating exec: #{exec}" } and (exec = eval(exec)) if eval_publish_exec and exec
  logger.debug { "Evaluating arguments: #{arguments}" } and (arguments = eval(arguments)) if eval_publish_arguments and arguments

  if exec
    cmd_line = arguments ? "#{exec} #{arguments}" : exec
  else
    cmd_line = arguments
  end

  logger.debug { "Publishing using command line. #{cmd_line}" }
  response = execute(cmd_line)
  logger.debug { "Publish command response: #{response}" }
  response
end
publish_to_workflow(params = { }) click to toggle source

@param [Hash] params @option params [Hash] :object @option params [Hash] :workflow @return [Boolean]

# File lib/udam_utils/publish_map_processor.rb, line 647
def publish_to_workflow(params = { })
  object = params.fetch(:object, @object)
  workflow = params[:workflow]
  workflow ||= @publish_params[:workflow] if @publish_params.is_a?(Hash)

  logger.debug { "Publishing To Workflow. Workflow: #{workflow}" }
  unless (workflow_name = workflow.fetch(:name, false))
    logger.error "No Workflow Name Specified. Object: #{object} Workflow: #{workflow}"
    return false
  end

  workflow_parameters = workflow.fetch(:parameters, false)
  workflow_parameter_values = eval_workflow_parameters(workflow_parameters, object) if workflow_parameters
  workflow_parameter_values ||= { }

  cmd_line = [ @udam_utils_exec, 'job', '--workflow', workflow_name, '--workflow-parameters', workflow_parameter_values.to_json].shelljoin
  logger.debug { "Publishing event using command line. #{cmd_line}" }
  response = execute(cmd_line)
  logger.debug { "Publish event command response: #{response}" }
  response
end