Class: OAI::Provider::Response::ListMetadataFormats

Inherits:
RecordResponse show all
Defined in:
backend/app/lib/oai/oai_gem_patches/list_metadata_formats_response.rb

Instance Method Summary collapse

Methods inherited from RecordResponse

#requested_format

Methods inherited from Base

#parse_date

Instance Method Details

#to_xmlObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'backend/app/lib/oai/oai_gem_patches/list_metadata_formats_response.rb', line 4

def to_xml
  # Get a list of all the formats the provider understands.
  formats = provider.formats.values

  # if it's a doc-specific request
  if options.include?(:identifier)
    uri = extract_identifier(options[:identifier])

    jsonmodel_type = JSONModel.parse_reference(uri).fetch(:type) { raise OAI::IdException.new }

    # Only select formats where this type is supported
    formats.select! {|f|
      format = ArchivesSpaceOAIRepository.available_record_types.fetch(f.prefix)
      format.record_types.any? {|jsonmodel_clz|
        jsonmodel_clz.my_jsonmodel.record_type == jsonmodel_type
      }
    }
  end

  response do |r|
    r.ListMetadataFormats do
      formats.each do |format|
        r.metadataFormat do
          r.metadataPrefix format.prefix
          r.schema format.schema
          r.metadataNamespace format.namespace
        end
      end
    end
  end
end