Class: METSModel

Inherits:
ASpaceExport::ExportModel show all
Includes:
JSONModel
Defined in:
backend/app/exporters/models/mets.rb

Constant Summary collapse

@@logical_div =
Struct.new(:label,
:dmdid,
:file_versions,
:children) do

Constants included from JSONModel

JSONModel::REFERENCE_KEY_REGEX

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from JSONModel

JSONModel, #JSONModel, add_error_handler, all, allow_unmapped_enum_value, backend_url, check_valid_refs, client_mode?, custom_validations, destroy_model, enum_default_value, enum_values, handle_error, init, load_schema, #models, models, parse_jsonmodel_ref, parse_reference, repository, repository_for, schema_src, set_publish_flags!, set_repository, strict_mode, strict_mode?, validate_schema, with_repository

Methods inherited from ASpaceExport::ExportModel

#apply_map, inherited, model_for, model_for?

Methods included from ASpaceExport::ExportModelHelpers

#extract_date_string, #extract_note_content, #get_subnotes_by_type

Constructor Details

#initialize(obj, tree) ⇒ METSModel

Returns a new instance of METSModel.



110
111
112
113
114
115
116
117
118
119
# File 'backend/app/exporters/models/mets.rb', line 110

def initialize(obj, tree)
  @json = obj
  @tree = tree
  @wrapped_dmd = []
  @extents = []
  @notes = []
  @subjects = []
  @names = []
  @parts = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth) ⇒ Object



183
184
185
186
187
188
189
# File 'backend/app/exporters/models/mets.rb', line 183

def method_missing(meth)
  if @json.respond_to?(meth)
    @json.send(meth)
  else
    nil
  end
end

Instance Attribute Details

#dc_modelObject

Returns the value of attribute dc_model



12
13
14
# File 'backend/app/exporters/models/mets.rb', line 12

def dc_model
  @dc_model
end

#dmd_idObject

Returns the value of attribute dmd_id



21
22
23
# File 'backend/app/exporters/models/mets.rb', line 21

def dmd_id
  @dmd_id
end

#extentsObject

Returns the value of attribute extents



15
16
17
# File 'backend/app/exporters/models/mets.rb', line 15

def extents
  @extents
end

#header_agent_nameObject

Returns the value of attribute header_agent_name



6
7
8
# File 'backend/app/exporters/models/mets.rb', line 6

def header_agent_name
  @header_agent_name
end

#header_agent_notesObject

Returns the value of attribute header_agent_notes



7
8
9
# File 'backend/app/exporters/models/mets.rb', line 7

def header_agent_notes
  @header_agent_notes
end

#header_agent_roleObject

Returns the value of attribute header_agent_role



8
9
10
# File 'backend/app/exporters/models/mets.rb', line 8

def header_agent_role
  @header_agent_role
end

#header_agent_typeObject

Returns the value of attribute header_agent_type



9
10
11
# File 'backend/app/exporters/models/mets.rb', line 9

def header_agent_type
  @header_agent_type
end

#mods_modelObject

Returns the value of attribute mods_model



11
12
13
# File 'backend/app/exporters/models/mets.rb', line 11

def mods_model
  @mods_model
end

#namesObject

Returns the value of attribute names



18
19
20
# File 'backend/app/exporters/models/mets.rb', line 18

def names
  @names
end

#notesObject

Returns the value of attribute notes



16
17
18
# File 'backend/app/exporters/models/mets.rb', line 16

def notes
  @notes
end

#partsObject

Returns the value of attribute parts



20
21
22
# File 'backend/app/exporters/models/mets.rb', line 20

def parts
  @parts
end

#subjectsObject

Returns the value of attribute subjects



17
18
19
# File 'backend/app/exporters/models/mets.rb', line 17

def subjects
  @subjects
end

#type_of_resourceObject

Returns the value of attribute type_of_resource



19
20
21
# File 'backend/app/exporters/models/mets.rb', line 19

def type_of_resource
  @type_of_resource
end

#wrapped_dmdObject

Returns the value of attribute wrapped_dmd



13
14
15
# File 'backend/app/exporters/models/mets.rb', line 13

def wrapped_dmd
  @wrapped_dmd
end

Class Method Details

.from_archival_object(obj, tree) ⇒ Object



143
144
145
146
147
# File 'backend/app/exporters/models/mets.rb', line 143

def self.from_archival_object(obj, tree)
  mets = self.from_aspace_object(obj, tree)
  mets.apply_map(obj, @archival_object_map)
  mets
end

.from_aspace_object(obj, tree) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'backend/app/exporters/models/mets.rb', line 127

def self.from_aspace_object(obj, tree)
  mets = self.new(obj, tree)

  if obj.respond_to?(:repo_id)
    repo_id = RequestContext.get(:repo_id)
    mets.apply_map(Repository.get_or_die(repo_id), @repository_map)
    mets.header_agent_role = "CREATOR"
    mets.header_agent_type = "ORGANIZATION"
  end

  mets.add_agent_note("Produced by ArchivesSpace")

  mets
end

.from_digital_object(obj, tree) ⇒ Object



150
151
152
153
154
155
156
157
158
159
# File 'backend/app/exporters/models/mets.rb', line 150

def self.from_digital_object(obj, tree)
  mets = self.from_archival_object(obj, tree)
  mets.type_of_resource = obj.digital_object_type
  mets.apply_map(obj, @digital_object_map)

  # wrapped DMD
  mets.mods_model = ASpaceExport.model(:mods).from_digital_object(obj, :ignore => [:tree])
  mets.dc_model = ASpaceExport.model(:dc).from_digital_object(obj)
  mets
end

.get_file_group(*args) ⇒ Object



122
123
124
# File 'backend/app/exporters/models/mets.rb', line 122

def self.get_file_group(*args)
  @file_group.new(*args)
end

.name_part_type_mapObject



167
168
169
# File 'backend/app/exporters/models/mets.rb', line 167

def self.name_part_type_map
  @name_part_type_map
end

.name_type_mapObject



162
163
164
# File 'backend/app/exporters/models/mets.rb', line 162

def self.name_type_map
  @name_type_map
end

Instance Method Details

#add_agent_note(val) ⇒ Object



172
173
174
175
# File 'backend/app/exporters/models/mets.rb', line 172

def add_agent_note(val)
  @header_agent_notes ||= []
  @header_agent_notes << val
end

#childrenObject



192
193
194
195
196
197
198
199
200
# File 'backend/app/exporters/models/mets.rb', line 192

def children
  return nil unless @tree['children']

  ao_class = self.class.instance_variable_get(:@doc)

  children = @tree['children'].map { |subtree| ao_class.new(subtree) }

  children
end

#dmd_wrap(mdtype, callback, data) ⇒ Object



178
179
180
# File 'backend/app/exporters/models/mets.rb', line 178

def dmd_wrap(mdtype, callback, data)
  self.wrapped_dmd << {'type' => mdtype, 'callback' => callback, 'data' => data}
end

#extract_file_versions(children) ⇒ Object



278
279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'backend/app/exporters/models/mets.rb', line 278

def extract_file_versions(children)
  file_versions = []

  children.each do |child|
    if child['file_versions']
      file_versions += child['file_versions']
    end
    if child['children']
      file_versions += extract_file_versions(child['children'])
    end
  end

  file_versions
end

#root_logical_divObject



260
261
262
263
264
265
266
# File 'backend/app/exporters/models/mets.rb', line 260

def root_logical_div
  @@logical_div.init
  @@logical_div.new(@json.title,
                    @json.id,
                    @json.file_versions,
                    @tree['children'])
end

#root_physical_divObject



269
270
271
272
273
274
275
# File 'backend/app/exporters/models/mets.rb', line 269

def root_physical_div
  @@logical_div.init
  @@logical_div.new(@json.title,
                    @json.id,
                    @json.file_versions,
                    @tree['children'])
end

#with_file_groupsObject



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'backend/app/exporters/models/mets.rb', line 203

def with_file_groups
  file_versions = @json.file_versions
  file_versions.each do |fv|
    fv['digital_object_id'] = @json.id
  end
  file_versions += extract_file_versions(@tree['children'])
  file_versions.compact!

  while file_versions.length > 0
    use_statement = file_versions[0]['use_statement']
    use_group = file_versions.select {|fv| fv['use_statement'] == use_statement }
    yield self.class.get_file_group(use_statement, use_group)

    file_versions.reject! {|fv| fv['use_statement'] == use_statement }
  end
end