Class: ImportRequest

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Statesman::Adapters::ActiveRecordQueries
Defined in:
app/models/import_request.rb

Instance Method Summary collapse

Instance Method Details

#check_importedObject



28
29
30
31
32
33
34
35
36
# File 'app/models/import_request.rb', line 28

def check_imported
  if isbn.present?
    identifier_type = IdentifierType.where(name: 'isbn').first
    identifier_type = IdentifierType.where(name: 'isbn').create! unless identifier_type
    if Identifier.where(body: isbn, identifier_type_id: identifier_type.id).first.try(:manifestation)
      errors.add(:isbn, I18n.t('import_request.isbn_taken'))
    end
  end
end

#check_isbnObject



22
23
24
25
26
# File 'app/models/import_request.rb', line 22

def check_isbn
  if isbn.present?
    errors.add(:isbn) unless StdNum::ISBN.valid?(isbn)
  end
end

#import!Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/models/import_request.rb', line 38

def import!
  return nil unless Manifestation.respond_to?(:import_isbn)
  unless manifestation
    manifestation = Manifestation.import_isbn(isbn)
    if manifestation
      self.manifestation = manifestation
      transition_to!(:completed)
      manifestation.index
      Sunspot.commit
    else
      transition_to!(:failed)
    end
  #else
  #  transition_to!(:failed)
  end
  save
rescue ActiveRecord::RecordInvalid
  transition_to!(:failed)
rescue NameError
  transition_to!(:failed)
rescue EnjuNdl::RecordNotFound
  transition_to!(:failed)
rescue EnjuNii::RecordNotFound
  transition_to!(:failed)
end

#state_machineObject



15
16
17
# File 'app/models/import_request.rb', line 15

def state_machine
  ImportRequestStateMachine.new(self, transition_class: ImportRequestTransition)
end