Class: ImportRequest
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- ImportRequest
- Includes:
- Statesman::Adapters::ActiveRecordQueries
- Defined in:
- app/models/import_request.rb,
app/models2/import_request.rb
Instance Method Summary collapse
Instance Method Details
#check_imported ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'app/models/import_request.rb', line 28 def check_imported if isbn.present? identifier_type = IdentifierType.find_by_or_create!(name: 'isbn') if Identifier.find_by(body: isbn, identifier_type_id: identifier_type.id)&.manifestation errors.add(:isbn, I18n.t('import_request.isbn_taken')) end end end |
#check_isbn ⇒ Object
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
37 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 63 |
# File 'app/models/import_request.rb', line 37 def import! exceptions = [ ActiveRecord::RecordInvalid, NameError, URI::InvalidURIError ] not_found_exceptions = [] not_found_exceptions << EnjuNdl::RecordNotFound if defined? EnjuNdl not_found_exceptions << EnjuNii::RecordNotFound if defined? EnjuNii begin 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 end save rescue *not_found_exceptions => e transition_to!(:failed) return :record_not_found rescue *exceptions => e transition_to!(:failed) return :error end end |
#state_machine ⇒ Object
15 16 17 |
# File 'app/models/import_request.rb', line 15 def state_machine ImportRequestStateMachine.new(self, transition_class: ImportRequestTransition) end |