Class: SupplejackApi::Harvester::RecordsController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/supplejack_api/harvester/records_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/supplejack_api/harvester/records_controller.rb', line 14

def create
  klass = params[:preview] ? SupplejackApi::PreviewRecord : SupplejackApi::Record
  @record = klass.find_or_initialize_by_identifier(params[:record])

  # In the long run this condition shouldn't be here.
  # It's because the data_handler interfaces are using update_from_harvest,
  # and clear_attributes that I can't factor it back in.
  if params[:record][:priority] && params[:record][:priority].to_i.nonzero?
    @record.create_or_update_fragment(params[:record])
  else
    @record.clear_attributes
    @record.update_from_harvest(params[:record])
  end

  @record.set_status(params[:required_fragments])
  @record.save
  @record.unset_null_fields
  render json: { record_id: @record.record_id }
end

#deleteObject



39
40
41
42
43
# File 'app/controllers/supplejack_api/harvester/records_controller.rb', line 39

def delete
  @record = Record.where(internal_identifier: params[:id]).first
  @record.update_attribute(:status, 'deleted') if @record.present?
  render nothing: true, status: 204
end

#flushObject



34
35
36
37
# File 'app/controllers/supplejack_api/harvester/records_controller.rb', line 34

def flush
  Resque.enqueue(FlushOldRecordsWorker, params[:source_id], params[:job_id])
  render nothing: true, status: 204
end

#showObject



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/controllers/supplejack_api/harvester/records_controller.rb', line 53

def show
  @record = Record.where(record_id: params[:id]).first

  if @record.present?
    render json: {
      record_id: @record.record_id,
      title: @record.title,
      status: @record.status
    }.to_json
  else
    render nothing: true, status: 204
  end
end

#updateObject



45
46
47
48
49
50
51
# File 'app/controllers/supplejack_api/harvester/records_controller.rb', line 45

def update
  @record = Record.custom_find(params[:id], nil, status: :all)
  if params[:record].present? && params[:record][:status].present?
    @record.update_attribute(:status, params[:record][:status])
  end
  respond_with @record
end