2024-09-02 16:33:54 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2025-04-23 17:36:16 -04:00
|
|
|
class Geojson::Importer
|
2024-11-04 07:06:04 -05:00
|
|
|
include Imports::Broadcaster
|
2025-03-23 14:13:59 -04:00
|
|
|
include PointValidation
|
2024-11-04 07:06:04 -05:00
|
|
|
|
2025-03-23 14:13:59 -04:00
|
|
|
attr_reader :import, :user_id
|
2024-09-02 16:33:54 -04:00
|
|
|
|
|
|
|
|
def initialize(import, user_id)
|
|
|
|
|
@import = import
|
|
|
|
|
@user_id = user_id
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def call
|
2025-04-23 17:27:55 -04:00
|
|
|
file_content = Imports::SecureFileDownloader.new(import.file).download_with_verification
|
|
|
|
|
json = Oj.load(file_content)
|
2024-09-02 16:33:54 -04:00
|
|
|
|
2025-04-23 17:27:55 -04:00
|
|
|
data = Geojson::Params.new(json).call
|
2024-09-02 16:33:54 -04:00
|
|
|
|
2025-04-23 17:27:55 -04:00
|
|
|
data.each.with_index(1) do |point, index|
|
|
|
|
|
next if point_exists?(point, user_id)
|
2024-11-04 07:06:04 -05:00
|
|
|
|
2025-04-23 17:27:55 -04:00
|
|
|
Point.create!(point.merge(user_id:, import_id: import.id))
|
2024-09-02 16:33:54 -04:00
|
|
|
|
2025-04-23 17:27:55 -04:00
|
|
|
broadcast_import_progress(import, index)
|
2025-03-23 14:13:59 -04:00
|
|
|
end
|
2024-09-02 16:33:54 -04:00
|
|
|
end
|
|
|
|
|
end
|