Class: URIResolver::ASModelResolver

Inherits:
ResolverType show all
Defined in:
backend/app/lib/uri_resolver.rb

Overview

A resolver for all standard ArchivesSpace record types (accession, resource, archival_object, digital_object, etc.)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ ASModelResolver

Returns a new instance of ASModelResolver.



333
334
335
# File 'backend/app/lib/uri_resolver.rb', line 333

def initialize(model)
  @model = model
end

Class Method Details

.handler_for(jsonmodel_type) ⇒ Object



328
329
330
331
# File 'backend/app/lib/uri_resolver.rb', line 328

def self.handler_for(jsonmodel_type)
  model = find_model_by_jsonmodel_type(jsonmodel_type)
  new(model) if model
end

Instance Method Details

#record_exists?(uri) ⇒ Boolean

Returns:

  • (Boolean)


337
338
339
340
341
# File 'backend/app/lib/uri_resolver.rb', line 337

def record_exists?(uri)
  id = JSONModel.parse_reference(uri)[:id]

  id && !@model[id].nil?
end

#resolve(uris) ⇒ Object



343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
# File 'backend/app/lib/uri_resolver.rb', line 343

def resolve(uris)
  ids_by_repo = group_by_repo_id(uris)

  Enumerator.new do |yielder|
    ids_by_repo.each do |repo_id, parsed_repo_uris|
      ids = parsed_repo_uris.map {|parsed| parsed[:id]}

      # Set our active repo just in case any of the models rely on it
      RequestContext.open(:repo_id => repo_id) do
        @model.sequel_to_jsonmodel(@model.any_repo.filter(:id => ids).all).each do |json|
          yielder << [json.uri, json.to_hash(:trusted)]
        end
      end
    end
  end
end