Class: UDAMUtils::GenericPublishMapProcessor

Inherits:
WorkflowPublishMapProcessor show all
Defined in:
lib/udam_utils/publish_map_processor.rb

Overview

EventBasedPublishMapProcessor

Instance Attribute Summary collapse

Attributes inherited from WorkflowPublishMapProcessor

#event

Attributes inherited from BasePublishMapProcessor

#logger

Instance Method Summary collapse

Methods inherited from WorkflowPublishMapProcessor

#confirm_event, #eval_workflow_parameters, #execute, #match_found_in_publish_maps?, #parse_event, #process_event, #process_events, #publish_event, #publish_event_to_workflow, #search_eval_publish_map, #search_glob_publish_map, #search_global_publish_map, #search_media_type_publish_map

Methods inherited from BasePublishMapProcessor

#load_configuration_from_file, process, publish_map, publish_map=, search_hash, #search_hash

Constructor Details

#initialize(params = {}) ⇒ GenericPublishMapProcessor



534
535
536
537
# 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

Instance Attribute Details

#objectObject

Returns the value of attribute object.



532
533
534
# File 'lib/udam_utils/publish_map_processor.rb', line 532

def object
  @object
end

Instance Method Details

#confirm(params = {}) ⇒ Object

publish



703
704
705
# File 'lib/udam_utils/publish_map_processor.rb', line 703

def confirm(params = {})

end

#init_publish_params(params) ⇒ Object



540
541
542
543
544
# 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 = { }) ⇒ Object

init_publish_params



546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
# 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]

     = object.fetch(:metadata_sources, { })
    @exiftool = [:exiftool] ||= { }
    @mediainfo = [:mediainfo] ||= { }
    @ffmpeg = [:ffmpeg] ||= { }
    @filemagic = [:filemagic] ||= { }
    @media = [:filemagic] ||= { }
    @common_media_info = [: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 = { }) ⇒ Object

process_events



583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
# 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 = {}) ⇒ Object



570
571
572
573
574
575
576
577
578
579
580
581
# 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) ⇒ Boolean

Options Hash (params):

  • :publish_event_exec (String|nil)
  • (false) (Boolean|nil)

    :eval_publish_event_exec

  • :publish_event_arguments (String|nil)
  • (true) (Boolean|nil)

    :eval_publish_event_exec



677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
# 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 = { }) ⇒ Boolean

Options Hash (params):

  • :object (Hash)
  • :workflow (Hash)


647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
# 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