dynamic_field_factory.rb 1.6 KB

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