2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2021-05-25 12:30:12 +00:00
|
|
|
class Sequencer
|
|
|
|
class Unit
|
|
|
|
module Import
|
|
|
|
module Freshdesk
|
|
|
|
module Ticket
|
|
|
|
class Mapping < Sequencer::Unit::Base
|
|
|
|
include ::Sequencer::Unit::Import::Common::Mapping::Mixin::ProvideMapped
|
|
|
|
|
|
|
|
uses :resource, :id_map
|
|
|
|
|
2021-06-01 09:44:33 +00:00
|
|
|
# Since the imports rely on a fresh Zammad installation, we
|
|
|
|
# can require the default priority and state names to be present.
|
|
|
|
def priority_map
|
|
|
|
@priority_map ||= {
|
|
|
|
1 => ::Ticket::Priority.find_by(name: '1 low')&.id, # low
|
|
|
|
2 => ::Ticket::Priority.find_by(name: '2 normal')&.id, # medium
|
|
|
|
3 => ::Ticket::Priority.find_by(name: '3 high')&.id, # high
|
|
|
|
4 => ::Ticket::Priority.find_by(name: '3 high')&.id, # urgent
|
|
|
|
}.freeze
|
|
|
|
end
|
|
|
|
|
|
|
|
def state_map
|
|
|
|
@state_map ||= {
|
|
|
|
2 => ::Ticket::State.find_by(name: 'open')&.id, # open
|
|
|
|
3 => ::Ticket::State.find_by(name: 'open')&.id, # pending
|
|
|
|
4 => ::Ticket::State.find_by(name: 'closed')&.id, # resolved
|
|
|
|
5 => ::Ticket::State.find_by(name: 'closed')&.id, # closed
|
|
|
|
}.freeze
|
|
|
|
end
|
2021-05-25 12:30:12 +00:00
|
|
|
|
|
|
|
def process # rubocop:disable Metrics/AbcSize
|
|
|
|
provide_mapped do
|
|
|
|
{
|
|
|
|
title: resource['subject'],
|
|
|
|
number: resource['id'],
|
|
|
|
group_id: group_id,
|
2021-06-01 09:44:33 +00:00
|
|
|
priority_id: priority_map[resource['priority']],
|
|
|
|
state_id: state_map[resource['status']],
|
2021-05-25 12:30:12 +00:00
|
|
|
owner_id: owner_id,
|
|
|
|
customer_id: customer_id,
|
2022-04-25 10:55:32 +00:00
|
|
|
type: resource['type'],
|
2021-05-25 12:30:12 +00:00
|
|
|
created_at: resource['created_at'],
|
|
|
|
updated_at: resource['updated_at'],
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def group_id
|
|
|
|
id_map.dig('Group', resource['group_id']) || ::Group.find_by(name: 'Support')&.id || 1
|
|
|
|
end
|
|
|
|
|
|
|
|
def customer_id
|
|
|
|
id_map['User'][resource['requester_id']]
|
|
|
|
end
|
|
|
|
|
|
|
|
def owner_id
|
|
|
|
id_map['User'][resource['responder_id']]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|