2016-11-25 16:10:37 +00:00
|
|
|
module Import
|
|
|
|
module OTRS
|
|
|
|
module DynamicFieldFactory
|
|
|
|
extend Import::Factory
|
|
|
|
extend Import::Helper
|
|
|
|
|
|
|
|
# rubocop:disable Style/ModuleFunction
|
|
|
|
extend self
|
|
|
|
|
2016-12-20 15:16:09 +00:00
|
|
|
def skip?(record, *_args)
|
2016-11-25 16:10:37 +00:00
|
|
|
return true if skip_field?(record['Name'])
|
2017-01-13 09:59:14 +00:00
|
|
|
return false if importable?(record)
|
|
|
|
@skip_fields.push(record['Name'])
|
|
|
|
true
|
2016-11-25 16:10:37 +00:00
|
|
|
end
|
|
|
|
|
2016-12-20 15:16:09 +00:00
|
|
|
def backend_class(record, *_args)
|
2016-11-25 16:10:37 +00:00
|
|
|
"Import::OTRS::DynamicField::#{record['FieldType']}".constantize
|
|
|
|
end
|
|
|
|
|
|
|
|
def skip_field?(dynamic_field_name)
|
|
|
|
skip_fields.include?(dynamic_field_name)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def importable?(dynamic_field)
|
|
|
|
return false if !supported_object_type?(dynamic_field)
|
|
|
|
supported_field_type?(dynamic_field)
|
|
|
|
end
|
|
|
|
|
|
|
|
def supported_object_type?(dynamic_field)
|
|
|
|
return true if dynamic_field['ObjectType'] == 'Ticket'
|
|
|
|
log "ERROR: Unsupported dynamic field object type '#{dynamic_field['ObjectType']}' for dynamic field '#{dynamic_field['Name']}'"
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def supported_field_type?(dynamic_field)
|
|
|
|
return true if supported_field_types.include?(dynamic_field['FieldType'])
|
|
|
|
log "ERROR: Unsupported dynamic field field type '#{dynamic_field['FieldType']}' for dynamic field '#{dynamic_field['Name']}'"
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def supported_field_types
|
2017-11-23 08:09:44 +00:00
|
|
|
%w[Text TextArea Checkbox DateTime Date Dropdown Multiselect]
|
2016-11-25 16:10:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def skip_fields
|
2017-01-13 09:59:14 +00:00
|
|
|
return @skip_fields if @skip_fields
|
2017-11-23 08:09:44 +00:00
|
|
|
@skip_fields = %w[ProcessManagementProcessID ProcessManagementActivityID ZammadMigratorChanged ZammadMigratorChangedOld]
|
2016-11-25 16:10:37 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|