Class: BaseIndexer::Collection
- Inherits:
-
Object
- Object
- BaseIndexer::Collection
- Defined in:
- lib/base_indexer/collection.rb
Overview
It caches the collection information such as name
Class Method Summary collapse
-
.get_collection_name(collection_druid) ⇒ String
Returns the collection name from cache, otherwise will fetch it from PURL.
-
.get_from_cahce(collection_druid) ⇒ String
Return the collection label from cache if available, nil otherwise.
-
.get_from_purl(collection_druid) ⇒ String
Return the collection label from purl if available, nil otherwise.
Class Method Details
.get_collection_name(collection_druid) ⇒ String
Returns the collection name from cache, otherwise will fetch it from PURL.
11 12 13 14 15 16 17 18 |
# File 'lib/base_indexer/collection.rb', line 11 def self.get_collection_name(collection_druid) collection_name = get_from_cahce(collection_druid) if collection_name.nil? collection_name = get_from_purl(collection_druid) end collection_name end |
.get_from_cahce(collection_druid) ⇒ String
Return the collection label from cache if available, nil otherwise
22 23 24 |
# File 'lib/base_indexer/collection.rb', line 22 def self.get_from_cahce(collection_druid) Rails.cache.read(collection_druid) end |
.get_from_purl(collection_druid) ⇒ String
Return the collection label from purl if available, nil otherwise
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/base_indexer/collection.rb', line 28 def self.get_from_purl(collection_druid) begin purl_model =DiscoveryIndexer::InputXml::Purlxml.new(collection_druid).load() unless purl_model.nil? or purl_model.label.nil? or not(purl_model.is_collection) Rails.cache.write(collection_druid, purl_model.label, expires_in: 1.hours) purl_model.label end rescue => e Rails.logger.error "There is a problem in retrieving collection name for #{collection_druid}. #{e.inspect}\n#{e. }\n#{e.backtrace}" return nil end end |