Class: Tasks::Dwc::DashboardController

Inherits:
ApplicationController
  • Object
show all
Includes:
TaskControllerConfiguration
Defined in:
app/controllers/tasks/dwc/dashboard_controller.rb

Instance Method Summary collapse

Methods included from TaskControllerConfiguration

#set_is_task_controller

Instance Method Details

#create_indexObject

TODO: throttle to 5k.



44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/tasks/dwc/dashboard_controller.rb', line 44

def create_index
  q = ::Queries::CollectionObject::Filter.new(params)
  q.project_id = nil

  if q.all(true)
    q.project_id = sessions_current_project_id
     = ::Export::Dwca.build_index_async(CollectionObject, q.all)
    render json: , status: :ok
  else
    render json: {}, status: :unprocessable_entity
  end
end

#generate_downloadObject

/tasks/dwc/dashboard/generate_download.json !! Run rails jobs:work in the terminal to complete builds



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/tasks/dwc/dashboard_controller.rb', line 10

def generate_download

  # TODO: to support scoping by other filters
  # we will have to scope all filter params throughout by their target base
  # e.g. collection_object[param]
  a = nil

  q = ::Queries::CollectionObject::Filter.new(params)
  q.project_id = nil

  if q.all(true)
    q.project_id = sessions_current_project_id
    a = DwcOccurrence.by_collection_object_filter(
      filter_scope: q.all,
      project_id: sessions_current_project_id)
  else
    a = DwcOccurrence.where(project_id: sessions_current_project_id)
    if params[:dwc_occurrence_start_date]
      a = a.where('dwc_occurrences.updated_at < ? and dwc_occurrences.updated_at > ?', params[:dwc_occurrence_start_date], params[:dwc_occurrence_end_date])
    end
  end

  @download = ::Export::Dwca.download_async(
    a, request.url,
    predicate_extensions: predicate_extension_params,
    extension_scopes: {
      biological_associations: params[:biological_associations_extension] ?
      ::Queries::BiologicalAssociation::Filter.new(collection_object_query: q.params).all.to_sql : nil
    }
  )
  render '/downloads/show'
end

#indexObject

DWC_TASK



5
6
# File 'app/controllers/tasks/dwc/dashboard_controller.rb', line 5

def index
end

#index_versionsObject



57
58
59
# File 'app/controllers/tasks/dwc/dashboard_controller.rb', line 57

def index_versions
  render json: ::Export::Dwca::INDEX_VERSION, status: :ok
end

#predicate_extension_paramsObject (private)



63
64
65
# File 'app/controllers/tasks/dwc/dashboard_controller.rb', line 63

def predicate_extension_params
  params.permit(collecting_event_predicate_id: [], collection_object_predicate_id: [] ).to_h.symbolize_keys
end