class Sufia::ResourceSync::ResourceListWriter

TODO: the big assumption I'm making here is that the repository has fewer than 50,000 resources to list. The Sitemap protocol is limited at 50,000 items, so if we require more than that, we must have multiple Resource lists and add a Resource List Index to point to all of them.

Attributes

capability_list_url[R]
resource_host[R]

Public Class Methods

new(resource_host:, capability_list_url:) click to toggle source
# File lib/sufia/resource_sync/resource_list_writer.rb, line 10
def initialize(resource_host:, capability_list_url:)
  @resource_host = resource_host
  @capability_list_url = capability_list_url
end

Public Instance Methods

write() click to toggle source
# File lib/sufia/resource_sync/resource_list_writer.rb, line 15
def write
  builder.to_xml
end

Private Instance Methods

build_collections(xml) click to toggle source
# File lib/sufia/resource_sync/resource_list_writer.rb, line 34
def build_collections(xml)
  Collection.search_in_batches(public_access) do |doc_set|
    build_resources(xml, doc_set)
  end
end
build_files(xml) click to toggle source
# File lib/sufia/resource_sync/resource_list_writer.rb, line 46
def build_files(xml)
  FileSet.search_in_batches(public_access) do |doc_set|
    build_resources(xml, doc_set)
  end
end
build_resource(xml, doc) click to toggle source
# File lib/sufia/resource_sync/resource_list_writer.rb, line 58
def build_resource(xml, doc)
  xml.url do
    key = doc.fetch('has_model_ssim', []).first.constantize.model_name.singular_route_key
    xml.loc routes.send(key + "_url", doc['id'], host: resource_host)
    xml.lastmod doc['system_modified_dtsi']
  end
end
build_resources(xml, doc_set) click to toggle source
# File lib/sufia/resource_sync/resource_list_writer.rb, line 52
def build_resources(xml, doc_set)
  doc_set.each do |doc|
    build_resource(xml, doc)
  end
end
build_works(xml) click to toggle source
# File lib/sufia/resource_sync/resource_list_writer.rb, line 40
def build_works(xml)
  CurationConcerns::WorkRelation.new.search_in_batches(public_access) do |doc_set|
    build_resources(xml, doc_set)
  end
end
builder() click to toggle source
# File lib/sufia/resource_sync/resource_list_writer.rb, line 21
def builder
  Nokogiri::XML::Builder.new do |xml|
    xml.urlset('xmlns' => 'http://www.sitemaps.org/schemas/sitemap/0.9',
               'xmlns:rs' => 'http://www.openarchives.org/rs/terms/') do
      xml['rs'].ln(rel: "up", href: capability_list_url)
      xml['rs'].md(capability: "resourcelist", at: Time.now.utc.iso8601)
      build_collections(xml)
      build_works(xml)
      build_files(xml)
    end
  end
end
public_access() click to toggle source
# File lib/sufia/resource_sync/resource_list_writer.rb, line 72
def public_access
  { Hydra.config.permissions.read.group => 'public' }
end
routes() click to toggle source
# File lib/sufia/resource_sync/resource_list_writer.rb, line 66
def routes
  Rails.application.routes.url_helpers
end