Class: DwcOccurrencesController

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

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

#invalid_object, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form

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



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

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

#api_paramsObject (protected)



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/controllers/dwc_occurrences_controller.rb', line 64

def api_params
  params.permit(
    :user_date_end,
    :user_date_start,

    # TODO: not a major risk, but perhaps
    # these need `token` proxy
    # :user_id,
    # :user_target,

    dwc_occurrence_id: [],
    dwc_occurrence_object_id: [],
    dwc_occurrence_object_type: []
  )
end

#collector_id_metadataObject



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

def 
  render json: helpers.
end

#createObject

TODO: remove



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

def create
  respond_to do |format|
    format.html do
      @object.set_dwc_occurrence
      redirect_to browse_collection_objects_task_path(collection_object_id: @object.id)
    end
    format.json {
      render status: 302 and return
    }
  end
end

#filter_paramsObject (protected)



80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/controllers/dwc_occurrences_controller.rb', line 80

def filter_params
  params.permit(
    :user_date_end,
    :user_date_start,
    :user_id,
    :user_target,
    :dwc_occurrence_id,
    dwc_occurrence_id: [],
    dwc_occurrence_object_id: [],
    dwc_occurrence_object_type: []
  )
end

#indexObject

.json only



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

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

#metadataObject



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

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

#predicatesObject



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

def predicates
end

#set_objectObject (protected)



93
94
95
96
97
98
99
# File 'app/controllers/dwc_occurrences_controller.rb', line 93

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

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

#statusObject



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

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