dynamic_field_factory.rb 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. module Import
  2. module OTRS
  3. module DynamicFieldFactory
  4. extend Import::Factory
  5. extend Import::Helper
  6. # rubocop:disable Style/ModuleFunction
  7. extend self
  8. def skip?(record, *_args)
  9. return true if skip_field?(record['Name'])
  10. return false if importable?(record)
  11. @skip_fields.push(record['Name'])
  12. true
  13. end
  14. def backend_class(record, *_args)
  15. "Import::OTRS::DynamicField::#{record['FieldType']}".constantize
  16. end
  17. def skip_field?(dynamic_field_name)
  18. skip_fields.include?(dynamic_field_name)
  19. end
  20. private
  21. def importable?(dynamic_field)
  22. return false if !supported_object_type?(dynamic_field)
  23. supported_field_type?(dynamic_field)
  24. end
  25. def supported_object_type?(dynamic_field)
  26. return true if dynamic_field['ObjectType'] == 'Ticket'
  27. log "ERROR: Unsupported dynamic field object type '#{dynamic_field['ObjectType']}' for dynamic field '#{dynamic_field['Name']}'"
  28. false
  29. end
  30. def supported_field_type?(dynamic_field)
  31. return true if supported_field_types.include?(dynamic_field['FieldType'])
  32. log "ERROR: Unsupported dynamic field field type '#{dynamic_field['FieldType']}' for dynamic field '#{dynamic_field['Name']}'"
  33. false
  34. end
  35. def supported_field_types
  36. %w(Text TextArea Checkbox DateTime Date Dropdown Multiselect)
  37. end
  38. def skip_fields
  39. return @skip_fields if @skip_fields
  40. @skip_fields = %w(ProcessManagementProcessID ProcessManagementActivityID ZammadMigratorChanged ZammadMigratorChangedOld)
  41. end
  42. end
  43. end
  44. end