Class: JournalTocsAdapter
- Inherits:
-
Service
- Object
- Service
- JournalTocsAdapter
- Defined in:
- app/service_adaptors/journal_tocs_adapter.rb
Class Method Summary collapse
-
.suitable_citation?(request) ⇒ Boolean
A class-method because we use it standalone in our resolve section visbility logic.
Instance Method Summary collapse
- #handle(request) ⇒ Object
-
#initialize(config) ⇒ JournalTocsAdapter
constructor
A new instance of JournalTocsAdapter.
- #service_types_generated ⇒ Object
Constructor Details
#initialize(config) ⇒ JournalTocsAdapter
Returns a new instance of JournalTocsAdapter.
5 6 7 8 9 |
# File 'app/service_adaptors/journal_tocs_adapter.rb', line 5 def initialize(config) @bento_search_engine = 'umlaut_journal_tocs' @max_items = 40 super(config) end |
Class Method Details
.suitable_citation?(request) ⇒ Boolean
A class-method because we use it standalone in our resolve section visbility logic.
45 46 47 48 49 |
# File 'app/service_adaptors/journal_tocs_adapter.rb', line 45 def self.suitable_citation?(request) # We do nothing for article-level, only journal-level # We can do nothing without ISSN. request.title_level_citation? && request.referent.issn.present? end |
Instance Method Details
#handle(request) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/service_adaptors/journal_tocs_adapter.rb', line 16 def handle(request) unless self.class.suitable_citation?(request) return request.dispatched(self, true) end searcher = BentoSearch.get_engine(@bento_search_engine) bento_results = searcher.fetch_by_issn(request.referent.issn) bento_results.slice!(@max_items, bento_results.length) # We store JSON serialization of results in the display_text field # of a single ServiceResponse, hacky but okay. if bento_results.length > 0 request.add_service_response( :service=>self, :service_data => bento_results.dump_to_json, :service_type_value => :journal_tocs_bento ) end return request.dispatched(self, true) rescue BentoSearch::FetchError => e Rails.logger.error("JournalTocsAdapter: Could not fetch results: #{e}") return request.dispatched(self, false, e) end |
#service_types_generated ⇒ Object
12 13 14 |
# File 'app/service_adaptors/journal_tocs_adapter.rb', line 12 def service_types_generated return [ServiceTypeValue[:journal_tocs_bento]] end |