Class: DwcOccurrencesController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/dwc_occurrences_controller.rb

Constant Summary

Constants included from ProjectsHelper

ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION

Instance Method Summary collapse

Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration

#annotator_params

Methods included from RedirectHelper

#destroy_redirect

Methods included from RequestType

#json_request?

Methods included from LogRecent

#log_user_recent_route

Methods included from Cookies

#digest_cookie, #digested_cookie_exists?

Methods included from Whitelist

#whitelist_constantize

Methods included from ProjectsHelper

#cumulative_gb_per_year, #document_cumulative_gb_per_year, #document_gb_per_year, #gb_per_year, #image_cumulative_gb_per_year, #image_gb_per_year, #invalid_object, #project_classification, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form, #taxonworks_classification, #week_in_review_graphs

Methods included from Api::Intercept

#intercept_api

Methods included from TokenAuthentication

#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate

Instance Method Details

#api_indexObject

GET /api/v1/dwc_occurrences.json



54
55
56
57
58
59
60
# File 'app/controllers/dwc_occurrences_controller.rb', line 54

def api_index
  @dwc_occurrences = Queries::DwcOccurrence::Filter.new(params.merge!(api: true))
    .all
    .where(project_id: sessions_current_project_id)
    .page(params[:page]).per(params[:per] || 1000)
  render '/dwc_occurrences/api/v1/index'
end

#attributesObject

TODO: extract this all, unify with Concerns::IsData model, and re-use in DwcOccurrence



75
76
77
78
79
80
# File 'app/controllers/dwc_occurrences_controller.rb', line 75

def attributes
  i = Queries::DwcOccurrence::Filter::ATTRIBUTES
  render json:  ::DwcOccurrence.columns.select{
    |a| i.include?(a.name.to_sym)
  }.collect{|b| {'name' => b.name, 'type' => b.type } }
end

#collector_id_metadataObject



36
37
38
# File 'app/controllers/dwc_occurrences_controller.rb', line 36

def 
  render json: helpers.
end

#createObject

TODO: remove



41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/dwc_occurrences_controller.rb', line 41

def create
  respond_to do |format|
    format.html do
      @object.set_dwc_occurrence # TODO: If sync is complete this is not needed.
      redirect_to browse_collection_objects_task_path(collection_object_id: @object.id)
    end
    format.json {
      render status: :found and return
    }
  end
end

#downloadObject

GET /dwc_occurence/download



63
64
65
66
# File 'app/controllers/dwc_occurrences_controller.rb', line 63

def download
  send_data Export::CSV.generate_csv(
    DwcOccurrence.where(project_id: sessions_current_project_id)), type: 'text', filename: "dwc_occurrence_#{DateTime.now}.tsv"
end

#indexObject

.json only



10
11
12
13
14
15
# File 'app/controllers/dwc_occurrences_controller.rb', line 10

def index
  @dwc_occurrences = Queries::DwcOccurrence::Filter.new(params).all
    .where(project_id: sessions_current_project_id)
    .page(params[:page])
    .per(params[:per] || 1)
end

#metadataObject



17
18
19
# File 'app/controllers/dwc_occurrences_controller.rb', line 17

def 
  @dwc_occurrences = DwcOccurrence.where(project_id: sessions_current_project_id)
end

#predicatesObject



21
22
# File 'app/controllers/dwc_occurrences_controller.rb', line 21

def predicates
end

#set_objectObject (protected)



84
85
86
87
88
89
90
# File 'app/controllers/dwc_occurrences_controller.rb', line 84

def set_object
  @object = GlobalID::Locator.locate(params[:object_global_id])

  if @object.nil? || (@object.project_id != sessions_current_project_id)
    render status: :not_found and return
  end
end

#statusObject



24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/dwc_occurrences_controller.rb', line 24

def status
  if @object
    render json: {
      object: params[:object_global_id],
      id: @object.dwc_occurrence&.id,
      updated_at:  @object.dwc_occurrence&.updated_at
    }
  else
    render json: {}, status: :unprocessable_entity
  end
end

#sweepObject

POST /dwc_occurrence/sweep (admin)



69
70
71
72
# File 'app/controllers/dwc_occurrences_controller.rb', line 69

def sweep
  DwcOccurrence.sweep
  redirect_to administration_data_health_task_path and return
end