Class: ArchivesSpaceOAIRepository

Inherits:
OAI::Provider::Model
  • Object
show all
Defined in:
backend/app/lib/oai/aspace_oai_repository.rb

Defined Under Namespace

Classes: FormatOptions

Constant Summary collapse

DELETES_PER_PAGE =
100
RESOLVE =
[
  'digital_object',
  'linked_agents',
  'repository',
  'resource',
  'subjects',
  'top_container',
  'top_container::container_profile'
] + AppConfig[:record_inheritance_resolves]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.available_record_typesObject



9
10
11
12
13
14
15
16
17
# File 'backend/app/lib/oai/aspace_oai_repository.rb', line 9

def self.available_record_types
  {
    'oai_dc' => FormatOptions.new([Resource, ArchivalObject], 25),
    'oai_dcterms' => FormatOptions.new([Resource, ArchivalObject], 25),
    'oai_marc' => FormatOptions.new([Resource, ArchivalObject], 25),
    'oai_mods' => FormatOptions.new([Resource, ArchivalObject], 25),
    'oai_ead' => FormatOptions.new([Resource], 1)
  }
end

.delete_lookupsObject

If a given record type supports deletes, we’ll need a way to look up its tombstone records. Since we only know the URIs of those tombstones, we’re pretty much stuck doing slow lookups.



32
33
34
35
36
37
# File 'backend/app/lib/oai/aspace_oai_repository.rb', line 32

def self.delete_lookups
  {
    Resource => Tombstone.where { Sequel.like(:uri, '%/resources/%') },
    ArchivalObject => Tombstone.where { Sequel.like(:uri, '%/archival_objects/%') },
  }
end

Instance Method Details

#earliestObject



52
53
54
# File 'backend/app/lib/oai/aspace_oai_repository.rb', line 52

def earliest
  Time.at(0).utc
end

#fetch_single_record(uri, options = {}) ⇒ Object

Raises:

  • (OAI::IdException)


108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'backend/app/lib/oai/aspace_oai_repository.rb', line 108

def fetch_single_record(uri, options = {})
  tombstone = Tombstone.filter(:uri => uri).first

  unless tombstone.nil?
    return OAIDeletion.new(tombstone)
  end

   = options.fetch(:metadata_prefix)

  format_options = options_for_type()
  parsed_ref = JSONModel.parse_reference(uri)

  raise OAI::IdException.new if parsed_ref.nil?

  model = format_options.record_types.find {|model| model.my_jsonmodel.record_type == parsed_ref.fetch(:type)}

  raise OAI::IdException.new unless model

  repo_uri = parsed_ref.fetch(:repository) { raise OAI::IdException.new }
  raise OAI::IdException.new if repo_uri.nil?

  repo_id = JSONModel.parse_reference(repo_uri).fetch(:id) { raise OAI::IdException.new }

  RequestContext.open(:repo_id => repo_id) do
    obj = add_visibility_restrictions(model.filter(:id => parsed_ref[:id])).first

    raise OAI::IdException.new unless obj

    ArchivesSpaceOAIRecord.new(obj, fetch_jsonmodels(model, [obj])[0])
  end
end

#find(selector, options = {}) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'backend/app/lib/oai/aspace_oai_repository.rb', line 140

def find(selector, options = {})
  if selector.is_a?(String)
    return fetch_single_record(selector, options)
  end

  resumption_token = if options.has_key?(:resumption_token)
                       ArchivesSpaceResumptionToken.parse(options.fetch(:resumption_token), ArchivesSpaceOAIRepository.available_record_types)
                     else
                       ArchivesSpaceResumptionToken.new(options, ArchivesSpaceOAIRepository.available_record_types)
                     end

  if resumption_token.state == ArchivesSpaceResumptionToken::PRODUCING_RECORDS_STATE
    records = produce_next_record_set(resumption_token, options)

    if records.is_a?(OAI::Provider::PartialResult) && records.records.empty?
      # We didn't match any records, but there might still be some deletes of interest...
      produce_next_delete_set(records.token, options)
    else
      records
    end
  elsif resumption_token.state == ArchivesSpaceResumptionToken::PRODUCING_DELETES_STATE
    produce_next_delete_set(resumption_token, options)
  else
    raise OAI::ResumptionTokenException.new
  end
end

#get_oai_config_valuesObject



19
20
21
22
23
24
25
26
27
# File 'backend/app/lib/oai/aspace_oai_repository.rb', line 19

def get_oai_config_values
  @oai_config          = OAIConfig.all.first
  @repo_set_codes      = @oai_config[:repo_set_codes] ? JSON.parse(@oai_config[:repo_set_codes]) : []
  @sponsor_set_names   = @oai_config[:sponsor_set_names] ? JSON.parse(@oai_config[:sponsor_set_names]) : []
  @repo_description    = @oai_config[:repo_set_description]
  @sponsor_description = @oai_config[:sponsor_set_description]
  @repo_set_name       = @oai_config[:repo_set_name]
  @sponsor_set_name    = @oai_config[:sponsor_set_name]
end

#latestObject



56
57
58
# File 'backend/app/lib/oai/aspace_oai_repository.rb', line 56

def latest
  Time.now.utc
end

#set_enabled?(set) ⇒ Boolean

returns true if set is enabled in at least one repository

Returns:

  • (Boolean)


92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'backend/app/lib/oai/aspace_oai_repository.rb', line 92

def set_enabled?(set)
  sets_in_repos = Repository.exclude(:publish => 0)
                            .exclude(:oai_is_disabled => 1)
                            .select(:oai_sets_available)
                            .map {|r| JSON::parse(r[:oai_sets_available]) rescue [] }

  # if oai_sets_available array is blank, then all sets are enabled for that repository.
  # if a repository is restricted to certain sets, then those set_ids will be in the oai_sets_available array.
  # So, we're looking to see if there is at least one repository with an empty set OR this set_id in the oai_sets_available array.
  set_id = BackendEnumSource.id_for_value("archival_record_level", set.name).to_s

  repos_enabling_set = sets_in_repos.select {|r| r.length == 0 || r.include?(set_id)}

  return repos_enabling_set.length > 0
end

#setsObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'backend/app/lib/oai/aspace_oai_repository.rb', line 60

def sets
  available_levels = BackendEnumSource.values_for("archival_record_level")
  get_oai_config_values

  # ANW-674:
  # Get set values from OAIConfig table instead of config file
  config_sets = []

  if @repo_set_codes.any? && !available_levels.include?(@repo_set_name)
    repo_oai_set = OAI::Set.new({:name => @repo_set_name,
                                 :spec => @repo_set_name,
                                 :description => build_set_description(@repo_description)})

    config_sets.push(repo_oai_set)
  end

  if @sponsor_set_names.any? && !available_levels.include?(@sponsor_set_name)
    repo_sponsor_set = OAI::Set.new({:name => @sponsor_set_name,
                                     :spec => @sponsor_set_name,
                                     :description => build_set_description(@sponsor_description)})

    config_sets.push(repo_sponsor_set)
  end

  level_sets = available_levels.map {|level|
    OAI::Set.new(:name => level, :spec => level)
  }

  config_sets + level_sets.select {|s| set_enabled?(s) }
end