class PIM::CommunicationPlan::ActionExecutor

Constants

REFERENCED_TYPE_MESSAGE_ID
REFERENCED_TYPE_PRIMARY_KEY
REFERENCED_TYPE_TAG
RESULT_ADDITIONAL_TAGS
RESULT_CUSTOM_VALUES
RESULT_RESPONSE_ID

Attributes

action_creator[RW]
action_date[RW]
action_type[RW]
channel[RW]
channel_type[RW]
organization[RW]
plan[RW]

Public Class Methods

new(plan, action_type, action_creator, action_tags, action_date, channel, organization, data) click to toggle source
# File pim.rb, line 9608
def initialize plan, action_type, action_creator, action_tags, action_date, channel, organization, data
  @plan = plan
  @action_type = action_type
  @action_creator = action_creator
  @action_tags = action_tags
  @action_date = action_date
  @channel = channel
  @channel_type = channel.type
  @organization = organization
  @data = data || {}
end

Public Instance Methods

add_action_result(item, status, status_message = nil, *tags) click to toggle source

DEPRECATED: Use “set_item_publication_result” instead

# File pim.rb, line 9874
def add_action_result item, status, status_message = nil, *tags
  set_item_publication_result item, status, status_message, tags
end
add_action_results(items, status, status_message = nil, *tags) click to toggle source

DEPRECATED: Use “set_item_publication_results” instead

# File pim.rb, line 9879
def add_action_results items, status, status_message = nil, *tags
  set_item_publication_results items, status, status_message, tags
end
create_content_message(content_type, prefix = nil, suffix = nil, &block) click to toggle source
# File pim.rb, line 9667
def create_content_message content_type, prefix = nil, suffix = nil, &block

  message_creation_parameters = service.create_message_creation_parameters
  message_content = PIM::Services::CommunicationPlanService.create_content(message_creation_parameters, &block)
  message = service.create_content_messaging_asset(@action_creator,
                                                   @channel,
                                                   message_creation_parameters,
                                                   message_content,
                                                   content_type,
                                                   prefix,
                                                   suffix,
                                                   true)
  set_message_update_result message, 'PENDING'

  message

end
create_publication_message_tag(reference_message) click to toggle source

DEPRECATED: Just use “reference_message.referenceMessageId” as tag

# File pim.rb, line 9869
def create_publication_message_tag reference_message
  reference_message.reference_message_id if reference_message
end
create_trafo_digital_asset(items, content_type, prefix = nil, suffix = nil, params = {}) click to toggle source
# File pim.rb, line 9726
def create_trafo_digital_asset items, content_type, prefix = nil, suffix = nil, params = {}
  params = unsymbolized_hash(params)
  service.create_trafo_digital_asset(@action_creator,
                                     items,
                                     content_type,
                                     prefix,
                                     suffix,
                                     params)
end
create_trafo_message(items, content_type, prefix = nil, suffix = nil, trafo_params = {}) click to toggle source
# File pim.rb, line 9685
def create_trafo_message items, content_type, prefix = nil, suffix = nil, trafo_params = {}, *message_params

  blocked_by_id = nil
  blocked_by_delay = nil
  expecting_response = nil
  tags = Set.new
  tags.merge @action_tags

  if message_params.length == 1 and is_hash?(message_params[0])
    message_params = message_params[0]
    blocked_by_id = message_params[:blocked_by_id]
    blocked_by_delay = message_params[:blocked_by_delay]
    expecting_response = message_params[:expecting_response]
    tags.merge(message_params[:tags]) unless message_params[:tags].nil?
  else
    blocked_by_id = message_params[0] if message_params.length >= 1
    blocked_by_delay = message_params[1] if message_params.length >= 2
  end

  trafo_params = unsymbolized_hash(trafo_params)
  message = service.create_trafo_messaging_asset(@action_creator,
                                                 tags,
                                                 @channel,
                                                 items,
                                                 content_type,
                                                 prefix,
                                                 suffix,
                                                 trafo_params,
                                                 blocked_by_id,
                                                 blocked_by_delay,
                                                 expecting_response)

  # Message will be created with state 'DEFERRED', if not blocked, so add an update result to make it 'PENDING'
  if message and blocked_by_id.nil?
    set_message_update_result message, 'PENDING'
  end

  message

end
create_trafo_public_asset(items, content_type, prefix = nil, suffix = nil, params = {}) click to toggle source
# File pim.rb, line 9736
def create_trafo_public_asset items, content_type, prefix = nil, suffix = nil, params = {}
  params = unsymbolized_hash(params)
  service.create_trafo_public_asset(@action_creator,
                                    items,
                                    content_type,
                                    prefix,
                                    suffix,
                                    params)
end
execute(&action) click to toggle source
# File pim.rb, line 9620
def execute &action
  @action_result = {}
  self.instance_exec(&action)
  @action_result.values
end
get_asset_content_stream(asset) click to toggle source
# File pim.rb, line 9746
def get_asset_content_stream asset
  service.get_asset_content_stream(asset)
end
get_item_primary_key(item) click to toggle source
# File pim.rb, line 9808
def get_item_primary_key item

  # Determine primary key
  if item.respond_to?(:primary_key)
    primary_key = item.primary_key
  elsif is_hash?(item)
    primary_key = item['primaryKey__']
  else
    primary_key = item.to_s
  end
  if is_empty?(primary_key)
    PIM.log_warn "No or empty primary key specified in action result"
    primary_key = nil
  end

  return primary_key
end
get_item_publication_result(item) click to toggle source
# File pim.rb, line 9826
def get_item_publication_result item
  primary_key = get_item_primary_key(item)
  return nil if !primary_key
  get_result REFERENCED_TYPE_PRIMARY_KEY, primary_key
end
get_message_id(message) click to toggle source
# File pim.rb, line 9844
def get_message_id message

  # Determine message id
  if message.respond_to?(:reference_message_id)
    message_id = message.reference_message_id
  elsif is_hash?(message)
    message_id = message['reference_message_id']
  else
    message_id = message.to_s
  end
  if is_empty?(message_id)
    PIM.log_warn "No or empty message id specified in action result"
    message_id = nil
  end

  return message_id
end
get_message_update_result(message) click to toggle source
# File pim.rb, line 9862
def get_message_update_result message
  message_id = get_message_id(message)
  return nil if !message_id
  get_result REFERENCED_TYPE_MESSAGE_ID, message_id
end
get_tag_publication_result(tag) click to toggle source
# File pim.rb, line 9782
def get_tag_publication_result tag
  get_result REFERENCED_TYPE_TAG, tag
end
item_hierarchies() click to toggle source
# File pim.rb, line 9630
def item_hierarchies
  @data['item_hierarchies']
end
items() click to toggle source
# File pim.rb, line 9626
def items
  @data['items']
end
load_item_with_publication(primary_key) click to toggle source
# File pim.rb, line 9755
def load_item_with_publication primary_key
  return nil if publication.nil?
  __service(:itemService).load_with_publication primary_key, publication.destination_id, publication.sub_destination
end
load_items_with_publications(*primary_keys) click to toggle source
# File pim.rb, line 9750
def load_items_with_publications *primary_keys
  return nil if publication.nil?
  __service(:itemService).load_with_publications primary_keys, publication.destination_id, publication.sub_destination
end
publication() click to toggle source
# File pim.rb, line 9646
def publication
  return action_creator if !action_creator.nil? and action_creator.messaging_creator_type.to_s == 'PUBLICATION'
end
publication_name() click to toggle source
# File pim.rb, line 9658
def publication_name
  if !publication.nil? and !publication.job_id.nil?
    job = PIM::Services::JobService.get_job(publication.job_id)
    return job.name unless job.nil?
  end

  nil
end
reference_message() click to toggle source
# File pim.rb, line 9634
def reference_message
  @data['reference_message']
end
response_message() click to toggle source
# File pim.rb, line 9638
def response_message
  @data['response_message']
end
responses() click to toggle source
# File pim.rb, line 9642
def responses
  @data['responses']
end
review() click to toggle source
# File pim.rb, line 9654
def review
  return action_creator if !action_creator.nil? and action_creator.messaging_creator_type.to_s == 'REVIEW'
end
send_publication_email(public_asset) click to toggle source
# File pim.rb, line 9760
def send_publication_email public_asset
  service.send_publication_email(@channel, public_asset)
end
set_item_publication_result(item, status, status_message = nil, tags = nil, custom_values = nil) click to toggle source
# File pim.rb, line 9786
def set_item_publication_result item, status, status_message = nil, tags = nil, custom_values = nil

  primary_key = get_item_primary_key(item)
  return if !primary_key

  result_values = {}
  if !tags.nil?
    tags = is_array?(tags) ? tags : [tags.to_s]
    result_values[RESULT_ADDITIONAL_TAGS] = tags
  end
  result_values[RESULT_CUSTOM_VALUES] = custom_values if !custom_values.nil?

  add_result REFERENCED_TYPE_PRIMARY_KEY, primary_key, status, status_message, result_values

end
set_item_publication_results(items, status, status_message = nil, tags = nil, custom_values = nil) click to toggle source
# File pim.rb, line 9802
def set_item_publication_results items, status, status_message = nil, tags = nil, custom_values = nil
  items.each do |item|
    set_item_publication_result item, status, status_message, tags, custom_values
  end
end
set_message_update_result(message, status, status_message = nil, response_id = nil) click to toggle source
# File pim.rb, line 9832
def set_message_update_result message, status, status_message = nil, response_id = nil

  message_id = get_message_id(message)
  return if !message_id

  result_values = {}
  result_values[RESULT_RESPONSE_ID] = response_id if !response_id.nil?

  add_result REFERENCED_TYPE_MESSAGE_ID, message_id, status, status_message, result_values

end
set_tag_publication_result(tag, status, status_message = nil, tags = nil, custom_values = nil) click to toggle source
# File pim.rb, line 9764
def set_tag_publication_result tag, status, status_message = nil, tags = nil, custom_values = nil

  if is_empty?(tag)
    PIM.log_warn "No or empty tag key specified in action result"
    return
  end

  result_values = {}
  if !tags.nil?
    tags = is_array?(tags) ? tags : [tags.to_s]
    result_values[RESULT_ADDITIONAL_TAGS] = tags
  end
  result_values[RESULT_CUSTOM_VALUES] = custom_values if !custom_values.nil?

  add_result REFERENCED_TYPE_TAG, tag, status, status_message, result_values

end
subscription() click to toggle source
# File pim.rb, line 9650
def subscription
  return action_creator if !action_creator.nil? and action_creator.messaging_creator_type.to_s == 'SUBSCRIPTION'
end